ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.5
Committed: Tue Dec 7 09:48:47 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.4: +1 -30 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/bin/sh
2
3 #############################################################################
4 # configuration to fill in
5
6 PERLVER=5.12.2 # 5.8.9 is also a good choice
7 STATICPERL=~/.staticperl
8 CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use
9 EMAIL="read the documentation <rtfm@example.org>"
10
11 MKBUNDLE="$STATICPERL/mkbundle"
12
13 # perl build variables
14 PREFIX="$STATICPERL/perl" # where the perl gets installed
15 PERL_CONFIGURE="" # additional Configure arguments
16 PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP"
17 PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
18
19 ARCH="$(uname -m)"
20
21 case "$ARCH" in
22 i*86 | x86_64 | amd64 )
23 PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64
24 case "$ARCH" in
25 i*86 )
26 PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only
27 ;;
28 esac
29 ;;
30 esac
31
32 # -Wl,--gc-sections makes it impossible to check for undefined references
33 # for some reason so we need to patch away the "-no" after Configure and before make :/
34 # -z muldefs is to work around uclibc's pthread static linking bug
35 PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs"
36 PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
37
38 # some configuration options for modules
39 export PERL_MM_USE_DEFAULT=1
40 #export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
41 export EV_EXTRA_DEFS='-DEV_FEATURES=4+8+16+64 -DEV_USE_SELECT=0 -DEV_USE_POLL=1 -DEV_USE_EPOLL=1 -DEV_NO_LOOPS -DEV_COMPAT3=0'
42
43 # which extra modules to install by default from CPAN that are
44 # required by mkbundle
45 STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage"
46
47 # which extra modules you might want to install
48 EXTRA_MODULES=""
49
50 # overridable functions
51 postconfigure() { : ; }
52 postbuild() { : ; }
53 postinstall() { : ; }
54
55 # now source user config, if any
56 [ -r /etc/staticperlrc ] && . /etc/staticperlrc
57 [ -r ~/.staticperlrc ] && . ~/.staticperlrc
58 [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
59
60 #############################################################################
61 # support
62
63 # set version in a way that Makefile.PL can extract
64 VERSION=VERSION; eval \
65 $VERSION=0.1
66
67 BZ2=bz2
68 BZIP2=bzip2
69
70 fatal() {
71 printf -- "\nFATAL: %s\n\n" "$*" >&2
72 exit 1
73 }
74
75 verbose() {
76 printf -- "%s\n" "$*"
77 }
78
79 verblock() {
80 verbose
81 verbose "***"
82 while read line; do
83 verbose "*** $line"
84 done
85 verbose "***"
86 verbose
87 }
88
89 rcd() {
90 cd "$1" || fatal "$1: cannot enter"
91 }
92
93 trace() {
94 prefix="$1"; shift
95 # "$@" 2>&1 | while read line; do
96 # echo "$prefix: $line"
97 # done
98 "$@"
99 }
100
101 trap wait 0
102
103 #############################################################################
104 # clean
105
106 distclean() {
107 verblock <<EOF
108 deleting everything installed by this script
109 EOF
110
111 rm -rf "$STATICPERL"
112 }
113
114 #############################################################################
115 # download/configure/compile/install perl
116
117 clean() {
118 cd "$STATICPERL/src/perl-$PERLVER" 2>/dev/null || return
119
120 rm -f staticstamp.configure
121 make distclean >/dev/null 2>&1
122 }
123
124 fetch() {
125 rcd "$STATICPERL"
126
127 mkdir -p src
128 rcd src
129
130 if ! [ -d "perl-$PERLVER" ]; then
131 if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then
132
133 URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2"
134
135 verblock <<EOF
136 downloading perl
137 to manually download perl yourself, place
138 perl-$PERLVER.tar.$BZ2 in $STATICPERL
139 trying $URL
140 EOF
141
142 curl >perl-$PERLVER.tar.$BZ2~ "$URL" \
143 || wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \
144 || fatal "$URL: unable to download"
145 mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2
146 fi
147
148 verblock <<EOF
149 unpacking perl
150 EOF
151
152 mkdir -p unpack
153 $BZIP2 -d <perl-$PERLVER.tar.bz2 | tar xpC unpack \
154 || fatal "perl-$PERLVER.tar.bz2: error during unpacking"
155 mv unpack/perl-$PERLVER perl-$PERLVER
156 rmdir -p unpack
157 fi
158 }
159
160 # similar to GNU-sed -i or perl -pi
161 sedreplace() {
162 sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
163 mv "$2~" "$2"
164 }
165
166 configure() {
167 fetch
168
169 rcd "$STATICPERL/src/perl-$PERLVER"
170
171 [ -e staticstamp.configure ] && return
172
173 verblock <<EOF
174 configuring $STATICPERL/src/perl-$PERLVER
175 EOF
176
177 clean
178
179 rm -f "$PREFIX/staticstamp.install"
180
181 # I hate them
182 grep -q -- -fstack-protector Configure && \
183 sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
184
185 # trace configure \
186 sh Configure -Duselargefiles \
187 -Uuse64bitint \
188 -Dusemymalloc=n \
189 -Uusedl \
190 -Uusethreads \
191 -Uuseithreads \
192 -Uusemultiplicity \
193 -Duseperlio \
194 -Uusesfio \
195 -Uuseshrplib \
196 -Dcppflags="$PERL_CPPFLAGS" \
197 -Dccflags="-g2 -fno-strict-aliasing" \
198 -Doptimize="$PERL_OPTIMIZE" \
199 -Dldflags="$PERL_LDFLAGS" \
200 -Dlibs="$PERL_LIBS" \
201 -Dprefix="$PREFIX" \
202 -Dbin="$PREFIX/bin" \
203 -Dprivlib="$PREFIX/lib" \
204 -Darchlib="$PREFIX/lib" \
205 -Uusevendorprefix \
206 -Dsitelib="$PREFIX/lib" \
207 -Dsitearch="$PREFIX/lib" \
208 -Usitelibexp \
209 -Uman1dir \
210 -Uman3dir \
211 -Usiteman1dir \
212 -Usiteman3dir \
213 -Dpager=/usr/bin/less \
214 -Demail="$EMAIL" \
215 -Dcf_email="$EMAIL" \
216 -Dcf_by="$EMAIL" \
217 $PERL_CONFIGURE \
218 -dE || fatal "Configure failed"
219
220 sedreplace '
221 s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
222 s/ *-fno-stack-protector */ /g
223 ' config.sh
224
225 sh Configure -S || fatal "Configure -S failed"
226
227 postconfigure || fatal "postconfigure hook failed"
228
229 touch staticstamp.configure
230 }
231
232 build() {
233 configure
234
235 rcd "$STATICPERL/src/perl-$PERLVER"
236
237 verblock <<EOF
238 building $STATICPERL/src/perl-$PERLVER
239 EOF
240
241 rm -f "$PREFIX/staticstamp.install"
242
243 make || fatal "make: error while building perl"
244
245 postbuild || fatal "postbuild hook failed"
246 }
247
248 install() {
249 [ -e "$PREFIX/staticstamp.install" ] && return
250
251 build
252
253 verblock <<EOF
254 installing $STATICPERL/src/perl-$PERLVER
255 to $PREFIX
256 EOF
257
258 rm -rf "$PREFIX"
259
260 make install || fatal "make install: error while installing"
261
262 rcd "$PREFIX"
263
264 # create a "make install" replacement for CPAN
265 cat >"$PREFIX"/bin/cpan-make-install <<EOF
266 make install UNINST=1
267 if find blib/arch/auto -type f | grep -q -v .exists; then
268 echo Probably an XS module, rebuilding perl
269 make perl
270 rm -f "$PREFIX"/bin/perl
271 make -f Makefile.aperl inst_perl
272 make -f Makefile.aperl map_clean
273 fi
274 EOF
275 chmod 755 "$PREFIX"/bin/cpan-make-install
276
277 # trick CPAN into avoiding ~/.cpan completely
278 echo 1 >"$PREFIX/lib/CPAN/MyConfig.pm"
279
280 "$PREFIX"/bin/perl -MCPAN -e '
281 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
282 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
283 CPAN::Shell->o (conf => q<init>);
284 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
285 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
286 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
287 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
288 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
289 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PREFIX"'/bin/cpan-make-install");
290 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
291 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
292 CPAN::Shell->o (conf => q<commit>);
293 ' || fatal "error while initialising CPAN"
294
295 NOCHECK_INSTALL=+
296 instcpan $STATICPERL_MODULES
297 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
298
299 postinstall || fatal "postinstall hook failed"
300
301 touch "$PREFIX/staticstamp.install"
302 }
303
304 #############################################################################
305 # install a module from CPAN
306
307 instcpan() {
308 [ $NOCHECK_INSTALL ] || install
309
310 verblock <<EOF
311 installing modules from CPAN
312 $@
313 EOF
314
315 for mod in "$@"; do
316 "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
317 || fatal "$mod: unable to install from CPAN"
318 done
319 rm -rf "$STATICPERL/build"
320 }
321
322 #############################################################################
323 # install a module from unpacked sources
324
325 instsrc() {
326 [ $NOCHECK_INSTALL ] || install
327
328 verblock <<EOF
329 installing modules from source
330 $@
331 EOF
332
333 for mod in "$@"; do
334 echo
335 echo $mod
336 (
337 rcd $mod
338 make -f Makefile.aperl map_clean >/dev/null 2>&1
339 make distclean >/dev/null 2>&1
340 "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
341 make || fatal "$mod: error building module"
342 "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
343 make distclean >/dev/null 2>&1
344 exit 0
345 ) || exit $?
346 done
347 }
348
349 #############################################################################
350 # main
351
352 podusage() {
353 echo
354 if [ -e "$PREFIX/bin/perl" ]; then
355 "$PREFIX/bin/perl" -MPod::Usage -e \
356 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
357 2>/dev/null && exit
358 fi
359 # try whatever perl we can find
360 perl -MPod::Usage -e \
361 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
362 2>/dev/null && exit
363
364 fatal "displaying documentation requires a working perl - try '$0 install' first"
365 }
366
367 usage() {
368 podusage 0
369 }
370
371 catmkbundle() {
372 {
373 read dummy
374 echo "#!$PREFIX/bin/perl"
375 cat
376 } <<'MKBUNDLE'
377 #CAT mkbundle
378 MKBUNDLE
379 }
380
381 bundle() {
382 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
383 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
384 "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@"
385 }
386
387 if [ $# -gt 0 ]; then
388 while [ $# -gt 0 ]; do
389 mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
390 mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create"
391
392 command="${1#--}"; shift
393 case "$command" in
394 fetch | configure | build | install | clean | distclean)
395 verblock <<EOF
396 $command
397 EOF
398 "$command"
399 ;;
400 instsrc )
401 instsrc "$@"
402 exit
403 ;;
404 instcpan )
405 instcpan "$@"
406 exit
407 ;;
408 cpan )
409 install
410 "$PREFIX/bin/cpan" "$@"
411 exit
412 ;;
413 mkbundle )
414 install
415 bundle "$@"
416 exit
417 ;;
418 mkperl )
419 install
420 bundle --perl "$@"
421 exit
422 ;;
423 help )
424 podusage 2
425 ;;
426 * )
427 exec 1>&2
428 echo
429 echo "Unknown command: $command"
430 podusage 0
431 ;;
432 esac
433 done
434 else
435 usage
436 fi
437
438 exit 0
439
440 #CAT staticperl.pod
441