ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
Revision: 1.37
Committed: Fri Mar 18 19:49:04 2011 UTC (13 years, 3 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-1_21
Changes since 1.36: +12 -4 lines
Log Message:
1.21

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