ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.22
Committed: Wed Dec 15 00:17:48 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-0_912
Changes since 1.21: +38 -14 lines
Log Message:
*** empty log message ***

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