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.46" |
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 |
trap wait 0 |
126 |
|
127 |
############################################################################# |
128 |
# clean |
129 |
|
130 |
distclean() { |
131 |
verblock <<EOF |
132 |
deleting everything installed by this script (rm -rf $STATICPERL) |
133 |
EOF |
134 |
|
135 |
rm -rf "$STATICPERL" |
136 |
} |
137 |
|
138 |
############################################################################# |
139 |
# download/configure/compile/install perl |
140 |
|
141 |
clean() { |
142 |
rm -rf "$STATICPERL/src" |
143 |
} |
144 |
|
145 |
realclean() { |
146 |
rm -f "$PERL_PREFIX/staticstamp.postinstall" |
147 |
rm -f "$PERL_PREFIX/staticstamp.install" |
148 |
rm -f "$STATICPERL/src/perl/staticstamp.configure" |
149 |
} |
150 |
|
151 |
fetch() { |
152 |
( |
153 |
rcd "$STATICPERL" |
154 |
|
155 |
mkdir -p src |
156 |
rcd src |
157 |
|
158 |
if ! [ -d "perl" ]; then |
159 |
rm -rf unpack |
160 |
mkdir -p unpack |
161 |
|
162 |
case "$PERL_VERSION" in |
163 |
*:* ) |
164 |
# url |
165 |
PERLURL="$PERL_VERSION" |
166 |
PERLTAR="$(basename "$PERL_VERSION")" |
167 |
;; |
168 |
/* ) |
169 |
# directory |
170 |
verbose "copying $PERL_VERSION" |
171 |
cp -Rp "$PERL_VERSION/." unpack/. |
172 |
chmod -R u+w unpack |
173 |
mv unpack perl |
174 |
return |
175 |
;; |
176 |
* ) |
177 |
PERLURL="$CPAN/src/5.0/perl-$PERL_VERSION.tar.gz" |
178 |
PERLTAR=perl-$PERL_VERSION.tar.gz |
179 |
;; |
180 |
esac |
181 |
|
182 |
if ! [ -e "$PERLTAR" ]; then |
183 |
verblock <<EOF |
184 |
downloading perl |
185 |
|
186 |
trying to download from $PERLURL |
187 |
|
188 |
you can configure a download cache directory via DLCACHE |
189 |
in your .staticperlrc to avoid repeated downloads. |
190 |
|
191 |
to manually download perl yourself, place a suitable tarball in |
192 |
$DLCACHE/$PERLTAR |
193 |
|
194 |
either curl or wget is required for automatic download. |
195 |
curl is tried first, then wget. |
196 |
EOF |
197 |
|
198 |
rm -f $PERLTAR~ # just to be on the safe side |
199 |
{ [ "$DLCACHE" ] && cp "$DLCACHE"/$PERLTAR $PERLTAR~ >/dev/null 2>&1; } \ |
200 |
|| wget -O $PERLTAR~ "$PERLURL" \ |
201 |
|| curl -f >$PERLTAR~ "$PERLURL" \ |
202 |
|| fatal "$URL: unable to download" |
203 |
rm -f $PERLTAR |
204 |
mv $PERLTAR~ $PERLTAR |
205 |
if [ "$DLCACHE" ]; then |
206 |
mkdir -p "$DLCACHE" |
207 |
cp $PERLTAR "$DLCACHE"/$PERLTAR~$$~ && \ |
208 |
mv "$DLCACHE"/$PERLTAR~$$~ "$DLCACHE"/$PERLTAR |
209 |
fi |
210 |
fi |
211 |
|
212 |
verblock <<EOF |
213 |
unpacking perl |
214 |
EOF |
215 |
|
216 |
case "$PERLTAR" in |
217 |
*.xz ) UNCOMPRESS="xz -d" ;; |
218 |
*.lzma ) UNCOMPRESS="lzma -d" ;; |
219 |
*.bz2 ) UNCOMPRESS="bzip2 -d" ;; |
220 |
*.gz ) UNCOMPRESS="gzip -d" ;; |
221 |
*.tar ) UNCOMPRESS="cat" ;; |
222 |
* ) |
223 |
fatal "don't know hot to uncompress $PERLTAR,\nonly tar, tar.gz, tar.bz2, tar.lzma and tar.xz are supported." |
224 |
exit 1 |
225 |
;; |
226 |
esac |
227 |
|
228 |
<"$PERLTAR" $UNCOMPRESS -d | ( cd unpack && tar xf - ) \ |
229 |
|| fatal "$PERLTAR: error during unpacking" |
230 |
|
231 |
if [ -d unpack/*/ ]; then |
232 |
chmod -R u+w unpack/*/ |
233 |
mv unpack/*/ perl |
234 |
rmdir -p unpack |
235 |
else |
236 |
fatal "unpacking $PERLTAR did not result in a single directory, don't know how to handle this" |
237 |
fi |
238 |
|
239 |
rm "$PERLTAR" |
240 |
fi |
241 |
) || exit |
242 |
} |
243 |
|
244 |
# similar to GNU-sed -i or perl -pi |
245 |
sedreplace() { |
246 |
sed -e "$1" <"$2" > "$2~" || fatal "error while running sed" |
247 |
rm -f "$2" |
248 |
mv "$2~" "$2" |
249 |
} |
250 |
|
251 |
configure_failure() { |
252 |
cat <<EOF |
253 |
|
254 |
|
255 |
*** |
256 |
*** Configure failed - see above for the exact error message(s). |
257 |
*** |
258 |
*** Most commonly, this is because the default PERL_CCFLAGS or PERL_OPTIMIZE |
259 |
*** flags are not supported by your compiler. Less often, this is because |
260 |
*** PERL_LIBS either contains a library not available on your system (such as |
261 |
*** -lcrypt), or because it lacks a required library (e.g. -lsocket or -lnsl). |
262 |
*** |
263 |
*** You can provide your own flags by creating a ~/.staticperlrc file with |
264 |
*** variable assignments. For example (these are the actual values used): |
265 |
*** |
266 |
|
267 |
PERL_CC="$PERL_CC" |
268 |
PERL_CCFLAGS="$PERL_CCFLAGS" |
269 |
PERL_OPTIMIZE="$PERL_OPTIMIZE" |
270 |
PERL_LDFLAGS="$PERL_LDFLAGS" |
271 |
PERL_LIBS="$PERL_LIBS" |
272 |
|
273 |
EOF |
274 |
exit 1 |
275 |
} |
276 |
|
277 |
configure() { |
278 |
( |
279 |
fetch |
280 |
|
281 |
rcd "$STATICPERL/src/perl" |
282 |
|
283 |
[ -e staticstamp.configure ] && return |
284 |
|
285 |
verblock <<EOF |
286 |
configuring $STATICPERL/src/perl |
287 |
EOF |
288 |
|
289 |
rm -f "$PERL_PREFIX/staticstamp.install" |
290 |
|
291 |
"$MAKE" distclean >/dev/null 2>&1 |
292 |
|
293 |
sedreplace '/^#define SITELIB/d' config_h.SH |
294 |
|
295 |
# I hate them for this |
296 |
grep -q -- -fstack-protector Configure && \ |
297 |
sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure |
298 |
|
299 |
# what did that bloke think |
300 |
grep -q -- usedl=.define hints/darwin.sh && \ |
301 |
sedreplace '/^usedl=.define.;$/d' hints/darwin.sh |
302 |
|
303 |
preconfigure || fatal "preconfigure hook failed" |
304 |
|
305 |
# trace configure \ |
306 |
sh Configure -Duselargefiles \ |
307 |
-Uuse64bitint \ |
308 |
-Dusemymalloc=n \ |
309 |
-Uusedl \ |
310 |
-Uusethreads \ |
311 |
-Uuseithreads \ |
312 |
-Uusemultiplicity \ |
313 |
-Uusesfio \ |
314 |
-Uuseshrplib \ |
315 |
-Uinstallusrbinperl \ |
316 |
-A ccflags=" $PERL_CCFLAGS" \ |
317 |
-Dcc="$PERL_CC" \ |
318 |
-Doptimize="$PERL_OPTIMIZE" \ |
319 |
-Dldflags="$PERL_LDFLAGS" \ |
320 |
-Dlibs="$PERL_LIBS" \ |
321 |
-Dprefix="$PERL_PREFIX" \ |
322 |
-Dbin="$PERL_PREFIX/bin" \ |
323 |
-Dprivlib="$PERL_PREFIX/lib" \ |
324 |
-Darchlib="$PERL_PREFIX/lib" \ |
325 |
-Uusevendorprefix \ |
326 |
-Dsitelib="$PERL_PREFIX/lib" \ |
327 |
-Dsitearch="$PERL_PREFIX/lib" \ |
328 |
-Uman1dir \ |
329 |
-Uman3dir \ |
330 |
-Usiteman1dir \ |
331 |
-Usiteman3dir \ |
332 |
-Dpager=/usr/bin/less \ |
333 |
-Demail="$EMAIL" \ |
334 |
-Dcf_email="$EMAIL" \ |
335 |
-Dcf_by="$EMAIL" \ |
336 |
$PERL_CONFIGURE \ |
337 |
-Duseperlio \ |
338 |
-Uversiononly \ |
339 |
-dE || configure_failure |
340 |
|
341 |
sedreplace ' |
342 |
s/-Wl,--no-gc-sections/-Wl,--gc-sections/g |
343 |
s/ *-fno-stack-protector */ /g |
344 |
' config.sh |
345 |
|
346 |
patchconfig || fatal "patchconfig hook failed" |
347 |
|
348 |
sh Configure -S || fatal "Configure -S failed" |
349 |
|
350 |
postconfigure || fatal "postconfigure hook failed" |
351 |
|
352 |
: > staticstamp.configure |
353 |
) || exit |
354 |
} |
355 |
|
356 |
write_shellscript() { |
357 |
{ |
358 |
echo "#!/bin/sh" |
359 |
echo "STATICPERL=\"$STATICPERL\"" |
360 |
echo "PERL_PREFIX=\"$PERL_PREFIX\"" |
361 |
echo "MAKE=\"$MAKE\"" |
362 |
cat |
363 |
} >"$PERL_PREFIX/bin/$1" |
364 |
chmod 755 "$PERL_PREFIX/bin/$1" |
365 |
} |
366 |
|
367 |
build() { |
368 |
( |
369 |
configure |
370 |
|
371 |
rcd "$STATICPERL/src/perl" |
372 |
|
373 |
verblock <<EOF |
374 |
building $STATICPERL/src/perl |
375 |
EOF |
376 |
|
377 |
rm -f "$PERL_PREFIX/staticstamp.install" |
378 |
|
379 |
"$MAKE" || fatal "make: error while building perl" |
380 |
|
381 |
postbuild || fatal "postbuild hook failed" |
382 |
) || exit |
383 |
} |
384 |
|
385 |
_postinstall() { |
386 |
if ! [ -e "$PERL_PREFIX/staticstamp.postinstall" ]; then |
387 |
NOCHECK_INSTALL=+ |
388 |
instcpan $STATICPERL_MODULES |
389 |
[ "$EXTRA_MODULES" ] && instcpan $EXTRA_MODULES |
390 |
|
391 |
postinstall || fatal "postinstall hook failed" |
392 |
|
393 |
: > "$PERL_PREFIX/staticstamp.postinstall" |
394 |
fi |
395 |
} |
396 |
|
397 |
install() { |
398 |
( |
399 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
400 |
build |
401 |
|
402 |
verblock <<EOF |
403 |
installing $STATICPERL/src/perl |
404 |
to $PERL_PREFIX |
405 |
EOF |
406 |
|
407 |
ln -sf "perl/bin/" "$STATICPERL/bin" |
408 |
ln -sf "perl/lib/" "$STATICPERL/lib" |
409 |
|
410 |
mkdir "$STATICPERL/patched" |
411 |
|
412 |
ln -sf "$PERL_PREFIX" "$STATICPERL/perl" # might get overwritten |
413 |
rm -rf "$PERL_PREFIX" # by this rm -rf |
414 |
|
415 |
rcd "$STATICPERL/src/perl" |
416 |
|
417 |
"$MAKE" install || fatal "make install: error while installing" |
418 |
|
419 |
rcd "$PERL_PREFIX" |
420 |
|
421 |
# create a "make install" replacement for CPAN |
422 |
write_shellscript SP-make-make <<'end_of_make' |
423 |
#CAT make-make.sh |
424 |
end_of_make |
425 |
|
426 |
# create a "make install" replacement for CPAN |
427 |
write_shellscript SP-make-install-make <<'end_of_make_install_make' |
428 |
#CAT make-install-make.sh |
429 |
end_of_make_install_make |
430 |
|
431 |
# create a "patch modules" helper |
432 |
write_shellscript SP-patch-postinstall <<'end_of_patch_postinstall' |
433 |
#CAT patch-postinstall.sh |
434 |
end_of_patch_postinstall |
435 |
|
436 |
# immediately use it |
437 |
"$PERL_PREFIX/bin/SP-patch-postinstall" |
438 |
|
439 |
# help to trick CPAN into avoiding ~/.cpan completely |
440 |
echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
441 |
|
442 |
# we call cpan with -MCPAN::MyConfig in this script, which |
443 |
# is strictly unnecessary as we have to patch CPAN anyway, |
444 |
# so consider it "for good measure". |
445 |
"$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' |
446 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
447 |
CPAN::Shell->o (conf => urllist => push => "'"$BACKPAN"'"); |
448 |
CPAN::Shell->o (conf => pushy_https => "0"); |
449 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
450 |
CPAN::Shell->o (conf => q<init>); |
451 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
452 |
CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
453 |
CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
454 |
CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
455 |
CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
456 |
CPAN::Shell->o (conf => q<makepl_arg>, "MAP_TARGET=perl"); |
457 |
CPAN::Shell->o (conf => q<make>, "'"$PERL_PREFIX"'/bin/SP-make-make"); |
458 |
CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/SP-make-install-make"); |
459 |
CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
460 |
CPAN::Shell->o (conf => q<build_requires_install_policy>, q<yes>); |
461 |
CPAN::Shell->o (conf => q<recommends_policy>, q<0>); |
462 |
CPAN::Shell->o (conf => q<suggests_policy>, q<0>); |
463 |
CPAN::Shell->o (conf => q<prefer_installer>, q<EUMM>); |
464 |
CPAN::Shell->o (conf => q<commit>); |
465 |
' || fatal "error while initialising CPAN" |
466 |
|
467 |
postcpanconfig |
468 |
|
469 |
: > "$PERL_PREFIX/staticstamp.install" |
470 |
fi |
471 |
|
472 |
_postinstall |
473 |
) || exit |
474 |
} |
475 |
|
476 |
import() { |
477 |
( |
478 |
IMPORT="$1" |
479 |
|
480 |
rcd "$STATICPERL" |
481 |
|
482 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
483 |
verblock <<EOF |
484 |
import perl from $IMPORT to $STATICPERL |
485 |
EOF |
486 |
|
487 |
rm -rf bin cpan lib patched perl src |
488 |
mkdir -m 755 perl perl/bin |
489 |
ln -s perl/bin/ bin |
490 |
ln -s "$IMPORT" perl/bin/ |
491 |
|
492 |
echo "$IMPORT" > "$PERL_PREFIX/.import" |
493 |
|
494 |
: > "$PERL_PREFIX/staticstamp.install" |
495 |
fi |
496 |
|
497 |
_postinstall |
498 |
) || exit |
499 |
} |
500 |
|
501 |
############################################################################# |
502 |
# install a module from CPAN |
503 |
|
504 |
instcpan() { |
505 |
[ $NOCHECK_INSTALL ] || install |
506 |
|
507 |
verblock <<EOF |
508 |
installing modules from CPAN |
509 |
$* |
510 |
EOF |
511 |
|
512 |
MYCONFIG= |
513 |
[ -e "$PERL_PREFIX/.import" ] || MYCONFIG=-MCPAN::MyConfig |
514 |
|
515 |
"$PERL_PREFIX"/bin/perl $MYCONFIG -MCPAN -e 'notest (install => $_) for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log" |
516 |
|
517 |
if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then |
518 |
fatal "failure while installing modules from CPAN ($*)" |
519 |
fi |
520 |
rm -f "$STATICPERL/instcpan.log" |
521 |
} |
522 |
|
523 |
############################################################################# |
524 |
# install a module from unpacked sources |
525 |
|
526 |
instsrc() { |
527 |
[ $NOCHECK_INSTALL ] || install |
528 |
|
529 |
verblock <<EOF |
530 |
installing modules from source |
531 |
$* |
532 |
EOF |
533 |
|
534 |
for mod in "$@"; do |
535 |
echo |
536 |
echo $mod |
537 |
( |
538 |
rcd $mod |
539 |
"$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 |
540 |
"$MAKE" distclean >/dev/null 2>&1 |
541 |
"$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
542 |
"$MAKE" || fatal "$mod: error building module" |
543 |
"$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module" |
544 |
"$MAKE" distclean >/dev/null 2>&1 |
545 |
exit 0 |
546 |
) || exit $? |
547 |
done |
548 |
} |
549 |
|
550 |
############################################################################# |
551 |
# main |
552 |
|
553 |
podusage() { |
554 |
echo |
555 |
|
556 |
if [ -e "$PERL_PREFIX/bin/perl" ]; then |
557 |
"$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
558 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
559 |
2>/dev/null && exit |
560 |
fi |
561 |
|
562 |
# try whatever perl we can find |
563 |
perl -MPod::Usage -e \ |
564 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
565 |
2>/dev/null && exit |
566 |
|
567 |
fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" |
568 |
} |
569 |
|
570 |
usage() { |
571 |
podusage 0 |
572 |
} |
573 |
|
574 |
catmkbundle() { |
575 |
{ |
576 |
read dummy |
577 |
echo "#!$PERL_PREFIX/bin/perl" |
578 |
cat |
579 |
} <<'end_of_mkbundle' |
580 |
#CAT mkbundle |
581 |
end_of_mkbundle |
582 |
} |
583 |
|
584 |
bundle() { |
585 |
MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" |
586 |
catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
587 |
chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
588 |
CACHE="$STATICPERL/cache" |
589 |
mkdir -p "$CACHE" |
590 |
"$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" |
591 |
} |
592 |
|
593 |
if [ $# -gt 0 ]; then |
594 |
while [ $# -gt 0 ]; do |
595 |
mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
596 |
mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
597 |
|
598 |
command="${1#--}"; shift |
599 |
case "$command" in |
600 |
version ) |
601 |
echo "staticperl version $VERSION" |
602 |
;; |
603 |
fetch | configure | build | install | clean | realclean | distclean ) |
604 |
( "$command" ) || exit |
605 |
;; |
606 |
import ) |
607 |
( import "$1" ) || exit |
608 |
shift |
609 |
;; |
610 |
instsrc ) |
611 |
( instsrc "$@" ) || exit |
612 |
exit |
613 |
;; |
614 |
instcpan ) |
615 |
( instcpan "$@" ) || exit |
616 |
exit |
617 |
;; |
618 |
perl ) |
619 |
( install ) || exit |
620 |
exec "$PERL_PREFIX/bin/perl" "$@" |
621 |
exit |
622 |
;; |
623 |
cpan ) |
624 |
( install ) || exit |
625 |
PERL="$PERL_PREFIX/bin/perl" |
626 |
export PERL |
627 |
exec "$PERL_PREFIX/bin/cpan" "$@" |
628 |
exit |
629 |
;; |
630 |
mkbundle ) |
631 |
( install ) || exit |
632 |
bundle "$@" |
633 |
exit |
634 |
;; |
635 |
mkperl ) |
636 |
( install ) || exit |
637 |
bundle --perl "$@" |
638 |
exit |
639 |
;; |
640 |
mkapp ) |
641 |
( install ) || exit |
642 |
bundle --app "$@" |
643 |
exit |
644 |
;; |
645 |
help ) |
646 |
podusage 2 |
647 |
;; |
648 |
* ) |
649 |
exec 1>&2 |
650 |
echo |
651 |
echo "Unknown command: $command" |
652 |
podusage 0 |
653 |
;; |
654 |
esac |
655 |
done |
656 |
else |
657 |
usage |
658 |
fi |
659 |
|
660 |
exit 0 |
661 |
|
662 |
#CAT staticperl.pod |
663 |
|