ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.16
Committed: Sat Dec 11 15:51:38 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
CVS Tags: rel-0_911
Changes since 1.15: +3 -4 lines
Log Message:
0.911

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