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