ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/App-Staticperl/staticperl.sh
Revision: 1.19
Committed: Mon Dec 13 17:25:17 2010 UTC (13 years, 7 months ago) by root
Content type: application/x-sh
Branch: MAIN
Changes since 1.18: +3 -1 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.6 PERL_VERSION=5.12.2 # 5.8.9 is also a good choice
12 root 1.19 PERL_CC=cc
13 root 1.4 PERL_CONFIGURE="" # additional Configure arguments
14 root 1.1 PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP"
15     PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
16    
17     ARCH="$(uname -m)"
18    
19     case "$ARCH" in
20     i*86 | x86_64 | amd64 )
21 root 1.18 #PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64
22     PERL_OPTIMIZE="$PERL_OPTIMIZE" # 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.16 $VERSION=0.911
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.6 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2
154 root 1.1 fi
155    
156     verblock <<EOF
157     unpacking perl
158     EOF
159    
160     mkdir -p unpack
161 root 1.13 $BZIP2 -d <perl-$PERL_VERSION.tar.bz2 | tar xfC - unpack \
162 root 1.6 || fatal "perl-$PERL_VERSION.tar.bz2: error during unpacking"
163 root 1.8 chmod -R u+w unpack/perl-$PERL_VERSION
164 root 1.6 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
165 root 1.1 rmdir -p unpack
166     fi
167     }
168    
169     # similar to GNU-sed -i or perl -pi
170     sedreplace() {
171     sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
172     mv "$2~" "$2"
173     }
174    
175     configure() {
176     fetch
177    
178 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
179 root 1.1
180     [ -e staticstamp.configure ] && return
181    
182     verblock <<EOF
183 root 1.6 configuring $STATICPERL/src/perl-$PERL_VERSION
184 root 1.1 EOF
185    
186 root 1.8 rm -f "$PERL_PREFIX/staticstamp.install"
187 root 1.1
188 root 1.8 make distclean >/dev/null 2>&1
189 root 1.1
190     # I hate them
191     grep -q -- -fstack-protector Configure && \
192     sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure
193    
194 root 1.7 preconfigure
195    
196 root 1.1 # trace configure \
197     sh Configure -Duselargefiles \
198     -Uuse64bitint \
199     -Dusemymalloc=n \
200     -Uusedl \
201     -Uusethreads \
202     -Uuseithreads \
203     -Uusemultiplicity \
204     -Uusesfio \
205     -Uuseshrplib \
206 root 1.19 -Dcc="$PERL_CC" \
207 root 1.1 -Dcppflags="$PERL_CPPFLAGS" \
208     -Dccflags="-g2 -fno-strict-aliasing" \
209     -Doptimize="$PERL_OPTIMIZE" \
210     -Dldflags="$PERL_LDFLAGS" \
211     -Dlibs="$PERL_LIBS" \
212 root 1.6 -Dprefix="$PERL_PREFIX" \
213     -Dbin="$PERL_PREFIX/bin" \
214     -Dprivlib="$PERL_PREFIX/lib" \
215     -Darchlib="$PERL_PREFIX/lib" \
216 root 1.1 -Uusevendorprefix \
217 root 1.6 -Dsitelib="$PERL_PREFIX/lib" \
218     -Dsitearch="$PERL_PREFIX/lib" \
219 root 1.1 -Usitelibexp \
220     -Uman1dir \
221     -Uman3dir \
222     -Usiteman1dir \
223     -Usiteman3dir \
224     -Dpager=/usr/bin/less \
225     -Demail="$EMAIL" \
226     -Dcf_email="$EMAIL" \
227     -Dcf_by="$EMAIL" \
228 root 1.4 $PERL_CONFIGURE \
229 root 1.19 -Duseperlio \
230 root 1.1 -dE || fatal "Configure failed"
231    
232     sedreplace '
233     s/-Wl,--no-gc-sections/-Wl,--gc-sections/g
234     s/ *-fno-stack-protector */ /g
235     ' config.sh
236    
237     sh Configure -S || fatal "Configure -S failed"
238    
239     postconfigure || fatal "postconfigure hook failed"
240    
241     touch staticstamp.configure
242     }
243    
244     build() {
245     configure
246    
247 root 1.6 rcd "$STATICPERL/src/perl-$PERL_VERSION"
248 root 1.1
249     verblock <<EOF
250 root 1.6 building $STATICPERL/src/perl-$PERL_VERSION
251 root 1.1 EOF
252    
253 root 1.6 rm -f "$PERL_PREFIX/staticstamp.install"
254 root 1.1
255     make || fatal "make: error while building perl"
256    
257     postbuild || fatal "postbuild hook failed"
258     }
259    
260     install() {
261 root 1.9 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
262     build
263 root 1.1
264 root 1.9 verblock <<EOF
265 root 1.6 installing $STATICPERL/src/perl-$PERL_VERSION
266     to $PERL_PREFIX
267 root 1.1 EOF
268    
269 root 1.14 ln -sf "perl/bin/" "$STATICPERL/bin"
270     ln -sf "perl/lib/" "$STATICPERL/lib"
271    
272     ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
273     rm -rf "$PERL_PREFIX" # by this rm -rf
274    
275 root 1.9 make install || fatal "make install: error while installing"
276 root 1.1
277 root 1.9 rcd "$PERL_PREFIX"
278 root 1.2
279 root 1.9 # create a "make install" replacement for CPAN
280     cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF
281 root 1.10 make || exit
282    
283 root 1.1 if find blib/arch/auto -type f | grep -q -v .exists; then
284     echo Probably an XS module, rebuilding perl
285 root 1.10 if make perl; then
286     mv perl "$PERL_PREFIX"/bin/perl
287     make -f Makefile.aperl map_clean
288     else
289     make -f Makefile.aperl map_clean
290     exit 1
291     fi
292 root 1.1 fi
293 root 1.10
294     make install UNINST=1
295 root 1.1 EOF
296 root 1.9 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
297    
298     # trick CPAN into avoiding ~/.cpan completely
299     echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
300 root 1.1
301 root 1.9 "$PERL_PREFIX"/bin/perl -MCPAN -e '
302     CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
303     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
304     CPAN::Shell->o (conf => q<init>);
305     CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
306     CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
307     CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
308     CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
309     CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
310     CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install");
311     CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
312     CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
313     CPAN::Shell->o (conf => q<commit>);
314     ' || fatal "error while initialising CPAN"
315 root 1.2
316 root 1.9 touch "$PERL_PREFIX/staticstamp.install"
317     fi
318    
319 root 1.10 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
320 root 1.9 NOCHECK_INSTALL=+
321     instcpan $STATICPERL_MODULES
322     [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
323 root 1.1
324 root 1.9 postinstall || fatal "postinstall hook failed"
325 root 1.1
326 root 1.9 touch "$PERL_PREFIX/staticstamp.postinstall"
327     fi
328 root 1.1 }
329    
330     #############################################################################
331     # install a module from CPAN
332    
333     instcpan() {
334     [ $NOCHECK_INSTALL ] || install
335    
336     verblock <<EOF
337     installing modules from CPAN
338     $@
339     EOF
340    
341     for mod in "$@"; do
342 root 1.6 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \
343 root 1.1 || fatal "$mod: unable to install from CPAN"
344     done
345     rm -rf "$STATICPERL/build"
346     }
347    
348     #############################################################################
349     # install a module from unpacked sources
350    
351     instsrc() {
352     [ $NOCHECK_INSTALL ] || install
353    
354     verblock <<EOF
355     installing modules from source
356     $@
357     EOF
358    
359     for mod in "$@"; do
360     echo
361     echo $mod
362     (
363     rcd $mod
364     make -f Makefile.aperl map_clean >/dev/null 2>&1
365     make distclean >/dev/null 2>&1
366 root 1.6 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
367 root 1.1 make || fatal "$mod: error building module"
368 root 1.6 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module"
369 root 1.1 make distclean >/dev/null 2>&1
370     exit 0
371     ) || exit $?
372     done
373     }
374    
375     #############################################################################
376     # main
377    
378     podusage() {
379     echo
380 root 1.17
381 root 1.6 if [ -e "$PERL_PREFIX/bin/perl" ]; then
382     "$PERL_PREFIX/bin/perl" -MPod::Usage -e \
383 root 1.1 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
384     2>/dev/null && exit
385     fi
386 root 1.17
387 root 1.1 # try whatever perl we can find
388     perl -MPod::Usage -e \
389     'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \
390     2>/dev/null && exit
391    
392 root 1.17 fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location"
393 root 1.1 }
394    
395     usage() {
396     podusage 0
397     }
398    
399     catmkbundle() {
400     {
401     read dummy
402 root 1.6 echo "#!$PERL_PREFIX/bin/perl"
403 root 1.1 cat
404     } <<'MKBUNDLE'
405     #CAT mkbundle
406     MKBUNDLE
407     }
408    
409     bundle() {
410     catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
411     chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
412 root 1.12 CACHE="$STATICPERL/cache"
413     mkdir -p "$CACHE"
414     "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
415 root 1.1 }
416    
417     if [ $# -gt 0 ]; then
418     while [ $# -gt 0 ]; do
419     mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create"
420 root 1.6 mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
421 root 1.1
422     command="${1#--}"; shift
423     case "$command" in
424 root 1.14 version )
425     echo "staticperl version $VERSION"
426     ;;
427 root 1.1 fetch | configure | build | install | clean | distclean)
428 root 1.6 ( "$command" )
429 root 1.1 ;;
430     instsrc )
431 root 1.6 ( instsrc "$@" )
432 root 1.1 exit
433     ;;
434     instcpan )
435 root 1.6 ( instcpan "$@" )
436 root 1.1 exit
437     ;;
438     cpan )
439 root 1.6 ( install )
440     "$PERL_PREFIX/bin/cpan" "$@"
441 root 1.1 exit
442     ;;
443     mkbundle )
444 root 1.6 ( install )
445 root 1.1 bundle "$@"
446     exit
447     ;;
448     mkperl )
449 root 1.6 ( install )
450 root 1.1 bundle --perl "$@"
451     exit
452     ;;
453 root 1.11 mkapp )
454     ( install )
455     bundle --app "$@"
456     exit
457     ;;
458 root 1.1 help )
459     podusage 2
460     ;;
461     * )
462     exec 1>&2
463     echo
464     echo "Unknown command: $command"
465     podusage 0
466     ;;
467     esac
468     done
469     else
470     usage
471     fi
472    
473     exit 0
474    
475     #CAT staticperl.pod
476