ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.47
Committed: Mon Jun 27 21:56:41 2011 UTC (13 years ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.46: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/bin/sh
2    
3     #############################################################################
4 root 1.45 # configuration to fill in (or to replace in your .staticperlrc)
5 root 1.1
6     STATICPERL=~/.staticperl
7 root 1.14 CPAN=http://mirror.netcologne.de/cpan # which mirror to use
8 root 1.1 EMAIL="read the documentation <rtfm@example.org>"
9 root 1.45 DLCACHE=
10 root 1.1
11     # perl build variables
12 root 1.21 MAKE=make
13 root 1.29 PERL_VERSION=5.12.3 # 5.8.9 is also a good choice
14 root 1.19 PERL_CC=cc
15 root 1.4 PERL_CONFIGURE="" # additional Configure arguments
16 root 1.32 PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG"
17 root 1.31 PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
18 root 1.1
19     ARCH="$(uname -m)"
20    
21     case "$ARCH" in
22     i*86 | x86_64 | amd64 )
23 root 1.22 PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64
24 root 1.1 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 root 1.16 # --allow-multiple-definition exists to work around uclibc's pthread static linking bug
35 root 1.37 #PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition"
36     PERL_LDFLAGS=
37 root 1.1 PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
38    
39     # some configuration options for modules
40 root 1.24 PERL_MM_USE_DEFAULT=1
41 root 1.39 PERL_MM_OPT="MAN1PODS= MAN3PODS="
42 root 1.24 #CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
43 root 1.47 #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'
44     export PERL_MM_USE_DEFAULT PERL_MM_OPT
45 root 1.1
46     # which extra modules to install by default from CPAN that are
47     # required by mkbundle
48 root 1.2 STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage"
49    
50     # which extra modules you might want to install
51     EXTRA_MODULES=""
52 root 1.1
53     # overridable functions
54 root 1.7 preconfigure() { : ; }
55 root 1.37 patchconfig() { : ; }
56 root 1.1 postconfigure() { : ; }
57     postbuild() { : ; }
58     postinstall() { : ; }
59    
60     # now source user config, if any
61 root 1.14 if [ "$STATICPERLRC" ]; then
62     . "$STATICPERLRC"
63     else
64     [ -r /etc/staticperlrc ] && . /etc/staticperlrc
65     [ -r ~/.staticperlrc ] && . ~/.staticperlrc
66     [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc"
67     fi
68 root 1.1
69     #############################################################################
70     # support
71    
72 root 1.14 PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed
73    
74 root 1.38 unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG
75 root 1.39 unset PERL_MB_OPT
76 root 1.24 LC_ALL=C; export LC_ALL # just to be on the safe side
77 root 1.12
78 root 1.38 # prepend PATH - not required by staticperl itself, but might make
79     # life easier when working in e.g. "staticperl cpan / look"
80     PATH="$PERL_PREFIX/perl/bin:$PATH"
81    
82 root 1.1 # set version in a way that Makefile.PL can extract
83     VERSION=VERSION; eval \
84 root 1.44 $VERSION="1.31"
85 root 1.1
86     BZ2=bz2
87     BZIP2=bzip2
88    
89     fatal() {
90     printf -- "\nFATAL: %s\n\n" "$*" >&2
91     exit 1
92     }
93    
94     verbose() {
95     printf -- "%s\n" "$*"
96     }
97    
98     verblock() {
99     verbose
100     verbose "***"
101     while read line; do
102     verbose "*** $line"
103     done
104     verbose "***"
105     verbose
106     }
107    
108     rcd() {
109     cd "$1" || fatal "$1: cannot enter"
110     }
111    
112     trace() {
113     prefix="$1"; shift
114     # "$@" 2>&1 | while read line; do
115     # echo "$prefix: $line"
116     # done
117     "$@"
118     }
119    
120     trap wait 0
121    
122     #############################################################################
123     # clean
124    
125     distclean() {
126     verblock <<EOF
127 root 1.14 deleting everything installed by this script (rm -rf $STATICPERL)
128 root 1.1 EOF
129    
130     rm -rf "$STATICPERL"
131     }
132    
133     #############################################################################
134     # download/configure/compile/install perl
135    
136     clean() {
137 root 1.7 rm -rf "$STATICPERL/src/perl-$PERL_VERSION"
138 root 1.1 }
139    
140 root 1.23 realclean() {
141     rm -f "$PERL_PREFIX/staticstamp.postinstall"
142     rm -f "$PERL_PREFIX/staticstamp.install"
143     rm -f "$STATICPERL/src/perl-"*"/staticstamp.configure"
144     }
145    
146 root 1.1 fetch() {
147     rcd "$STATICPERL"
148    
149     mkdir -p src
150     rcd src
151    
152 root 1.6 if ! [ -d "perl-$PERL_VERSION" ]; then
153 root 1.45 PERLTAR=perl-$PERL_VERSION.tar.$BZ2
154 root 1.1
155 root 1.45 if ! [ -e $PERLTAR ]; then
156     URL="$CPAN/src/5.0/$PERLTAR"
157 root 1.1
158     verblock <<EOF
159     downloading perl
160     to manually download perl yourself, place
161 root 1.6 perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
162 root 1.1 trying $URL
163 root 1.42
164     either curl or wget is required for automatic download.
165     curl is tried first, then wget.
166 root 1.45
167     you can configure a download cache directory via DLCACHE
168     in your .staticperlrc to avoid repeated downloads.
169 root 1.1 EOF
170    
171 root 1.45 rm -f $PERLTAR~ # just to be on the safe side
172 root 1.46 { [ "$DLCACHE" ] && cp "$DLCACHE"/$PERLTAR $PERLTAR~; } \
173 root 1.45 || wget -O $PERLTAR~ "$URL" \
174     || curl -f >$PERLTAR~ "$URL" \
175 root 1.5 || fatal "$URL: unable to download"
176 root 1.45 rm -f $PERLTAR
177     mv $PERLTAR~ $PERLTAR
178     if [ "$DLCACHE" ]; then
179     mkdir -p "$DLCACHE"
180 root 1.46 cp $PERLTAR "$DLCACHE"/$PERLTAR~ && \
181 root 1.45 mv "$DLCACHE"/$PERLTAR~ "$DLCACHE"/$PERLTAR
182     fi
183 root 1.1 fi
184    
185     verblock <<EOF
186     unpacking perl
187     EOF
188    
189     mkdir -p unpack
190 root 1.20 rm -rf unpack/perl-$PERL_VERSION
191 root 1.45 $BZIP2 -d <$PERLTAR | ( cd unpack && tar xf - ) \
192     || fatal "$PERLTAR: error during unpacking"
193 root 1.8 chmod -R u+w unpack/perl-$PERL_VERSION
194 root 1.6 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
195 root 1.1 rmdir -p unpack
196     fi
197     }
198    
199     # similar to GNU-sed -i or perl -pi
200     sedreplace() {
201     sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
202 root 1.20 rm -f "$2"
203 root 1.1 mv "$2~" "$2"
204     }
205    
206 root 1.22 configure_failure() {
207     cat <<EOF
208    
209    
210     ***
211     *** Configure failed - see above for the exact error message(s).
212     ***
213     *** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE
214     *** flags are not supported by your compiler. Less often, this is because
215     *** PERL_LIBS either contains a library not available on your system (such as
216     *** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl).
217     ***
218     *** You can provide your own flags by creating a ~/.staticperlrc file with
219     *** variable assignments. For example (these are the actual values used):
220     ***
221    
222     PERL_CC="$PERL_CC"
223     PERL_CCFLAGS="$PERL_CCFLAGS"
224     PERL_OPTIMIZE="$PERL_OPTIMIZE"
225     PERL_LDFLAGS="$PERL_LDFLAGS"
226     PERL_LIBS="$PERL_LIBS"
227    
228     EOF
229     exit 1
230     }
231    
232 root 1.1 configure() {
233     fetch
234    
235 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
236 root 1.1
237     [ -e staticstamp.configure ] && return
238    
239     verblock <<EOF
240 root 1.6 configuring $STATICPERL/src/perl-$PERL_VERSION
241 root 1.1 EOF
242    
243 root 1.8 rm -f "$PERL_PREFIX/staticstamp.install"
244 root 1.1
245 root 1.21 "$MAKE" distclean >/dev/null 2>&1
246 root 1.1
247 root 1.23 sedreplace '/^#define SITELIB/d' config_h.SH
248    
249     # I hate them for this
250 root 1.1 grep -q -- -fstack-protector Configure && \
251     sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
252    
253 root 1.37 # what did that bloke think
254     grep -q -- usedl=.define hints/darwin.sh && \
255     sedreplace '/^usedl=.define.;$/d' hints/darwin.sh
256    
257     preconfigure || fatal "preconfigure hook failed"
258 root 1.7
259 root 1.1 # trace configure \
260     sh Configure -Duselargefiles \
261     -Uuse64bitint \
262     -Dusemymalloc=n \
263     -Uusedl \
264     -Uusethreads \
265     -Uuseithreads \
266     -Uusemultiplicity \
267     -Uusesfio \
268     -Uuseshrplib \
269 root 1.26 -Uinstallusrbinperl \
270 root 1.22 -A ccflags=" $PERL_CCFLAGS" \
271 root 1.19 -Dcc="$PERL_CC" \
272 root 1.1 -Doptimize="$PERL_OPTIMIZE" \
273     -Dldflags="$PERL_LDFLAGS" \
274     -Dlibs="$PERL_LIBS" \
275 root 1.6 -Dprefix="$PERL_PREFIX" \
276     -Dbin="$PERL_PREFIX/bin" \
277     -Dprivlib="$PERL_PREFIX/lib" \
278     -Darchlib="$PERL_PREFIX/lib" \
279 root 1.1 -Uusevendorprefix \
280 root 1.6 -Dsitelib="$PERL_PREFIX/lib" \
281     -Dsitearch="$PERL_PREFIX/lib" \
282 root 1.1 -Uman1dir \
283     -Uman3dir \
284     -Usiteman1dir \
285     -Usiteman3dir \
286     -Dpager=/usr/bin/less \
287     -Demail="$EMAIL" \
288     -Dcf_email="$EMAIL" \
289     -Dcf_by="$EMAIL" \
290 root 1.4 $PERL_CONFIGURE \
291 root 1.19 -Duseperlio \
292 root 1.22 -dE || configure_failure
293 root 1.1
294     sedreplace '
295     s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
296     s/ *-fno-stack-protector */ /g
297     ' config.sh
298    
299 root 1.37 patchconfig || fatal "patchconfig hook failed"
300    
301 root 1.1 sh Configure -S || fatal "Configure -S failed"
302    
303     postconfigure || fatal "postconfigure hook failed"
304    
305     touch staticstamp.configure
306     }
307    
308 root 1.39 write_shellscript() {
309     {
310     echo "#!/bin/sh"
311     echo "STATICPERL=\"$STATICPERL\""
312     echo "PERL_PREFIX=\"$PERL_PREFIX\""
313     echo "MAKE=\"$MAKE\""
314     cat
315     } >"$PERL_PREFIX/bin/$1"
316     chmod 755 "$PERL_PREFIX/bin/$1"
317     }
318    
319 root 1.1 build() {
320     configure
321    
322 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
323 root 1.1
324     verblock <<EOF
325 root 1.6 building $STATICPERL/src/perl-$PERL_VERSION
326 root 1.1 EOF
327    
328 root 1.6 rm -f "$PERL_PREFIX/staticstamp.install"
329 root 1.1
330 root 1.21 "$MAKE" || fatal "make: error while building perl"
331 root 1.1
332     postbuild || fatal "postbuild hook failed"
333     }
334    
335     install() {
336 root 1.9 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
337     build
338 root 1.1
339 root 1.9 verblock <<EOF
340 root 1.6 installing $STATICPERL/src/perl-$PERL_VERSION
341     to $PERL_PREFIX
342 root 1.1 EOF
343    
344 root 1.14 ln -sf "perl/bin/" "$STATICPERL/bin"
345     ln -sf "perl/lib/" "$STATICPERL/lib"
346    
347 root 1.39 mkdir "$STATICPERL/patched"
348    
349 root 1.14 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
350     rm -rf "$PERL_PREFIX" # by this rm -rf
351    
352 root 1.21 "$MAKE" install || fatal "make install: error while installing"
353 root 1.1
354 root 1.9 rcd "$PERL_PREFIX"
355 root 1.2
356 root 1.9 # create a "make install" replacement for CPAN
357 root 1.39 write_shellscript SP-make-install-make <<'EOF'
358     #CAT make-install-make.sh
359     EOF
360 root 1.10
361 root 1.39 # create a "patch modules" helper
362     write_shellscript SP-patch-postinstall <<'EOF'
363     #CAT patch-postinstall.sh
364     EOF
365 root 1.10
366 root 1.39 "$PERL_PREFIX/bin/SP-patch-postinstall"
367 root 1.9
368 root 1.39 # help to trick CPAN into avoiding ~/.cpan completely
369 root 1.9 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
370 root 1.1
371 root 1.39 # we call cpan with -MCPAN::MyConfig in this script, which
372     # is strictly unnecssary as we have to patch CPAN anyway,
373     # so consider it "for good measure".
374 root 1.36 "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e '
375 root 1.9 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
376     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
377     CPAN::Shell->o (conf => q<init>);
378     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
379     CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
380     CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
381     CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
382     CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
383 root 1.39 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/SP-make-install-make");
384 root 1.9 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
385     CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
386 root 1.36 CPAN::Shell->o (conf => q<prefer_installer>, "EUMM");
387 root 1.9 CPAN::Shell->o (conf => q<commit>);
388     ' || fatal "error while initialising CPAN"
389 root 1.2
390 root 1.9 touch "$PERL_PREFIX/staticstamp.install"
391     fi
392    
393 root 1.10 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
394 root 1.9 NOCHECK_INSTALL=+
395     instcpan $STATICPERL_MODULES
396     [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
397 root 1.1
398 root 1.9 postinstall || fatal "postinstall hook failed"
399 root 1.1
400 root 1.9 touch "$PERL_PREFIX/staticstamp.postinstall"
401     fi
402 root 1.1 }
403    
404     #############################################################################
405     # install a module from CPAN
406    
407     instcpan() {
408     [ $NOCHECK_INSTALL ] || install
409    
410     verblock <<EOF
411     installing modules from CPAN
412     $@
413     EOF
414    
415     for mod in "$@"; do
416 root 1.36 "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e 'notest install => "'"$mod"'"' \
417 root 1.1 || fatal "$mod: unable to install from CPAN"
418     done
419     rm -rf "$STATICPERL/build"
420     }
421    
422     #############################################################################
423     # install a module from unpacked sources
424    
425     instsrc() {
426     [ $NOCHECK_INSTALL ] || install
427    
428     verblock <<EOF
429     installing modules from source
430     $@
431     EOF
432    
433     for mod in "$@"; do
434     echo
435     echo $mod
436     (
437     rcd $mod
438 root 1.21 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
439     "$MAKE" distclean >/dev/null 2>&1
440 root 1.6 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
441 root 1.21 "$MAKE" || fatal "$mod: error building module"
442 root 1.39 "$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module"
443 root 1.21 "$MAKE" distclean >/dev/null 2>&1
444 root 1.1 exit 0
445     ) || exit $?
446     done
447     }
448    
449     #############################################################################
450     # main
451    
452     podusage() {
453     echo
454 root 1.17
455 root 1.6 if [ -e "$PERL_PREFIX/bin/perl" ]; then
456     "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
457 root 1.1 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
458     2>/dev/null && exit
459     fi
460 root 1.17
461 root 1.1 # try whatever perl we can find
462     perl -MPod::Usage -e \
463     'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
464     2>/dev/null && exit
465    
466 root 1.17 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
467 root 1.1 }
468    
469     usage() {
470     podusage 0
471     }
472    
473     catmkbundle() {
474     {
475     read dummy
476 root 1.6 echo "#!$PERL_PREFIX/bin/perl"
477 root 1.1 cat
478     } <<'MKBUNDLE'
479     #CAT mkbundle
480     MKBUNDLE
481     }
482    
483     bundle() {
484 root 1.39 MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}"
485 root 1.1 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
486     chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
487 root 1.12 CACHE="$STATICPERL/cache"
488     mkdir -p "$CACHE"
489     "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
490 root 1.1 }
491    
492     if [ $# -gt 0 ]; then
493     while [ $# -gt 0 ]; do
494     mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
495 root 1.6 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
496 root 1.1
497     command="${1#--}"; shift
498     case "$command" in
499 root 1.14 version )
500     echo "staticperl version $VERSION"
501     ;;
502 root 1.23 fetch | configure | build | install | clean | realclean | distclean)
503 root 1.22 ( "$command" ) || exit
504 root 1.1 ;;
505     instsrc )
506 root 1.22 ( instsrc "$@" ) || exit
507 root 1.1 exit
508     ;;
509     instcpan )
510 root 1.22 ( instcpan "$@" ) || exit
511 root 1.1 exit
512     ;;
513 root 1.39 perl )
514     ( install ) || exit
515     exec "$PERL_PREFIX/bin/perl" "$@"
516     exit
517     ;;
518 root 1.1 cpan )
519 root 1.22 ( install ) || exit
520 root 1.39 exec "$PERL_PREFIX/bin/cpan" "$@"
521 root 1.1 exit
522     ;;
523     mkbundle )
524 root 1.22 ( install ) || exit
525 root 1.40 bundle "$@"
526 root 1.1 exit
527     ;;
528     mkperl )
529 root 1.22 ( install ) || exit
530 root 1.40 bundle --perl "$@"
531 root 1.1 exit
532     ;;
533 root 1.11 mkapp )
534 root 1.22 ( install ) || exit
535 root 1.40 bundle --app "$@"
536 root 1.11 exit
537     ;;
538 root 1.1 help )
539     podusage 2
540     ;;
541     * )
542     exec 1>&2
543     echo
544     echo "Unknown command: $command"
545     podusage 0
546     ;;
547     esac
548     done
549     else
550     usage
551     fi
552    
553     exit 0
554    
555     #CAT staticperl.pod
556