| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
############################################################################# |
| 4 |
# configuration to fill in (or to replace in your .staticperlrc) |
| 5 |
|
| 6 |
STATICPERL=~/.staticperl |
| 7 |
CPAN=https://mirror.netcologne.de/cpan # which mirror to use |
| 8 |
BACKPAN=https://backpan.perl.org/ |
| 9 |
EMAIL="read the documentation <rtfm@example.org>" |
| 10 |
DLCACHE= |
| 11 |
|
| 12 |
# perl build variables |
| 13 |
MAKE=make |
| 14 |
PERL_VERSION=http://stableperl.schmorp.de/dist/latest.tar.gz # 5.12.5 and 5.8.9 are good choices for small builds |
| 15 |
PERL_CC=cc |
| 16 |
PERL_CONFIGURE="" # additional Configure arguments |
| 17 |
PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG" |
| 18 |
PERL_OPTIMIZE="-Os" # -Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" |
| 19 |
|
| 20 |
ARCH="$(uname -m)" |
| 21 |
|
| 22 |
#case "$ARCH" in |
| 23 |
# i*86 | x86_64 | amd64 ) |
| 24 |
# PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 |
| 25 |
# case "$ARCH" in |
| 26 |
# i*86 ) |
| 27 |
# PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only |
| 28 |
# ;; |
| 29 |
# esac |
| 30 |
# ;; |
| 31 |
#esac |
| 32 |
|
| 33 |
# -Wl,--gc-sections makes it impossible to check for undefined references |
| 34 |
# for some reason so we need to patch away the "-no" after Configure and before make :/ |
| 35 |
# --allow-multiple-definition exists to work around uclibc's pthread static linking bug |
| 36 |
#PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition" |
| 37 |
PERL_LDFLAGS= |
| 38 |
PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself |
| 39 |
|
| 40 |
# some configuration options for modules |
| 41 |
PERL_MM_USE_DEFAULT=1 |
| 42 |
PERL_MM_OPT="MAN1PODS= MAN3PODS=" |
| 43 |
#CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow |
| 44 |
#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' |
| 45 |
export PERL_MM_USE_DEFAULT PERL_MM_OPT |
| 46 |
|
| 47 |
# which extra modules to install by default from CPAN that are |
| 48 |
# required by mkbundle |
| 49 |
STATICPERL_MODULES="ExtUtils::MakeMaker ExtUtils::CBuilder common::sense Pod::Strip PPI PPI::XS Pod::Usage" |
| 50 |
|
| 51 |
# which extra modules you might want to install |
| 52 |
EXTRA_MODULES="" |
| 53 |
|
| 54 |
# overridable functions |
| 55 |
preconfigure() { : ; } |
| 56 |
patchconfig() { : ; } |
| 57 |
postconfigure() { : ; } |
| 58 |
postbuild() { : ; } |
| 59 |
postcpanconfig() { : ; } |
| 60 |
postinstall() { : ; } |
| 61 |
|
| 62 |
# now source user config, if any |
| 63 |
if [ "$STATICPERLRC" ]; then |
| 64 |
. "$STATICPERLRC" |
| 65 |
else |
| 66 |
[ -r /etc/staticperlrc ] && . /etc/staticperlrc |
| 67 |
[ -r ~/.staticperlrc ] && . ~/.staticperlrc |
| 68 |
[ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" |
| 69 |
fi |
| 70 |
|
| 71 |
############################################################################# |
| 72 |
# support |
| 73 |
|
| 74 |
# work around ExtUtils::CBuilder and others |
| 75 |
export CC="$PERL_CC" |
| 76 |
export CFLAGS="$PERL_CFLAGS" |
| 77 |
export LD="$PERL_CC" |
| 78 |
export LDFLAGS="$PERL_LDFLAGS" |
| 79 |
unset LIBS |
| 80 |
|
| 81 |
PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed |
| 82 |
|
| 83 |
unset PERL PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO PERLIO_DEBUG PERL_MB_OPT |
| 84 |
LC_ALL=C; export LC_ALL # just to be on the safe side |
| 85 |
|
| 86 |
# prepend PATH - not required by staticperl itself, but might make |
| 87 |
# life easier when working in e.g. "staticperl cpan / look" |
| 88 |
PATH="$PERL_PREFIX/perl/bin:$PATH" |
| 89 |
|
| 90 |
# set version in a way that Makefile.PL can extract |
| 91 |
VERSION=VERSION; eval \ |
| 92 |
$VERSION="1.5" |
| 93 |
|
| 94 |
fatal() { |
| 95 |
printf -- "\nFATAL: %s\n\n" "$*" >&2 |
| 96 |
exit 1 |
| 97 |
} |
| 98 |
|
| 99 |
verbose() { |
| 100 |
printf -- "%s\n" "$*" |
| 101 |
} |
| 102 |
|
| 103 |
verblock() { |
| 104 |
verbose |
| 105 |
verbose "***" |
| 106 |
while read line; do |
| 107 |
verbose "*** $line" |
| 108 |
done |
| 109 |
verbose "***" |
| 110 |
verbose |
| 111 |
} |
| 112 |
|
| 113 |
rcd() { |
| 114 |
cd "$1" || fatal "$1: cannot enter" |
| 115 |
} |
| 116 |
|
| 117 |
trace() { |
| 118 |
prefix="$1"; shift |
| 119 |
# "$@" 2>&1 | while read line; do |
| 120 |
# echo "$prefix: $line" |
| 121 |
# done |
| 122 |
"$@" |
| 123 |
} |
| 124 |
|
| 125 |
download() { |
| 126 |
url="$1" |
| 127 |
file="$2" |
| 128 |
|
| 129 |
rm -f "$file~" # just to be on the safe side |
| 130 |
if [ "$DLCACHE" ] && cp "$DLCACHE/$file" "$file~" >/dev/null 2>&1; then |
| 131 |
verbose "found $file in \$DLCACHE" |
| 132 |
rm -f "$file"; mv "$file~" "$file" |
| 133 |
return |
| 134 |
fi |
| 135 |
|
| 136 |
wget -O "$file~" "$url" \ |
| 137 |
|| curl -f >"$file~" "$url" \ |
| 138 |
|| fatal "$url: unable to download" |
| 139 |
|
| 140 |
rm -f "$file"; mv "$file~" "$file" |
| 141 |
|
| 142 |
if [ "$DLCACHE" ]; then |
| 143 |
mkdir -p "$DLCACHE" |
| 144 |
cp "$file" "$DLCACHE/$file~$$~" && \ |
| 145 |
mv "$DLCACHE/$file~$$~" "$DLCACHE/$file" |
| 146 |
fi |
| 147 |
} |
| 148 |
|
| 149 |
trap wait 0 |
| 150 |
|
| 151 |
############################################################################# |
| 152 |
# clean |
| 153 |
|
| 154 |
distclean() { |
| 155 |
verblock <<EOF |
| 156 |
deleting everything installed by this script (rm -rf $STATICPERL) |
| 157 |
EOF |
| 158 |
|
| 159 |
rm -rf "$STATICPERL" |
| 160 |
} |
| 161 |
|
| 162 |
############################################################################# |
| 163 |
# download/configure/compile/install perl |
| 164 |
|
| 165 |
clean() { |
| 166 |
rm -rf "$STATICPERL/src" |
| 167 |
} |
| 168 |
|
| 169 |
realclean() { |
| 170 |
rm -f "$PERL_PREFIX/staticstamp.postinstall" |
| 171 |
rm -f "$PERL_PREFIX/staticstamp.install" |
| 172 |
rm -f "$STATICPERL/src/perl/staticstamp.configure" |
| 173 |
} |
| 174 |
|
| 175 |
fetch() { |
| 176 |
( |
| 177 |
rcd "$STATICPERL" |
| 178 |
|
| 179 |
mkdir -p src |
| 180 |
rcd src |
| 181 |
|
| 182 |
if ! [ -d "perl" ]; then |
| 183 |
rm -rf unpack |
| 184 |
mkdir -p unpack |
| 185 |
|
| 186 |
case "$PERL_VERSION" in |
| 187 |
*:* ) |
| 188 |
# url |
| 189 |
PERLURL="$PERL_VERSION" |
| 190 |
PERLTAR="$(basename -- "$PERL_VERSION")" |
| 191 |
;; |
| 192 |
/* ) |
| 193 |
# directory |
| 194 |
verbose "copying $PERL_VERSION" |
| 195 |
cp -Rp "$PERL_VERSION/." unpack/. |
| 196 |
chmod -R u+w unpack |
| 197 |
mv unpack perl |
| 198 |
return |
| 199 |
;; |
| 200 |
* ) |
| 201 |
PERLURL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.gz" |
| 202 |
PERLTAR=perl-$PERL_VERSION.tar.gz |
| 203 |
;; |
| 204 |
esac |
| 205 |
|
| 206 |
if ! [ -e "$PERLTAR" ]; then |
| 207 |
verblock <<EOF |
| 208 |
downloading perl |
| 209 |
|
| 210 |
trying to download from $PERLURL |
| 211 |
|
| 212 |
you can configure a download cache directory via DLCACHE |
| 213 |
in your .staticperlrc to avoid repeated downloads. |
| 214 |
|
| 215 |
to manually download perl yourself, place a suitable tarball in |
| 216 |
$DLCACHE/$PERLTAR |
| 217 |
|
| 218 |
either curl or wget is required for automatic download. |
| 219 |
curl is tried first, then wget. |
| 220 |
EOF |
| 221 |
|
| 222 |
download "$PERLURL" "$PERLTAR" |
| 223 |
fi |
| 224 |
|
| 225 |
verblock <<EOF |
| 226 |
unpacking perl |
| 227 |
EOF |
| 228 |
|
| 229 |
case "$PERLTAR" in |
| 230 |
*.xz ) UNCOMPRESS="xz -d" ;; |
| 231 |
*.lzma ) UNCOMPRESS="lzma -d" ;; |
| 232 |
*.bz2 ) UNCOMPRESS="bzip2 -d" ;; |
| 233 |
*.gz ) UNCOMPRESS="gzip -d" ;; |
| 234 |
*.tar ) UNCOMPRESS="cat" ;; |
| 235 |
* ) |
| 236 |
fatal "don't know hot to uncompress $PERLTAR,\nonly tar, tar.gz, tar.bz2, tar.lzma and tar.xz are supported." |
| 237 |
exit 1 |
| 238 |
;; |
| 239 |
esac |
| 240 |
|
| 241 |
<"$PERLTAR" $UNCOMPRESS -d | ( cd unpack && tar xf - ) \ |
| 242 |
|| fatal "$PERLTAR: error during unpacking" |
| 243 |
|
| 244 |
if [ -d unpack/*/ ]; then |
| 245 |
chmod -R u+w unpack/*/ |
| 246 |
mv unpack/*/ perl |
| 247 |
rmdir -p unpack |
| 248 |
else |
| 249 |
fatal "unpacking $PERLTAR did not result in a single directory, don't know how to handle this" |
| 250 |
fi |
| 251 |
|
| 252 |
rm "$PERLTAR" |
| 253 |
fi |
| 254 |
) || exit |
| 255 |
} |
| 256 |
|
| 257 |
# similar to GNU-sed -i or perl -pi |
| 258 |
sedreplace() { |
| 259 |
sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
| 260 |
rm -f "$2" |
| 261 |
mv "$2~" "$2" |
| 262 |
} |
| 263 |
|
| 264 |
configure_failure() { |
| 265 |
cat <<EOF |
| 266 |
|
| 267 |
|
| 268 |
*** |
| 269 |
*** Configure failed - see above for the exact error message(s). |
| 270 |
*** |
| 271 |
*** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE |
| 272 |
*** flags are not supported by your compiler. Less often, this is because |
| 273 |
*** PERL_LIBS either contains a library not available on your system (such as |
| 274 |
*** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl). |
| 275 |
*** |
| 276 |
*** You can provide your own flags by creating a ~/.staticperlrc file with |
| 277 |
*** variable assignments. For example (these are the actual values used): |
| 278 |
*** |
| 279 |
|
| 280 |
PERL_CC="$PERL_CC" |
| 281 |
PERL_CCFLAGS="$PERL_CCFLAGS" |
| 282 |
PERL_OPTIMIZE="$PERL_OPTIMIZE" |
| 283 |
PERL_LDFLAGS="$PERL_LDFLAGS" |
| 284 |
PERL_LIBS="$PERL_LIBS" |
| 285 |
|
| 286 |
EOF |
| 287 |
exit 1 |
| 288 |
} |
| 289 |
|
| 290 |
configure() { |
| 291 |
( |
| 292 |
fetch |
| 293 |
|
| 294 |
rcd "$STATICPERL/src/perl" |
| 295 |
|
| 296 |
[ -e staticstamp.configure ] && return |
| 297 |
|
| 298 |
verblock <<EOF |
| 299 |
configuring $STATICPERL/src/perl |
| 300 |
EOF |
| 301 |
|
| 302 |
rm -f "$PERL_PREFIX/staticstamp.install" |
| 303 |
|
| 304 |
"$MAKE" distclean >/dev/null 2>&1 |
| 305 |
|
| 306 |
sedreplace '/^#define SITELIB/d' config_h.SH |
| 307 |
|
| 308 |
# I hate them for this |
| 309 |
grep -q -- -fstack-protector Configure && \ |
| 310 |
sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
| 311 |
|
| 312 |
# what did that bloke think |
| 313 |
grep -q -- usedl=.define hints/darwin.sh && \ |
| 314 |
sedreplace '/^usedl=.define.;$/d' hints/darwin.sh |
| 315 |
|
| 316 |
preconfigure || fatal "preconfigure hook failed" |
| 317 |
|
| 318 |
# trace configure \ |
| 319 |
sh Configure -Duselargefiles \ |
| 320 |
-Uuse64bitint \ |
| 321 |
-Dusemymalloc=n \ |
| 322 |
-Uusedl \ |
| 323 |
-Uusethreads \ |
| 324 |
-Uuseithreads \ |
| 325 |
-Uusemultiplicity \ |
| 326 |
-Uusesfio \ |
| 327 |
-Uuseshrplib \ |
| 328 |
-Uinstallusrbinperl \ |
| 329 |
-A ccflags=" $PERL_CCFLAGS" \ |
| 330 |
-Dcc="$PERL_CC" \ |
| 331 |
-Doptimize="$PERL_OPTIMIZE" \ |
| 332 |
-Dldflags="$PERL_LDFLAGS" \ |
| 333 |
-Dlibs="$PERL_LIBS" \ |
| 334 |
-Dprefix="$PERL_PREFIX" \ |
| 335 |
-Dbin="$PERL_PREFIX/bin" \ |
| 336 |
-Dprivlib="$PERL_PREFIX/lib" \ |
| 337 |
-Darchlib="$PERL_PREFIX/lib" \ |
| 338 |
-Uusevendorprefix \ |
| 339 |
-Dsitelib="$PERL_PREFIX/lib" \ |
| 340 |
-Dsitearch="$PERL_PREFIX/lib" \ |
| 341 |
-Uman1dir \ |
| 342 |
-Uman3dir \ |
| 343 |
-Usiteman1dir \ |
| 344 |
-Usiteman3dir \ |
| 345 |
-Dpager=/usr/bin/less \ |
| 346 |
-Demail="$EMAIL" \ |
| 347 |
-Dcf_email="$EMAIL" \ |
| 348 |
-Dcf_by="$EMAIL" \ |
| 349 |
$PERL_CONFIGURE \ |
| 350 |
-Duseperlio \ |
| 351 |
-Uversiononly \ |
| 352 |
-dE || configure_failure |
| 353 |
|
| 354 |
sedreplace ' |
| 355 |
s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
| 356 |
s/ *-fno-stack-protector */ /g |
| 357 |
' config.sh |
| 358 |
|
| 359 |
patchconfig || fatal "patchconfig hook failed" |
| 360 |
|
| 361 |
sh Configure -S || fatal "Configure -S failed" |
| 362 |
|
| 363 |
postconfigure || fatal "postconfigure hook failed" |
| 364 |
|
| 365 |
: > staticstamp.configure |
| 366 |
) || exit |
| 367 |
} |
| 368 |
|
| 369 |
write_shellscript() { |
| 370 |
{ |
| 371 |
echo "#!/bin/sh" |
| 372 |
echo "STATICPERL=\"$STATICPERL\"" |
| 373 |
echo "PERL_PREFIX=\"$PERL_PREFIX\"" |
| 374 |
echo "MAKE=\"$MAKE\"" |
| 375 |
cat |
| 376 |
} >"$PERL_PREFIX/bin/$1" |
| 377 |
chmod 755 "$PERL_PREFIX/bin/$1" |
| 378 |
} |
| 379 |
|
| 380 |
build() { |
| 381 |
( |
| 382 |
configure |
| 383 |
|
| 384 |
rcd "$STATICPERL/src/perl" |
| 385 |
|
| 386 |
verblock <<EOF |
| 387 |
building $STATICPERL/src/perl |
| 388 |
EOF |
| 389 |
|
| 390 |
rm -f "$PERL_PREFIX/staticstamp.install" |
| 391 |
|
| 392 |
"$MAKE" || fatal "make: error while building perl" |
| 393 |
|
| 394 |
postbuild || fatal "postbuild hook failed" |
| 395 |
) || exit |
| 396 |
} |
| 397 |
|
| 398 |
_postinstall() { |
| 399 |
if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then |
| 400 |
NOCHECK_INSTALL=+ |
| 401 |
instcpan $STATICPERL_MODULES |
| 402 |
[ "$EXTRA_MODULES" ] && instcpan $EXTRA_MODULES |
| 403 |
|
| 404 |
postinstall || fatal "postinstall hook failed" |
| 405 |
|
| 406 |
: > "$PERL_PREFIX/staticstamp.postinstall" |
| 407 |
fi |
| 408 |
} |
| 409 |
|
| 410 |
install() { |
| 411 |
( |
| 412 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
| 413 |
build |
| 414 |
|
| 415 |
verblock <<EOF |
| 416 |
installing $STATICPERL/src/perl |
| 417 |
to $PERL_PREFIX |
| 418 |
EOF |
| 419 |
|
| 420 |
ln -sf "perl/bin/" "$STATICPERL/bin" |
| 421 |
ln -sf "perl/lib/" "$STATICPERL/lib" |
| 422 |
|
| 423 |
mkdir "$STATICPERL/patched" |
| 424 |
|
| 425 |
ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten |
| 426 |
rm -rf "$PERL_PREFIX" # by this rm -rf |
| 427 |
|
| 428 |
rcd "$STATICPERL/src/perl" |
| 429 |
|
| 430 |
"$MAKE" install || fatal "make install: error while installing" |
| 431 |
|
| 432 |
rcd "$PERL_PREFIX" |
| 433 |
|
| 434 |
# create a "make install" replacement for CPAN |
| 435 |
write_shellscript SP-make-make <<'end_of_make' |
| 436 |
#CAT make-make.sh |
| 437 |
end_of_make |
| 438 |
|
| 439 |
# create a "make install" replacement for CPAN |
| 440 |
write_shellscript SP-make-install-make <<'end_of_make_install_make' |
| 441 |
#CAT make-install-make.sh |
| 442 |
end_of_make_install_make |
| 443 |
|
| 444 |
# create a "patch modules" helper |
| 445 |
write_shellscript SP-patch-postinstall <<'end_of_patch_postinstall' |
| 446 |
#CAT patch-postinstall.sh |
| 447 |
end_of_patch_postinstall |
| 448 |
|
| 449 |
# immediately use it |
| 450 |
"$PERL_PREFIX/bin/SP-patch-postinstall" |
| 451 |
|
| 452 |
# help to trick CPAN into avoiding ~/.cpan completely |
| 453 |
echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
| 454 |
|
| 455 |
# we call cpan with -MCPAN::MyConfig in this script, which |
| 456 |
# is strictly unnecessary as we have to patch CPAN anyway, |
| 457 |
# so consider it "for good measure". |
| 458 |
"$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' |
| 459 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
| 460 |
CPAN::Shell->o (conf => urllist => push => "'"$BACKPAN"'"); |
| 461 |
CPAN::Shell->o (conf => pushy_https => "0"); |
| 462 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
| 463 |
CPAN::Shell->o (conf => q<init>); |
| 464 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
| 465 |
CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
| 466 |
CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
| 467 |
CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
| 468 |
CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
| 469 |
CPAN::Shell->o (conf => q<makepl_arg>, "MAP_TARGET=perl"); |
| 470 |
CPAN::Shell->o (conf => q<make>, "'"$PERL_PREFIX"'/bin/SP-make-make"); |
| 471 |
CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/SP-make-install-make"); |
| 472 |
CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
| 473 |
CPAN::Shell->o (conf => q<build_requires_install_policy>, q<yes>); |
| 474 |
CPAN::Shell->o (conf => q<recommends_policy>, q<0>); |
| 475 |
CPAN::Shell->o (conf => q<suggests_policy>, q<0>); |
| 476 |
CPAN::Shell->o (conf => q<prefer_installer>, q<EUMM>); |
| 477 |
CPAN::Shell->o (conf => q<commit>); |
| 478 |
' || fatal "error while initialising CPAN" |
| 479 |
|
| 480 |
postcpanconfig |
| 481 |
|
| 482 |
: > "$PERL_PREFIX/staticstamp.install" |
| 483 |
fi |
| 484 |
|
| 485 |
_postinstall |
| 486 |
) || exit |
| 487 |
} |
| 488 |
|
| 489 |
import() { |
| 490 |
( |
| 491 |
IMPORT="$1" |
| 492 |
|
| 493 |
rcd "$STATICPERL" |
| 494 |
|
| 495 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
| 496 |
verblock <<EOF |
| 497 |
import perl from $IMPORT to $STATICPERL |
| 498 |
EOF |
| 499 |
|
| 500 |
rm -rf bin cpan lib patched perl src |
| 501 |
mkdir -m 755 perl perl/bin |
| 502 |
ln -s perl/bin/ bin |
| 503 |
ln -s "$IMPORT" perl/bin/ |
| 504 |
|
| 505 |
echo "$IMPORT" > "$PERL_PREFIX/.import" |
| 506 |
|
| 507 |
: > "$PERL_PREFIX/staticstamp.install" |
| 508 |
fi |
| 509 |
|
| 510 |
_postinstall |
| 511 |
) || exit |
| 512 |
} |
| 513 |
|
| 514 |
############################################################################# |
| 515 |
# install a module from CPAN |
| 516 |
|
| 517 |
instcpan() { |
| 518 |
[ $NOCHECK_INSTALL ] || install |
| 519 |
|
| 520 |
verblock <<EOF |
| 521 |
installing modules from CPAN |
| 522 |
$* |
| 523 |
EOF |
| 524 |
|
| 525 |
MYCONFIG= |
| 526 |
[ -e "$PERL_PREFIX/.import" ] || MYCONFIG=-MCPAN::MyConfig |
| 527 |
|
| 528 |
"$PERL_PREFIX"/bin/perl $MYCONFIG -MCPAN -e 'notest (install => $_) for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log" |
| 529 |
|
| 530 |
if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then |
| 531 |
fatal "failure while installing modules from CPAN ($*)" |
| 532 |
fi |
| 533 |
rm -f "$STATICPERL/instcpan.log" |
| 534 |
} |
| 535 |
|
| 536 |
############################################################################# |
| 537 |
# install a module from unpacked sources, archive, or url |
| 538 |
|
| 539 |
instsrc() { |
| 540 |
[ $NOCHECK_INSTALL ] || install |
| 541 |
|
| 542 |
verblock <<EOF |
| 543 |
installing modules from source |
| 544 |
$* |
| 545 |
EOF |
| 546 |
|
| 547 |
for mod in "$@"; do |
| 548 |
echo |
| 549 |
echo $mod |
| 550 |
( |
| 551 |
rcd $mod |
| 552 |
"$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 |
| 553 |
"$MAKE" distclean >/dev/null 2>&1 |
| 554 |
"$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
| 555 |
"$MAKE" || fatal "$mod: error building module" |
| 556 |
"$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module" |
| 557 |
"$MAKE" distclean >/dev/null 2>&1 |
| 558 |
exit 0 |
| 559 |
) || exit $? |
| 560 |
done |
| 561 |
} |
| 562 |
|
| 563 |
instdist() { |
| 564 |
for distfile in "$@"; do |
| 565 |
( |
| 566 |
TDIR=$(mktemp -d -p /var/tmp staticperl-instdist-XXXXXX) |
| 567 |
trap 'rm -rf "$TDIR"' 0 INT TERM |
| 568 |
|
| 569 |
verbose "unpacking archive $file" |
| 570 |
tar xfC "$distfile" "$TDIR" |
| 571 |
|
| 572 |
rcd "$TDIR" |
| 573 |
instsrc ./*/ |
| 574 |
) |
| 575 |
done |
| 576 |
} |
| 577 |
|
| 578 |
insturl() { |
| 579 |
for url in "$@"; do |
| 580 |
( |
| 581 |
TDIR=$(mktemp -d -p /var/tmp staticperl-insturl-XXXXXX) |
| 582 |
trap 'rm -rf "$TDIR"' 0 INT TERM |
| 583 |
|
| 584 |
rcd "$TDIR" |
| 585 |
file="$(basename -- "$url")" |
| 586 |
verbose "downloading $url to $file" |
| 587 |
download "$url" "$file" |
| 588 |
instdist "$file" |
| 589 |
) |
| 590 |
done |
| 591 |
} |
| 592 |
|
| 593 |
############################################################################# |
| 594 |
# main |
| 595 |
|
| 596 |
podusage() { |
| 597 |
echo |
| 598 |
|
| 599 |
if [ -e "$PERL_PREFIX/bin/perl" ]; then |
| 600 |
"$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
| 601 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
| 602 |
2>/dev/null && exit |
| 603 |
fi |
| 604 |
|
| 605 |
# try whatever perl we can find |
| 606 |
perl -MPod::Usage -e \ |
| 607 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
| 608 |
2>/dev/null && exit |
| 609 |
|
| 610 |
fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" |
| 611 |
} |
| 612 |
|
| 613 |
usage() { |
| 614 |
podusage 0 |
| 615 |
} |
| 616 |
|
| 617 |
catmkbundle() { |
| 618 |
{ |
| 619 |
read dummy |
| 620 |
echo "#!$PERL_PREFIX/bin/perl" |
| 621 |
cat |
| 622 |
} <<'end_of_mkbundle' |
| 623 |
#CAT mkbundle |
| 624 |
end_of_mkbundle |
| 625 |
} |
| 626 |
|
| 627 |
bundle() { |
| 628 |
MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" |
| 629 |
catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
| 630 |
chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
| 631 |
CACHE="$STATICPERL/cache" |
| 632 |
mkdir -p "$CACHE" |
| 633 |
"$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" |
| 634 |
} |
| 635 |
|
| 636 |
if [ $# -gt 0 ]; then |
| 637 |
while [ $# -gt 0 ]; do |
| 638 |
mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
| 639 |
mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
| 640 |
|
| 641 |
command="${1#--}"; shift |
| 642 |
case "$command" in |
| 643 |
version ) |
| 644 |
echo "staticperl version $VERSION" |
| 645 |
;; |
| 646 |
fetch | configure | build | install | clean | realclean | distclean ) |
| 647 |
( "$command" ) || exit |
| 648 |
;; |
| 649 |
import ) |
| 650 |
( import "$1" ) || exit |
| 651 |
shift |
| 652 |
;; |
| 653 |
instsrc ) |
| 654 |
( instsrc "$@" ) || exit |
| 655 |
exit |
| 656 |
;; |
| 657 |
instcpan ) |
| 658 |
( instcpan "$@" ) || exit |
| 659 |
exit |
| 660 |
;; |
| 661 |
instdist ) |
| 662 |
( instdist "$@" ) || exit |
| 663 |
exit |
| 664 |
;; |
| 665 |
insturl ) |
| 666 |
( insturl "$@" ) || exit |
| 667 |
exit |
| 668 |
;; |
| 669 |
perl ) |
| 670 |
( install ) || exit |
| 671 |
exec "$PERL_PREFIX/bin/perl" "$@" |
| 672 |
exit |
| 673 |
;; |
| 674 |
cpan ) |
| 675 |
( install ) || exit |
| 676 |
PERL="$PERL_PREFIX/bin/perl" |
| 677 |
export PERL |
| 678 |
exec "$PERL_PREFIX/bin/cpan" "$@" |
| 679 |
exit |
| 680 |
;; |
| 681 |
mkbundle ) |
| 682 |
( install ) || exit |
| 683 |
bundle "$@" |
| 684 |
exit |
| 685 |
;; |
| 686 |
mkperl ) |
| 687 |
( install ) || exit |
| 688 |
bundle --perl "$@" |
| 689 |
exit |
| 690 |
;; |
| 691 |
mkapp ) |
| 692 |
( install ) || exit |
| 693 |
bundle --app "$@" |
| 694 |
exit |
| 695 |
;; |
| 696 |
help ) |
| 697 |
podusage 2 |
| 698 |
;; |
| 699 |
* ) |
| 700 |
exec 1>&2 |
| 701 |
echo |
| 702 |
echo "Unknown command: $command" |
| 703 |
podusage 0 |
| 704 |
;; |
| 705 |
esac |
| 706 |
done |
| 707 |
else |
| 708 |
usage |
| 709 |
fi |
| 710 |
|
| 711 |
exit 0 |
| 712 |
|
| 713 |
#CAT staticperl.pod |
| 714 |
|