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