--- App-Staticperl/staticperl.sh 2010/12/13 17:35:51 1.20 +++ App-Staticperl/staticperl.sh 2023/08/04 03:14:33 1.76 @@ -1,56 +1,65 @@ #!/bin/sh ############################################################################# -# configuration to fill in +# configuration to fill in (or to replace in your .staticperlrc) + +# clean up the environment a bit +unset PERL PERLLIB PERL5LIB PERL5OPT PERL_UNICODE PERLIO STATICPERL=~/.staticperl CPAN=http://mirror.netcologne.de/cpan # which mirror to use EMAIL="read the documentation " +DLCACHE= # perl build variables -PERL_VERSION=5.12.2 # 5.8.9 is also a good choice +MAKE=make +PERL_VERSION=http://stableperl.schmorp.de/dist/latest.tar.gz # 5.12.5 and 5.8.9 are good choices for small builds 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_OPTIMIZE="-Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" +PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG" +PERL_OPTIMIZE="-Os" # -Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" ARCH="$(uname -m)" -case "$ARCH" in - i*86 | x86_64 | amd64 ) - #PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 - PERL_OPTIMIZE="$PERL_OPTIMIZE" # x86/amd64 - case "$ARCH" in - i*86 ) - PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only - ;; - esac - ;; -esac +#case "$ARCH" in +# i*86 | x86_64 | amd64 ) +# PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 +# case "$ARCH" in +# i*86 ) +# PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only +# ;; +# esac +# ;; +#esac # -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 :/ # --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="-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 # which extra modules to install by default from CPAN that are # required by mkbundle -STATICPERL_MODULES="common::sense Pod::Strip PPI::XS Pod::Usage" +STATICPERL_MODULES="ExtUtils::MakeMaker ExtUtils::CBuilder common::sense Pod::Strip PPI PPI::XS Pod::Usage" # which extra modules you might want to install EXTRA_MODULES="" # overridable functions -preconfigure() { : ; } -postconfigure() { : ; } -postbuild() { : ; } -postinstall() { : ; } +preconfigure() { : ; } +patchconfig() { : ; } +postconfigure() { : ; } +postbuild() { : ; } +postcpanconfig() { : ; } +postinstall() { : ; } # now source user config, if any if [ "$STATICPERLRC" ]; then @@ -64,18 +73,26 @@ ############################################################################# # support -MKBUNDLE="${MKBUNDLE:=$STATICPERL/mkbundle}" +# work around ExtUtils::CBuilder and others +export CC="$PERL_CC" +export CFLAGS="$PERL_CFLAGS" +export LD="$PERL_CC" +export LDFLAGS="$PERL_LDFLAGS" +unset LIBS + 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 +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.911 - -BZ2=bz2 -BZIP2=bzip2 +$VERSION="1.46" fatal() { printf -- "\nFATAL: %s\n\n" "$*" >&2 @@ -125,47 +142,106 @@ # download/configure/compile/install perl clean() { - rm -rf "$STATICPERL/src/perl-$PERL_VERSION" + rm -rf "$STATICPERL/src" +} + +realclean() { + rm -f "$PERL_PREFIX/staticstamp.postinstall" + rm -f "$PERL_PREFIX/staticstamp.install" + rm -f "$STATICPERL/src/perl/staticstamp.configure" } fetch() { +( rcd "$STATICPERL" mkdir -p src rcd src - if ! [ -d "perl-$PERL_VERSION" ]; then - if ! [ -e "perl-$PERL_VERSION.tar.$BZ2" ]; then + if ! [ -d "perl" ]; then + rm -rf unpack + mkdir -p unpack - URL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.$BZ2" + case "$PERL_VERSION" in + *:* ) + # url + PERLURL="$PERL_VERSION" + PERLTAR="$(basename "$PERL_VERSION")" + ;; + /* ) + # directory + verbose "copying $PERL_VERSION" + cp -Rp "$PERL_VERSION/." unpack/. + chmod -R u+w unpack + mv unpack perl + return + ;; + * ) + PERLURL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.gz" + PERLTAR=perl-$PERL_VERSION.tar.gz + ;; + esac + if ! [ -e "$PERLTAR" ]; then verblock <perl-$PERL_VERSION.tar.$BZ2~ "$URL" \ + rm -f $PERLTAR~ # just to be on the safe side + { [ "$DLCACHE" ] && cp "$DLCACHE"/$PERLTAR $PERLTAR~ >/dev/null 2>&1; } \ + || wget -O $PERLTAR~ "$PERLURL" \ + || curl -f >$PERLTAR~ "$PERLURL" \ || fatal "$URL: unable to download" - rm -f perl-$PERL_VERSION.tar.$BZ2 - mv perl-$PERL_VERSION.tar.$BZ2~ perl-$PERL_VERSION.tar.$BZ2 + rm -f $PERLTAR + mv $PERLTAR~ $PERLTAR + if [ "$DLCACHE" ]; then + mkdir -p "$DLCACHE" + cp $PERLTAR "$DLCACHE"/$PERLTAR~$$~ && \ + mv "$DLCACHE"/$PERLTAR~$$~ "$DLCACHE"/$PERLTAR + fi fi verblock </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 - preconfigure + # 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 \ @@ -206,9 +315,9 @@ -Uusemultiplicity \ -Uusesfio \ -Uuseshrplib \ + -Uinstallusrbinperl \ + -A ccflags=" $PERL_CCFLAGS" \ -Dcc="$PERL_CC" \ - -Dcppflags="$PERL_CPPFLAGS" \ - -Dccflags="-g2 -fno-strict-aliasing" \ -Doptimize="$PERL_OPTIMIZE" \ -Dldflags="$PERL_LDFLAGS" \ -Dlibs="$PERL_LIBS" \ @@ -219,7 +328,6 @@ -Uusevendorprefix \ -Dsitelib="$PERL_PREFIX/lib" \ -Dsitearch="$PERL_PREFIX/lib" \ - -Usitelibexp \ -Uman1dir \ -Uman3dir \ -Usiteman1dir \ @@ -230,81 +338,116 @@ -Dcf_by="$EMAIL" \ $PERL_CONFIGURE \ -Duseperlio \ - -dE || fatal "Configure failed" + -Uversiononly \ + -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" - touch staticstamp.configure + : > staticstamp.configure +) || exit +} + +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-$PERL_VERSION" + rcd "$STATICPERL/src/perl" verblock < "$PERL_PREFIX/staticstamp.postinstall" + fi } install() { +( if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then build verblock <"$PERL_PREFIX"/bin/cpan-make-install <"$PERL_PREFIX/lib/CPAN/MyConfig.pm" - "$PERL_PREFIX"/bin/perl -MCPAN -e ' + # we call cpan with -MCPAN::MyConfig in this script, which + # is strictly unnecessary 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 => pushy_https => "0"); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); CPAN::Shell->o (conf => q); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); @@ -312,24 +455,49 @@ 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, "MAP_TARGET=perl"); + CPAN::Shell->o (conf => q, "'"$PERL_PREFIX"'/bin/SP-make-make"); + 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, q); + CPAN::Shell->o (conf => q, q<0>); + CPAN::Shell->o (conf => q, q<0>); + CPAN::Shell->o (conf => q, q); CPAN::Shell->o (conf => q); ' || fatal "error while initialising CPAN" - touch "$PERL_PREFIX/staticstamp.install" + postcpanconfig + + : > "$PERL_PREFIX/staticstamp.install" fi - if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then - NOCHECK_INSTALL=+ - instcpan $STATICPERL_MODULES - [ $EXTRA_MODULES ] && instcpan $EXTRA_MODULES + _postinstall +) || exit +} - postinstall || fatal "postinstall hook failed" +import() { +( + IMPORT="$1" + + rcd "$STATICPERL" + + if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then + verblock < "$PERL_PREFIX/.import" - touch "$PERL_PREFIX/staticstamp.postinstall" + : > "$PERL_PREFIX/staticstamp.install" fi + + _postinstall +) || exit } ############################################################################# @@ -340,14 +508,18 @@ verblock < "'"$mod"'"' \ - || fatal "$mod: unable to install from CPAN" - done - rm -rf "$STATICPERL/build" + MYCONFIG= + [ -e "$PERL_PREFIX/.import" ] || MYCONFIG=-MCPAN::MyConfig + + "$PERL_PREFIX"/bin/perl $MYCONFIG -MCPAN -e 'notest (install => $_) for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log" + + if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then + fatal "failure while installing modules from CPAN ($*)" + fi + rm -f "$STATICPERL/instcpan.log" } ############################################################################# @@ -358,7 +530,7 @@ verblock </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" - "$PERL_PREFIX"/bin/cpan-make-install || fatal "$mod: error installing module" - make distclean >/dev/null 2>&1 + "$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 @@ -406,12 +578,13 @@ read dummy echo "#!$PERL_PREFIX/bin/perl" cat - } <<'MKBUNDLE' + } <<'end_of_mkbundle' #CAT mkbundle -MKBUNDLE +end_of_mkbundle } bundle() { + MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" CACHE="$STATICPERL/cache" @@ -429,34 +602,45 @@ version ) echo "staticperl version $VERSION" ;; - fetch | configure | build | install | clean | distclean) - ( "$command" ) + fetch | configure | build | install | clean | realclean | distclean ) + ( "$command" ) || exit + ;; + import ) + ( import "$1" ) || exit + shift ;; instsrc ) - ( instsrc "$@" ) + ( instsrc "$@" ) || exit exit ;; instcpan ) - ( instcpan "$@" ) + ( instcpan "$@" ) || exit + exit + ;; + perl ) + ( install ) || exit + exec "$PERL_PREFIX/bin/perl" "$@" exit ;; cpan ) - ( install ) - "$PERL_PREFIX/bin/cpan" "$@" + ( install ) || exit + PERL="$PERL_PREFIX/bin/perl" + export PERL + exec "$PERL_PREFIX/bin/cpan" "$@" exit ;; mkbundle ) - ( install ) + ( install ) || exit bundle "$@" exit ;; mkperl ) - ( install ) + ( install ) || exit bundle --perl "$@" exit ;; mkapp ) - ( install ) + ( install ) || exit bundle --app "$@" exit ;;