--- App-Staticperl/staticperl.sh 2010/12/07 19:55:56 1.8 +++ App-Staticperl/staticperl.sh 2010/12/18 13:58:12 1.23 @@ -4,16 +4,15 @@ # configuration to fill in 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 -PERL_PREFIX="$STATICPERL/perl" # where the perl gets installed +MAKE=make PERL_VERSION=5.12.2 # 5.8.9 is also a good choice +PERL_CC=cc PERL_CONFIGURE="" # additional Configure arguments -PERL_CPPFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG -USITELIB_EXP -USITEARCHEXP -UARCHLIB_EXP" +PERL_CCFLAGS="-DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=65536 -D_GNU_SOURCE -DNDEBUG" PERL_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" ARCH="$(uname -m)" @@ -31,8 +30,8 @@ # -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_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself # some configuration options for modules @@ -54,16 +53,26 @@ 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 +MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}" +PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed + +unset PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO_DEBUG +export LC_ALL=C # just to be on the safe side + # set version in a way that Makefile.PL can extract VERSION=VERSION; eval \ -$VERSION=0.1 +$VERSION=0.912 BZ2=bz2 BZIP2=bzip2 @@ -106,7 +115,7 @@ distclean() { verblock <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 @@ -149,7 +165,8 @@ EOF mkdir -p unpack - $BZIP2 -d "$2~" || fatal "error while running sed" + rm -f "$2" mv "$2~" "$2" } +configure_failure() { + cat </dev/null 2>&1 + "$MAKE" distclean >/dev/null 2>&1 + + 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 @@ -192,11 +238,10 @@ -Uusethreads \ -Uuseithreads \ -Uusemultiplicity \ - -Duseperlio \ -Uusesfio \ -Uuseshrplib \ - -Dcppflags="$PERL_CPPFLAGS" \ - -Dccflags="-g2 -fno-strict-aliasing" \ + -A ccflags=" $PERL_CCFLAGS" \ + -Dcc="$PERL_CC" \ -Doptimize="$PERL_OPTIMIZE" \ -Dldflags="$PERL_LDFLAGS" \ -Dlibs="$PERL_LIBS" \ @@ -207,7 +252,6 @@ -Uusevendorprefix \ -Dsitelib="$PERL_PREFIX/lib" \ -Dsitearch="$PERL_PREFIX/lib" \ - -Usitelibexp \ -Uman1dir \ -Uman3dir \ -Usiteman1dir \ @@ -217,7 +261,8 @@ -Dcf_email="$EMAIL" \ -Dcf_by="$EMAIL" \ $PERL_CONFIGURE \ - -dE || fatal "Configure failed" + -Duseperlio \ + -dE || configure_failure sedreplace ' s/-Wl,--no-gc-sections/-Wl,--gc-sections/g @@ -242,65 +287,81 @@ rm -f "$PERL_PREFIX/staticstamp.install" - make || fatal "make: error while building perl" + "$MAKE" || fatal "make: error while building perl" postbuild || fatal "postbuild hook failed" } install() { - [ -e "$PERL_PREFIX/staticstamp.install" ] && return + if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then + build - build - - verblock <"$PERL_PREFIX"/bin/cpan-make-install <"$PERL_PREFIX"/bin/cpan-make-install <"$PERL_PREFIX/lib/CPAN/MyConfig.pm" - # trick CPAN into avoiding ~/.cpan completely - echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" + "$PERL_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, "'"$PERL_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" - "$PERL_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, "'"$PERL_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 + touch "$PERL_PREFIX/staticstamp.install" + fi + + 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 "$PERL_PREFIX/staticstamp.install" + touch "$PERL_PREFIX/staticstamp.postinstall" + fi } ############################################################################# @@ -337,12 +398,12 @@ echo $mod ( rcd $mod - make -f Makefile.aperl map_clean >/dev/null 2>&1 - 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" + "$MAKE" || fatal "$mod: error building module" "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" - make distclean >/dev/null 2>&1 + "$MAKE" distclean >/dev/null 2>&1 exit 0 ) || exit $? done @@ -353,17 +414,19 @@ podusage() { echo + 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() { @@ -383,7 +446,9 @@ bundle() { catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" - "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" "$@" + CACHE="$STATICPERL/cache" + mkdir -p "$CACHE" + "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" } if [ $# -gt 0 ]; then @@ -393,35 +458,40 @@ command="${1#--}"; shift case "$command" in - fetch | configure | build | install | clean | distclean) - verblock <