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 |
#! sh |
424 |
|
425 |
# newer Storable versions have some weird hack to try to measure the |
426 |
# stack size at build time, for reasons not well understood. it seems |
427 |
# perl5-porters think that stack sizes cannot be configured so compile time |
428 |
# stack size always equals runtime stack size. very weird, potential security |
429 |
# bug and doesn't even work, so work around it. |
430 |
if [ -e Storable.pm.PL ] && [ -e stacksize ]; then |
431 |
echo patching stacksize bug in Storable |
432 |
cat >stacksize <<'EOSS' |
433 |
#! perl |
434 |
mkdir "lib", 0777; |
435 |
mkdir "lib/Storable", 0777; |
436 |
open my $fh, ">lib/Storable/Limit.pm" or die; |
437 |
syswrite $fh, <<EOPM; |
438 |
# patched by staticperl |
439 |
\$Storable::recursion_limit = 512 |
440 |
unless defined \$Storable::recursion_limit; |
441 |
\$Storable::recursion_limit_hash = 512 |
442 |
unless defined \$Storable::recursion_limit_hash; |
443 |
1; |
444 |
EOPM |
445 |
EOSS |
446 |
fi |
447 |
|
448 |
"$MAKE" "$@" |
449 |
|
450 |
end_of_make |
451 |
|
452 |
# create a "make install" replacement for CPAN |
453 |
write_shellscript SP-make-install-make <<'end_of_make_install_make' |
454 |
#! sh |
455 |
|
456 |
"$MAKE" || exit |
457 |
|
458 |
make_install() { |
459 |
"$MAKE" install UNINST=1 \ |
460 |
&& "$PERL_PREFIX"/bin/SP-patch-postinstall |
461 |
} |
462 |
|
463 |
install_success= |
464 |
|
465 |
if find blib/arch/auto -type f \( -name "*.a" -o -name "*.obj" -o -name "*.lib" \) | grep -q .; then |
466 |
echo "Probably a static XS module, rebuilding perl" |
467 |
|
468 |
# perl seems to try to link against both installed and blib files at |
469 |
# the same time, at least in the case of Encode. |
470 |
# |
471 |
# To work aorund this, we try to install the module first, which, due |
472 |
# to the UNINST=1, should get rid of any duplicates first. We remember |
473 |
# whether the installw as successful so we don't re-run it later, but |
474 |
# if it fails, we install later again. |
475 |
# |
476 |
# Uninstall using packlists won't work, as modules embedded in perl |
477 |
# (e.g. Encode) do not have a (Separate) .packlist file |
478 |
|
479 |
if make_install; then |
480 |
install_success=+ |
481 |
fi |
482 |
|
483 |
rm -f Makefile.aperl |
484 |
|
485 |
if "$MAKE" all perl; then |
486 |
mv perl "$PERL_PREFIX"/bin/perl~ \ |
487 |
&& rm -f "$PERL_PREFIX"/bin/perl \ |
488 |
&& mv "$PERL_PREFIX"/bin/perl~ "$PERL_PREFIX"/bin/perl |
489 |
"$MAKE" -f Makefile.aperl map_clean |
490 |
else |
491 |
"$MAKE" -f Makefile.aperl map_clean |
492 |
exit 1 |
493 |
fi |
494 |
fi |
495 |
|
496 |
if [ "$install_success" ]; then |
497 |
true |
498 |
else |
499 |
make_install |
500 |
fi |
501 |
|
502 |
end_of_make_install_make |
503 |
|
504 |
# create a "patch modules" helper |
505 |
write_shellscript SP-patch-postinstall <<'end_of_patch_postinstall' |
506 |
#! sh |
507 |
|
508 |
# helper to apply patches after installation |
509 |
|
510 |
patch() { |
511 |
path="$PERL_PREFIX/lib/$1" |
512 |
cache="$STATICPERL/patched/$2" |
513 |
sed="$3" |
514 |
|
515 |
if "$PERL_PREFIX/bin/perl" -e 'exit 0+((stat shift)[7] == (stat shift)[7])' "$path" "$cache" || |
516 |
"$PERL_PREFIX/bin/perl" -e 'exit 0+((stat shift)[9] <= (stat shift)[9])' "$path" "$cache" |
517 |
then |
518 |
if [ -e "$path" ]; then |
519 |
echo "patching $path for a better tomorrrow" |
520 |
|
521 |
umask 022 |
522 |
if ! sed -e "$sed" <"$path" > "$cache~"; then |
523 |
echo |
524 |
echo "*** FATAL: error while patching $path" |
525 |
echo |
526 |
else |
527 |
rm -f "$path" |
528 |
mv "$cache~" "$path" |
529 |
cp "$path" "$cache" |
530 |
fi |
531 |
fi |
532 |
fi |
533 |
} |
534 |
|
535 |
# patch CPAN::HandleConfig.pm to always include _our_ MyConfig.pm, |
536 |
# not the one in the users homedirectory, to avoid clobbering his. |
537 |
patch CPAN/HandleConfig.pm cpan_handleconfig_pm ' |
538 |
1i\ |
539 |
use CPAN::MyConfig; # patched by staticperl |
540 |
' |
541 |
|
542 |
# patch ExtUtils::MM_Unix to always search blib for modules |
543 |
# when building a perl - this works around Pango/Gtk2 being misdetected |
544 |
# as not being an XS module. |
545 |
patch ExtUtils/MM_Unix.pm mm_unix_pm ' |
546 |
/^sub staticmake/,/^}/ s/if (@{$self->{C}}) {/if (@{$self->{C}} or $self->{NAME} =~ m%^(Pango|Gtk2)$%) { # patched by staticperl/ |
547 |
' |
548 |
|
549 |
# patch ExtUtils::Miniperl to always add DynaLoader |
550 |
# this is required for dynamic loading in static perls, |
551 |
# and static loading in dynamic perls, when rebuilding a new perl. |
552 |
# Why this patch is necessray I don't understand. Yup. |
553 |
patch ExtUtils/Miniperl.pm extutils_miniperl.pm ' |
554 |
/^sub writemain/ a\ |
555 |
push @_, "DynaLoader"; # patched by staticperl |
556 |
' |
557 |
|
558 |
# ExtUtils::CBuilder always tries to link shared libraries |
559 |
# even on systems without shared library support. From the same |
560 |
# source as Module::Build, so no wonder it's broken beyond fixing. |
561 |
# and since so many dependent modules are even worse, |
562 |
# we hardwire to 0 to get their pure-perl versions. |
563 |
patch ExtUtils/CBuilder/Base.pm extutils_cbuilder_base.pm ' |
564 |
/^sub have_compiler/ a\ |
565 |
return 0; # patched by staticperl |
566 |
' |
567 |
|
568 |
end_of_patch_postinstall |
569 |
|
570 |
# immediately use it |
571 |
"$PERL_PREFIX/bin/SP-patch-postinstall" |
572 |
|
573 |
# help to trick CPAN into avoiding ~/.cpan completely |
574 |
echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" |
575 |
|
576 |
# we call cpan with -MCPAN::MyConfig in this script, which |
577 |
# is strictly unnecessary as we have to patch CPAN anyway, |
578 |
# so consider it "for good measure". |
579 |
"$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' |
580 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
581 |
CPAN::Shell->o (conf => urllist => push => "'"$BACKPAN"'"); |
582 |
CPAN::Shell->o (conf => pushy_https => "0"); |
583 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
584 |
CPAN::Shell->o (conf => q<init>); |
585 |
CPAN::Shell->o (conf => q<cpan_home>, "'"$STATICPERL"'/cpan"); |
586 |
CPAN::Shell->o (conf => q<build_dir>, "'"$STATICPERL"'/cpan/build"); |
587 |
CPAN::Shell->o (conf => q<prefs_dir>, "'"$STATICPERL"'/cpan/prefs"); |
588 |
CPAN::Shell->o (conf => q<histfile> , "'"$STATICPERL"'/cpan/histfile"); |
589 |
CPAN::Shell->o (conf => q<keep_source_where>, "'"$STATICPERL"'/cpan/sources"); |
590 |
CPAN::Shell->o (conf => q<makepl_arg>, "MAP_TARGET=perl"); |
591 |
CPAN::Shell->o (conf => q<make>, "'"$PERL_PREFIX"'/bin/SP-make-make"); |
592 |
CPAN::Shell->o (conf => q<make_install_make_command>, "'"$PERL_PREFIX"'/bin/SP-make-install-make"); |
593 |
CPAN::Shell->o (conf => q<prerequisites_policy>, q<follow>); |
594 |
CPAN::Shell->o (conf => q<build_requires_install_policy>, q<yes>); |
595 |
CPAN::Shell->o (conf => q<recommends_policy>, q<0>); |
596 |
CPAN::Shell->o (conf => q<suggests_policy>, q<0>); |
597 |
CPAN::Shell->o (conf => q<prefer_installer>, q<EUMM>); |
598 |
CPAN::Shell->o (conf => q<commit>); |
599 |
' || fatal "error while initialising CPAN" |
600 |
|
601 |
postcpanconfig |
602 |
|
603 |
: > "$PERL_PREFIX/staticstamp.install" |
604 |
fi |
605 |
|
606 |
_postinstall |
607 |
) || exit |
608 |
} |
609 |
|
610 |
import() { |
611 |
( |
612 |
IMPORT="$1" |
613 |
|
614 |
rcd "$STATICPERL" |
615 |
|
616 |
if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then |
617 |
verblock <<EOF |
618 |
import perl from $IMPORT to $STATICPERL |
619 |
EOF |
620 |
|
621 |
rm -rf bin cpan lib patched perl src |
622 |
mkdir -m 755 perl perl/bin |
623 |
ln -s perl/bin/ bin |
624 |
ln -s "$IMPORT" perl/bin/ |
625 |
|
626 |
echo "$IMPORT" > "$PERL_PREFIX/.import" |
627 |
|
628 |
: > "$PERL_PREFIX/staticstamp.install" |
629 |
fi |
630 |
|
631 |
_postinstall |
632 |
) || exit |
633 |
} |
634 |
|
635 |
############################################################################# |
636 |
# install a module from CPAN |
637 |
|
638 |
instcpan() { |
639 |
[ $NOCHECK_INSTALL ] || install |
640 |
|
641 |
verblock <<EOF |
642 |
installing modules from CPAN |
643 |
$* |
644 |
EOF |
645 |
|
646 |
MYCONFIG= |
647 |
[ -e "$PERL_PREFIX/.import" ] || MYCONFIG=-MCPAN::MyConfig |
648 |
|
649 |
"$PERL_PREFIX"/bin/perl $MYCONFIG -MCPAN -e 'notest (install => $_) for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log" |
650 |
|
651 |
if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then |
652 |
fatal "failure while installing modules from CPAN ($*)" |
653 |
fi |
654 |
rm -f "$STATICPERL/instcpan.log" |
655 |
} |
656 |
|
657 |
############################################################################# |
658 |
# install a module from unpacked sources |
659 |
|
660 |
instsrc() { |
661 |
[ $NOCHECK_INSTALL ] || install |
662 |
|
663 |
verblock <<EOF |
664 |
installing modules from source |
665 |
$* |
666 |
EOF |
667 |
|
668 |
for mod in "$@"; do |
669 |
echo |
670 |
echo $mod |
671 |
( |
672 |
rcd $mod |
673 |
"$MAKE" -f Makefile.aperl map_clean >/dev/null 2>&1 |
674 |
"$MAKE" distclean >/dev/null 2>&1 |
675 |
"$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" |
676 |
"$MAKE" || fatal "$mod: error building module" |
677 |
"$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module" |
678 |
"$MAKE" distclean >/dev/null 2>&1 |
679 |
exit 0 |
680 |
) || exit $? |
681 |
done |
682 |
} |
683 |
|
684 |
############################################################################# |
685 |
# main |
686 |
|
687 |
podusage() { |
688 |
echo |
689 |
|
690 |
if [ -e "$PERL_PREFIX/bin/perl" ]; then |
691 |
"$PERL_PREFIX/bin/perl" -MPod::Usage -e \ |
692 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
693 |
2>/dev/null && exit |
694 |
fi |
695 |
|
696 |
# try whatever perl we can find |
697 |
perl -MPod::Usage -e \ |
698 |
'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ |
699 |
2>/dev/null && exit |
700 |
|
701 |
fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" |
702 |
} |
703 |
|
704 |
usage() { |
705 |
podusage 0 |
706 |
} |
707 |
|
708 |
catmkbundle() { |
709 |
{ |
710 |
read dummy |
711 |
echo "#!$PERL_PREFIX/bin/perl" |
712 |
cat |
713 |
} <<'end_of_mkbundle' |
714 |
#!/opt/bin/perl |
715 |
|
716 |
############################################################################# |
717 |
# cannot load modules till after the tracer BEGIN block |
718 |
|
719 |
our $VERBOSE = 1; |
720 |
our $STRIP = "pod"; # none, pod or ppi |
721 |
our $COMPRESS = "lzf"; |
722 |
our $KEEPNL = 0; |
723 |
our $UNISTRIP = 1; # always on, try to strip unicore swash data |
724 |
our $PERL = 0; |
725 |
our $APP; |
726 |
our $VERIFY = 0; |
727 |
our $STATIC = 0; |
728 |
our $PACKLIST = 0; |
729 |
our $IGNORE_ENV = 0; |
730 |
our $ALLOW_DYNAMIC = 0; |
731 |
our $HAVE_DYNAMIC; # maybe useful? |
732 |
our $EXTRA_CFLAGS = ""; |
733 |
our $EXTRA_LDFLAGS = ""; |
734 |
our $EXTRA_LIBS = ""; |
735 |
|
736 |
# TODO: at least with lzf, OPTIMIZE_SIZE sesm to be a win? (also, does not respect KEEPNL) |
737 |
our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? |
738 |
|
739 |
our $CACHE; |
740 |
our $CACHEVER = 2; # do not change unless you know what you are doing |
741 |
|
742 |
my $PREFIX = "bundle"; |
743 |
my $PACKAGE = "static"; |
744 |
|
745 |
my %pm; |
746 |
my %pmbin; |
747 |
my @libs; |
748 |
my @static_ext; |
749 |
my $extralibs; |
750 |
my @staticlibs; |
751 |
my @incext; |
752 |
|
753 |
@ARGV |
754 |
or die "$0: use 'staticperl help' (or read the sources of staticperl)\n"; |
755 |
|
756 |
# remove "." from @INC - staticperl.sh does it for us, but be on the safe side |
757 |
BEGIN { @INC = grep !/^\.$/, @INC } |
758 |
|
759 |
$|=1; |
760 |
|
761 |
our ($TRACER_W, $TRACER_R); |
762 |
|
763 |
sub find_incdir($) { |
764 |
for (@INC) { |
765 |
next if ref; |
766 |
return $_ if -e "$_/$_[0]"; |
767 |
} |
768 |
|
769 |
undef |
770 |
} |
771 |
|
772 |
sub find_inc($) { |
773 |
my $dir = find_incdir $_[0]; |
774 |
|
775 |
return "$dir/$_[0]" |
776 |
if defined $dir; |
777 |
|
778 |
undef |
779 |
} |
780 |
|
781 |
BEGIN { |
782 |
# create a loader process to detect @INC requests before we load any modules |
783 |
my ($W_TRACER, $R_TRACER); # used by tracer |
784 |
|
785 |
pipe $R_TRACER, $TRACER_W or die "pipe: $!"; |
786 |
pipe $TRACER_R, $W_TRACER or die "pipe: $!"; |
787 |
|
788 |
unless (fork) { |
789 |
close $TRACER_R; |
790 |
close $TRACER_W; |
791 |
|
792 |
my $pkg = "pkg000000"; |
793 |
|
794 |
unshift @INC, sub { |
795 |
my $dir = find_incdir $_[1] |
796 |
or return; |
797 |
|
798 |
syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; |
799 |
|
800 |
open my $fh, "<:raw:perlio", "$dir/$_[1]" |
801 |
or warn "ERROR: $dir/$_[1]: $!\n"; |
802 |
|
803 |
$fh |
804 |
}; |
805 |
|
806 |
while (<$R_TRACER>) { |
807 |
if (/use (.*)$/) { |
808 |
my $mod = $1; |
809 |
my $eval; |
810 |
|
811 |
if ($mod =~ /^'.*'$/ or $mod =~ /^".*"$/) { |
812 |
$eval = "require $mod"; |
813 |
} elsif ($mod =~ y%/.%%) { |
814 |
$eval = "require q\x00$mod\x00"; |
815 |
} else { |
816 |
my $pkg = ++$pkg; |
817 |
$eval = "{ package $pkg; use $mod; }"; |
818 |
} |
819 |
|
820 |
eval $eval; |
821 |
warn "ERROR: $@ (while loading '$mod')\n" |
822 |
if $@; |
823 |
} elsif (/eval (.*)$/) { |
824 |
my $eval = $1; |
825 |
eval $eval; |
826 |
warn "ERROR: $@ (in '$eval')\n" |
827 |
if $@; |
828 |
} |
829 |
|
830 |
syswrite $W_TRACER, "\n"; |
831 |
} |
832 |
|
833 |
exit 0; |
834 |
} |
835 |
} |
836 |
|
837 |
# module loading is now safe |
838 |
|
839 |
sub trace_parse { |
840 |
for (;;) { |
841 |
<$TRACER_R> =~ /^-$/ or last; |
842 |
my $dir = <$TRACER_R>; chomp $dir; |
843 |
my $name = <$TRACER_R>; chomp $name; |
844 |
|
845 |
$pm{$name} = "$dir/$name"; |
846 |
|
847 |
print "+ found potential dependency $name\n" |
848 |
if $VERBOSE >= 3; |
849 |
} |
850 |
} |
851 |
|
852 |
sub trace_module { |
853 |
print "tracing module $_[0]\n" |
854 |
if $VERBOSE >= 2; |
855 |
|
856 |
syswrite $TRACER_W, "use $_[0]\n"; |
857 |
trace_parse; |
858 |
} |
859 |
|
860 |
sub trace_eval { |
861 |
print "tracing eval $_[0]\n" |
862 |
if $VERBOSE >= 2; |
863 |
|
864 |
syswrite $TRACER_W, "eval $_[0]\n"; |
865 |
trace_parse; |
866 |
} |
867 |
|
868 |
sub trace_finish { |
869 |
close $TRACER_W; |
870 |
close $TRACER_R; |
871 |
} |
872 |
|
873 |
############################################################################# |
874 |
# now we can use modules |
875 |
|
876 |
use common::sense; |
877 |
use Config; |
878 |
use Digest::MD5; |
879 |
|
880 |
sub cache($$$) { |
881 |
my ($variant, $src, $filter) = @_; |
882 |
|
883 |
if (length $CACHE and 2048 <= length $src and defined $variant) { |
884 |
my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; |
885 |
|
886 |
if (open my $fh, "<:raw:perlio", $file) { |
887 |
print "using cache for $file\n" |
888 |
if $VERBOSE >= 7; |
889 |
|
890 |
local $/; |
891 |
return <$fh>; |
892 |
} |
893 |
|
894 |
$src = $filter->($src); |
895 |
|
896 |
print "creating cache entry $file\n" |
897 |
if $VERBOSE >= 8; |
898 |
|
899 |
if (open my $fh, ">:raw:perlio", "$file~") { |
900 |
if ((syswrite $fh, $src) == length $src) { |
901 |
close $fh; |
902 |
rename "$file~", $file; |
903 |
} |
904 |
} |
905 |
|
906 |
return $src; |
907 |
} |
908 |
|
909 |
$filter->($src) |
910 |
} |
911 |
|
912 |
sub dump_string { |
913 |
my ($fh, $data) = @_; |
914 |
|
915 |
if (length $data) { |
916 |
if ($^O eq "MSWin32") { |
917 |
# 16 bit system, strings can't be longer than 64k. seriously. |
918 |
print $fh "{\n"; |
919 |
for ( |
920 |
my $ofs = 0; |
921 |
length (my $substr = substr $data, $ofs, 20); |
922 |
$ofs += 20 |
923 |
) { |
924 |
$substr = join ",", map ord, split //, $substr; |
925 |
print $fh " $substr,\n"; |
926 |
} |
927 |
print $fh " 0 }\n"; |
928 |
} else { |
929 |
for ( |
930 |
my $ofs = 0; |
931 |
length (my $substr = substr $data, $ofs, 80); |
932 |
$ofs += 80 |
933 |
) { |
934 |
$substr =~ s/([^\x20-\x21\x23-\x5b\x5d-\x7e])/sprintf "\\%03o", ord $1/ge; |
935 |
$substr =~ s/\?/\\?/g; # trigraphs... |
936 |
print $fh " \"$substr\"\n"; |
937 |
} |
938 |
} |
939 |
} else { |
940 |
print $fh " \"\"\n"; |
941 |
} |
942 |
} |
943 |
|
944 |
############################################################################# |
945 |
|
946 |
sub glob2re { |
947 |
for (quotemeta $_[0]) { |
948 |
s/\\\*/\x00/g; |
949 |
s/\x00\x00/.*/g; |
950 |
s/\x00/[^\/]*/g; |
951 |
s/\\\?/[^\/]/g; |
952 |
|
953 |
$_ = s/^\\\/// ? "^$_\$" : "(?:^|/)$_\$"; |
954 |
|
955 |
s/(?: \[\^\/\] | \. ) \*\$$//x; |
956 |
|
957 |
return qr<$_>s |
958 |
} |
959 |
} |
960 |
|
961 |
our %INCSKIP = ( |
962 |
"unicore/TestProp.pl" => undef, # 3.5MB of insanity, apparently just some testcase |
963 |
); |
964 |
|
965 |
sub get_dirtree { |
966 |
my $root = shift; |
967 |
|
968 |
my @tree; |
969 |
my $skip; |
970 |
|
971 |
my $scan; $scan = sub { |
972 |
for (sort do { |
973 |
opendir my $fh, $_[0] |
974 |
or return; |
975 |
readdir $fh |
976 |
}) { |
977 |
next if /^\./; |
978 |
|
979 |
my $path = "$_[0]/$_"; |
980 |
|
981 |
if (-d "$path/.") { |
982 |
$scan->($path); |
983 |
} else { |
984 |
$path = substr $path, $skip; |
985 |
push @tree, $path |
986 |
unless exists $INCSKIP{$path}; |
987 |
} |
988 |
} |
989 |
}; |
990 |
|
991 |
$root =~ s/\/$//; |
992 |
$skip = 1 + length $root; |
993 |
$scan->($root); |
994 |
|
995 |
\@tree |
996 |
} |
997 |
|
998 |
my $inctrees; |
999 |
|
1000 |
sub get_inctrees { |
1001 |
unless ($inctrees) { |
1002 |
my %inctree; |
1003 |
$inctree{$_} ||= [$_, get_dirtree $_] # entries in @INC are often duplicates |
1004 |
for @INC; |
1005 |
$inctrees = [values %inctree]; |
1006 |
} |
1007 |
|
1008 |
@$inctrees |
1009 |
} |
1010 |
|
1011 |
############################################################################# |
1012 |
|
1013 |
sub cmd_boot { |
1014 |
$pm{"!boot"} = $_[0]; |
1015 |
} |
1016 |
|
1017 |
sub cmd_add { |
1018 |
$_[0] =~ /^(.*?)(?:\s+(\S+))?$/ |
1019 |
or die "$_[0]: cannot parse"; |
1020 |
|
1021 |
my $file = $1; |
1022 |
my $as = defined $2 ? $2 : $1; |
1023 |
|
1024 |
$pm{$as} = $file; |
1025 |
$pmbin{$as} = 1 if $_[1]; |
1026 |
} |
1027 |
|
1028 |
sub cmd_staticlib { |
1029 |
push @staticlibs, $_ |
1030 |
for split /\s+/, $_[0]; |
1031 |
} |
1032 |
|
1033 |
sub cmd_include { |
1034 |
push @incext, [$_[1], glob2re $_[0]]; |
1035 |
} |
1036 |
|
1037 |
sub cmd_incglob { |
1038 |
my ($pattern) = @_; |
1039 |
|
1040 |
$pattern = glob2re $pattern; |
1041 |
|
1042 |
for (get_inctrees) { |
1043 |
my ($dir, $files) = @$_; |
1044 |
|
1045 |
$pm{$_} = "$dir/$_" |
1046 |
for grep /$pattern/ && /\.(pl|pm)$/, @$files; |
1047 |
} |
1048 |
} |
1049 |
|
1050 |
sub parse_argv; |
1051 |
|
1052 |
sub cmd_file { |
1053 |
open my $fh, "<", $_[0] |
1054 |
or die "$_[0]: $!\n"; |
1055 |
|
1056 |
local @ARGV; |
1057 |
|
1058 |
while (<$fh>) { |
1059 |
chomp; |
1060 |
next unless /\S/; |
1061 |
next if /^\s*#/; |
1062 |
|
1063 |
s/^\s*-*/--/; |
1064 |
my ($cmd, $args) = split / /, $_, 2; |
1065 |
|
1066 |
push @ARGV, $cmd; |
1067 |
push @ARGV, $args if defined $args; |
1068 |
} |
1069 |
|
1070 |
parse_argv; |
1071 |
} |
1072 |
|
1073 |
use Getopt::Long; |
1074 |
|
1075 |
sub parse_argv { |
1076 |
GetOptions |
1077 |
"perl" => \$PERL, |
1078 |
"app=s" => \$APP, |
1079 |
|
1080 |
"verbose|v" => sub { ++$VERBOSE }, |
1081 |
"quiet|q" => sub { --$VERBOSE }, |
1082 |
|
1083 |
"strip=s" => \$STRIP, |
1084 |
"keepnl" => \$KEEPNL, |
1085 |
"compress=s" => \$COMPRESS, |
1086 |
"cache=s" => \$CACHE, # internal option |
1087 |
"eval|e=s" => sub { trace_eval $_[1] }, |
1088 |
"use|M=s" => sub { trace_module $_[1] }, |
1089 |
"boot=s" => sub { cmd_boot $_[1] }, |
1090 |
"add=s" => sub { cmd_add $_[1], 0 }, |
1091 |
"addbin=s" => sub { cmd_add $_[1], 1 }, |
1092 |
"incglob=s" => sub { cmd_incglob $_[1] }, |
1093 |
"include|i=s" => sub { cmd_include $_[1], 1 }, |
1094 |
"exclude|x=s" => sub { cmd_include $_[1], 0 }, |
1095 |
"usepacklists!" => \$PACKLIST, |
1096 |
|
1097 |
"static!" => \$STATIC, |
1098 |
"staticlib=s" => sub { cmd_staticlib $_[1] }, |
1099 |
"allow-dynamic!" => \$ALLOW_DYNAMIC, |
1100 |
"ignore-env" => \$IGNORE_ENV, |
1101 |
|
1102 |
"extra-cflags=s" => \$EXTRA_CFLAGS, |
1103 |
"extra-ldflags=s" => \$EXTRA_LDFLAGS, |
1104 |
"extra-libs=s" => \$EXTRA_LIBS, |
1105 |
|
1106 |
"<>" => sub { cmd_file $_[0] }, |
1107 |
or exit 1; |
1108 |
} |
1109 |
|
1110 |
Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); |
1111 |
|
1112 |
parse_argv; |
1113 |
|
1114 |
die "cannot specify both --app and --perl\n" |
1115 |
if $PERL and defined $APP; |
1116 |
|
1117 |
die "--compress must be either none or lzf\n" |
1118 |
unless $COMPRESS =~ /^(?:none|lzf)\z/; |
1119 |
|
1120 |
# required for @INC loading, unfortunately |
1121 |
trace_module "PerlIO::scalar"; |
1122 |
|
1123 |
############################################################################# |
1124 |
# apply include/exclude |
1125 |
|
1126 |
{ |
1127 |
my %pmi; |
1128 |
|
1129 |
for (@incext) { |
1130 |
my ($inc, $glob) = @$_; |
1131 |
|
1132 |
my @match = grep /$glob/, keys %pm; |
1133 |
|
1134 |
if ($inc) { |
1135 |
# include |
1136 |
@pmi{@match} = delete @pm{@match}; |
1137 |
|
1138 |
print "applying include $glob - protected ", (scalar @match), " files.\n" |
1139 |
if $VERBOSE >= 5; |
1140 |
} else { |
1141 |
# exclude |
1142 |
delete @pm{@match}; |
1143 |
|
1144 |
print "applying exclude $glob - removed ", (scalar @match), " files.\n" |
1145 |
if $VERBOSE >= 5; |
1146 |
} |
1147 |
} |
1148 |
|
1149 |
my @pmi = keys %pmi; |
1150 |
@pm{@pmi} = delete @pmi{@pmi}; |
1151 |
} |
1152 |
|
1153 |
############################################################################# |
1154 |
# scan for AutoLoader, static archives and other dependencies |
1155 |
|
1156 |
sub scan_al { |
1157 |
my ($auto, $autodir) = @_; |
1158 |
|
1159 |
my $ix = "$autodir/autosplit.ix"; |
1160 |
|
1161 |
print "processing autoload index for '$auto'\n" |
1162 |
if $VERBOSE >= 6; |
1163 |
|
1164 |
$pm{"$auto/autosplit.ix"} = $ix; |
1165 |
|
1166 |
open my $fh, "<:perlio", $ix |
1167 |
or die "$ix: $!"; |
1168 |
|
1169 |
my $package; |
1170 |
|
1171 |
while (<$fh>) { |
1172 |
if (/^\s*sub\s+ ([^[:space:];]+) \s* (?:\([^)]*\))? \s*;?\s*$/x) { |
1173 |
my $al = "auto/$package/$1.al"; |
1174 |
my $inc = find_inc $al; |
1175 |
|
1176 |
defined $inc or die "$al: autoload file not found, but should be there.\n"; |
1177 |
|
1178 |
$pm{$al} = $inc; |
1179 |
print "found autoload function '$al'\n" |
1180 |
if $VERBOSE >= 6; |
1181 |
|
1182 |
} elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { |
1183 |
($package = $1) =~ s/::/\//g; |
1184 |
} elsif (/^\s*(?:#|1?\s*;?\s*$)/) { |
1185 |
# nop |
1186 |
} else { |
1187 |
warn "WARNING: $ix: unparsable line, please report: $_"; |
1188 |
} |
1189 |
} |
1190 |
} |
1191 |
|
1192 |
for my $pm (keys %pm) { |
1193 |
if ($pm =~ /^(.*)\.pm$/) { |
1194 |
my $auto = "auto/$1"; |
1195 |
my $autodir = find_inc $auto; |
1196 |
|
1197 |
if (defined $autodir && -d $autodir) { |
1198 |
# AutoLoader |
1199 |
scan_al $auto, $autodir |
1200 |
if -f "$autodir/autosplit.ix"; |
1201 |
|
1202 |
# extralibs.ld |
1203 |
if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { |
1204 |
print "found extralibs for $pm\n" |
1205 |
if $VERBOSE >= 6; |
1206 |
|
1207 |
local $/; |
1208 |
$extralibs .= " " . <$fh>; |
1209 |
} |
1210 |
|
1211 |
$pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; |
1212 |
|
1213 |
my $base = $1; |
1214 |
|
1215 |
# static ext |
1216 |
if (-f "$autodir/$base$Config{_a}") { |
1217 |
print "found static archive for $pm\n" |
1218 |
if $VERBOSE >= 3; |
1219 |
|
1220 |
push @libs, "$autodir/$base$Config{_a}"; |
1221 |
push @static_ext, $pm; |
1222 |
} |
1223 |
|
1224 |
# dynamic object |
1225 |
if (-f "$autodir/$base.$Config{dlext}") { |
1226 |
if ($ALLOW_DYNAMIC) { |
1227 |
my $as = "!$auto/$base.$Config{dlext}"; |
1228 |
$pm{$as} = "$autodir/$base.$Config{dlext}"; |
1229 |
$pmbin{$as} = 1; |
1230 |
|
1231 |
$HAVE_DYNAMIC = 1; |
1232 |
|
1233 |
print "+ added dynamic object $as\n" |
1234 |
if $VERBOSE >= 3; |
1235 |
} else { |
1236 |
die "ERROR: found shared object '$autodir/$base.$Config{dlext}' but --allow-dynamic not given, aborting.\n" |
1237 |
} |
1238 |
} |
1239 |
|
1240 |
if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { |
1241 |
print "found .packlist for $pm\n" |
1242 |
if $VERBOSE >= 3; |
1243 |
|
1244 |
while (<$fh>) { |
1245 |
chomp; |
1246 |
s/ .*$//; # newer-style .packlists might contain key=value pairs |
1247 |
|
1248 |
# only include certain files (.al, .ix, .pm, .pl) |
1249 |
if (/\.(pm|pl|al|ix)$/) { |
1250 |
for my $inc (@INC) { |
1251 |
# in addition, we only add files that are below some @INC path |
1252 |
$inc =~ s/\/*$/\//; |
1253 |
|
1254 |
if ($inc eq substr $_, 0, length $inc) { |
1255 |
my $base = substr $_, length $inc; |
1256 |
$pm{$base} = $_; |
1257 |
|
1258 |
print "+ added .packlist dependency $base\n" |
1259 |
if $VERBOSE >= 3; |
1260 |
} |
1261 |
|
1262 |
last; |
1263 |
} |
1264 |
} |
1265 |
} |
1266 |
} |
1267 |
} |
1268 |
} |
1269 |
} |
1270 |
|
1271 |
############################################################################# |
1272 |
|
1273 |
print "processing bundle files (try more -v power if you get bored waiting here)...\n" |
1274 |
if $VERBOSE >= 1; |
1275 |
|
1276 |
my $compress = sub { shift }; |
1277 |
|
1278 |
if ($COMPRESS eq "lzf") { |
1279 |
require Compress::LZF; |
1280 |
$compress = sub { Compress::LZF::compress_best (shift) }; |
1281 |
} |
1282 |
|
1283 |
my $data; |
1284 |
my @index; |
1285 |
my @order = sort { |
1286 |
length $a <=> length $b |
1287 |
or $a cmp $b |
1288 |
} keys %pm; |
1289 |
|
1290 |
# sorting by name - better compression, but needs more metadata |
1291 |
# sorting by length - faster lookup |
1292 |
# usually, the metadata overhead beats the loss through compression |
1293 |
|
1294 |
for my $pm (@order) { |
1295 |
my $path = $pm{$pm}; |
1296 |
|
1297 |
128 > length $pm |
1298 |
or die "ERROR: $pm: path too long (only 128 octets supported)\n"; |
1299 |
|
1300 |
my $src = ref $path |
1301 |
? $$path |
1302 |
: do { |
1303 |
open my $pm, "<:raw:perlio", $path |
1304 |
or die "$path: $!"; |
1305 |
|
1306 |
local $/; |
1307 |
|
1308 |
<$pm> |
1309 |
}; |
1310 |
|
1311 |
my $size = length $src; |
1312 |
|
1313 |
unless ($pmbin{$pm}) { # only do this unless the file is binary |
1314 |
if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { |
1315 |
if ($src =~ /^ unimpl \"/m) { |
1316 |
print "$pm: skipping (raises runtime error only).\n" |
1317 |
if $VERBOSE >= 3; |
1318 |
next; |
1319 |
} |
1320 |
} |
1321 |
|
1322 |
$src = cache "$STRIP,$UNISTRIP,$KEEPNL,$OPTIMISE_SIZE,$COMPRESS", $src, sub { |
1323 |
if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { |
1324 |
print "applying unicore stripping $pm\n" |
1325 |
if $VERBOSE >= 6; |
1326 |
|
1327 |
# special stripping for unicore swashes and properties |
1328 |
# much more could be done by going binary |
1329 |
$src =~ s{ |
1330 |
(^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) |
1331 |
}{ |
1332 |
my ($pre, $data, $post) = ($1, $2, $3); |
1333 |
|
1334 |
for ($data) { |
1335 |
s/^([0-9a-fA-F]+)\t([0-9a-fA-F]+)\t/sprintf "%X\t%X", hex $1, hex $2/gem |
1336 |
if $OPTIMISE_SIZE; |
1337 |
|
1338 |
# s{ |
1339 |
# ^([0-9a-fA-F]+)\t([0-9a-fA-F]*)\t |
1340 |
# }{ |
1341 |
# # ww - smaller filesize, UU - compress better |
1342 |
# pack "C0UU", |
1343 |
# hex $1, |
1344 |
# length $2 ? (hex $2) - (hex $1) : 0 |
1345 |
# }gemx; |
1346 |
|
1347 |
s/#.*\n/\n/mg; |
1348 |
s/\s+\n/\n/mg; |
1349 |
} |
1350 |
|
1351 |
"$pre$data$post" |
1352 |
}smex; |
1353 |
} |
1354 |
|
1355 |
if ($STRIP =~ /ppi/i) { |
1356 |
require PPI; |
1357 |
|
1358 |
# PPI (quite correctly) treats pod in __DATA__ as data, not pod, so |
1359 |
# we don't have to work around Opcode.pm, as with Pod::Strip |
1360 |
|
1361 |
if (my $ppi = PPI::Document->new (\$src)) { |
1362 |
for my $node ( |
1363 |
@{ $ppi->find (PPI::Token::Comment::) }, |
1364 |
@{ $ppi->find (PPI::Token::Pod::) } |
1365 |
) { |
1366 |
if ($KEEPNL) { |
1367 |
$node->{content} =~ s/[^\n]//g; |
1368 |
$node->insert_after (PPI::Token::Whitespace->new ("\n")) if length $node->{content}; |
1369 |
} |
1370 |
|
1371 |
$node->delete; |
1372 |
} |
1373 |
|
1374 |
# prune END stuff |
1375 |
for (my $last = $ppi->last_element; $last; ) { |
1376 |
my $prev = $last->previous_token; |
1377 |
|
1378 |
if ($last->isa (PPI::Token::Whitespace::)) { |
1379 |
$last->delete; |
1380 |
} elsif ($last->isa (PPI::Statement::End::)) { |
1381 |
$last->delete; |
1382 |
last; |
1383 |
} elsif ($last->isa (PPI::Token::Pod::)) { |
1384 |
$last->delete; |
1385 |
} elsif ($last->isa (PPI::Token::Comment::)) { |
1386 |
$last->delete; |
1387 |
} else { |
1388 |
last; |
1389 |
} |
1390 |
|
1391 |
$last = $prev; |
1392 |
} |
1393 |
|
1394 |
# prune some but not all insignificant whitespace |
1395 |
for my $ws (@{ $ppi->find (PPI::Token::Whitespace::) }) { |
1396 |
my $prev = $ws->previous_token; |
1397 |
my $next = $ws->next_token; |
1398 |
|
1399 |
if (!$prev || !$next) { |
1400 |
$ws->delete; |
1401 |
} else { |
1402 |
if ($next->isa (PPI::Token::Whitespace::)) { |
1403 |
# push this whitespace data into the next node |
1404 |
$next->{content} = "$ws->{content}$next->{content}"; |
1405 |
$ws->{content} = ""; |
1406 |
} elsif ( |
1407 |
( |
1408 |
$next->isa (PPI::Token::Operator::) && $next->{content} =~ /^(?:,|=|!|!=|==|=>)$/ # no ., because of digits. == float |
1409 |
or $prev->isa (PPI::Token::Operator::) && $prev->{content} =~ /^(?:,|=|\.|!|!=|==|=>)$/ |
1410 |
or $prev->isa (PPI::Token::Structure::) |
1411 |
or ($OPTIMISE_SIZE && |
1412 |
($prev->isa (PPI::Token::Word::) |
1413 |
&& (PPI::Token::Symbol:: eq ref $next |
1414 |
|| $next->isa (PPI::Structure::Block::) |
1415 |
|| $next->isa (PPI::Structure::List::) |
1416 |
|| $next->isa (PPI::Structure::Condition::))) |
1417 |
) |
1418 |
) |
1419 |
# perl has some idiotic warning about nonexisting operators (Reverse %s operator) |
1420 |
# also catch "= ~" |
1421 |
&& !( |
1422 |
$prev->isa (PPI::Token::Operator::) && $prev->{content} eq "=" |
1423 |
&& $next->isa (PPI::Token::Operator::) && $next->{content} =~ /[+\-\~]/ |
1424 |
) |
1425 |
) { |
1426 |
if ($KEEPNL) { |
1427 |
$ws->{content} =~ s/[^\n]//g; |
1428 |
} else { |
1429 |
$ws->{content} = ''; |
1430 |
} |
1431 |
} else { |
1432 |
if ($KEEPNL) { |
1433 |
$ws->{content} =~ s/[^\n]//g; |
1434 |
$ws->{content} ||= ' '; # keep at least one space |
1435 |
} else { |
1436 |
$ws->{content} = ' '; |
1437 |
} |
1438 |
} |
1439 |
} |
1440 |
} |
1441 |
|
1442 |
# prune whitespace around blocks |
1443 |
if ($OPTIMISE_SIZE) { |
1444 |
# these usually decrease size, but decrease compressability more |
1445 |
for my $struct (PPI::Structure::Block::, PPI::Structure::Condition::) { |
1446 |
for my $node (@{ $ppi->find ($struct) }) { |
1447 |
my $n1 = $node->first_token; |
1448 |
my $n2 = $n1->previous_token; |
1449 |
$n1->delete if $n1->isa (PPI::Token::Whitespace::); |
1450 |
$n2->delete if $n2 && $n2->isa (PPI::Token::Whitespace::); |
1451 |
my $n1 = $node->last_token; |
1452 |
my $n2 = $n1->next_token; |
1453 |
$n1->delete if $n1->isa (PPI::Token::Whitespace::); |
1454 |
$n2->delete if $n2 && $n2->isa (PPI::Token::Whitespace::); |
1455 |
} |
1456 |
} |
1457 |
|
1458 |
for my $node (@{ $ppi->find (PPI::Structure::List::) }) { |
1459 |
my $n1 = $node->first_token; |
1460 |
$n1->delete if $n1->isa (PPI::Token::Whitespace::); |
1461 |
my $n1 = $node->last_token; |
1462 |
$n1->delete if $n1->isa (PPI::Token::Whitespace::); |
1463 |
} |
1464 |
} |
1465 |
|
1466 |
# reformat qw() lists which often have lots of whitespace |
1467 |
for my $node (@{ $ppi->find (PPI::Token::QuoteLike::Words::) }) { |
1468 |
if ($node->{content} =~ /^qw(.)(.*)(.)$/s) { |
1469 |
my ($a, $qw, $b) = ($1, $2, $3); |
1470 |
$qw =~ s/^\s+//; |
1471 |
$qw =~ s/\s+$//; |
1472 |
$qw =~ s/\s+/ /g; |
1473 |
$node->{content} = "qw$a$qw$b"; |
1474 |
} |
1475 |
} |
1476 |
|
1477 |
$src = $ppi->serialize; |
1478 |
} else { |
1479 |
warn "WARNING: $pm{$pm}: PPI failed to parse this file\n"; |
1480 |
} |
1481 |
} elsif ($STRIP =~ /pod/i && $pm ne "Opcode.pm") { # opcode parses its own pod |
1482 |
require Pod::Strip; |
1483 |
|
1484 |
my $stripper = Pod::Strip->new; |
1485 |
|
1486 |
my $out; |
1487 |
$stripper->output_string (\$out); |
1488 |
$stripper->parse_string_document ($src) |
1489 |
or die; |
1490 |
$src = $out; |
1491 |
} |
1492 |
|
1493 |
if ($VERIFY && $pm =~ /\.pm$/ && $pm ne "Opcode.pm") { |
1494 |
if (open my $fh, "-|") { |
1495 |
<$fh>; |
1496 |
} else { |
1497 |
eval "#line 1 \"$pm\"\n$src" or warn "\n\n\n$pm\n\n$src\n$@\n\n\n"; |
1498 |
exit 0; |
1499 |
} |
1500 |
} |
1501 |
|
1502 |
$src |
1503 |
}; |
1504 |
|
1505 |
# if ($pm eq "Opcode.pm") { |
1506 |
# open my $fh, ">x" or die; print $fh $src;#d# |
1507 |
# exit 1; |
1508 |
# } |
1509 |
} |
1510 |
|
1511 |
$src = $compress->($src); |
1512 |
|
1513 |
print "adding $pm (original size $size, stored size ", length $src, ")\n" |
1514 |
if $VERBOSE >= 2; |
1515 |
|
1516 |
push @index, ((length $pm) << 25) | length $data; |
1517 |
$data .= $pm . $src; |
1518 |
} |
1519 |
|
1520 |
length $data < 2**25 |
1521 |
or die "ERROR: bundle too large (only 32MB supported)\n"; |
1522 |
|
1523 |
my $varpfx = "bundle"; |
1524 |
|
1525 |
############################################################################# |
1526 |
# output |
1527 |
|
1528 |
print "generating $PREFIX.h... " |
1529 |
if $VERBOSE >= 1; |
1530 |
|
1531 |
{ |
1532 |
open my $fh, ">", "$PREFIX.h" |
1533 |
or die "$PREFIX.h: $!\n"; |
1534 |
|
1535 |
print $fh <<EOF; |
1536 |
/* do not edit, automatically created by staticperl */ |
1537 |
|
1538 |
#include <EXTERN.h> |
1539 |
#include <perl.h> |
1540 |
#include <XSUB.h> |
1541 |
|
1542 |
/* public API */ |
1543 |
EXTERN_C PerlInterpreter *staticperl; |
1544 |
EXTERN_C void staticperl_xs_init (pTHX); |
1545 |
EXTERN_C void staticperl_init (XSINIT_t xs_init); /* argument can be 0 */ |
1546 |
EXTERN_C void staticperl_cleanup (void); |
1547 |
|
1548 |
EOF |
1549 |
} |
1550 |
|
1551 |
print "\n" |
1552 |
if $VERBOSE >= 1; |
1553 |
|
1554 |
############################################################################# |
1555 |
# output |
1556 |
|
1557 |
print "generating $PREFIX.c... " |
1558 |
if $VERBOSE >= 1; |
1559 |
|
1560 |
open my $fh, ">", "$PREFIX.c" |
1561 |
or die "$PREFIX.c: $!\n"; |
1562 |
|
1563 |
print $fh <<EOF; |
1564 |
/* do not edit, automatically created by staticperl */ |
1565 |
|
1566 |
#include "bundle.h" |
1567 |
|
1568 |
/* public API */ |
1569 |
PerlInterpreter *staticperl; |
1570 |
|
1571 |
EOF |
1572 |
|
1573 |
############################################################################# |
1574 |
# lzf decompressor |
1575 |
|
1576 |
if ($COMPRESS eq "lzf") { |
1577 |
print $fh <<'EOF'; |
1578 |
/* stripped down/perlified version of lzf_d.c from liblzf-3.7 */ |
1579 |
|
1580 |
#if (__i386 || __amd64) && __GNUC__ >= 3 |
1581 |
# define lzf_movsb(dst, src, len) \ |
1582 |
asm ("rep movsb" \ |
1583 |
: "=D" (dst), "=S" (src), "=c" (len) \ |
1584 |
: "0" (dst), "1" (src), "2" (len)); |
1585 |
#endif |
1586 |
|
1587 |
static unsigned int |
1588 |
lzf_decompress (const void *const in_data, unsigned int in_len, |
1589 |
void *out_data, unsigned int out_len) |
1590 |
{ |
1591 |
U8 const *ip = (const U8 *)in_data; |
1592 |
U8 *op = (U8 *)out_data; |
1593 |
U8 const *const in_end = ip + in_len; |
1594 |
U8 *const out_end = op + out_len; |
1595 |
|
1596 |
do |
1597 |
{ |
1598 |
unsigned int ctrl = *ip++; |
1599 |
|
1600 |
if (ctrl < (1 << 5)) /* literal run */ |
1601 |
{ |
1602 |
ctrl++; |
1603 |
|
1604 |
if (op + ctrl > out_end) |
1605 |
return 0; |
1606 |
|
1607 |
#ifdef lzf_movsb |
1608 |
lzf_movsb (op, ip, ctrl); |
1609 |
#else |
1610 |
while (ctrl--) |
1611 |
*op++ = *ip++; |
1612 |
#endif |
1613 |
} |
1614 |
else /* back reference */ |
1615 |
{ |
1616 |
unsigned int len = ctrl >> 5; |
1617 |
|
1618 |
U8 *ref = op - ((ctrl & 0x1f) << 8) - 1; |
1619 |
|
1620 |
if (len == 7) |
1621 |
len += *ip++; |
1622 |
|
1623 |
ref -= *ip++; |
1624 |
|
1625 |
if (op + len + 2 > out_end) |
1626 |
return 0; |
1627 |
|
1628 |
if (ref < (U8 *)out_data) |
1629 |
return 0; |
1630 |
|
1631 |
len += 2; |
1632 |
#ifdef lzf_movsb |
1633 |
lzf_movsb (op, ref, len); |
1634 |
#else |
1635 |
do |
1636 |
*op++ = *ref++; |
1637 |
while (--len); |
1638 |
#endif |
1639 |
} |
1640 |
} |
1641 |
while (ip < in_end); |
1642 |
|
1643 |
return op - (U8 *)out_data; |
1644 |
} |
1645 |
|
1646 |
static SV * |
1647 |
static_to_sv (const char *ptr, STRLEN len) |
1648 |
{ |
1649 |
SV *res; |
1650 |
const U8 *p = (const U8 *)ptr; |
1651 |
|
1652 |
if (len == 0) /* empty */ |
1653 |
res = newSVpvn ("", 0); |
1654 |
else if (*p == 0) /* not compressed */ |
1655 |
res = newSVpvn (p + 1, len - 1); |
1656 |
else /* lzf compressed, with UTF-8-encoded original size in front */ |
1657 |
{ |
1658 |
STRLEN ulenlen; |
1659 |
UV ulen = utf8n_to_uvchr (p, len, &ulenlen, 0); |
1660 |
|
1661 |
p += ulenlen; |
1662 |
len -= ulenlen; |
1663 |
|
1664 |
res = NEWSV (0, ulen); |
1665 |
sv_upgrade (res, SVt_PV); |
1666 |
SvPOK_only (res); |
1667 |
lzf_decompress (p, len, SvPVX (res), ulen); |
1668 |
SvCUR_set (res, ulen); |
1669 |
} |
1670 |
|
1671 |
return res; |
1672 |
} |
1673 |
|
1674 |
EOF |
1675 |
} else { |
1676 |
print $fh <<EOF; |
1677 |
|
1678 |
#define static_to_sv(ptr,len) newSVpvn (ptr, len) |
1679 |
|
1680 |
EOF |
1681 |
} |
1682 |
|
1683 |
############################################################################# |
1684 |
# bundle data |
1685 |
|
1686 |
my $count = @index; |
1687 |
|
1688 |
print $fh <<EOF; |
1689 |
#include "bundle.h" |
1690 |
|
1691 |
/* bundle data */ |
1692 |
|
1693 |
static const U32 $varpfx\_count = $count; |
1694 |
static const U32 $varpfx\_index [$count + 1] = { |
1695 |
EOF |
1696 |
|
1697 |
my $col; |
1698 |
for (@index) { |
1699 |
printf $fh "0x%08x,", $_; |
1700 |
print $fh "\n" unless ++$col % 10; |
1701 |
|
1702 |
} |
1703 |
printf $fh "0x%08x\n};\n", (length $data); |
1704 |
|
1705 |
print $fh "static const char $varpfx\_data [] =\n"; |
1706 |
dump_string $fh, $data; |
1707 |
|
1708 |
print $fh ";\n\n"; |
1709 |
|
1710 |
############################################################################# |
1711 |
# bootstrap |
1712 |
|
1713 |
# boot file for staticperl |
1714 |
# this file will be eval'ed at initialisation time |
1715 |
|
1716 |
# lines marked with "^D" are only used when $HAVE_DYNAMIC |
1717 |
my $bootstrap = ' |
1718 |
BEGIN { |
1719 |
package ' . $PACKAGE . '; |
1720 |
|
1721 |
# the path prefix to use when putting files into %INC |
1722 |
our $inc_prefix; |
1723 |
|
1724 |
# the @INC hook to use when we have PerlIO::scalar available |
1725 |
my $perlio_inc = sub { |
1726 |
my $data = find "$_[1]" |
1727 |
or return; |
1728 |
|
1729 |
$INC{$_[1]} = "$inc_prefix$_[1]"; |
1730 |
|
1731 |
open my $fh, "<", \$data; |
1732 |
$fh |
1733 |
}; |
1734 |
|
1735 |
D if (defined &PerlIO::scalar::bootstrap) { |
1736 |
# PerlIO::scalar statically compiled in |
1737 |
PerlIO::scalar->bootstrap; |
1738 |
@INC = $perlio_inc; |
1739 |
D } else { |
1740 |
D # PerlIO::scalar not available, use slower method |
1741 |
D @INC = sub { |
1742 |
D # always check if PerlIO::scalar might now be available |
1743 |
D if (defined &PerlIO::scalar::bootstrap) { |
1744 |
D # switch to the faster perlio_inc hook |
1745 |
D @INC = map { $_ == $_[0] ? $perlio_inc : $_ } @INC; |
1746 |
D goto &$perlio_inc; |
1747 |
D } |
1748 |
D |
1749 |
D my $data = find "$_[1]" |
1750 |
D or return; |
1751 |
D |
1752 |
D $INC{$_[1]} = "$inc_prefix$_[1]"; |
1753 |
D |
1754 |
D sub { |
1755 |
D $data =~ /\G([^\n]*\n?)/g |
1756 |
D or return; |
1757 |
D |
1758 |
D $_ = $1; |
1759 |
D 1 |
1760 |
D } |
1761 |
D }; |
1762 |
D } |
1763 |
} |
1764 |
'; |
1765 |
|
1766 |
$bootstrap .= "require '!boot';" |
1767 |
if exists $pm{"!boot"}; |
1768 |
|
1769 |
if ($HAVE_DYNAMIC) { |
1770 |
$bootstrap =~ s/^D/ /mg; |
1771 |
} else { |
1772 |
$bootstrap =~ s/^D.*$//mg; |
1773 |
} |
1774 |
|
1775 |
$bootstrap =~ s/#.*$//mg; |
1776 |
$bootstrap =~ s/\s+/ /g; |
1777 |
$bootstrap =~ s/(\W) /$1/g; |
1778 |
$bootstrap =~ s/ (\W)/$1/g; |
1779 |
|
1780 |
print $fh "const char bootstrap [] = "; |
1781 |
dump_string $fh, $bootstrap; |
1782 |
print $fh ";\n\n"; |
1783 |
|
1784 |
print $fh <<EOF; |
1785 |
/* search all bundles for the given file, using binary search */ |
1786 |
XS(find) |
1787 |
{ |
1788 |
dXSARGS; |
1789 |
|
1790 |
if (items != 1) |
1791 |
Perl_croak (aTHX_ "Usage: $PACKAGE\::find (\$path)"); |
1792 |
|
1793 |
{ |
1794 |
STRLEN namelen; |
1795 |
char *name = SvPV (ST (0), namelen); |
1796 |
SV *res = 0; |
1797 |
|
1798 |
int l = 0, r = $varpfx\_count; |
1799 |
|
1800 |
while (l <= r) |
1801 |
{ |
1802 |
int m = (l + r) >> 1; |
1803 |
U32 idx = $varpfx\_index [m]; |
1804 |
int comp = namelen - (idx >> 25); |
1805 |
|
1806 |
if (!comp) |
1807 |
{ |
1808 |
int ofs = idx & 0x1FFFFFFU; |
1809 |
comp = memcmp (name, $varpfx\_data + ofs, namelen); |
1810 |
|
1811 |
if (!comp) |
1812 |
{ |
1813 |
/* found */ |
1814 |
int ofs2 = $varpfx\_index [m + 1] & 0x1FFFFFFU; |
1815 |
|
1816 |
ofs += namelen; |
1817 |
res = static_to_sv ($varpfx\_data + ofs, ofs2 - ofs); |
1818 |
goto found; |
1819 |
} |
1820 |
} |
1821 |
|
1822 |
if (comp < 0) |
1823 |
r = m - 1; |
1824 |
else |
1825 |
l = m + 1; |
1826 |
} |
1827 |
|
1828 |
XSRETURN (0); |
1829 |
|
1830 |
found: |
1831 |
ST (0) = sv_2mortal (res); |
1832 |
} |
1833 |
|
1834 |
XSRETURN (1); |
1835 |
} |
1836 |
|
1837 |
/* list all files in the bundle */ |
1838 |
XS(list) |
1839 |
{ |
1840 |
dXSARGS; |
1841 |
|
1842 |
if (items != 0) |
1843 |
Perl_croak (aTHX_ "Usage: $PACKAGE\::list"); |
1844 |
|
1845 |
{ |
1846 |
int i; |
1847 |
|
1848 |
EXTEND (SP, $varpfx\_count); |
1849 |
|
1850 |
for (i = 0; i < $varpfx\_count; ++i) |
1851 |
{ |
1852 |
U32 idx = $varpfx\_index [i]; |
1853 |
|
1854 |
PUSHs (sv_2mortal (newSVpvn ($varpfx\_data + (idx & 0x1FFFFFFU), idx >> 25))); |
1855 |
} |
1856 |
} |
1857 |
|
1858 |
XSRETURN ($varpfx\_count); |
1859 |
} |
1860 |
|
1861 |
#ifdef STATICPERL_BUNDLE_INCLUDE |
1862 |
#include STATICPERL_BUNDLE_INCLUDE |
1863 |
#endif |
1864 |
|
1865 |
EOF |
1866 |
|
1867 |
############################################################################# |
1868 |
# xs_init |
1869 |
|
1870 |
print $fh <<EOF; |
1871 |
void |
1872 |
staticperl_xs_init (pTHX) |
1873 |
{ |
1874 |
EOF |
1875 |
|
1876 |
@static_ext = sort @static_ext; |
1877 |
|
1878 |
# prototypes |
1879 |
for (@static_ext) { |
1880 |
s/\.pm$//; |
1881 |
(my $cname = $_) =~ s/\//__/g; |
1882 |
print $fh " EXTERN_C void boot_$cname (pTHX_ CV* cv);\n"; |
1883 |
} |
1884 |
|
1885 |
print $fh <<EOF; |
1886 |
char *file = __FILE__; |
1887 |
dXSUB_SYS; |
1888 |
|
1889 |
newXSproto ("$PACKAGE\::find", find, file, "\$"); |
1890 |
newXSproto ("$PACKAGE\::list", list, file, ""); |
1891 |
|
1892 |
#ifdef STATICPERL_BUNDLE_XS_INIT |
1893 |
STATICPERL_BUNDLE_XS_INIT; |
1894 |
#endif |
1895 |
EOF |
1896 |
|
1897 |
# calls |
1898 |
for (@static_ext) { |
1899 |
s/\.pm$//; |
1900 |
|
1901 |
(my $cname = $_) =~ s/\//__/g; |
1902 |
(my $pname = $_) =~ s/\//::/g; |
1903 |
|
1904 |
my $bootstrap = $pname eq "DynaLoader" ? "boot_DynaLoader" : "bootstrap"; |
1905 |
|
1906 |
print $fh " newXS (\"$pname\::$bootstrap\", boot_$cname, file);\n"; |
1907 |
} |
1908 |
|
1909 |
print $fh <<EOF; |
1910 |
Safefree (PL_origfilename); |
1911 |
PL_origfilename = savepv (PL_origargv [0]); |
1912 |
sv_setpv (GvSV (gv_fetchpvs ("0", GV_ADD|GV_NOTQUAL, SVt_PV)), PL_origfilename); |
1913 |
|
1914 |
#ifdef _WIN32 |
1915 |
/* windows perls usually trail behind unix perls 8-10 years in exporting symbols */ |
1916 |
|
1917 |
if (!PL_preambleav) |
1918 |
PL_preambleav = newAV (); |
1919 |
|
1920 |
av_unshift (PL_preambleav, 1); |
1921 |
av_store (PL_preambleav, 0, newSVpv (bootstrap, sizeof (bootstrap) - 1)); |
1922 |
#else |
1923 |
Perl_av_create_and_unshift_one (&PL_preambleav, newSVpv (bootstrap, sizeof (bootstrap) - 1)); |
1924 |
#endif |
1925 |
|
1926 |
if (PL_oldname) |
1927 |
((XSINIT_t)PL_oldname)(aTHX); |
1928 |
} |
1929 |
EOF |
1930 |
|
1931 |
############################################################################# |
1932 |
# optional perl_init/perl_destroy |
1933 |
|
1934 |
if ($IGNORE_ENV) { |
1935 |
$IGNORE_ENV = <<EOF; |
1936 |
unsetenv ("PERL_UNICODE"); |
1937 |
unsetenv ("PERL_HASH_SEED_DEBUG"); |
1938 |
unsetenv ("PERL_DESTRUCT_LEVEL"); |
1939 |
unsetenv ("PERL_SIGNALS"); |
1940 |
unsetenv ("PERL_DEBUG_MSTATS"); |
1941 |
unsetenv ("PERL5OPT"); |
1942 |
unsetenv ("PERLIO_DEBUG"); |
1943 |
unsetenv ("PERLIO"); |
1944 |
unsetenv ("PERL_HASH_SEED"); |
1945 |
EOF |
1946 |
} else { |
1947 |
$IGNORE_ENV = ""; |
1948 |
} |
1949 |
|
1950 |
if ($APP) { |
1951 |
print $fh <<EOF; |
1952 |
|
1953 |
int |
1954 |
main (int argc, char *argv []) |
1955 |
{ |
1956 |
extern char **environ; |
1957 |
int i, exitstatus; |
1958 |
char **args = malloc ((argc + 3) * sizeof (const char *)); |
1959 |
|
1960 |
args [0] = argv [0]; |
1961 |
args [1] = "-e"; |
1962 |
args [2] = "0"; |
1963 |
args [3] = "--"; |
1964 |
|
1965 |
for (i = 1; i < argc; ++i) |
1966 |
args [i + 3] = argv [i]; |
1967 |
|
1968 |
$IGNORE_ENV |
1969 |
PERL_SYS_INIT3 (&argc, &argv, &environ); |
1970 |
staticperl = perl_alloc (); |
1971 |
perl_construct (staticperl); |
1972 |
|
1973 |
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
1974 |
|
1975 |
exitstatus = perl_parse (staticperl, staticperl_xs_init, argc + 3, args, environ); |
1976 |
if (!exitstatus) |
1977 |
perl_run (staticperl); |
1978 |
|
1979 |
exitstatus = perl_destruct (staticperl); |
1980 |
perl_free (staticperl); |
1981 |
PERL_SYS_TERM (); |
1982 |
/*free (args); no point doing it this late */ |
1983 |
|
1984 |
return exitstatus; |
1985 |
} |
1986 |
EOF |
1987 |
} elsif ($PERL) { |
1988 |
print $fh <<EOF; |
1989 |
|
1990 |
int |
1991 |
main (int argc, char *argv []) |
1992 |
{ |
1993 |
extern char **environ; |
1994 |
int exitstatus; |
1995 |
|
1996 |
$IGNORE_ENV |
1997 |
PERL_SYS_INIT3 (&argc, &argv, &environ); |
1998 |
staticperl = perl_alloc (); |
1999 |
perl_construct (staticperl); |
2000 |
|
2001 |
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
2002 |
|
2003 |
exitstatus = perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
2004 |
if (!exitstatus) |
2005 |
perl_run (staticperl); |
2006 |
|
2007 |
exitstatus = perl_destruct (staticperl); |
2008 |
perl_free (staticperl); |
2009 |
PERL_SYS_TERM (); |
2010 |
|
2011 |
return exitstatus; |
2012 |
} |
2013 |
EOF |
2014 |
} else { |
2015 |
print $fh <<EOF; |
2016 |
|
2017 |
EXTERN_C void |
2018 |
staticperl_init (XSINIT_t xs_init) |
2019 |
{ |
2020 |
static char *args[] = { |
2021 |
"staticperl", |
2022 |
"-e", |
2023 |
"0" |
2024 |
}; |
2025 |
|
2026 |
extern char **environ; |
2027 |
int argc = sizeof (args) / sizeof (args [0]); |
2028 |
char **argv = args; |
2029 |
|
2030 |
$IGNORE_ENV |
2031 |
PERL_SYS_INIT3 (&argc, &argv, &environ); |
2032 |
staticperl = perl_alloc (); |
2033 |
perl_construct (staticperl); |
2034 |
PL_origalen = 1; |
2035 |
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
2036 |
PL_oldname = (char *)xs_init; |
2037 |
perl_parse (staticperl, staticperl_xs_init, argc, argv, environ); |
2038 |
|
2039 |
perl_run (staticperl); |
2040 |
} |
2041 |
|
2042 |
EXTERN_C void |
2043 |
staticperl_cleanup (void) |
2044 |
{ |
2045 |
perl_destruct (staticperl); |
2046 |
perl_free (staticperl); |
2047 |
staticperl = 0; |
2048 |
PERL_SYS_TERM (); |
2049 |
} |
2050 |
EOF |
2051 |
} |
2052 |
|
2053 |
close $fh; |
2054 |
|
2055 |
print -s "$PREFIX.c", " octets (", (length $data) , " data octets).\n\n" |
2056 |
if $VERBOSE >= 1; |
2057 |
|
2058 |
############################################################################# |
2059 |
# libs, cflags |
2060 |
|
2061 |
my $ccopts; |
2062 |
|
2063 |
{ |
2064 |
print "generating $PREFIX.ccopts... " |
2065 |
if $VERBOSE >= 1; |
2066 |
|
2067 |
$ccopts = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE $EXTRA_CFLAGS"; |
2068 |
$ccopts =~ s/([\(\)])/\\$1/g; |
2069 |
|
2070 |
open my $fh, ">$PREFIX.ccopts" |
2071 |
or die "$PREFIX.ccopts: $!"; |
2072 |
print $fh $ccopts; |
2073 |
|
2074 |
print "$ccopts\n\n" |
2075 |
if $VERBOSE >= 1; |
2076 |
} |
2077 |
|
2078 |
my $ldopts; |
2079 |
|
2080 |
{ |
2081 |
print "generating $PREFIX.ldopts... "; |
2082 |
|
2083 |
$ldopts = $STATIC ? "-static " : ""; |
2084 |
|
2085 |
$ldopts .= "$Config{ccdlflags} $Config{ldflags} $EXTRA_LDFLAGS @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs} $EXTRA_LIBS"; |
2086 |
|
2087 |
my %seen; |
2088 |
$ldopts .= " $_" for reverse grep !$seen{$_}++, reverse +($extralibs =~ /(\S+)/g); |
2089 |
|
2090 |
for (@staticlibs) { |
2091 |
$ldopts =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; |
2092 |
} |
2093 |
|
2094 |
$ldopts =~ s/([\(\)])/\\$1/g; |
2095 |
|
2096 |
open my $fh, ">$PREFIX.ldopts" |
2097 |
or die "$PREFIX.ldopts: $!"; |
2098 |
print $fh $ldopts; |
2099 |
|
2100 |
print "$ldopts\n\n" |
2101 |
if $VERBOSE >= 1; |
2102 |
} |
2103 |
|
2104 |
if ($PERL or defined $APP) { |
2105 |
$APP = "perl" unless defined $APP; |
2106 |
|
2107 |
my $build = "$Config{cc} $ccopts -o \Q$APP\E$Config{_exe} bundle.c $ldopts"; |
2108 |
|
2109 |
print "build $APP...\n" |
2110 |
if $VERBOSE >= 1; |
2111 |
|
2112 |
print "$build\n" |
2113 |
if $VERBOSE >= 2; |
2114 |
|
2115 |
system $build; |
2116 |
|
2117 |
unlink "$PREFIX.$_" |
2118 |
for qw(ccopts ldopts c h); |
2119 |
|
2120 |
print "\n" |
2121 |
if $VERBOSE >= 1; |
2122 |
} |
2123 |
|
2124 |
end_of_mkbundle |
2125 |
} |
2126 |
|
2127 |
bundle() { |
2128 |
MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" |
2129 |
catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" |
2130 |
chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" |
2131 |
CACHE="$STATICPERL/cache" |
2132 |
mkdir -p "$CACHE" |
2133 |
"$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" |
2134 |
} |
2135 |
|
2136 |
if [ $# -gt 0 ]; then |
2137 |
while [ $# -gt 0 ]; do |
2138 |
mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" |
2139 |
mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" |
2140 |
|
2141 |
command="${1#--}"; shift |
2142 |
case "$command" in |
2143 |
version ) |
2144 |
echo "staticperl version $VERSION" |
2145 |
;; |
2146 |
fetch | configure | build | install | clean | realclean | distclean ) |
2147 |
( "$command" ) || exit |
2148 |
;; |
2149 |
import ) |
2150 |
( import "$1" ) || exit |
2151 |
shift |
2152 |
;; |
2153 |
instsrc ) |
2154 |
( instsrc "$@" ) || exit |
2155 |
exit |
2156 |
;; |
2157 |
instcpan ) |
2158 |
( instcpan "$@" ) || exit |
2159 |
exit |
2160 |
;; |
2161 |
perl ) |
2162 |
( install ) || exit |
2163 |
exec "$PERL_PREFIX/bin/perl" "$@" |
2164 |
exit |
2165 |
;; |
2166 |
cpan ) |
2167 |
( install ) || exit |
2168 |
PERL="$PERL_PREFIX/bin/perl" |
2169 |
export PERL |
2170 |
exec "$PERL_PREFIX/bin/cpan" "$@" |
2171 |
exit |
2172 |
;; |
2173 |
mkbundle ) |
2174 |
( install ) || exit |
2175 |
bundle "$@" |
2176 |
exit |
2177 |
;; |
2178 |
mkperl ) |
2179 |
( install ) || exit |
2180 |
bundle --perl "$@" |
2181 |
exit |
2182 |
;; |
2183 |
mkapp ) |
2184 |
( install ) || exit |
2185 |
bundle --app "$@" |
2186 |
exit |
2187 |
;; |
2188 |
help ) |
2189 |
podusage 2 |
2190 |
;; |
2191 |
* ) |
2192 |
exec 1>&2 |
2193 |
echo |
2194 |
echo "Unknown command: $command" |
2195 |
podusage 0 |
2196 |
;; |
2197 |
esac |
2198 |
done |
2199 |
else |
2200 |
usage |
2201 |
fi |
2202 |
|
2203 |
exit 0 |
2204 |
|
2205 |
=head1 NAME |
2206 |
|
2207 |
staticperl - perl, libc, 100 modules, all in one standalone 500kb file |
2208 |
|
2209 |
=head1 SYNOPSIS |
2210 |
|
2211 |
staticperl help # print the embedded documentation |
2212 |
staticperl fetch # fetch and unpack perl sources |
2213 |
staticperl configure # fetch and then configure perl |
2214 |
staticperl build # configure and then build perl |
2215 |
staticperl install # build and then install perl |
2216 |
staticperl clean # clean most intermediate files (restart at configure) |
2217 |
staticperl distclean # delete everything installed by this script |
2218 |
staticperl perl ... # invoke the perlinterpreter |
2219 |
staticperl cpan # invoke CPAN shell |
2220 |
staticperl instsrc path... # install unpacked modules |
2221 |
staticperl instcpan modulename... # install modules from CPAN |
2222 |
staticperl mkbundle <bundle-args...> # see documentation |
2223 |
staticperl mkperl <bundle-args...> # see documentation |
2224 |
staticperl mkapp appname <bundle-args...> # see documentation |
2225 |
|
2226 |
Typical Examples: |
2227 |
|
2228 |
staticperl install # fetch, configure, build and install perl |
2229 |
staticperl cpan # run interactive cpan shell |
2230 |
staticperl mkperl -MConfig_heavy.pl # build a perl that supports -V |
2231 |
staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http |
2232 |
# build a perl with the above modules linked in |
2233 |
staticperl mkapp myapp --boot mainprog mymodules |
2234 |
# build a binary "myapp" from mainprog and mymodules |
2235 |
|
2236 |
=head1 DESCRIPTION |
2237 |
|
2238 |
This script helps you to create single-file perl interpreters |
2239 |
or applications, or embedding a perl interpreter in your |
2240 |
applications. Single-file means that it is fully self-contained - no |
2241 |
separate shared objects, no autoload fragments, no .pm or .pl files are |
2242 |
needed. And when linking statically, you can create (or embed) a single |
2243 |
file that contains perl interpreter, libc, all the modules you need, all |
2244 |
the libraries you need and of course your actual program. |
2245 |
|
2246 |
With F<uClibc> and F<upx> on x86, you can create a single 500kb binary |
2247 |
that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
2248 |
Coro and so on. Or any other choice of modules (and some other size :). |
2249 |
|
2250 |
To see how this turns out, you can try out smallperl and bigperl, two |
2251 |
pre-built static and compressed perl binaries with many and even more |
2252 |
modules: just follow the links at L<http://staticperl.schmorp.de/>. |
2253 |
|
2254 |
The created files do not need write access to the file system (like PAR |
2255 |
does). In fact, since this script is in many ways similar to PAR::Packer, |
2256 |
here are the differences: |
2257 |
|
2258 |
=over 4 |
2259 |
|
2260 |
=item * The generated executables are much smaller than PAR created ones. |
2261 |
|
2262 |
Shared objects and the perl binary contain a lot of extra info, while |
2263 |
the static nature of F<staticperl> allows the linker to remove all |
2264 |
functionality and meta-info not required by the final executable. Even |
2265 |
extensions statically compiled into perl at build time will only be |
2266 |
present in the final executable when needed. |
2267 |
|
2268 |
In addition, F<staticperl> can strip perl sources much more effectively |
2269 |
than PAR. |
2270 |
|
2271 |
=item * The generated executables start much faster. |
2272 |
|
2273 |
There is no need to unpack files, or even to parse Zip archives (which is |
2274 |
slow and memory-consuming business). |
2275 |
|
2276 |
=item * The generated executables don't need a writable filesystem. |
2277 |
|
2278 |
F<staticperl> loads all required files directly from memory. There is no |
2279 |
need to unpack files into a temporary directory. |
2280 |
|
2281 |
=item * More control over included files, more burden. |
2282 |
|
2283 |
PAR tries to be maintenance and hassle-free - it tries to include more |
2284 |
files than necessary to make sure everything works out of the box. It |
2285 |
mostly succeeds at this, but he extra files (such as the unicode database) |
2286 |
can take substantial amounts of memory and file size. |
2287 |
|
2288 |
With F<staticperl>, the burden is mostly with the developer - only direct |
2289 |
compile-time dependencies and L<AutoLoader> are handled automatically. |
2290 |
This means the modules to include often need to be tweaked manually. |
2291 |
|
2292 |
All this does not preclude more permissive modes to be implemented in |
2293 |
the future, but right now, you have to resolve hidden dependencies |
2294 |
manually. |
2295 |
|
2296 |
=item * PAR works out of the box, F<staticperl> does not. |
2297 |
|
2298 |
Maintaining your own custom perl build can be a pain in the ass, and while |
2299 |
F<staticperl> tries to make this easy, it still requires a custom perl |
2300 |
build and possibly fiddling with some modules. PAR is likely to produce |
2301 |
results faster. |
2302 |
|
2303 |
Ok, PAR never has worked for me out of the box, and for some people, |
2304 |
F<staticperl> does work out of the box, as they don't count "fiddling with |
2305 |
module use lists" against it, but nevertheless, F<staticperl> is certainly |
2306 |
a bit more difficult to use. |
2307 |
|
2308 |
=back |
2309 |
|
2310 |
=head1 HOW DOES IT WORK? |
2311 |
|
2312 |
Simple: F<staticperl> downloads, compile and installs a perl version of |
2313 |
your choice in F<~/.staticperl>. You can add extra modules either by |
2314 |
letting F<staticperl> install them for you automatically, or by using CPAN |
2315 |
and doing it interactively. This usually takes 5-10 minutes, depending on |
2316 |
the speed of your computer and your internet connection. |
2317 |
|
2318 |
It is possible to do program development at this stage, too. |
2319 |
|
2320 |
Afterwards, you create a list of files and modules you want to include, |
2321 |
and then either build a new perl binary (that acts just like a normal perl |
2322 |
except everything is compiled in), or you create bundle files (basically C |
2323 |
sources you can use to embed all files into your project). |
2324 |
|
2325 |
This step is very fast (a few seconds if PPI is not used for stripping, or |
2326 |
the stripped files are in the cache), and can be tweaked and repeated as |
2327 |
often as necessary. |
2328 |
|
2329 |
=head1 THE F<STATICPERL> SCRIPT |
2330 |
|
2331 |
This module installs a script called F<staticperl> into your perl |
2332 |
binary directory. The script is fully self-contained, and can be |
2333 |
used without perl (for example, in an uClibc/dietlibc/musl chroot |
2334 |
environment). In fact, it can be extracted from the C<App::Staticperl> |
2335 |
distribution tarball as F<bin/staticperl>, without any installation. The |
2336 |
newest (possibly alpha) version can also be downloaded from |
2337 |
L<http://staticperl.schmorp.de/staticperl>. |
2338 |
|
2339 |
F<staticperl> interprets the first argument as a command to execute, |
2340 |
optionally followed by any parameters. |
2341 |
|
2342 |
There are two command categories: the "phase 1" commands which deal with |
2343 |
installing perl and perl modules, and the "phase 2" commands, which deal |
2344 |
with creating binaries and bundle files. |
2345 |
|
2346 |
=head2 PHASE 1 COMMANDS: INSTALLING PERL |
2347 |
|
2348 |
The most important command is F<install>, which does basically |
2349 |
everything. The default is to download and install perl 5.12.3 and a few |
2350 |
modules required by F<staticperl> itself, but all this can (and should) be |
2351 |
changed - see L<CONFIGURATION>, below. |
2352 |
|
2353 |
The command |
2354 |
|
2355 |
staticperl install |
2356 |
|
2357 |
is normally all you need: It installs the perl interpreter in |
2358 |
F<~/.staticperl/perl>. It downloads, configures, builds and installs the |
2359 |
perl interpreter if required. |
2360 |
|
2361 |
Most of the following F<staticperl> subcommands simply run one or more |
2362 |
steps of this sequence. |
2363 |
|
2364 |
If it fails, then most commonly because the compiler options I selected |
2365 |
are not supported by your compiler - either edit the F<staticperl> script |
2366 |
yourself or create F<~/.staticperl> shell script where your set working |
2367 |
C<PERL_CCFLAGS> etc. variables. |
2368 |
|
2369 |
To force recompilation or reinstallation, you need to run F<staticperl |
2370 |
distclean> first. |
2371 |
|
2372 |
=over 4 |
2373 |
|
2374 |
=item F<staticperl version> |
2375 |
|
2376 |
Prints some info about the version of the F<staticperl> script you are using. |
2377 |
|
2378 |
=item F<staticperl fetch> |
2379 |
|
2380 |
Runs only the download and unpack phase, unless this has already happened. |
2381 |
|
2382 |
=item F<staticperl configure> |
2383 |
|
2384 |
Configures the unpacked perl sources, potentially after downloading them first. |
2385 |
|
2386 |
=item F<staticperl build> |
2387 |
|
2388 |
Builds the configured perl sources, potentially after automatically |
2389 |
configuring them. |
2390 |
|
2391 |
=item F<staticperl install> |
2392 |
|
2393 |
Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
2394 |
installs the perl distribution, potentially after building it first. |
2395 |
|
2396 |
=item F<staticperl perl> [args...] |
2397 |
|
2398 |
Invokes the compiled perl interpreter with the given |
2399 |
arguments. Basically the same as starting perl directly (usually via |
2400 |
F<~/.staticperl/bin/perl>), but beats typing the path sometimes. |
2401 |
|
2402 |
Example: check that the Gtk2 module is installed and loadable. |
2403 |
|
2404 |
staticperl perl -MGtk2 -e0 |
2405 |
|
2406 |
=item F<staticperl cpan> [args...] |
2407 |
|
2408 |
Starts an interactive CPAN shell that you can use to install further |
2409 |
modules. Installs the perl first if necessary, but apart from that, |
2410 |
no magic is involved: you could just as well run it manually via |
2411 |
F<~/.staticperl/perl/bin/cpan>, except that F<staticperl> additionally |
2412 |
sets the environment variable C<$PERL> to the path of the perl |
2413 |
interpreter, which is handy in subshells. |
2414 |
|
2415 |
Any additional arguments are simply passed to the F<cpan> command. |
2416 |
|
2417 |
=item F<staticperl instcpan> module... |
2418 |
|
2419 |
Tries to install all the modules given and their dependencies, using CPAN. |
2420 |
|
2421 |
Example: |
2422 |
|
2423 |
staticperl instcpan EV AnyEvent::HTTPD Coro |
2424 |
|
2425 |
=item F<staticperl instsrc> directory... |
2426 |
|
2427 |
In the unlikely case that you have unpacked perl modules around and want |
2428 |
to install from these instead of from CPAN, you can do this using this |
2429 |
command by specifying all the directories with modules in them that you |
2430 |
want to have built. |
2431 |
|
2432 |
=item F<staticperl clean> |
2433 |
|
2434 |
Deletes the perl source directory (and potentially cleans up other |
2435 |
intermediate files). This can be used to clean up files only needed for |
2436 |
building perl, without removing the installed perl interpreter. |
2437 |
|
2438 |
At the moment, it doesn't delete downloaded tarballs. |
2439 |
|
2440 |
The exact semantics of this command will probably change. |
2441 |
|
2442 |
=item F<staticperl distclean> |
2443 |
|
2444 |
This wipes your complete F<~/.staticperl> directory. Be careful with this, |
2445 |
it nukes your perl download, perl sources, perl distribution and any |
2446 |
installed modules. It is useful if you wish to start over "from scratch" |
2447 |
or when you want to uninstall F<staticperl>. |
2448 |
|
2449 |
=back |
2450 |
|
2451 |
=head2 PHASE 2 COMMANDS: BUILDING PERL BUNDLES |
2452 |
|
2453 |
Building (linking) a new F<perl> binary is handled by a separate |
2454 |
script. To make it easy to use F<staticperl> from a F<chroot>, the script |
2455 |
is embedded into F<staticperl>, which will write it out and call for you |
2456 |
with any arguments you pass: |
2457 |
|
2458 |
staticperl mkbundle mkbundle-args... |
2459 |
|
2460 |
In the oh so unlikely case of something not working here, you |
2461 |
can run the script manually as well (by default it is written to |
2462 |
F<~/.staticperl/mkbundle>). |
2463 |
|
2464 |
F<mkbundle> is a more conventional command and expect the argument |
2465 |
syntax commonly used on UNIX clones. For example, this command builds |
2466 |
a new F<perl> binary and includes F<Config.pm> (for F<perl -V>), |
2467 |
F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd> |
2468 |
in this distribution): |
2469 |
|
2470 |
# first make sure we have perl and the required modules |
2471 |
staticperl instcpan AnyEvent::HTTPD |
2472 |
|
2473 |
# now build the perl |
2474 |
staticperl mkperl -MConfig_heavy.pl -MAnyEvent::Impl::Perl \ |
2475 |
-MAnyEvent::HTTPD -MURI::http \ |
2476 |
--add 'eg/httpd httpd.pm' |
2477 |
|
2478 |
# finally, invoke it |
2479 |
./perl -Mhttpd |
2480 |
|
2481 |
As you can see, things are not quite as trivial: the L<Config> module has |
2482 |
a hidden dependency which is not even a perl module (F<Config_heavy.pl>), |
2483 |
L<AnyEvent> needs at least one event loop backend that we have to |
2484 |
specify manually (here L<AnyEvent::Impl::Perl>), and the F<URI> module |
2485 |
(required by L<AnyEvent::HTTPD>) implements various URI schemes as extra |
2486 |
modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need |
2487 |
to include that module. I found out about these dependencies by carefully |
2488 |
watching any error messages about missing modules... |
2489 |
|
2490 |
Instead of building a new perl binary, you can also build a standalone |
2491 |
application: |
2492 |
|
2493 |
# build the app |
2494 |
staticperl mkapp app --boot eg/httpd \ |
2495 |
-MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http |
2496 |
|
2497 |
# run it |
2498 |
./app |
2499 |
|
2500 |
Here are the three phase 2 commands: |
2501 |
|
2502 |
=over 4 |
2503 |
|
2504 |
=item F<staticperl mkbundle> args... |
2505 |
|
2506 |
The "default" bundle command - it interprets the given bundle options and |
2507 |
writes out F<bundle.h>, F<bundle.c>, F<bundle.ccopts> and F<bundle.ldopts> |
2508 |
files, useful for embedding. |
2509 |
|
2510 |
=item F<staticperl mkperl> args... |
2511 |
|
2512 |
Creates a bundle just like F<staticperl mkbundle> (in fact, it's the same |
2513 |
as invoking F<staticperl mkbundle --perl> args...), but then compiles and |
2514 |
links a new perl interpreter that embeds the created bundle, then deletes |
2515 |
all intermediate files. |
2516 |
|
2517 |
=item F<staticperl mkapp> filename args... |
2518 |
|
2519 |
Does the same as F<staticperl mkbundle> (in fact, it's the same as |
2520 |
invoking F<staticperl mkbundle --app> filename args...), but then compiles |
2521 |
and links a new standalone application that simply initialises the perl |
2522 |
interpreter. |
2523 |
|
2524 |
The difference to F<staticperl mkperl> is that the standalone application |
2525 |
does not act like a perl interpreter would - in fact, by default it would |
2526 |
just do nothing and exit immediately, so you should specify some code to |
2527 |
be executed via the F<--boot> option. |
2528 |
|
2529 |
=back |
2530 |
|
2531 |
=head3 OPTION PROCESSING |
2532 |
|
2533 |
All options can be given as arguments on the command line (typically |
2534 |
using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
2535 |
specifying a lot of options can make the command line very long and |
2536 |
unwieldy, you can put all long options into a "bundle specification file" |
2537 |
(one option per line, with or without C<--> prefix) and specify this |
2538 |
bundle file instead. |
2539 |
|
2540 |
For example, the command given earlier to link a new F<perl> could also |
2541 |
look like this: |
2542 |
|
2543 |
staticperl mkperl httpd.bundle |
2544 |
|
2545 |
With all options stored in the F<httpd.bundle> file (one option per line, |
2546 |
everything after the option is an argument): |
2547 |
|
2548 |
use "Config_heavy.pl" |
2549 |
use AnyEvent::Impl::Perl |
2550 |
use AnyEvent::HTTPD |
2551 |
use URI::http |
2552 |
add eg/httpd httpd.pm |
2553 |
|
2554 |
All options that specify modules or files to be added are processed in the |
2555 |
order given on the command line. |
2556 |
|
2557 |
=head3 BUNDLE CREATION WORKFLOW / STATICPERL MKBUNDLE OPTIONS |
2558 |
|
2559 |
F<staticperl mkbundle> works by first assembling a list of candidate |
2560 |
files and modules to include, then filtering them by include/exclude |
2561 |
patterns. The remaining modules (together with their direct dependencies, |
2562 |
such as link libraries and L<AutoLoader> files) are then converted into |
2563 |
bundle files suitable for embedding. F<staticperl mkbundle> can then |
2564 |
optionally build a new perl interpreter or a standalone application. |
2565 |
|
2566 |
=over 4 |
2567 |
|
2568 |
=item Step 0: Generic argument processing. |
2569 |
|
2570 |
The following options influence F<staticperl mkbundle> itself. |
2571 |
|
2572 |
=over 4 |
2573 |
|
2574 |
=item C<--verbose> | C<-v> |
2575 |
|
2576 |
Increases the verbosity level by one (the default is C<1>). |
2577 |
|
2578 |
=item C<--quiet> | C<-q> |
2579 |
|
2580 |
Decreases the verbosity level by one. |
2581 |
|
2582 |
=item any other argument |
2583 |
|
2584 |
Any other argument is interpreted as a bundle specification file, which |
2585 |
supports all options (without extra quoting), one option per line, in the |
2586 |
format C<option> or C<option argument>. They will effectively be expanded |
2587 |
and processed as if they were directly written on the command line, in |
2588 |
place of the file name. |
2589 |
|
2590 |
=back |
2591 |
|
2592 |
=item Step 1: gather candidate files and modules |
2593 |
|
2594 |
In this step, modules, perl libraries (F<.pl> files) and other files are |
2595 |
selected for inclusion in the bundle. The relevant options are executed |
2596 |
in order (this makes a difference mostly for C<--eval>, which can rely on |
2597 |
earlier C<--use> options to have been executed). |
2598 |
|
2599 |
=over 4 |
2600 |
|
2601 |
=item C<--use> F<module> | C<-M>F<module> |
2602 |
|
2603 |
Include the named module or perl library and trace direct |
2604 |
dependencies. This is done by loading the module in a subprocess and |
2605 |
tracing which other modules and files it actually loads. |
2606 |
|
2607 |
Example: include AnyEvent and AnyEvent::Impl::Perl. |
2608 |
|
2609 |
staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
2610 |
|
2611 |
Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
2612 |
maybe other weirdly named files. To support this, the C<--use> option |
2613 |
actually tries to do what you mean, depending on the string you specify: |
2614 |
|
2615 |
=over 4 |
2616 |
|
2617 |
=item a possibly valid module name, e.g. F<common::sense>, F<Carp>, |
2618 |
F<Coro::Mysql>. |
2619 |
|
2620 |
If the string contains no quotes, no F</> and no F<.>, then C<--use> |
2621 |
assumes that it is a normal module name. It will create a new package and |
2622 |
evaluate a C<use module> in it, i.e. it will load the package and do a |
2623 |
default import. |
2624 |
|
2625 |
The import step is done because many modules trigger more dependencies |
2626 |
when something is imported than without. |
2627 |
|
2628 |
=item anything that contains F</> or F<.> characters, |
2629 |
e.g. F<utf8_heavy.pl>, F<Module/private/data.pl>. |
2630 |
|
2631 |
The string will be quoted and passed to require, as if you used C<require |
2632 |
$module>. Nothing will be imported. |
2633 |
|
2634 |
=item "path" or 'path', e.g. C<"utf8_heavy.pl">. |
2635 |
|
2636 |
If you enclose the name into single or double quotes, then the quotes will |
2637 |
be removed and the resulting string will be passed to require. This syntax |
2638 |
is form compatibility with older versions of staticperl and should not be |
2639 |
used anymore. |
2640 |
|
2641 |
=back |
2642 |
|
2643 |
Example: C<use> AnyEvent::Socket, once using C<use> (importing the |
2644 |
symbols), and once via C<require>, not importing any symbols. The first |
2645 |
form is preferred as many modules load some extra dependencies when asked |
2646 |
to export symbols. |
2647 |
|
2648 |
staticperl mkbundle -MAnyEvent::Socket # use + import |
2649 |
staticperl mkbundle -MAnyEvent/Socket.pm # require only |
2650 |
|
2651 |
Example: include the required files for F<perl -V> to work in all its |
2652 |
glory (F<Config.pm> is included automatically by the dependency tracker). |
2653 |
|
2654 |
# shell command |
2655 |
staticperl mkbundle -MConfig_heavy.pl |
2656 |
|
2657 |
# bundle specification file |
2658 |
use Config_heavy.pl |
2659 |
|
2660 |
The C<-M>module syntax is included as a convenience that might be easier |
2661 |
to remember than C<--use> - it's the same switch as perl itself uses |
2662 |
to load modules. Or maybe it confuses people. Time will tell. Or maybe |
2663 |
not. Sigh. |
2664 |
|
2665 |
=item C<--eval> "perl code" | C<-e> "perl code" |
2666 |
|
2667 |
Sometimes it is easier (or necessary) to specify dependencies using perl |
2668 |
code, or maybe one of the modules you use need a special use statement. In |
2669 |
that case, you can use C<--eval> to execute some perl snippet or set some |
2670 |
variables or whatever you need. All files C<require>'d or C<use>'d while |
2671 |
executing the snippet are included in the final bundle. |
2672 |
|
2673 |
Keep in mind that F<mkbundle> will not import any symbols from the modules |
2674 |
named by the C<--use> option, so do not expect the symbols from modules |
2675 |
you C<--use>'d earlier on the command line to be available. |
2676 |
|
2677 |
Example: force L<AnyEvent> to detect a backend and therefore include it |
2678 |
in the final bundle. |
2679 |
|
2680 |
staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
2681 |
|
2682 |
# or like this |
2683 |
staticperl mkbundle -MAnyEvent --eval 'AnyEvent::detect' |
2684 |
|
2685 |
Example: use a separate "bootstrap" script that C<use>'s lots of modules |
2686 |
and also include this in the final bundle, to be executed automatically |
2687 |
when the interpreter is initialised. |
2688 |
|
2689 |
staticperl mkbundle --eval 'do "bootstrap"' --boot bootstrap |
2690 |
|
2691 |
=item C<--boot> F<filename> |
2692 |
|
2693 |
Include the given file in the bundle and arrange for it to be |
2694 |
executed (using C<require>) before the main program when the new perl |
2695 |
is initialised. This can be used to modify C<@INC> or do similar |
2696 |
modifications before the perl interpreter executes scripts given on the |
2697 |
command line (or via C<-e>). This works even in an embedded interpreter - |
2698 |
the file will be executed during interpreter initialisation in that case. |
2699 |
|
2700 |
=item C<--incglob> pattern |
2701 |
|
2702 |
This goes through all standard library directories and tries to match any |
2703 |
F<.pm> and F<.pl> files against the extended glob pattern (see below). If |
2704 |
a file matches, it is added. The pattern is matched against the full path |
2705 |
of the file (sans the library directory prefix), e.g. F<Sys/Syslog.pm>. |
2706 |
|
2707 |
This is very useful to include "everything": |
2708 |
|
2709 |
--incglob '*' |
2710 |
|
2711 |
It is also useful for including perl libraries, or trees of those, such as |
2712 |
the unicode database files needed by some perl built-ins, the regex engine |
2713 |
and other modules. |
2714 |
|
2715 |
--incglob '/unicore/**.pl' |
2716 |
|
2717 |
=item C<--add> F<file> | C<--add> "F<file> alias" |
2718 |
|
2719 |
Adds the given (perl) file into the bundle (and optionally call it |
2720 |
"alias"). The F<file> is either an absolute path or a path relative to the |
2721 |
current directory. If an alias is specified, then this is the name it will |
2722 |
use for C<@INC> searches, otherwise the path F<file> will be used as the |
2723 |
internal name. |
2724 |
|
2725 |
This switch is used to include extra files into the bundle. |
2726 |
|
2727 |
Example: embed the file F<httpd> in the current directory as F<httpd.pm> |
2728 |
when creating the bundle. |
2729 |
|
2730 |
staticperl mkperl --add "httpd httpd.pm" |
2731 |
|
2732 |
# can be accessed via "use httpd" |
2733 |
|
2734 |
Example: add a file F<initcode> from the current directory. |
2735 |
|
2736 |
staticperl mkperl --add 'initcode &initcode' |
2737 |
|
2738 |
# can be accessed via "do '&initcode'" |
2739 |
|
2740 |
Example: add local files as extra modules in the bundle. |
2741 |
|
2742 |
# specification file |
2743 |
add file1 myfiles/file1.pm |
2744 |
add file2 myfiles/file2.pm |
2745 |
add file3 myfiles/file3.pl |
2746 |
|
2747 |
# then later, in perl, use |
2748 |
use myfiles::file1; |
2749 |
require myfiles::file2; |
2750 |
my $res = do "myfiles/file3.pl"; |
2751 |
|
2752 |
=item C<--addbin> F<file> | C<--addbin> "F<file> alias" |
2753 |
|
2754 |
Just like C<--add>, except that it treats the file as binary and adds it |
2755 |
without any post-processing (perl files might get stripped to reduce their |
2756 |
size). |
2757 |
|
2758 |
If you specify an alias you should probably add a C</> prefix to avoid |
2759 |
clashing with embedded perl files (whose paths never start with C</>), |
2760 |
and/or use a special directory prefix, such as C</res/name>. |
2761 |
|
2762 |
You can later get a copy of these files by calling C<static::find |
2763 |
"alias">. |
2764 |
|
2765 |
An alternative way to embed binary files is to convert them to perl and |
2766 |
use C<do> to get the contents - this method is a bit cumbersome, but works |
2767 |
both inside and outside of a staticperl bundle, without extra ado: |
2768 |
|
2769 |
# a "binary" file, call it "bindata.pl" |
2770 |
<<'SOME_MARKER' |
2771 |
binary data NOT containing SOME_MARKER |
2772 |
SOME_MARKER |
2773 |
|
2774 |
# load the binary |
2775 |
chomp (my $data = do "bindata.pl"); |
2776 |
|
2777 |
=item C<--allow-dynamic> |
2778 |
|
2779 |
By default, when F<mkbundle> hits a dynamic perl extension (e.g. a F<.so> |
2780 |
or F<.dll> file), it will stop with a fatal error. |
2781 |
|
2782 |
When this option is enabled, F<mkbundle> packages the shared |
2783 |
object into the bundle instead, with a prefix of F<!> |
2784 |
(e.g. F<!auto/List/Util/Util.so>). What you do with that is currently up |
2785 |
to you, F<staticperl> has no special support for this at the moment, apart |
2786 |
from working around the lack of availability of F<PerlIO::scalar> while |
2787 |
bootstrapping, at a speed cost. |
2788 |
|
2789 |
One way to deal with this is to write all files starting with F<!> into |
2790 |
some directory and then C<unshift> that path onto C<@INC>. |
2791 |
|
2792 |
(TODO for future self: write and insert a suitable example here, if |
2793 |
somebody requests it). |
2794 |
|
2795 |
=back |
2796 |
|
2797 |
=item Step 2: filter all files using C<--include> and C<--exclude> options. |
2798 |
|
2799 |
After all candidate files and modules are added, they are I<filtered> |
2800 |
by a combination of C<--include> and C<--exclude> patterns (there is an |
2801 |
implicit C<--include *> at the end, so if no filters are specified, all |
2802 |
files are included). |
2803 |
|
2804 |
All that this step does is potentially reduce the number of files that are |
2805 |
to be included - no new files are added during this step. |
2806 |
|
2807 |
=over 4 |
2808 |
|
2809 |
=item C<--include> pattern | C<-i> pattern | C<--exclude> pattern | C<-x> pattern |
2810 |
|
2811 |
These specify an include or exclude pattern to be applied to the candidate |
2812 |
file list. An include makes sure that the given files will be part of the |
2813 |
resulting file set, an exclude will exclude remaining files. The patterns |
2814 |
are "extended glob patterns" (see below). |
2815 |
|
2816 |
The patterns are applied "in order" - files included via earlier |
2817 |
C<--include> specifications cannot be removed by any following |
2818 |
C<--exclude>, and likewise, and file excluded by an earlier C<--exclude> |
2819 |
cannot be added by any following C<--include>. |
2820 |
|
2821 |
For example, to include everything except C<Devel> modules, but still |
2822 |
include F<Devel::PPPort>, you could use this: |
2823 |
|
2824 |
--incglob '*' -i '/Devel/PPPort.pm' -x '/Devel/**' |
2825 |
|
2826 |
=back |
2827 |
|
2828 |
=item Step 3: add any extra or "hidden" dependencies. |
2829 |
|
2830 |
F<staticperl> currently knows about three extra types of depdendencies |
2831 |
that are added automatically. Only one (F<.packlist> files) is currently |
2832 |
optional and can be influenced, the others are always included: |
2833 |
|
2834 |
=over 4 |
2835 |
|
2836 |
=item C<--usepacklists> |
2837 |
|
2838 |
Read F<.packlist> files for each distribution that happens to match a |
2839 |
module name you specified. Sounds weird, and it is, so expect semantics to |
2840 |
change somehow in the future. |
2841 |
|
2842 |
The idea is that most CPAN distributions have a F<.pm> file that matches |
2843 |
the name of the distribution (which is rather reasonable after all). |
2844 |
|
2845 |
If this switch is enabled, then if any of the F<.pm> files that have been |
2846 |
selected match an install distribution, then all F<.pm>, F<.pl>, F<.al> |
2847 |
and F<.ix> files installed by this distribution are also included. |
2848 |
|
2849 |
For example, using this switch, when the L<URI> module is specified, then |
2850 |
all L<URI> submodules that have been installed via the CPAN distribution |
2851 |
are included as well, so you don't have to manually specify them. |
2852 |
|
2853 |
=item L<AutoLoader> splitfiles |
2854 |
|
2855 |
Some modules use L<AutoLoader> - less commonly (hopefully) used functions |
2856 |
are split into separate F<.al> files, and an index (F<.ix>) file contains |
2857 |
the prototypes. |
2858 |
|
2859 |
Both F<.ix> and F<.al> files will be detected automatically and added to |
2860 |
the bundle. |
2861 |
|
2862 |
=item link libraries (F<.a> files) |
2863 |
|
2864 |
Modules using XS (or any other non-perl language extension compiled at |
2865 |
installation time) will have a static archive (typically F<.a>). These |
2866 |
will automatically be added to the linker options in F<bundle.ldopts>. |
2867 |
|
2868 |
Should F<staticperl> find a dynamic link library (typically F<.so>) it |
2869 |
will warn about it - obviously this shouldn't happen unless you use |
2870 |
F<staticperl> on the wrong perl, or one (probably wrongly) configured to |
2871 |
use dynamic loading. |
2872 |
|
2873 |
=item extra libraries (F<extralibs.ld>) |
2874 |
|
2875 |
Some modules need linking against external libraries - these are found in |
2876 |
F<extralibs.ld> and added to F<bundle.ldopts>. |
2877 |
|
2878 |
=back |
2879 |
|
2880 |
=item Step 4: write bundle files and optionally link a program |
2881 |
|
2882 |
At this point, the select files will be read, processed (stripped) and |
2883 |
finally the bundle files get written to disk, and F<staticperl mkbundle> |
2884 |
is normally finished. Optionally, it can go a step further and either link |
2885 |
a new F<perl> binary with all selected modules and files inside, or build |
2886 |
a standalone application. |
2887 |
|
2888 |
Both the contents of the bundle files and any extra linking is controlled |
2889 |
by these options: |
2890 |
|
2891 |
=over 4 |
2892 |
|
2893 |
=item C<--strip> C<none>|C<pod>|C<ppi> |
2894 |
|
2895 |
Specify the stripping method applied to reduce the file of the perl |
2896 |
sources included. |
2897 |
|
2898 |
The default is C<pod>, which uses the L<Pod::Strip> module to remove all |
2899 |
pod documentation, which is very fast and reduces file size a lot. |
2900 |
|
2901 |
The C<ppi> method uses L<PPI> to parse and condense the perl sources. This |
2902 |
saves a lot more than just L<Pod::Strip>, and is generally safer, |
2903 |
but is also a lot slower (some files take almost a minute to strip - |
2904 |
F<staticperl> maintains a cache of stripped files to speed up subsequent |
2905 |
runs for this reason). Note that this method doesn't optimise for raw file |
2906 |
size, but for best compression (that means that the uncompressed file size |
2907 |
is a bit larger, but the files compress better, e.g. with F<upx>). |
2908 |
|
2909 |
Last not least, if you need accurate line numbers in error messages, |
2910 |
or in the unlikely case where C<pod> is too slow, or some module gets |
2911 |
mistreated, you can specify C<none> to not mangle included perl sources in |
2912 |
any way. |
2913 |
|
2914 |
=item C<--compress> C<none>|C<lzf> |
2915 |
|
2916 |
Compress each included library file with C<lzf> (default), or do not |
2917 |
compress (C<none>). LZF compression typically halves the size of the |
2918 |
included library data at almost no overhead, but is counterproductive if |
2919 |
you are using another compression solution such as C<UPX>, so it can be |
2920 |
disabled. |
2921 |
|
2922 |
=item C<--perl> |
2923 |
|
2924 |
After writing out the bundle files, try to link a new perl interpreter. It |
2925 |
will be called F<perl> and will be left in the current working |
2926 |
directory. The bundle files will be removed. |
2927 |
|
2928 |
This switch is automatically used when F<staticperl> is invoked with the |
2929 |
C<mkperl> command instead of C<mkbundle>. |
2930 |
|
2931 |
Example: build a new F<./perl> binary with only L<common::sense> inside - |
2932 |
it will be even smaller than the standard perl interpreter as none of the |
2933 |
modules of the base distribution (such as L<Fcntl>) will be included. |
2934 |
|
2935 |
staticperl mkperl -Mcommon::sense |
2936 |
|
2937 |
=item C<--app> F<name> |
2938 |
|
2939 |
After writing out the bundle files, try to link a new standalone |
2940 |
program. It will be called C<name>, and the bundle files get removed after |
2941 |
linking it. |
2942 |
|
2943 |
This switch is automatically used when F<staticperl> is invoked with the |
2944 |
C<mkapp> command instead of C<mkbundle>. |
2945 |
|
2946 |
The difference to the (mutually exclusive) C<--perl> option is that the |
2947 |
binary created by this option will not try to act as a perl interpreter - |
2948 |
instead it will simply initialise the perl interpreter, clean it up and |
2949 |
exit. |
2950 |
|
2951 |
This means that, by default, it will do nothing but burn a few CPU cycles |
2952 |
- for it to do something useful you I<must> add some boot code, e.g. with |
2953 |
the C<--boot> option. |
2954 |
|
2955 |
Example: create a standalone perl binary called F<./myexe> that will |
2956 |
execute F<appfile> when it is started. |
2957 |
|
2958 |
staticperl mkbundle --app myexe --boot appfile |
2959 |
|
2960 |
=item C<--ignore-env> |
2961 |
|
2962 |
Generates extra code to unset some environment variables before |
2963 |
initialising/running perl. Perl supports a lot of environment variables |
2964 |
that might alter execution in ways that might be undesirable for |
2965 |
standalone applications, and this option removes those known to cause |
2966 |
trouble. |
2967 |
|
2968 |
Specifically, these are removed: |
2969 |
|
2970 |
C<PERL_HASH_SEED_DEBUG> and C<PERL_DEBUG_MSTATS> can cause undesirable |
2971 |
output, C<PERL5OPT>, C<PERL_DESTRUCT_LEVEL>, C<PERL_HASH_SEED> and |
2972 |
C<PERL_SIGNALS> can alter execution significantly, and C<PERL_UNICODE>, |
2973 |
C<PERLIO_DEBUG> and C<PERLIO> can affect input and output. |
2974 |
|
2975 |
The variables C<PERL_LIB> and C<PERL5_LIB> are always ignored because the |
2976 |
startup code used by F<staticperl> overrides C<@INC> in all cases. |
2977 |
|
2978 |
This option will not make your program more secure (unless you are |
2979 |
running with elevated privileges), but it will reduce the surprise effect |
2980 |
when a user has these environment variables set and doesn't expect your |
2981 |
standalone program to act like a perl interpreter. |
2982 |
|
2983 |
=item C<--static> |
2984 |
|
2985 |
Add C<-static> to F<bundle.ldopts>, which means a fully static (if |
2986 |
supported by the OS) executable will be created. This is not immensely |
2987 |
useful when just creating the bundle files, but is most useful when |
2988 |
linking a binary with the C<--perl> or C<--app> options. |
2989 |
|
2990 |
The default is to link the new binary dynamically (that means all perl |
2991 |
modules are linked statically, but all external libraries are still |
2992 |
referenced dynamically). |
2993 |
|
2994 |
Keep in mind that Solaris doesn't support static linking at all, and |
2995 |
systems based on GNU libc don't really support it in a very usable fashion |
2996 |
either. Try dietlibc or musl if you want to create fully statically linked |
2997 |
executables, or try the C<--staticlib> option to link only some libraries |
2998 |
statically. |
2999 |
|
3000 |
=item C<--staticlib> libname |
3001 |
|
3002 |
When not linking fully statically, this option allows you to link specific |
3003 |
libraries statically. What it does is simply replace all occurrences of |
3004 |
C<-llibname> with the GCC-specific C<-Wl,-Bstatic -llibname -Wl,-Bdynamic> |
3005 |
option. |
3006 |
|
3007 |
This will have no effect unless the library is actually linked against, |
3008 |
specifically, C<--staticlib> will not link against the named library |
3009 |
unless it would be linked against anyway. |
3010 |
|
3011 |
Example: link libcrypt statically into the final binary. |
3012 |
|
3013 |
staticperl mkperl -MIO::AIO --staticlib crypt |
3014 |
|
3015 |
# ldopts might now contain: |
3016 |
# -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread |
3017 |
|
3018 |
=item C<--extra-cflags> string |
3019 |
|
3020 |
Specifies extra compiler flags, used when compiling the bundle file. The |
3021 |
flags are appended to all the existing flags, so can be sued to override |
3022 |
settings. |
3023 |
|
3024 |
=item C<--extra-ldflags> string |
3025 |
|
3026 |
Specifies extra linker flags, used when linking the bundle. |
3027 |
|
3028 |
=item C<--extra-libs> string |
3029 |
|
3030 |
Extra linker flags, appended at the end when linking. The difference to |
3031 |
C<--extra-ldflags> is that the ldflags are appended to the flags, before |
3032 |
the objects and libraries, and the extra libs are added at the end. |
3033 |
|
3034 |
=back |
3035 |
|
3036 |
=back |
3037 |
|
3038 |
=head3 EXTENDED GLOB PATTERNS |
3039 |
|
3040 |
Some options of F<staticperl mkbundle> expect an I<extended glob |
3041 |
pattern>. This is neither a normal shell glob nor a regex, but something |
3042 |
in between. The idea has been copied from rsync, and there are the current |
3043 |
matching rules: |
3044 |
|
3045 |
=over 4 |
3046 |
|
3047 |
=item Patterns starting with F</> will be a anchored at the root of the library tree. |
3048 |
|
3049 |
That is, F</unicore> will match the F<unicore> directory in C<@INC>, but |
3050 |
nothing inside, and neither any other file or directory called F<unicore> |
3051 |
anywhere else in the hierarchy. |
3052 |
|
3053 |
=item Patterns not starting with F</> will be anchored at the end of the path. |
3054 |
|
3055 |
That is, F<idna.pl> will match any file called F<idna.pl> anywhere in the |
3056 |
hierarchy, but not any directories of the same name. |
3057 |
|
3058 |
=item A F<*> matches anything within a single path component. |
3059 |
|
3060 |
That is, F</unicore/*.pl> would match all F<.pl> files directly inside |
3061 |
C</unicore>, not any deeper level F<.pl> files. Or in other words, F<*> |
3062 |
will not match slashes. |
3063 |
|
3064 |
=item A F<**> matches anything. |
3065 |
|
3066 |
That is, F</unicore/**.pl> would match all F<.pl> files under F</unicore>, |
3067 |
no matter how deeply nested they are inside subdirectories. |
3068 |
|
3069 |
=item A F<?> matches a single character within a component. |
3070 |
|
3071 |
That is, F</Encode/??.pm> matches F</Encode/JP.pm>, but not the |
3072 |
hypothetical F</Encode/J/.pm>, as F<?> does not match F</>. |
3073 |
|
3074 |
=back |
3075 |
|
3076 |
=head2 F<STATICPERL> CONFIGURATION AND HOOKS |
3077 |
|
3078 |
During (each) startup, F<staticperl> tries to source some shell files to |
3079 |
allow you to fine-tune/override configuration settings. |
3080 |
|
3081 |
In them you can override shell variables, or define shell functions |
3082 |
("hooks") to be called at specific phases during installation. For |
3083 |
example, you could define a C<postinstall> hook to install additional |
3084 |
modules from CPAN each time you start from scratch. |
3085 |
|
3086 |
If the environment variable C<$STATICPERLRC> is set, then F<staticperl> |
3087 |
will try to source the file named with it only. Otherwise, it tries the |
3088 |
following shell files in order: |
3089 |
|
3090 |
/etc/staticperlrc |
3091 |
~/.staticperlrc |
3092 |
$STATICPERL/rc |
3093 |
|
3094 |
Note that the last file is erased during F<staticperl distclean>, so |
3095 |
generally should not be used. |
3096 |
|
3097 |
=head3 CONFIGURATION VARIABLES |
3098 |
|
3099 |
=head4 Variables you I<should> override |
3100 |
|
3101 |
=over 4 |
3102 |
|
3103 |
=item C<EMAIL> |
3104 |
|
3105 |
The e-mail address of the person who built this binary. Has no good |
3106 |
default, so should be specified by you. |
3107 |
|
3108 |
=item C<CPAN> |
3109 |
|
3110 |
The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). |
3111 |
|
3112 |
=item C<EXTRA_MODULES> |
3113 |
|
3114 |
Additional modules installed during F<staticperl install>. Here you can |
3115 |
set which modules you want have to installed from CPAN. |
3116 |
|
3117 |
Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO. |
3118 |
|
3119 |
EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO" |
3120 |
|
3121 |
Note that you can also use a C<postinstall> hook to achieve this, and |
3122 |
more. |
3123 |
|
3124 |
=back |
3125 |
|
3126 |
=head4 Variables you might I<want> to override |
3127 |
|
3128 |
=over 4 |
3129 |
|
3130 |
=item C<STATICPERL> |
3131 |
|
3132 |
The directory where staticperl stores all its files |
3133 |
(default: F<~/.staticperl>). |
3134 |
|
3135 |
=item C<DLCACHE> |
3136 |
|
3137 |
The path to a directory (will be created if it doesn't exist) where |
3138 |
downloaded perl sources are being cached, to avoid downloading them |
3139 |
again. The default is empty, which means there is no cache. |
3140 |
|
3141 |
=item C<PERL_VERSION> |
3142 |
|
3143 |
The perl version to install - C<5.12.5> is a good choice for small builds, |
3144 |
but C<5.8.9> is also a good choice (5.8.9 is much smaller than 5.12.5), if |
3145 |
it builds on your system. |
3146 |
|
3147 |
You can also set this variable to the absolute URL of a tarball (F<.tar>, |
3148 |
F<.tar.gz>, F<.tar.bz2>, F<.tar.lzma> or F<.tar.xz>), or to the absolute |
3149 |
path of an unpacked perl source tree, which will be copied. |
3150 |
|
3151 |
The default is currently |
3152 |
F<http://stableperl.schmorp.de/dist/latest.tar.gz>, i.e. the latest |
3153 |
stableperl release. |
3154 |
|
3155 |
=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
3156 |
|
3157 |
Usually set to C<1> to make modules "less inquisitive" during their |
3158 |
installation. You can set (and export!) any environment variable you want |
3159 |
- some modules (such as L<Coro> or L<EV>) use environment variables for |
3160 |
further tweaking. |
3161 |
|
3162 |
=item C<PERL_PREFIX> |
3163 |
|
3164 |
The directory where perl gets installed (default: F<$STATICPERL/perl>), |
3165 |
i.e. where the F<bin> and F<lib> subdirectories will end up. Previous |
3166 |
contents will be removed on installation. |
3167 |
|
3168 |
=item C<PERL_CONFIGURE> |
3169 |
|
3170 |
Additional Configure options - these are simply passed to the perl |
3171 |
Configure script. For example, if you wanted to enable dynamic loading, |
3172 |
you could pass C<-Dusedl>. To enable ithreads (Why would you want that |
3173 |
insanity? Don't! Use L<Coro> or L<forks> instead!) you would pass |
3174 |
C<-Duseithreads> and so on. |
3175 |
|
3176 |
More commonly, you would either activate 64 bit integer support |
3177 |
(C<-Duse64bitint>), or disable large files support (C<-Uuselargefiles>), |
3178 |
to reduce file size further. |
3179 |
|
3180 |
=item C<PERL_CC>, C<PERL_CCFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
3181 |
|
3182 |
These flags are passed to perl's F<Configure> script, and are generally |
3183 |
optimised for small size (at the cost of performance). Since they also |
3184 |
contain subtle workarounds around various build issues, changing these |
3185 |
usually requires understanding their default values - best look at |
3186 |
the top of the F<staticperl> script for more info on these, and use a |
3187 |
F<~/.staticperlrc> to override them. |
3188 |
|
3189 |
Most of the variables override (or modify) the corresponding F<Configure> |
3190 |
variable, except C<PERL_CCFLAGS>, which gets appended. |
3191 |
|
3192 |
The default for C<PERL_OPTIMIZE> is C<-Os> (assuming gcc or compatible |
3193 |
compilers), and for C<PERL_LIBS> is C<-lm -lcrypt>, which should be good |
3194 |
for most (but not all) systems. |
3195 |
|
3196 |
For other compilers or more customised optimisation settings, you need to |
3197 |
adjust these, e.g. in your F<~/.staticperlrc>. |
3198 |
|
3199 |
With gcc on x86 and amd64, you can often get more space-savings by using: |
3200 |
|
3201 |
-Os -ffunction-sections -fdata-sections -finline-limit=8 -mpush-args |
3202 |
-mno-inline-stringops-dynamically -mno-align-stringops |
3203 |
|
3204 |
And on x86 and pentium3 and newer (basically everything you might ever |
3205 |
want to run on), adding these is even better for space-savings (use |
3206 |
C<-mtune=core2> or something newer for much faster code, too): |
3207 |
|
3208 |
-fomit-frame-pointer -march=pentium3 -mtune=i386 |
3209 |
|
3210 |
=back |
3211 |
|
3212 |
=head4 Variables you probably I<do not want> to override |
3213 |
|
3214 |
=over 4 |
3215 |
|
3216 |
=item C<MAKE> |
3217 |
|
3218 |
The make command to use - default is C<make>. |
3219 |
|
3220 |
=item C<MKBUNDLE> |
3221 |
|
3222 |
Where F<staticperl> writes the C<mkbundle> command to |
3223 |
(default: F<$STATICPERL/mkbundle>). |
3224 |
|
3225 |
=item C<STATICPERL_MODULES> |
3226 |
|
3227 |
Additional modules needed by C<mkbundle> - should therefore not be changed |
3228 |
unless you know what you are doing. |
3229 |
|
3230 |
=back |
3231 |
|
3232 |
=head3 OVERRIDABLE HOOKS |
3233 |
|
3234 |
In addition to environment variables, it is possible to provide some |
3235 |
shell functions that are called at specific times. To provide your own |
3236 |
commands, just define the corresponding function. |
3237 |
|
3238 |
The actual order in which hooks are invoked during a full install |
3239 |
from scratch is C<preconfigure>, C<patchconfig>, C<postconfigure>, |
3240 |
C<postbuild>, C<postinstall>. |
3241 |
|
3242 |
Example: install extra modules from CPAN and from some directories |
3243 |
at F<staticperl install> time. |
3244 |
|
3245 |
postinstall() { |
3246 |
rm -rf lib/threads* # weg mit Schaden |
3247 |
instcpan IO::AIO EV |
3248 |
instsrc ~/src/AnyEvent |
3249 |
instsrc ~/src/XML-Sablotron-1.0100001 |
3250 |
instcpan Anyevent::AIO AnyEvent::HTTPD |
3251 |
} |
3252 |
|
3253 |
=over 4 |
3254 |
|
3255 |
=item preconfigure |
3256 |
|
3257 |
Called just before running F<./Configure> in the perl source |
3258 |
directory. Current working directory is the perl source directory. |
3259 |
|
3260 |
This can be used to set any C<PERL_xxx> variables, which might be costly |
3261 |
to compute. |
3262 |
|
3263 |
=item patchconfig |
3264 |
|
3265 |
Called after running F<./Configure> in the perl source directory to create |
3266 |
F<./config.sh>, but before running F<./Configure -S> to actually apply the |
3267 |
config. Current working directory is the perl source directory. |
3268 |
|
3269 |
Can be used to tailor/patch F<config.sh> or do any other modifications. |
3270 |
|
3271 |
=item postconfigure |
3272 |
|
3273 |
Called after configuring, but before building perl. Current working |
3274 |
directory is the perl source directory. |
3275 |
|
3276 |
=item postbuild |
3277 |
|
3278 |
Called after building, but before installing perl. Current working |
3279 |
directory is the perl source directory. |
3280 |
|
3281 |
I have no clue what this could be used for - tell me. |
3282 |
|
3283 |
=item postcpanconfig |
3284 |
|
3285 |
Called just after CPAN has been configured, but before it has been used to |
3286 |
install anything. You can further change the configuration like this: |
3287 |
|
3288 |
"$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' |
3289 |
CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
3290 |
' || fatal "error while initialising CPAN in postcpanconfig" |
3291 |
|
3292 |
=item postinstall |
3293 |
|
3294 |
Called after perl and any extra modules have been installed in C<$PREFIX>, |
3295 |
but before setting the "installation O.K." flag. |
3296 |
|
3297 |
The current working directory is C<$PREFIX>, but maybe you should not rely |
3298 |
on that. |
3299 |
|
3300 |
This hook is most useful to customise the installation, by deleting files, |
3301 |
or installing extra modules using the C<instcpan> or C<instsrc> functions. |
3302 |
|
3303 |
The script must return with a zero exit status, or the installation will |
3304 |
fail. |
3305 |
|
3306 |
=back |
3307 |
|
3308 |
=head1 ANATOMY OF A BUNDLE |
3309 |
|
3310 |
When not building a new perl binary, C<mkbundle> will leave a number of |
3311 |
files in the current working directory, which can be used to embed a perl |
3312 |
interpreter in your program. |
3313 |
|
3314 |
Intimate knowledge of L<perlembed> and preferably some experience with |
3315 |
embedding perl is highly recommended. |
3316 |
|
3317 |
C<mkperl> (or the C<--perl> option) basically does this to link the new |
3318 |
interpreter (it also adds a main program to F<bundle.>): |
3319 |
|
3320 |
$Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts) |
3321 |
|
3322 |
=over 4 |
3323 |
|
3324 |
=item bundle.h |
3325 |
|
3326 |
A header file that contains the prototypes of the few symbols "exported" |
3327 |
by bundle.c, and also exposes the perl headers to the application. |
3328 |
|
3329 |
=over 4 |
3330 |
|
3331 |
=item staticperl_init (xs_init = 0) |
3332 |
|
3333 |
Initialises the perl interpreter. You can use the normal perl functions |
3334 |
after calling this function, for example, to define extra functions or |
3335 |
to load a .pm file that contains some initialisation code, or the main |
3336 |
program function: |
3337 |
|
3338 |
XS (xsfunction) |
3339 |
{ |
3340 |
dXSARGS; |
3341 |
|
3342 |
// now we have items, ST(i) etc. |
3343 |
} |
3344 |
|
3345 |
static void |
3346 |
run_myapp(void) |
3347 |
{ |
3348 |
staticperl_init (0); |
3349 |
newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
3350 |
eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" |
3351 |
} |
3352 |
|
3353 |
When your boot code already wants to access some XS functions at compile |
3354 |
time, then you need to supply an C<xs_init> function pointer that is |
3355 |
called as soon as perl is initialised enough to define XS functions, but |
3356 |
before the preamble code is executed: |
3357 |
|
3358 |
static void |
3359 |
xs_init (pTHX) |
3360 |
{ |
3361 |
newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
3362 |
} |
3363 |
|
3364 |
static void |
3365 |
run_myapp(void) |
3366 |
{ |
3367 |
staticperl_init (xs_init); |
3368 |
} |
3369 |
|
3370 |
=item staticperl_cleanup () |
3371 |
|
3372 |
In the unlikely case that you want to destroy the perl interpreter, here |
3373 |
is the corresponding function. |
3374 |
|
3375 |
=item staticperl_xs_init (pTHX) |
3376 |
|
3377 |
Sometimes you need direct control over C<perl_parse> and C<perl_run>, in |
3378 |
which case you do not want to use C<staticperl_init> but call them on your |
3379 |
own. |
3380 |
|
3381 |
Then you need this function - either pass it directly as the C<xs_init> |
3382 |
function to C<perl_parse>, or call it as one of the first things from your |
3383 |
own C<xs_init> function. |
3384 |
|
3385 |
=item PerlInterpreter *staticperl |
3386 |
|
3387 |
The perl interpreter pointer used by staticperl. Not normally so useful, |
3388 |
but there it is. |
3389 |
|
3390 |
=back |
3391 |
|
3392 |
=item bundle.ccopts |
3393 |
|
3394 |
Contains the compiler options required to compile at least F<bundle.c> and |
3395 |
any file that includes F<bundle.h> - you should probably use it in your |
3396 |
C<CFLAGS>. |
3397 |
|
3398 |
=item bundle.ldopts |
3399 |
|
3400 |
The linker options needed to link the final program. |
3401 |
|
3402 |
=back |
3403 |
|
3404 |
=head1 RUNTIME FUNCTIONALITY |
3405 |
|
3406 |
Binaries created with C<mkbundle>/C<mkperl> contain extra functionality, |
3407 |
mostly related to the extra files bundled in the binary (the virtual |
3408 |
filesystem). All of this data is statically compiled into the binary, and |
3409 |
accessing means copying it from a read-only section of your binary. Data |
3410 |
pages in this way are usually freed by the operating system, as they aren't |
3411 |
used more then once. |
3412 |
|
3413 |
=head2 VIRTUAL FILESYSTEM |
3414 |
|
3415 |
Every bundle has a virtual filesystem. The only information stored in it |
3416 |
is the path and contents of each file that was bundled. |
3417 |
|
3418 |
=head3 LAYOUT |
3419 |
|
3420 |
Any paths starting with an ampersand (F<&>) or exclamation mark (F<!>) are |
3421 |
reserved by F<staticperl>. They must only be used as described in this |
3422 |
section. |
3423 |
|
3424 |
=over 4 |
3425 |
|
3426 |
=item ! |
3427 |
|
3428 |
All files that typically cannot be loaded from memory (such as dynamic |
3429 |
objects or shared libraries), but have to reside in the filesystem, are |
3430 |
prefixed with F<!>. Typically these files get written out to some |
3431 |
(semi-)temporary directory shortly after program startup, or before being |
3432 |
used. |
3433 |
|
3434 |
=item !boot |
3435 |
|
3436 |
The bootstrap file, if specified during bundling. |
3437 |
|
3438 |
=item !auto/ |
3439 |
|
3440 |
Shared objects or dlls corresponding to dynamically-linked perl extensions |
3441 |
are stored with an F<!auto/> prefix. |
3442 |
|
3443 |
=item !lib/ |
3444 |
|
3445 |
External shared libraries are stored in this directory. |
3446 |
|
3447 |
=item any letter |
3448 |
|
3449 |
Any path starting with a letter is a perl library file. For example, |
3450 |
F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and |
3451 |
F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">. |
3452 |
|
3453 |
Obviously, module names shouldn't start with any other characters than |
3454 |
letters :) |
3455 |
|
3456 |
=back |
3457 |
|
3458 |
=head3 FUNCTIONS |
3459 |
|
3460 |
=over 4 |
3461 |
|
3462 |
=item $file = static::find $path |
3463 |
|
3464 |
Returns the data associated with the given C<$path> |
3465 |
(e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>). |
3466 |
|
3467 |
Returns C<undef> if the file isn't embedded. |
3468 |
|
3469 |
=item @paths = static::list |
3470 |
|
3471 |
Returns the list of all paths embedded in this binary. |
3472 |
|
3473 |
=back |
3474 |
|
3475 |
=head2 EXTRA FEATURES |
3476 |
|
3477 |
In addition, for the embedded loading of perl files to work, F<staticperl> |
3478 |
overrides the C<@INC> array. |
3479 |
|
3480 |
=head1 FULLY STATIC BINARIES - ALPINE LINUX |
3481 |
|
3482 |
This section once contained a way to build fully static (including |
3483 |
uClibc) binaries with buildroot. Unfortunately, buildroot no longer |
3484 |
supports a compiler, so I recommend using alpine linux instead |
3485 |
(L<http://alpinelinux.org/>). Get yourself a VM (e.g. with qemu), run an |
3486 |
older alpine linux verison in it (e.g. 2.4), copy staticperl inside and |
3487 |
use it. |
3488 |
|
3489 |
The reason you might want an older alpine linux is that uClibc can be |
3490 |
quite dependent on kernel versions, so the newest version of alpine linux |
3491 |
might need a newer kernel then you might want for, if you plan to run your |
3492 |
binaries on on other kernels. |
3493 |
|
3494 |
=head1 RECIPES / SPECIFIC MODULES |
3495 |
|
3496 |
This section contains some common(?) recipes and information about |
3497 |
problems with some common modules or perl constructs that require extra |
3498 |
files to be included. |
3499 |
|
3500 |
=head2 MODULES |
3501 |
|
3502 |
=over 4 |
3503 |
|
3504 |
=item utf8 |
3505 |
|
3506 |
Some functionality in the C<utf8> module, such as swash handling |
3507 |
(used for unicode character ranges in regexes) is implemented in the |
3508 |
C<utf8_heavy.pl> library: |
3509 |
|
3510 |
-Mutf8_heavy.pl |
3511 |
|
3512 |
Many Unicode properties in turn are defined in separate modules, |
3513 |
such as C<unicore/Heavy.pl> and more specific data tables such as |
3514 |
C<unicore/To/Digit.pl> or C<unicore/lib/Perl/Word.pl>. These tables |
3515 |
are big (7MB uncompressed, although F<staticperl> contains special |
3516 |
handling for those files), so including them only on demand in your |
3517 |
application might pay off. |
3518 |
|
3519 |
To simply include the whole unicode database, use: |
3520 |
|
3521 |
--incglob '/unicore/**.pl' |
3522 |
|
3523 |
=item AnyEvent |
3524 |
|
3525 |
AnyEvent needs a backend implementation that it will load in a delayed |
3526 |
fashion. The L<AnyEvent::Impl::Perl> backend is the default choice |
3527 |
for AnyEvent if it can't find anything else, and is usually a safe |
3528 |
fallback. If you plan to use e.g. L<EV> (L<POE>...), then you need to |
3529 |
include the L<AnyEvent::Impl::EV> (L<AnyEvent::Impl::POE>...) backend as |
3530 |
well. |
3531 |
|
3532 |
If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
3533 |
functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
3534 |
C<"AnyEvent/Util/uts46data.pl">. |
3535 |
|
3536 |
Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
3537 |
everything. |
3538 |
|
3539 |
=item Cairo |
3540 |
|
3541 |
See Glib, same problem, same solution. |
3542 |
|
3543 |
=item Carp |
3544 |
|
3545 |
Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
3546 |
perl 5.12.2 (maybe earlier), this dependency no longer exists. |
3547 |
|
3548 |
=item Config |
3549 |
|
3550 |
The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
3551 |
turn might need L<"Config_heavy.pl">. Including the latter gives you |
3552 |
both. |
3553 |
|
3554 |
=item Glib |
3555 |
|
3556 |
Glib literally requires Glib to be installed already to build - it tries |
3557 |
to fake this by running Glib out of the build directory before being |
3558 |
built. F<staticperl> tries to work around this by forcing C<MAN1PODS> and |
3559 |
C<MAN3PODS> to be empty via the C<PERL_MM_OPT> environment variable. |
3560 |
|
3561 |
=item Gtk2 |
3562 |
|
3563 |
See Pango, same problems, same solution. |
3564 |
|
3565 |
=item Net::SSLeay |
3566 |
|
3567 |
This module hasn't been significantly updated since OpenSSL is called |
3568 |
OpenSSL, and fails to properly link against dependent libraries, most |
3569 |
commonly, it forgets to specify C<-ldl> when linking. |
3570 |
|
3571 |
On GNU/Linux systems this usually goes undetected, as perl usually links |
3572 |
against C<-ldl> itself and OpenSSL just happens to pick it up that way, by |
3573 |
chance. |
3574 |
|
3575 |
For static builds, you either have to configure C<-ldl> manually, or you |
3576 |
can use the following snippet in your C<postinstall> hook which patches |
3577 |
Net::SSLeay after installation, which happens to work most of the time: |
3578 |
|
3579 |
postinstall() { |
3580 |
# first install it |
3581 |
instcpan Net::SSLeay |
3582 |
# then add -ldl for future linking |
3583 |
chmod u+w "$PERL_PREFIX"/lib/auto/Net/SSLeay/extralibs.ld |
3584 |
echo " -ldl" >>"$PERL_PREFIX"/lib/auto/Net/SSLeay/extralibs.ld |
3585 |
} |
3586 |
|
3587 |
=item Pango |
3588 |
|
3589 |
In addition to the C<MAN3PODS> problem in Glib, Pango also routes around |
3590 |
L<ExtUtils::MakeMaker> by compiling its files on its own. F<staticperl> |
3591 |
tries to patch L<ExtUtils::MM_Unix> to route around Pango. |
3592 |
|
3593 |
=item Term::ReadLine::Perl |
3594 |
|
3595 |
Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
3596 |
|
3597 |
=item URI |
3598 |
|
3599 |
URI implements schemes as separate modules - the generic URL scheme is |
3600 |
implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
3601 |
you need to use any of these schemes, you should include these manually, |
3602 |
or use C<--usepacklists>. |
3603 |
|
3604 |
=back |
3605 |
|
3606 |
=head2 RECIPES |
3607 |
|
3608 |
=over 4 |
3609 |
|
3610 |
=item Just link everything in |
3611 |
|
3612 |
To link just about everything installed in the perl library into a new |
3613 |
perl, try this (the first time this runs it will take a long time, as a |
3614 |
lot of files need to be parsed): |
3615 |
|
3616 |
staticperl mkperl -v --strip ppi --incglob '*' |
3617 |
|
3618 |
If you don't mind the extra megabytes, this can be a very effective way of |
3619 |
creating bundles without having to worry about forgetting any modules. |
3620 |
|
3621 |
You get even more useful variants of this method by first selecting |
3622 |
everything, and then excluding stuff you are reasonable sure not to need - |
3623 |
L<bigperl|http://staticperl.schmorp.de/bigperl.html> uses this approach. |
3624 |
|
3625 |
=item Getting rid of netdb functions |
3626 |
|
3627 |
The perl core has lots of netdb functions (C<getnetbyname>, C<getgrent> |
3628 |
and so on) that few applications use. You can avoid compiling them in by |
3629 |
putting the following fragment into a C<preconfigure> hook: |
3630 |
|
3631 |
preconfigure() { |
3632 |
for sym in \ |
3633 |
d_getgrnam_r d_endgrent d_endgrent_r d_endhent \ |
3634 |
d_endhostent_r d_endnent d_endnetent_r d_endpent \ |
3635 |
d_endprotoent_r d_endpwent d_endpwent_r d_endsent \ |
3636 |
d_endservent_r d_getgrent d_getgrent_r d_getgrgid_r \ |
3637 |
d_getgrnam_r d_gethbyaddr d_gethent d_getsbyport \ |
3638 |
d_gethostbyaddr_r d_gethostbyname_r d_gethostent_r \ |
3639 |
d_getlogin_r d_getnbyaddr d_getnbyname d_getnent \ |
3640 |
d_getnetbyaddr_r d_getnetbyname_r d_getnetent_r \ |
3641 |
d_getpent d_getpbyname d_getpbynumber d_getprotobyname_r \ |
3642 |
d_getprotobynumber_r d_getprotoent_r d_getpwent \ |
3643 |
d_getpwent_r d_getpwnam_r d_getpwuid_r d_getsent \ |
3644 |
d_getservbyname_r d_getservbyport_r d_getservent_r \ |
3645 |
d_getspnam_r d_getsbyname |
3646 |
# d_gethbyname |
3647 |
do |
3648 |
PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
3649 |
done |
3650 |
} |
3651 |
|
3652 |
This mostly gains space when linking statically, as the functions will |
3653 |
likely not be linked in. The gain for dynamically-linked binaries is |
3654 |
smaller. |
3655 |
|
3656 |
Also, this leaves C<gethostbyname> in - not only is it actually used |
3657 |
often, the L<Socket> module also exposes it, so leaving it out usually |
3658 |
gains little. Why Socket exposes a C function that is in the core already |
3659 |
is anybody's guess. |
3660 |
|
3661 |
=back |
3662 |
|
3663 |
=head1 ADDITIONAL RESOURCES |
3664 |
|
3665 |
Some guy has made a repository on github |
3666 |
(L<https://github.com/gh0stwizard/staticperl-modules>) with some modules |
3667 |
patched to build with staticperl. |
3668 |
|
3669 |
=head1 AUTHOR |
3670 |
|
3671 |
Marc Lehmann <schmorp@schmorp.de> |
3672 |
http://software.schmorp.de/pkg/staticperl.html |
3673 |
|
3674 |
|