--- App-Staticperl/staticperl.sh 2010/12/06 21:10:41 1.3 +++ App-Staticperl/staticperl.sh 2011/05/01 07:56:26 1.40 @@ -3,16 +3,16 @@ ############################################################################# # configuration to fill in -PERLVER=5.12.2 # 5.8.9 is also a good choice STATICPERL=~/.staticperl -CPAN=http://mirror.netcologne.de/cpan/ # which mirror to use +CPAN=http://mirror.netcologne.de/cpan # which mirror to use EMAIL="read the documentation " -MKBUNDLE="$STATICPERL/mkbundle" - # perl build variables -PREFIX="$STATICPERL/perl" # where the perl gets installed -PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" +MAKE=make +PERL_VERSION=5.12.3 # 5.8.9 is also a good choice +PERL_CC=cc +PERL_CONFIGURE="" # additional Configure arguments +PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG" PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" ARCH="$(uname -m)" @@ -30,14 +30,17 @@ # -Wl,--gc-sections makes it impossible to check for undefined references # for some reason so we need to patch away the "-no" after Configure and before make :/ -# -z muldefs is to work around uclibc's pthread static linking bug -PERL_LDFLAGS="-Wl,--no-gc-sections -z muldefs" +# --allow-multiple-definition exists to work around uclibc's pthread static linking bug +#PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition" +PERL_LDFLAGS= PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself # some configuration options for modules -export PERL_MM_USE_DEFAULT=1 -#export CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow -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' +PERL_MM_USE_DEFAULT=1 +PERL_MM_OPT="MAN1PODS= MAN3PODS=" +#CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow +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' +export PERL_MM_USE_DEFAULT PERL_MM_OPT CORO_INTERFACE EV_EXTRA_DEFS # which extra modules to install by default from CPAN that are # required by mkbundle @@ -47,21 +50,37 @@ EXTRA_MODULES="" # overridable functions +preconfigure() { : ; } +patchconfig() { : ; } postconfigure() { : ; } postbuild() { : ; } postinstall() { : ; } # now source user config, if any -[ -r /etc/staticperlrc ] && . /etc/staticperlrc -[ -r ~/.staticperlrc ] && . ~/.staticperlrc -[ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" +if [ "$STATICPERLRC" ]; then + . "$STATICPERLRC" +else + [ -r /etc/staticperlrc ] && . /etc/staticperlrc + [ -r ~/.staticperlrc ] && . ~/.staticperlrc + [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" +fi ############################################################################# # support +PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed + +unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG +unset PERL_MB_OPT +LC_ALL=C; export LC_ALL # just to be on the safe side + +# prepend PATH - not required by staticperl itself, but might make +# life easier when working in e.g. "staticperl cpan / look" +PATH="$PERL_PREFIX/perl/bin:$PATH" + # set version in a way that Makefile.PL can extract VERSION=VERSION; eval \ -$VERSION=0.1 +$VERSION="1.21" BZ2=bz2 BZIP2=bzip2 @@ -104,7 +123,7 @@ distclean() { verblock </dev/null || return + rm -rf "$STATICPERL/src/perl-$PERL_VERSION" +} - rm -f staticstamp.configure - make distclean >/dev/null 2>&1 +realclean() { + rm -f "$PERL_PREFIX/staticstamp.postinstall" + rm -f "$PERL_PREFIX/staticstamp.install" + rm -f "$STATICPERL/src/perl-"*"/staticstamp.configure" } fetch() { @@ -126,22 +148,24 @@ mkdir -p src rcd src - if ! [ -d "perl-$PERLVER" ]; then - if ! [ -e "perl-$PERLVER.tar.$BZ2" ]; then + if ! [ -d "perl-$PERL_VERSION" ]; then + if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then - URL="$CPAN/src/5.0/perl-$PERLVER.tar.$BZ2" + URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2" verblock <perl-$PERLVER.tar.$BZ2~ "$URL" \ - || wget -O perl-$PERLVER.tar.$BZ2~ "$URL" \ - || fatal "$URL: error during downloading" - mv perl-$PERLVER.tar.$BZ2~ perl-$PERLVER.tar.$BZ2 + rm -f perl-$PERL_VERSION.tar.$BZ2~ # just to be on the safe side + curl -f >perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ + || wget -O perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ + || fatal "$URL: unable to download" + rm -f perl-$PERL_VERSION.tar.$BZ2 + mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 fi verblock < "$2~" || fatal "error while running sed" + rm -f "$2" mv "$2~" "$2" } +configure_failure() { + cat </dev/null 2>&1 - rm -f "$PREFIX/staticstamp.install" + sedreplace '/^#define SITELIB/d' config_h.SH - # I hate them + # I hate them for this grep -q -- -fstack-protector Configure && \ sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure + # what did that bloke think + grep -q -- usedl=.define hints/darwin.sh && \ + sedreplace '/^usedl=.define.;$/d' hints/darwin.sh + + preconfigure || fatal "preconfigure hook failed" + # trace configure \ sh Configure -Duselargefiles \ -Uuse64bitint \ @@ -189,22 +250,21 @@ -Uusethreads \ -Uuseithreads \ -Uusemultiplicity \ - -Duseperlio \ -Uusesfio \ -Uuseshrplib \ - -Dcppflags="$PERL_CPPFLAGS" \ - -Dccflags="-g2 -fno-strict-aliasing" \ + -Uinstallusrbinperl \ + -A ccflags=" $PERL_CCFLAGS" \ + -Dcc="$PERL_CC" \ -Doptimize="$PERL_OPTIMIZE" \ -Dldflags="$PERL_LDFLAGS" \ -Dlibs="$PERL_LIBS" \ - -Dprefix="$PREFIX" \ - -Dbin="$PREFIX/bin" \ - -Dprivlib="$PREFIX/lib" \ - -Darchlib="$PREFIX/lib" \ + -Dprefix="$PERL_PREFIX" \ + -Dbin="$PERL_PREFIX/bin" \ + -Dprivlib="$PERL_PREFIX/lib" \ + -Darchlib="$PERL_PREFIX/lib" \ -Uusevendorprefix \ - -Dsitelib="$PREFIX/lib" \ - -Dsitearch="$PREFIX/lib" \ - -Usitelibexp \ + -Dsitelib="$PERL_PREFIX/lib" \ + -Dsitearch="$PERL_PREFIX/lib" \ -Uman1dir \ -Uman3dir \ -Usiteman1dir \ @@ -213,13 +273,17 @@ -Demail="$EMAIL" \ -Dcf_email="$EMAIL" \ -Dcf_by="$EMAIL" \ - -dE || fatal "Configure failed" + $PERL_CONFIGURE \ + -Duseperlio \ + -dE || configure_failure sedreplace ' s/-Wl,--no-gc-sections/-Wl,--gc-sections/g s/ *-fno-stack-protector */ /g ' config.sh + patchconfig || fatal "patchconfig hook failed" + sh Configure -S || fatal "Configure -S failed" postconfigure || fatal "postconfigure hook failed" @@ -227,76 +291,100 @@ touch staticstamp.configure } +write_shellscript() { + { + echo "#!/bin/sh" + echo "STATICPERL=\"$STATICPERL\"" + echo "PERL_PREFIX=\"$PERL_PREFIX\"" + echo "MAKE=\"$MAKE\"" + cat + } >"$PERL_PREFIX/bin/$1" + chmod 755 "$PERL_PREFIX/bin/$1" +} + build() { configure - rcd "$STATICPERL/src/perl-$PERLVER" + rcd "$STATICPERL/src/perl-$PERL_VERSION" verblock <"$PREFIX"/bin/cpan-make-install <"$PREFIX/lib/CPAN/MyConfig.pm" + "$PERL_PREFIX/bin/SP-patch-postinstall" + + # help to trick CPAN into avoiding ~/.cpan completely + echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" + + # we call cpan with -MCPAN::MyConfig in this script, which + # is strictly unnecssary as we have to patch CPAN anyway, + # so consider it "for good measure". + "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' + CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); + CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); + CPAN::Shell->o (conf => q); + CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); + CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/build"); + CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/prefs"); + CPAN::Shell->o (conf => q , "'"$STATICPERL"'/cpan/histfile"); + CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/sources"); + CPAN::Shell->o (conf => q, "'"$PERL_PREFIX"'/bin/SP-make-install-make"); + CPAN::Shell->o (conf => q, q); + CPAN::Shell->o (conf => q, q); + CPAN::Shell->o (conf => q, "EUMM"); + CPAN::Shell->o (conf => q); + ' || fatal "error while initialising CPAN" + + touch "$PERL_PREFIX/staticstamp.install" + fi - "$PREFIX"/bin/perl -MCPAN -e ' - CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); - CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); - CPAN::Shell->o (conf => q); - CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); - CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/build"); - CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/prefs"); - CPAN::Shell->o (conf => q , "'"$STATICPERL"'/cpan/histfile"); - CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/sources"); - CPAN::Shell->o (conf => q, "'"$PREFIX"'/bin/cpan-make-install"); - CPAN::Shell->o (conf => q, q); - CPAN::Shell->o (conf => q, q); - CPAN::Shell->o (conf => q); - ' || fatal "error while initialising CPAN" - - NOCHECK_INSTALL=+ - instcpan $STATICPERL_MODULES - [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES + if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then + NOCHECK_INSTALL=+ + instcpan $STATICPERL_MODULES + [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES - postinstall || fatal "postinstall hook failed" + postinstall || fatal "postinstall hook failed" - touch "$PREFIX/staticstamp.install" + touch "$PERL_PREFIX/staticstamp.postinstall" + fi } ############################################################################# @@ -311,7 +399,7 @@ EOF for mod in "$@"; do - "$PREFIX"/bin/perl -MCPAN -e 'notest install => "'"$mod"'"' \ + "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e 'notest install => "'"$mod"'"' \ || fatal "$mod: unable to install from CPAN" done rm -rf "$STATICPERL/build" @@ -333,59 +421,35 @@ echo $mod ( rcd $mod - make -f Makefile.aperl map_clean >/dev/null 2>&1 - make distclean >/dev/null 2>&1 - "$PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" - make || fatal "$mod: error building module" - "$PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" - make distclean >/dev/null 2>&1 + "$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 + "$MAKE" distclean >/dev/null 2>&1 + "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" + "$MAKE" || fatal "$mod: error building module" + "$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module" + "$MAKE" distclean >/dev/null 2>&1 exit 0 ) || exit $? done } ############################################################################# -# do schmorpy stuff - -MODSRCDIR=~/src - -instmodsrc() { - for mod in "$@"; do - instmod_src "$MODSRCDIR/$mod" - done -} - -install_schmorp() { - install - - instcpan Data::Dump Term::ReadLine::Perl Term::ANSIColor Term::ReadKey - instcpan Digest::SHA Digest::MD6 Digest::SHA256 Digest::MD4 Digest::HMAC_MD5 Digest::HMAC_MD6 Digest::FNV - #instcpan Net::SSLeay # requires static -ldl - - instmodsrc common-sense Crypt-Twofish2 Array-Heap Convert-Scalar Compress-LZF JSON-XS - instmodsrc EV Guard Async-Interrupt IO-AIO - instmodsrc AnyEvent AnyEvent-AIO Coro AnyEvent-HTTP - instmodsrc Linux-Inotify2 EV-Loop-Async - - instcpan AnyEvent::HTTPD -} - -############################################################################# # main podusage() { echo - if [ -e "$PREFIX/bin/perl" ]; then - "$PREFIX/bin/perl" -MPod::Usage -e \ + + if [ -e "$PERL_PREFIX/bin/perl" ]; then + "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 2>/dev/null && exit fi + # try whatever perl we can find perl -MPod::Usage -e \ 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 2>/dev/null && exit - fatal "displaying documentation requires a working perl - try '$0 install' first" + fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" } usage() { @@ -395,7 +459,7 @@ catmkbundle() { { read dummy - echo "#!$PREFIX/bin/perl" + echo "#!$PERL_PREFIX/bin/perl" cat } <<'MKBUNDLE' #CAT mkbundle @@ -403,50 +467,60 @@ } bundle() { + MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" - "$PREFIX/bin/perl" -- "$MKBUNDLE" "$@" + CACHE="$STATICPERL/cache" + mkdir -p "$CACHE" + "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" } if [ $# -gt 0 ]; then while [ $# -gt 0 ]; do mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" - mkdir -p "$PREFIX" || fatal "$PREFIX: cannot create" + mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" command="${1#--}"; shift case "$command" in - fetch | configure | build | install | clean | distclean) - verblock <