ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.36
Committed: Sun Mar 13 23:20:21 2011 UTC (13 years, 4 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-1_2
Changes since 1.35: +24 -3 lines
Log Message:
1.2

File Contents

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