App-Staticperl
view release on metacpan or search on metacpan
staticperl.sh view on Meta::CPAN
rcd() {
cd "$1" || fatal "$1: cannot enter"
}
trace() {
prefix="$1"; shift
# "$@" 2>&1 | while read line; do
# echo "$prefix: $line"
# done
"$@"
}
trap wait 0
#############################################################################
# clean
distclean() {
verblock <<EOF
deleting everything installed by this script (rm -rf $STATICPERL)
EOF
rm -rf "$STATICPERL"
}
#############################################################################
# download/configure/compile/install perl
clean() {
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" ]; then
rm -rf unpack
mkdir -p unpack
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.bz2"
PERLTAR=perl-$PERL_VERSION.tar.bz2
;;
esac
if ! [ -e "$PERLTAR" ]; then
verblock <<EOF
downloading perl
trying to download from $PERLURL
you can configure a download cache directory via DLCACHE
in your .staticperlrc to avoid repeated downloads.
to manually download perl yourself, place a suitable tarball in
$DLCACHE/$PERLTAR
either curl or wget is required for automatic download.
curl is tried first, then wget.
EOF
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 $PERLTAR
mv $PERLTAR~ $PERLTAR
if [ "$DLCACHE" ]; then
mkdir -p "$DLCACHE"
cp $PERLTAR "$DLCACHE"/$PERLTAR~$$~ && \
mv "$DLCACHE"/$PERLTAR~$$~ "$DLCACHE"/$PERLTAR
fi
fi
verblock <<EOF
unpacking perl
EOF
case "$PERLTAR" in
*.xz ) UNCOMPRESS="xz -d" ;;
*.lzma ) UNCOMPRESS="lzma -d" ;;
*.bz2 ) UNCOMPRESS="bzip2 -d" ;;
*.gz ) UNCOMPRESS="gzip -d" ;;
*.tar ) UNCOMPRESS="cat" ;;
* )
fatal "don't know hot to uncompress $PERLTAR,\nonly tar, tar.gz, tar.bz2, tar.lzma and tar.xz are supported."
exit 1
;;
esac
<"$PERLTAR" $UNCOMPRESS -d | ( cd unpack && tar xf - ) \
|| fatal "$PERLTAR: error during unpacking"
if [ -d unpack/*/ ]; then
chmod -R u+w unpack/*/
mv unpack/*/ perl
rmdir -p unpack
else
fatal "unpacking $PERLTAR did not result in a single directory, don't know how to handle this"
fi
rm "$PERLTAR"
fi
) || exit
}
# similar to GNU-sed -i or perl -pi
sedreplace() {
sed -e "$1" <"$2" > "$2~" || fatal "error while running sed"
rm -f "$2"
mv "$2~" "$2"
}
configure_failure() {
cat <<EOF
***
*** Configure failed - see above for the exact error message(s).
***
*** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE
*** flags are not supported by your compiler. Less often, this is because
*** PERL_LIBS either contains a library not available on your system (such as
*** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl).
***
*** You can provide your own flags by creating a ~/.staticperlrc file with
*** variable assignments. For example (these are the actual values used):
***
PERL_CC="$PERL_CC"
PERL_CCFLAGS="$PERL_CCFLAGS"
PERL_OPTIMIZE="$PERL_OPTIMIZE"
PERL_LDFLAGS="$PERL_LDFLAGS"
PERL_LIBS="$PERL_LIBS"
EOF
exit 1
}
configure() {
(
fetch
rcd "$STATICPERL/src/perl"
[ -e staticstamp.configure ] && return
verblock <<EOF
configuring $STATICPERL/src/perl
EOF
rm -f "$PERL_PREFIX/staticstamp.install"
"$MAKE" distclean >/dev/null 2>&1
staticperl.sh view on Meta::CPAN
# trace configure \
sh Configure -Duselargefiles \
-Uuse64bitint \
-Dusemymalloc=n \
-Uusedl \
-Uusethreads \
-Uuseithreads \
-Uusemultiplicity \
-Uusesfio \
-Uuseshrplib \
-Uinstallusrbinperl \
-A ccflags=" $PERL_CCFLAGS" \
-Dcc="$PERL_CC" \
-Doptimize="$PERL_OPTIMIZE" \
-Dldflags="$PERL_LDFLAGS" \
-Dlibs="$PERL_LIBS" \
-Dprefix="$PERL_PREFIX" \
-Dbin="$PERL_PREFIX/bin" \
-Dprivlib="$PERL_PREFIX/lib" \
-Darchlib="$PERL_PREFIX/lib" \
-Uusevendorprefix \
-Dsitelib="$PERL_PREFIX/lib" \
-Dsitearch="$PERL_PREFIX/lib" \
-Uman1dir \
-Uman3dir \
-Usiteman1dir \
-Usiteman3dir \
-Dpager=/usr/bin/less \
-Demail="$EMAIL" \
-Dcf_email="$EMAIL" \
-Dcf_by="$EMAIL" \
$PERL_CONFIGURE \
-Duseperlio \
-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"
: > 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"
verblock <<EOF
building $STATICPERL/src/perl
EOF
rm -f "$PERL_PREFIX/staticstamp.install"
"$MAKE" || fatal "make: error while building perl"
postbuild || fatal "postbuild hook failed"
) || exit
}
_postinstall() {
if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then
NOCHECK_INSTALL=+
instcpan $STATICPERL_MODULES
[ "$EXTRA_MODULES" ] && instcpan $EXTRA_MODULES
postinstall || fatal "postinstall hook failed"
: > "$PERL_PREFIX/staticstamp.postinstall"
fi
}
install() {
(
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then
build
verblock <<EOF
installing $STATICPERL/src/perl
to $PERL_PREFIX
EOF
ln -sf "perl/bin/" "$STATICPERL/bin"
ln -sf "perl/lib/" "$STATICPERL/lib"
mkdir "$STATICPERL/patched"
ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten
rm -rf "$PERL_PREFIX" # by this rm -rf
rcd "$STATICPERL/src/perl"
"$MAKE" install || fatal "make install: error while installing"
rcd "$PERL_PREFIX"
# create a "make install" replacement for CPAN
write_shellscript SP-make-make <<'end_of_make'
#CAT make-make.sh
end_of_make
staticperl.sh view on Meta::CPAN
[ $NOCHECK_INSTALL ] || install
verblock <<EOF
installing modules from source
$*
EOF
for mod in "$@"; do
echo
echo $mod
(
rcd $mod
"$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
}
#############################################################################
# main
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' to build one in a safe location"
}
usage() {
podusage 0
}
catmkbundle() {
{
read dummy
echo "#!$PERL_PREFIX/bin/perl"
cat
} <<'end_of_mkbundle'
#CAT 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"
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 "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create"
command="${1#--}"; shift
case "$command" in
version )
echo "staticperl version $VERSION"
;;
fetch | configure | build | install | clean | realclean | distclean )
( "$command" ) || exit
;;
import )
( import "$1" ) || exit
shift
;;
instsrc )
( instsrc "$@" ) || exit
exit
;;
instcpan )
( instcpan "$@" ) || exit
exit
;;
perl )
( install ) || exit
exec "$PERL_PREFIX/bin/perl" "$@"
exit
;;
cpan )
( install ) || exit
PERL="$PERL_PREFIX/bin/perl"
export PERL
exec "$PERL_PREFIX/bin/cpan" "$@"
exit
;;
mkbundle )
( install ) || exit
bundle "$@"
exit
;;
mkperl )
( install ) || exit
bundle --perl "$@"
exit
;;
mkapp )
( install ) || exit
bundle --app "$@"
exit
;;
help )
podusage 2
;;
( run in 1.045 second using v1.01-cache-2.11-cpan-39bf76dae61 )