ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.sh
(Generate patch)

Comparing App-Staticperl/staticperl.sh (file contents):
Revision 1.37 by root, Fri Mar 18 19:49:04 2011 UTC vs.
Revision 1.49 by root, Sun Jul 10 01:37:56 2011 UTC

1#!/bin/sh 1#!/bin/sh
2 2
3############################################################################# 3#############################################################################
4# configuration to fill in 4# configuration to fill in (or to replace in your .staticperlrc)
5 5
6STATICPERL=~/.staticperl 6STATICPERL=~/.staticperl
7CPAN=http://mirror.netcologne.de/cpan # which mirror to use 7CPAN=http://mirror.netcologne.de/cpan # which mirror to use
8EMAIL="read the documentation <rtfm@example.org>" 8EMAIL="read the documentation <rtfm@example.org>"
9DLCACHE=
9 10
10# perl build variables 11# perl build variables
11MAKE=make 12MAKE=make
12PERL_VERSION=5.12.3 # 5.8.9 is also a good choice 13PERL_VERSION=5.12.4 # 5.8.9 is also a good choice
13PERL_CC=cc 14PERL_CC=cc
14PERL_CONFIGURE="" # additional Configure arguments 15PERL_CONFIGURE="" # additional Configure arguments
15PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG" 16PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG"
16PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" 17PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math"
17 18
35PERL_LDFLAGS= 36PERL_LDFLAGS=
36PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself 37PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself
37 38
38# some configuration options for modules 39# some configuration options for modules
39PERL_MM_USE_DEFAULT=1 40PERL_MM_USE_DEFAULT=1
41PERL_MM_OPT="MAN1PODS= MAN3PODS="
40#CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow 42#CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow
41EV_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' 43#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'
42export PERL_MM_USE_DEFAULT CORO_INTERFACE EV_EXTRA_DEFS 44export PERL_MM_USE_DEFAULT PERL_MM_OPT
43 45
44# which extra modules to install by default from CPAN that are 46# which extra modules to install by default from CPAN that are
45# required by mkbundle 47# required by mkbundle
46STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage" 48STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage"
47 49
65fi 67fi
66 68
67############################################################################# 69#############################################################################
68# support 70# support
69 71
70MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}"
71PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed 72PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed
72 73
73unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG 74unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG
75unset PERL_MB_OPT
74LC_ALL=C; export LC_ALL # just to be on the safe side 76LC_ALL=C; export LC_ALL # just to be on the safe side
77
78# prepend PATH - not required by staticperl itself, but might make
79# life easier when working in e.g. "staticperl cpan / look"
80PATH="$PERL_PREFIX/perl/bin:$PATH"
75 81
76# set version in a way that Makefile.PL can extract 82# set version in a way that Makefile.PL can extract
77VERSION=VERSION; eval \ 83VERSION=VERSION; eval \
78$VERSION="1.21" 84$VERSION="1.31"
79 85
80BZ2=bz2 86BZ2=bz2
81BZIP2=bzip2 87BZIP2=bzip2
82 88
83fatal() { 89fatal() {
126 132
127############################################################################# 133#############################################################################
128# download/configure/compile/install perl 134# download/configure/compile/install perl
129 135
130clean() { 136clean() {
131 rm -rf "$STATICPERL/src/perl-$PERL_VERSION" 137 rm -rf "$STATICPERL/src"
132} 138}
133 139
134realclean() { 140realclean() {
135 rm -f "$PERL_PREFIX/staticstamp.postinstall" 141 rm -f "$PERL_PREFIX/staticstamp.postinstall"
136 rm -f "$PERL_PREFIX/staticstamp.install" 142 rm -f "$PERL_PREFIX/staticstamp.install"
142 148
143 mkdir -p src 149 mkdir -p src
144 rcd src 150 rcd src
145 151
146 if ! [ -d "perl-$PERL_VERSION" ]; then 152 if ! [ -d "perl-$PERL_VERSION" ]; then
147 if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then 153 PERLTAR=perl-$PERL_VERSION.tar.$BZ2
148 154
155 if ! [ -e $PERLTAR ]; then
149 URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2" 156 URL="$CPAN/src/5.0/$PERLTAR"
150 157
151 verblock <<EOF 158 verblock <<EOF
152downloading perl 159downloading perl
153to manually download perl yourself, place 160to manually download perl yourself, place
154perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL 161perl-$PERL_VERSION.tar.$BZ2 in $STATICPERL
155trying $URL 162trying $URL
156EOF
157 163
164either curl or wget is required for automatic download.
165curl is tried first, then wget.
166
167you can configure a download cache directory via DLCACHE
168in your .staticperlrc to avoid repeated downloads.
169EOF
170
158 rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side 171 rm -f $PERLTAR~ # just to be on the safe side
159 curl -f >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 172 { [ "$DLCACHE" ] && cp "$DLCACHE"/$PERLTAR $PERLTAR~ >/dev/null 2>&1; } \
160 || wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ 173 || wget -O $PERLTAR~ "$URL" \
174 || curl -f >$PERLTAR~ "$URL" \
161 || fatal "$URL: unable to download" 175 || fatal "$URL: unable to download"
162 rm -f perl-$PERL_VERSION.tar.$BZ2 176 rm -f $PERLTAR
163 mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 177 mv $PERLTAR~ $PERLTAR
178 if [ "$DLCACHE" ]; then
179 mkdir -p "$DLCACHE"
180 cp $PERLTAR "$DLCACHE"/$PERLTAR~ && \
181 mv "$DLCACHE"/$PERLTAR~ "$DLCACHE"/$PERLTAR
182 fi
164 fi 183 fi
165 184
166 verblock <<EOF 185 verblock <<EOF
167unpacking perl 186unpacking perl
168EOF 187EOF
169 188
170 mkdir -p unpack 189 mkdir -p unpack
171 rm -rf unpack/perl-$PERL_VERSION 190 rm -rf unpack/perl-$PERL_VERSION
172 $BZIP2 -d <perl-$PERL_VERSION.tar.$BZ2 | ( cd unpack && tar xf - ) \ 191 $BZIP2 -d <$PERLTAR | ( cd unpack && tar xf - ) \
173 || fatal "perl-$PERL_VERSION.tar.$BZ2: error during unpacking" 192 || fatal "$PERLTAR: error during unpacking"
174 chmod -R u+w unpack/perl-$PERL_VERSION 193 chmod -R u+w unpack/perl-$PERL_VERSION
175 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION 194 mv unpack/perl-$PERL_VERSION perl-$PERL_VERSION
176 rmdir -p unpack 195 rmdir -p unpack
177 fi 196 fi
178} 197}
281 300
282 sh Configure -S || fatal "Configure -S failed" 301 sh Configure -S || fatal "Configure -S failed"
283 302
284 postconfigure || fatal "postconfigure hook failed" 303 postconfigure || fatal "postconfigure hook failed"
285 304
286 touch staticstamp.configure 305 : > staticstamp.configure
306}
307
308write_shellscript() {
309 {
310 echo "#!/bin/sh"
311 echo "STATICPERL=\"$STATICPERL\""
312 echo "PERL_PREFIX=\"$PERL_PREFIX\""
313 echo "MAKE=\"$MAKE\""
314 cat
315 } >"$PERL_PREFIX/bin/$1"
316 chmod 755 "$PERL_PREFIX/bin/$1"
287} 317}
288 318
289build() { 319build() {
290 configure 320 configure
291 321
298 rm -f "$PERL_PREFIX/staticstamp.install" 328 rm -f "$PERL_PREFIX/staticstamp.install"
299 329
300 "$MAKE" || fatal "make: error while building perl" 330 "$MAKE" || fatal "make: error while building perl"
301 331
302 postbuild || fatal "postbuild hook failed" 332 postbuild || fatal "postbuild hook failed"
333}
334
335_postinstall() {
336 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
337 NOCHECK_INSTALL=+
338 instcpan $STATICPERL_MODULES
339 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES
340
341 postinstall || fatal "postinstall hook failed"
342
343 : > "$PERL_PREFIX/staticstamp.postinstall"
344 fi
303} 345}
304 346
305install() { 347install() {
306 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then 348 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
307 build 349 build
312EOF 354EOF
313 355
314 ln -sf "perl/bin/" "$STATICPERL/bin" 356 ln -sf "perl/bin/" "$STATICPERL/bin"
315 ln -sf "perl/lib/" "$STATICPERL/lib" 357 ln -sf "perl/lib/" "$STATICPERL/lib"
316 358
359 mkdir "$STATICPERL/patched"
360
317 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten 361 ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
318 rm -rf "$PERL_PREFIX" # by this rm -rf 362 rm -rf "$PERL_PREFIX" # by this rm -rf
319 363
320 "$MAKE" install || fatal "make install: error while installing" 364 "$MAKE" install || fatal "make install: error while installing"
321 365
322 rcd "$PERL_PREFIX" 366 rcd "$PERL_PREFIX"
323 367
324 # create a "make install" replacement for CPAN 368 # create a "make install" replacement for CPAN
325 cat >"$PERL_PREFIX"/bin/cpan-make-install <<EOF 369 write_shellscript SP-make-install-make <<'EOF'
326"$MAKE" || exit 370#CAT make-install-make.sh
327
328# patch CPAN::HandleConfig.pm
329HCPM="$PERL_PREFIX"/lib/CPAN/HandleConfig.pm
330case "\$(head -n1 "\$HCPM")" in
331 *CPAN::MyConfig* )
332 ;;
333 * )
334 echo "patching \$HCPM for a safer tomorrow"
335 {
336 echo "use CPAN::MyConfig;"
337 cat "\$HCPM"
338 } >"\$HCPM~"
339 rm -f "\$HCPM"
340 mv "\$HCPM~" "\$HCPM"
341 ;;
342esac
343
344if find blib/arch/auto -type f | grep -q -v .exists; then
345 echo Probably an XS module, rebuilding perl
346 if "$MAKE" perl; then
347 mv perl "$PERL_PREFIX"/bin/perl~ \
348 && rm -f "$PERL_PREFIX"/bin/perl \
349 && mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl
350 "$MAKE" -f Makefile.aperl map_clean
351 else
352 "$MAKE" -f Makefile.aperl map_clean
353 exit 1
354 fi
355fi
356
357"$MAKE" install UNINST=1
358EOF 371EOF
359 chmod 755 "$PERL_PREFIX"/bin/cpan-make-install
360 372
373 # create a "patch modules" helper
374 write_shellscript SP-patch-postinstall <<'EOF'
375#CAT patch-postinstall.sh
376EOF
377
378 "$PERL_PREFIX/bin/SP-patch-postinstall"
379
361 # trick CPAN into avoiding ~/.cpan completely 380 # help to trick CPAN into avoiding ~/.cpan completely
362 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" 381 echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm"
363 382
364 # we call cpan with -MCPAN::MyConfig in this script, but 383 # we call cpan with -MCPAN::MyConfig in this script, which
365 # every make install will patch CPAN::HandleConfig.pm to 384 # is strictly unnecssary as we have to patch CPAN anyway,
366 # protect the user. 385 # so consider it "for good measure".
367
368 "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' 386 "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e '
369 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); 387 CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'");
370 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 388 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
371 CPAN::Shell->o (conf => q<init>); 389 CPAN::Shell->o (conf => q<init>);
372 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); 390 CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan");
373 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); 391 CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build");
374 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); 392 CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs");
375 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); 393 CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile");
376 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); 394 CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources");
377 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/cpan-make-install"); 395 CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/SP-make-install-make");
378 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); 396 CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>);
379 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>); 397 CPAN::Shell->o (conf => q<build_requires_install_policy>, q<no>);
380 CPAN::Shell->o (conf => q<prefer_installer>, "EUMM"); 398 CPAN::Shell->o (conf => q<prefer_installer>, "EUMM");
381 CPAN::Shell->o (conf => q<commit>); 399 CPAN::Shell->o (conf => q<commit>);
382 ' || fatal "error while initialising CPAN" 400 ' || fatal "error while initialising CPAN"
383 401
384 touch "$PERL_PREFIX/staticstamp.install" 402 : > "$PERL_PREFIX/staticstamp.install"
385 fi 403 fi
386 404
405 _postinstall
406}
407
408import() {
409 IMPORT="$1"
410
411 rcd "$STATICPERL"
412
387 if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then 413 if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
388 NOCHECK_INSTALL=+ 414 verblock <<EOF
389 instcpan $STATICPERL_MODULES 415import perl from $IMPORT to $STATICPERL
390 [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES 416EOF
391 417
392 postinstall || fatal "postinstall hook failed" 418 rm -rf bin cpan lib patched perl src
419 mkdir -m 755 perl perl/bin
420 ln -s perl/bin/ bin
421 ln -s "$IMPORT" perl/bin/
393 422
394 touch "$PERL_PREFIX/staticstamp.postinstall" 423 : > "$PERL_PREFIX/staticstamp.install"
395 fi 424 fi
425
426 _postinstall
396} 427}
397 428
398############################################################################# 429#############################################################################
399# install a module from CPAN 430# install a module from CPAN
400 431
404 verblock <<EOF 435 verblock <<EOF
405installing modules from CPAN 436installing modules from CPAN
406$@ 437$@
407EOF 438EOF
408 439
409 for mod in "$@"; do 440 #"$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e 'notest install $_ for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log"
410 "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e 'notest install => "'"$mod"'"' \ 441 "$PERL_PREFIX"/bin/perl -MCPAN -e 'notest install $_ for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log"
411 || fatal "$mod: unable to install from CPAN" 442
412 done 443 if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then
444 fatal "failure while installing modules from CPAN ($@)"
445 fi
413 rm -rf "$STATICPERL/build" 446 rm -f "$STATICPERL/instcpan.log"
414} 447}
415 448
416############################################################################# 449#############################################################################
417# install a module from unpacked sources 450# install a module from unpacked sources
418 451
431 rcd $mod 464 rcd $mod
432 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 465 "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1
433 "$MAKE" distclean >/dev/null 2>&1 466 "$MAKE" distclean >/dev/null 2>&1
434 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" 467 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL"
435 "$MAKE" || fatal "$mod: error building module" 468 "$MAKE" || fatal "$mod: error building module"
436 "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" 469 "$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module"
437 "$MAKE" distclean >/dev/null 2>&1 470 "$MAKE" distclean >/dev/null 2>&1
438 exit 0 471 exit 0
439 ) || exit $? 472 ) || exit $?
440 done 473 done
441} 474}
473#CAT mkbundle 506#CAT mkbundle
474MKBUNDLE 507MKBUNDLE
475} 508}
476 509
477bundle() { 510bundle() {
511 MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}"
478 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" 512 catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create"
479 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" 513 chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE"
480 CACHE="$STATICPERL/cache" 514 CACHE="$STATICPERL/cache"
481 mkdir -p "$CACHE" 515 mkdir -p "$CACHE"
482 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" 516 "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@"
490 command="${1#--}"; shift 524 command="${1#--}"; shift
491 case "$command" in 525 case "$command" in
492 version ) 526 version )
493 echo "staticperl version $VERSION" 527 echo "staticperl version $VERSION"
494 ;; 528 ;;
495 fetch | configure | build | install | clean | realclean | distclean) 529 fetch | configure | build | install | clean | realclean | distclean )
496 ( "$command" ) || exit 530 ( "$command" ) || exit
531 ;;
532 import )
533 ( import "$1" ) || exit
534 shift
497 ;; 535 ;;
498 instsrc ) 536 instsrc )
499 ( instsrc "$@" ) || exit 537 ( instsrc "$@" ) || exit
500 exit 538 exit
501 ;; 539 ;;
502 instcpan ) 540 instcpan )
503 ( instcpan "$@" ) || exit 541 ( instcpan "$@" ) || exit
504 exit 542 exit
505 ;; 543 ;;
544 perl )
545 ( install ) || exit
546 exec "$PERL_PREFIX/bin/perl" "$@"
547 exit
548 ;;
506 cpan ) 549 cpan )
507 ( install ) || exit 550 ( install ) || exit
551 PERL="$PERL_PREFIX/bin/perl"
552 export PERL
508 "$PERL_PREFIX/bin/cpan" "$@" 553 exec "$PERL_PREFIX/bin/cpan" "$@"
509 exit 554 exit
510 ;; 555 ;;
511 mkbundle ) 556 mkbundle )
512 ( install ) || exit 557 ( install ) || exit
513 bundle "$@" 558 bundle "$@"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines