ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/README
Revision: 1.8
Committed: Fri Dec 10 21:15:06 2010 UTC (15 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-0_91, rel-0_911
Changes since 1.7: +268 -24 lines
Log Message:
0.91

File Contents

# Content
1 NAME
2 staticperl - perl, libc, 100 modules, all in one 500kb file
3
4 SYNOPSIS
5 staticperl help # print the embedded documentation
6 staticperl fetch # fetch and unpack perl sources
7 staticperl configure # fetch and then configure perl
8 staticperl build # configure and then build perl
9 staticperl install # build and then install perl
10 staticperl clean # clean most intermediate files (restart at configure)
11 staticperl distclean # delete everything installed by this script
12 staticperl cpan # invoke CPAN shell
13 staticperl instmod path... # install unpacked modules
14 staticperl instcpan modulename... # install modules from CPAN
15 staticperl mkbundle <bundle-args...> # see documentation
16 staticperl mkperl <bundle-args...> # see documentation
17 staticperl mkapp appname <bundle-args...> # see documentation
18
19 Typical Examples:
20
21 staticperl install # fetch, configure, build and install perl
22 staticperl cpan # run interactive cpan shell
23 staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V
24 staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http
25 # build a perl with the above modules linked in
26 staticperl mkapp myapp --boot mainprog mymodules
27 # build a binary "myapp" from mainprog and mymodules
28
29 DESCRIPTION
30 This script helps you to create single-file perl interpreters or
31 applications, or embedding a perl interpreter in your applications.
32 Single-file means that it is fully self-contained - no separate shared
33 objects, no autoload fragments, no .pm or .pl files are needed. And when
34 linking statically, you can create (or embed) a single file that
35 contains perl interpreter, libc, all the modules you need, all the
36 libraries you need and of course your actual program.
37
38 With uClibc and upx on x86, you can create a single 500kb binary that
39 contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, Coro
40 and so on. Or any other choice of modules.
41
42 To see how this turns out, you can try out smallperl and bigperl, two
43 pre-built static and compressed perl binaries with many and even more
44 modules: just follow the links at <http://staticperl.schmorp.de/>.
45
46 The created files do not need write access to the file system (like PAR
47 does). In fact, since this script is in many ways similar to
48 PAR::Packer, here are the differences:
49
50 * The generated executables are much smaller than PAR created ones.
51
52 Shared objects and the perl binary contain a lot of extra info,
53 while the static nature of staticperl allows the linker to remove
54 all functionality and meta-info not required by the final
55 executable. Even extensions statically compiled into perl at build
56 time will only be present in the final executable when needed.
57
58 In addition, staticperl can strip perl sources much more effectively
59 than PAR.
60
61 * The generated executables start much faster.
62
63 There is no need to unpack files, or even to parse Zip archives
64 (which is slow and memory-consuming business).
65
66 * The generated executables don't need a writable filesystem.
67
68 staticperl loads all required files directly from memory. There is
69 no need to unpack files into a temporary directory.
70
71 * More control over included files, more burden.
72
73 PAR tries to be maintenance and hassle-free - it tries to include
74 more files than necessary to make sure everything works out of the
75 box. It mostly succeeds at this, but he extra files (such as the
76 unicode database) can take substantial amounts of memory and file
77 size.
78
79 With staticperl, the burden is mostly with the developer - only
80 direct compile-time dependencies and AutoLoader are handled
81 automatically. This means the modules to include often need to be
82 tweaked manually.
83
84 All this does not preclude more permissive modes to be implemented
85 in the future, but right now, you have to resolve state hidden
86 dependencies manually.
87
88 * PAR works out of the box, staticperl does not.
89
90 Maintaining your own custom perl build can be a pain in the ass, and
91 while staticperl tries to make this easy, it still requires a custom
92 perl build and possibly fiddling with some modules. PAR is likely to
93 produce results faster.
94
95 Ok, PAR never has worked for me out of the box, and for some people,
96 staticperl does work out of the box, as they don't count "fiddling
97 with module use lists" against it, but nevertheless, staticperl is
98 certainly a bit more difficult to use.
99
100 HOW DOES IT WORK?
101 Simple: staticperl downloads, compile and installs a perl version of
102 your choice in ~/.staticperl. You can add extra modules either by
103 letting staticperl install them for you automatically, or by using CPAN
104 and doing it interactively. This usually takes 5-10 minutes, depending
105 on the speed of your computer and your internet connection.
106
107 It is possible to do program development at this stage, too.
108
109 Afterwards, you create a list of files and modules you want to include,
110 and then either build a new perl binary (that acts just like a normal
111 perl except everything is compiled in), or you create bundle files
112 (basically C sources you can use to embed all files into your project).
113
114 This step is very fast (a few seconds if PPI is not used for stripping,
115 or the stripped files are in the cache), and can be tweaked and repeated
116 as often as necessary.
117
118 THE STATICPERL SCRIPT
119 This module installs a script called staticperl into your perl binary
120 directory. The script is fully self-contained, and can be used without
121 perl (for example, in an uClibc chroot environment). In fact, it can be
122 extracted from the "App::Staticperl" distribution tarball as
123 bin/staticperl, without any installation.
124
125 staticperl interprets the first argument as a command to execute,
126 optionally followed by any parameters.
127
128 There are two command categories: the "phase 1" commands which deal with
129 installing perl and perl modules, and the "phase 2" commands, which deal
130 with creating binaries and bundle files.
131
132 PHASE 1 COMMANDS: INSTALLING PERL
133 The most important command is install, which does basically everything.
134 The default is to download and install perl 5.12.2 and a few modules
135 required by staticperl itself, but all this can (and should) be changed
136 - see CONFIGURATION, below.
137
138 The command
139
140 staticperl install
141
142 Is normally all you need: It installs the perl interpreter in
143 ~/.staticperl/perl. It downloads, configures, builds and installs the
144 perl interpreter if required.
145
146 Most of the following commands simply run one or more steps of this
147 sequence.
148
149 To force recompilation or reinstallation, you need to run staticperl
150 distclean first.
151
152 staticperl version
153 Prints some info about the version of the staticperl script you are
154 using.
155
156 staticperl fetch
157 Runs only the download and unpack phase, unless this has already
158 happened.
159
160 staticperl configure
161 Configures the unpacked perl sources, potentially after downloading
162 them first.
163
164 staticperl build
165 Builds the configured perl sources, potentially after automatically
166 configuring them.
167
168 staticperl install
169 Wipes the perl installation directory (usually ~/.staticperl/perl)
170 and installs the perl distribution, potentially after building it
171 first.
172
173 staticperl cpan [args...]
174 Starts an interactive CPAN shell that you can use to install further
175 modules. Installs the perl first if necessary, but apart from that,
176 no magic is involved: you could just as well run it manually via
177 ~/.staticperl/perl/bin/cpan.
178
179 Any additional arguments are simply passed to the cpan command.
180
181 staticperl instcpan module...
182 Tries to install all the modules given and their dependencies, using
183 CPAN.
184
185 Example:
186
187 staticperl instcpan EV AnyEvent::HTTPD Coro
188
189 staticperl instsrc directory...
190 In the unlikely case that you have unpacked perl modules around and
191 want to install from these instead of from CPAN, you can do this
192 using this command by specifying all the directories with modules in
193 them that you want to have built.
194
195 staticperl clean
196 Deletes the perl source directory (and potentially cleans up other
197 intermediate files). This can be used to clean up files only needed
198 for building perl, without removing the installed perl interpreter,
199 or to force a re-build from scratch.
200
201 At the moment, it doesn't delete downloaded tarballs.
202
203 staticperl distclean
204 This wipes your complete ~/.staticperl directory. Be careful with
205 this, it nukes your perl download, perl sources, perl distribution
206 and any installed modules. It is useful if you wish to start over
207 "from scratch" or when you want to uninstall staticperl.
208
209 PHASE 2 COMMANDS: BUILDING PERL BUNDLES
210 Building (linking) a new perl binary is handled by a separate script. To
211 make it easy to use staticperl from a chroot, the script is embedded
212 into staticperl, which will write it out and call for you with any
213 arguments you pass:
214
215 staticperl mkbundle mkbundle-args...
216
217 In the oh so unlikely case of something not working here, you can run
218 the script manually as well (by default it is written to
219 ~/.staticperl/mkbundle).
220
221 mkbundle is a more conventional command and expect the argument syntax
222 commonly used on UNIX clones. For example, this command builds a new
223 perl binary and includes Config.pm (for perl -V), AnyEvent::HTTPD, URI
224 and a custom httpd script (from eg/httpd in this distribution):
225
226 # first make sure we have perl and the required modules
227 staticperl instcpan AnyEvent::HTTPD
228
229 # now build the perl
230 staticperl mkperl -M'"Config_heavy.pl"' -MAnyEvent::Impl::Perl \
231 -MAnyEvent::HTTPD -MURI::http \
232 --add 'eg/httpd httpd.pm'
233
234 # finally, invoke it
235 ./perl -Mhttpd
236
237 As you can see, things are not quite as trivial: the Config module has a
238 hidden dependency which is not even a perl module (Config_heavy.pl),
239 AnyEvent needs at least one event loop backend that we have to specify
240 manually (here AnyEvent::Impl::Perl), and the URI module (required by
241 AnyEvent::HTTPD) implements various URI schemes as extra modules - since
242 AnyEvent::HTTPD only needs "http" URIs, we only need to include that
243 module. I found out about these dependencies by carefully watching any
244 error messages about missing modules...
245
246 Instead of building a new perl binary, you can also build a standalone
247 application:
248
249 # build the app
250 staticperl mkapp app --boot eg/httpd \
251 -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http
252
253 # run it
254 ./app
255
256 OPTION PROCESSING
257 All options can be given as arguments on the command line (typically
258 using long (e.g. "--verbose") or short option (e.g. "-v") style). Since
259 specifying a lot of modules can make the command line very cumbersome,
260 you can put all long options into a "bundle specification file" (with or
261 without "--" prefix) and specify this bundle file instead.
262
263 For example, the command given earlier could also look like this:
264
265 staticperl mkperl httpd.bundle
266
267 And all options could be in httpd.bundle:
268
269 use "Config_heavy.pl"
270 use AnyEvent::Impl::Perl
271 use AnyEvent::HTTPD
272 use URI::http
273 add eg/httpd httpd.pm
274
275 All options that specify modules or files to be added are processed in
276 the order given on the command line (that affects the "--use" and
277 "--eval" options at the moment).
278
279 PACKAGE SELECTION WORKFLOW
280 staticperl mkbundle has a number of options to control package
281 selection. This section describes how they interact with each other.
282 Also, since I am still a newbie w.r.t. these issues, maybe future
283 versions of staticperl will change this, so watch out :)
284
285 The idiom "in order" means "in order that they are specified on the
286 commandline". If you use a bundle specification file, then the options
287 will be processed as if they were given in place of the bundle file
288 name.
289
290 1. apply all "--use", "--eval", "--add", "--addbin" and "--incglob"
291 options, in order.
292 In addition, "--use" and "--eval" dependencies will be added when
293 the options are processed.
294
295 2. apply all "--include" and "--exclude" options, in order.
296 All this step does is potentially reduce the number of files already
297 selected or found in phase 1.
298
299 3. find all modules (== .pm files), gather their static archives (.a)
300 and AutoLoader splitfiles (.ix and .al files), find any extra libraries
301 they need for linking (extralibs.ld) and optionally evaluate any
302 .packlist files.
303 This step is required to link against XS extensions and also adds
304 files required for AutoLoader to do it's job.
305
306 After this, all the files selected for bundling will be read and
307 processed (stripped), the bundle files will be written, and optionally a
308 new perl or application binary will be linked.
309
310 MKBUNDLE OPTIONS
311 --verbose | -v
312 Increases the verbosity level by one (the default is 1).
313
314 --quiet | -q
315 Decreases the verbosity level by one.
316
317 --strip none|pod|ppi
318 Specify the stripping method applied to reduce the file of the perl
319 sources included.
320
321 The default is "pod", which uses the Pod::Strip module to remove all
322 pod documentation, which is very fast and reduces file size a lot.
323
324 The "ppi" method uses PPI to parse and condense the perl sources.
325 This saves a lot more than just Pod::Strip, and is generally safer,
326 but is also a lot slower (some files take almost a minute to strip -
327 staticperl maintains a cache of stripped files to speed up
328 subsequent runs for this reason). Note that this method doesn't
329 optimise for raw file size, but for best compression (that means
330 that the uncompressed file size is a bit larger, but the files
331 compress better, e.g. with upx).
332
333 Last not least, if you need accurate line numbers in error messages,
334 or in the unlikely case where "pod" is too slow, or some module gets
335 mistreated, you can specify "none" to not mangle included perl
336 sources in any way.
337
338 --perl
339 After writing out the bundle files, try to link a new perl
340 interpreter. It will be called perl and will be left in the current
341 working directory. The bundle files will be removed.
342
343 This switch is automatically used when staticperl is invoked with
344 the "mkperl" command (instead of "mkbundle"):
345
346 # build a new ./perl with only common::sense in it - very small :)
347 staticperl mkperl -Mcommon::sense
348
349 --app name
350 After writing out the bundle files, try to link a new standalone
351 program. It will be called "name", and the bundle files get removed
352 after linking it.
353
354 The difference to the (mutually exclusive) "--perl" option is that
355 the binary created by this option will not try to act as a perl
356 interpreter - instead it will simply initialise the perl
357 interpreter, clean it up and exit.
358
359 This switch is automatically used when staticperl is invoked with
360 the "mkapp" command (instead of "mkbundle"):
361
362 To let it do something useful you *must* add some boot code, e.g.
363 with the "--boot" option.
364
365 Example: create a standalone perl binary that will execute appfile
366 when it is started.
367
368 staticperl mkbundle --app myexe --boot appfile
369
370 --use module | -Mmodule
371 Include the named module and all direct dependencies. This is done
372 by "require"'ing the module in a subprocess and tracing which other
373 modules and files it actually loads. If the module uses AutoLoader,
374 then all splitfiles will be included as well.
375
376 Example: include AnyEvent and AnyEvent::Impl::Perl.
377
378 staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl
379
380 Sometimes you want to load old-style "perl libraries" (.pl files),
381 or maybe other weirdly named files. To do that, you need to quote
382 the name in single or double quotes. When given on the command line,
383 you probably need to quote once more to avoid your shell
384 interpreting it. Common cases that need this are Config_heavy.pl and
385 utf8_heavy.pl.
386
387 Example: include the required files for perl -V to work in all its
388 glory (Config.pm is included automatically by this).
389
390 # bourne shell
391 staticperl mkbundle --use '"Config_heavy.pl"'
392
393 # bundle specification file
394 use "Config_heavy.pl"
395
396 The "-Mmodule" syntax is included as an alias that might be easier
397 to remember than "use". Or maybe it confuses people. Time will tell.
398 Or maybe not. Argh.
399
400 --eval "perl code" | -e "perl code"
401 Sometimes it is easier (or necessary) to specify dependencies using
402 perl code, or maybe one of the modules you use need a special use
403 statement. In that case, you can use "eval" to execute some perl
404 snippet or set some variables or whatever you need. All files
405 "require"'d or "use"'d in the script are included in the final
406 bundle.
407
408 Keep in mind that mkbundle will only "require" the modules named by
409 the "--use" option, so do not expect the symbols from modules you
410 "--use"'d earlier on the command line to be available.
411
412 Example: force AnyEvent to detect a backend and therefore include it
413 in the final bundle.
414
415 staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect'
416
417 # or like this
418 staticperl mkbundle -MAnyEvent --eval 'use AnyEvent; AnyEvent::detect'
419
420 Example: use a separate "bootstrap" script that "use"'s lots of
421 modules and include this in the final bundle, to be executed
422 automatically.
423
424 staticperl mkbundle --eval 'do "bootstrap"' --boot bootstrap
425
426 --boot filename
427 Include the given file in the bundle and arrange for it to be
428 executed (using a "require") before anything else when the new perl
429 is initialised. This can be used to modify @INC or anything else
430 before the perl interpreter executes scripts given on the command
431 line (or via "-e"). This works even in an embedded interpreter.
432
433 --usepacklist
434 Read .packlist files for each distribution that happens to match a
435 module name you specified. Sounds weird, and it is, so expect
436 semantics to change somehow in the future.
437
438 The idea is that most CPAN distributions have a .pm file that
439 matches the name of the distribution (which is rather reasonable
440 after all).
441
442 If this switch is enabled, then if any of the .pm files that have
443 been selected match an install distribution, then all .pm, .pl, .al
444 and .ix files installed by this distribution are also included.
445
446 For example, using this switch, when the URI module is specified,
447 then all URI submodules that have been installed via the CPAN
448 distribution are included as well, so you don't have to manually
449 specify them.
450
451 --incglob pattern
452 This goes through all library directories and tries to match any .pm
453 and .pl files against the extended glob pattern (see below). If a
454 file matches, it is added. This switch will automatically detect
455 AutoLoader files and the required link libraries for XS modules, but
456 it will *not* scan the file for dependencies (at the moment).
457
458 This is mainly useful to include "everything":
459
460 --incglob '*'
461
462 Or to include perl libraries, or trees of those, such as the unicode
463 database files needed by many other modules:
464
465 --incglob '/unicore/**.pl'
466
467 --add file | --add "file alias"
468 Adds the given (perl) file into the bundle (and optionally call it
469 "alias"). This is useful to include any custom files into the
470 bundle.
471
472 Example: embed the file httpd as httpd.pm when creating the bundle.
473
474 staticperl mkperl --add "httpd httpd.pm"
475
476 It is also a great way to add any custom modules:
477
478 # specification file
479 add file1 myfiles/file1
480 add file2 myfiles/file2
481 add file3 myfiles/file3
482
483 --binadd file | --add "file alias"
484 Just like "--add", except that it treats the file as binary and adds
485 it without any processing.
486
487 You should probably add a "/" prefix to avoid clashing with embedded
488 perl files (whose paths do not start with "/"), and/or use a special
489 directory, such as "/res/name".
490
491 You can later get a copy of these files by calling "staticperl::find
492 "alias"".
493
494 --include pattern | -i pattern | --exclude pattern | -x pattern
495 These two options define an include/exclude filter that is used
496 after all files selected by the other options have been found. Each
497 include/exclude is applied to all files found so far - an include
498 makes sure that the given files will be part of the resulting file
499 set, an exclude will exclude files. The patterns are "extended glob
500 patterns" (see below).
501
502 For example, to include everything, except "Devel" modules, but
503 still include Devel::PPPort, you could use this:
504
505 --incglob '*' -i '/Devel/PPPort.pm' -x '/Devel/**'
506
507 --static
508 When "--perl" is also given, link statically instead of dynamically.
509 The default is to link the new perl interpreter fully dynamic (that
510 means all perl modules are linked statically, but all external
511 libraries are still referenced dynamically).
512
513 Keep in mind that Solaris doesn't support static linking at all, and
514 systems based on GNU libc don't really support it in a usable
515 fashion either. Try uClibc if you want to create fully statically
516 linked executables, or try the "--staticlibs" option to link only
517 some libraries statically.
518
519 --staticlib libname
520 When not linking fully statically, this option allows you to link
521 specific libraries statically. What it does is simply replace all
522 occurances of "-llibname" with the GCC-specific "-Wl,-Bstatic
523 -llibname -Wl,-Bdynamic" option.
524
525 This will have no effect unless the library is actually linked
526 against, specifically, "--staticlib" will not link against the named
527 library unless it would be linked against anyway.
528
529 Example: link libcrypt statically into the binary.
530
531 staticperl mkperl -MIO::AIO --staticlib crypt
532
533 # ldopts might nwo contain:
534 # -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread
535
536 any other argument
537 Any other argument is interpreted as a bundle specification file,
538 which supports most long options (without extra quoting), one option
539 per line.
540
541 EXTENDED GLOB PATTERNS
542 Some options of staticperl mkbundle expect an *extended glob pattern*.
543 This is neither a normal shell glob nor a regex, but something in
544 between. The idea has been copied from rsync, and there are the current
545 matching rules:
546
547 Patterns starting with / will be a anchored at the root of the library
548 tree.
549 That is, /unicore will match the unicore directory in @INC, but
550 nothing inside, and neither any other file or directory called
551 unicore anywhere else in the hierarchy.
552
553 Patterns not starting with / will be anchored at the end of the path.
554 That is, idna.pl will match any file called idna.pl anywhere in the
555 hierarchy, but not any directories of the same name.
556
557 A * matches any single component.
558 That is, /unicore/*.pl would match all .pl files directly inside
559 "/unicore", not any deeper level .pl files. Or in other words, *
560 will not match slashes.
561
562 A ** matches anything.
563 That is, /unicore/**.pl would match all .pl files under /unicore, no
564 matter how deeply nested they are inside subdirectories.
565
566 A ? matches a single character within a component.
567 That is, /Encode/??.pm matches /Encode/JP.pm, but not the
568 hypothetical /Encode/J/.pm, as ? does not match /.
569
570 STATICPERL CONFIGURATION AND HOOKS
571 During (each) startup, staticperl tries to source some shell files to
572 allow you to fine-tune/override configuration settings.
573
574 In them you can override shell variables, or define shell functions
575 ("hooks") to be called at specific phases during installation. For
576 example, you could define a "postinstall" hook to install additional
577 modules from CPAN each time you start from scratch.
578
579 If the env variable $STATICPERLRC is set, then staticperl will try to
580 source the file named with it only. Otherwise, it tries the following
581 shell files in order:
582
583 /etc/staticperlrc
584 ~/.staticperlrc
585 $STATICPERL/rc
586
587 Note that the last file is erased during staticperl distclean, so
588 generally should not be used.
589
590 CONFIGURATION VARIABLES
591 Variables you *should* override
592 "EMAIL"
593 The e-mail address of the person who built this binary. Has no good
594 default, so should be specified by you.
595
596 "CPAN"
597 The URL of the CPAN mirror to use (e.g.
598 <http://mirror.netcologne.de/cpan/>).
599
600 "EXTRA_MODULES"
601 Additional modules installed during staticperl install. Here you can
602 set which modules you want have to installed from CPAN.
603
604 Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO.
605
606 EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO"
607
608 Note that you can also use a "postinstall" hook to achieve this, and
609 more.
610
611 Variables you might *want* to override
612 "STATICPERL"
613 The directory where staticperl stores all its files (default:
614 ~/.staticperl).
615
616 "PERL_MM_USE_DEFAULT", "EV_EXTRA_DEFS", ...
617 Usually set to 1 to make modules "less inquisitive" during their
618 installation, you can set any environment variable you want - some
619 modules (such as Coro or EV) use environment variables for further
620 tweaking.
621
622 "PERL_VERSION"
623 The perl version to install - default is currently 5.12.2, but 5.8.9
624 is also a good choice (5.8.9 is much smaller than 5.12.2, while
625 5.10.1 is about as big as 5.12.2).
626
627 "PERL_PREFIX"
628 The prefix where perl gets installed (default: $STATICPERL/perl),
629 i.e. where the bin and lib subdirectories will end up.
630
631 "PERL_CONFIGURE"
632 Additional Configure options - these are simply passed to the perl
633 Configure script. For example, if you wanted to enable dynamic
634 loading, you could pass "-Dusedl". To enable ithreads (Why would you
635 want that insanity? Don't! Use forks instead!) you would pass
636 "-Duseithreads" and so on.
637
638 More commonly, you would either activate 64 bit integer support
639 ("-Duse64bitint"), or disable large files support (-Uuselargefiles),
640 to reduce filesize further.
641
642 "PERL_CPPFLAGS", "PERL_OPTIMIZE", "PERL_LDFLAGS", "PERL_LIBS"
643 These flags are passed to perl's Configure script, and are generally
644 optimised for small size (at the cost of performance). Since they
645 also contain subtle workarounds around various build issues,
646 changing these usually requires understanding their default values -
647 best look at the top of the staticperl script for more info on
648 these.
649
650 Variables you probably *do not want* to override
651 "MKBUNDLE"
652 Where staticperl writes the "mkbundle" command to (default:
653 $STATICPERL/mkbundle).
654
655 "STATICPERL_MODULES"
656 Additional modules needed by "mkbundle" - should therefore not be
657 changed unless you know what you are doing.
658
659 OVERRIDABLE HOOKS
660 In addition to environment variables, it is possible to provide some
661 shell functions that are called at specific times. To provide your own
662 commands, just define the corresponding function.
663
664 Example: install extra modules from CPAN and from some directories at
665 staticperl install time.
666
667 postinstall() {
668 rm -rf lib/threads* # weg mit Schaden
669 instcpan IO::AIO EV
670 instsrc ~/src/AnyEvent
671 instsrc ~/src/XML-Sablotron-1.0100001
672 instcpan Anyevent::AIO AnyEvent::HTTPD
673 }
674
675 preconfigure
676 Called just before running ./Configur in the perl source directory.
677 Current working directory is the perl source directory.
678
679 This can be used to set any "PERL_xxx" variables, which might be
680 costly to compute.
681
682 postconfigure
683 Called after configuring, but before building perl. Current working
684 directory is the perl source directory.
685
686 Could be used to tailor/patch config.sh (followed by sh Configure
687 -S) or do any other modifications.
688
689 postbuild
690 Called after building, but before installing perl. Current working
691 directory is the perl source directory.
692
693 I have no clue what this could be used for - tell me.
694
695 postinstall
696 Called after perl and any extra modules have been installed in
697 $PREFIX, but before setting the "installation O.K." flag.
698
699 The current working directory is $PREFIX, but maybe you should not
700 rely on that.
701
702 This hook is most useful to customise the installation, by deleting
703 files, or installing extra modules using the "instcpan" or "instsrc"
704 functions.
705
706 The script must return with a zero exit status, or the installation
707 will fail.
708
709 ANATOMY OF A BUNDLE
710 When not building a new perl binary, "mkbundle" will leave a number of
711 files in the current working directory, which can be used to embed a
712 perl interpreter in your program.
713
714 Intimate knowledge of perlembed and preferably some experience with
715 embedding perl is highly recommended.
716
717 "mkperl" (or the "--perl" option) basically does this to link the new
718 interpreter (it also adds a main program to bundle.):
719
720 $Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts)
721
722 bundle.h
723 A header file that contains the prototypes of the few symbols
724 "exported" by bundle.c, and also exposes the perl headers to the
725 application.
726
727 staticperl_init ()
728 Initialises the perl interpreter. You can use the normal perl
729 functions after calling this function, for example, to define
730 extra functions or to load a .pm file that contains some
731 initialisation code, or the main program function:
732
733 XS (xsfunction)
734 {
735 dXSARGS;
736
737 // now we have items, ST(i) etc.
738 }
739
740 static void
741 run_myapp(void)
742 {
743 staticperl_init ();
744 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
745 eval_pv ("require myapp::main", 1); // executes "myapp/main.pm"
746 }
747
748 staticperl_xs_init (pTHX)
749 Sometimes you need direct control over "perl_parse" and
750 "perl_run", in which case you do not want to use
751 "staticperl_init" but call them on your own.
752
753 Then you need this function - either pass it directly as the
754 "xs_init" function to "perl_parse", or call it from your own
755 "xs_init" function.
756
757 staticperl_cleanup ()
758 In the unlikely case that you want to destroy the perl
759 interpreter, here is the corresponding function.
760
761 PerlInterpreter *staticperl
762 The perl interpreter pointer used by staticperl. Not normally so
763 useful, but there it is.
764
765 bundle.ccopts
766 Contains the compiler options required to compile at least bundle.c
767 and any file that includes bundle.h - you should probably use it in
768 your "CFLAGS".
769
770 bundle.ldopts
771 The linker options needed to link the final program.
772
773 RUNTIME FUNCTIONALITY
774 Binaries created with "mkbundle"/"mkperl" contain extra functions, which
775 are required to access the bundled perl sources, but might be useful for
776 other purposes.
777
778 In addition, for the embedded loading of perl files to work, staticperl
779 overrides the @INC array.
780
781 $file = staticperl::find $path
782 Returns the data associated with the given $path (e.g.
783 "Digest/MD5.pm", "auto/POSIX/autosplit.ix"), which is basically the
784 UNIX path relative to the perl library directory.
785
786 Returns "undef" if the file isn't embedded.
787
788 @paths = staticperl::list
789 Returns the list of all paths embedded in this binary.
790
791 FULLY STATIC BINARIES - BUILDROOT
792 To make truly static (Linux-) libraries, you might want to have a look
793 at buildroot (<http://buildroot.uclibc.org/>).
794
795 Buildroot is primarily meant to set up a cross-compile environment
796 (which is not so useful as perl doesn't quite like cross compiles), but
797 it can also compile a chroot environment where you can use staticperl.
798
799 To do so, download buildroot, and enable "Build options => development
800 files in target filesystem" and optionally "Build options => gcc
801 optimization level (optimize for size)". At the time of writing, I had
802 good experiences with GCC 4.4.x but not GCC 4.5.
803
804 To minimise code size, I used "-pipe -ffunction-sections -fdata-sections
805 -finline-limit=8 -fno-builtin-strlen -mtune=i386". The "-mtune=i386"
806 doesn't decrease codesize much, but it makes the file much more
807 compressible.
808
809 If you don't need Coro or threads, you can go with "linuxthreads.old"
810 (or no thread support). For Coro, it is highly recommended to switch to
811 a uClibc newer than 0.9.31 (at the time of this writing, I used the
812 20101201 snapshot) and enable NPTL, otherwise Coro needs to be
813 configured with the ultra-slow pthreads backend to work around
814 linuxthreads bugs (it also uses twice the address space needed for
815 stacks).
816
817 If you use "linuxthreads.old", then you should also be aware that uClibc
818 shares "errno" between all threads when statically linking. See
819 <http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a
820 workaround (And <https://bugs.uclibc.org/2089> for discussion).
821
822 "ccache" support is also recommended, especially if you want to play
823 around with buildroot options. Enabling the "miniperl" package will
824 probably enable all options required for a successful perl build.
825 staticperl itself additionally needs either "wget" (recommended, for
826 CPAN) or "curl".
827
828 As for shells, busybox should provide all that is needed, but the
829 default busybox configuration doesn't include comm which is needed by
830 perl - either make a custom busybox config, or compile coreutils.
831
832 For the latter route, you might find that bash has some bugs that keep
833 it from working properly in a chroot - either use dash (and link it to
834 /bin/sh inside the chroot) or link busybox to /bin/sh, using it's
835 built-in ash shell.
836
837 Finally, you need /dev/null inside the chroot for many scripts to work -
838 cp /dev/null output/target/dev or bind-mounting your /dev will both
839 provide this.
840
841 After you have compiled and set up your buildroot target, you can copy
842 staticperl from the "App::Staticperl" distribution or from your perl
843 f<bin> directory (if you installed it) into the output/target
844 filesystem, chroot inside and run it.
845
846 RECIPES / SPECIFIC MODULES
847 This section contains some common(?) recipes and information about
848 problems with some common modules or perl constructs that require extra
849 files to be included.
850
851 MODULES
852 utf8
853 Some functionality in the utf8 module, such as swash handling (used
854 for unicode character ranges in regexes) is implemented in the
855 "utf8_heavy.pl" library:
856
857 -M'"utf8_heavy.pl"'
858
859 Many Unicode properties in turn are defined in separate modules,
860 such as "unicore/Heavy.pl" and more specific data tables such as
861 "unicore/To/Digit.pl" or "unicore/lib/Perl/Word.pl". These tables
862 are big (7MB uncompressed, although staticperl contains special
863 handling for those files), so including them on demand by your
864 application only might pay off.
865
866 To simply include the whole unicode database, use:
867
868 --incglob '/unicore/*.pl'
869
870 AnyEvent
871 AnyEvent needs a backend implementation that it will load in a
872 delayed fashion. The AnyEvent::Impl::Perl backend is the default
873 choice for AnyEvent if it can't find anything else, and is usually a
874 safe fallback. If you plan to use e.g. EV (POE...), then you need to
875 include the AnyEvent::Impl::EV (AnyEvent::Impl::POE...) backend as
876 well.
877
878 If you want to handle IRIs or IDNs (AnyEvent::Util punycode and idn
879 functions), you also need to include "AnyEvent/Util/idna.pl" and
880 "AnyEvent/Util/uts46data.pl".
881
882 Or you can use "--usepacklist" and specify "-MAnyEvent" to include
883 everything.
884
885 Carp
886 Carp had (in older versions of perl) a dependency on Carp::Heavy. As
887 of perl 5.12.2 (maybe earlier), this dependency no longer exists.
888
889 Config
890 The perl -V switch (as well as many modules) needs Config, which in
891 turn might need "Config_heavy.pl". Including the latter gives you
892 both.
893
894 Term::ReadLine::Perl
895 Also needs Term::ReadLine::readline, or "--usepacklist".
896
897 URI URI implements schemes as separate modules - the generic URL scheme
898 is implemented in URI::_generic, HTTP is implemented in URI::http.
899 If you need to use any of these schemes, you should include these
900 manually, or use "--usepacklist".
901
902 RECIPES
903 Linking everything in
904 To link just about everything installed in the perl library into a
905 new perl, try this:
906
907 staticperl mkperl --strip ppi --incglob '*'
908
909 Getting rid of netdb function
910 The perl core has lots of netdb functions ("getnetbyname",
911 "getgrent" and so on) that few applications use. You can avoid
912 compiling them in by putting the following fragment into a
913 "preconfigure" hook:
914
915 preconfigure() {
916 for sym in \
917 d_getgrnam_r d_endgrent d_endgrent_r d_endhent \
918 d_endhostent_r d_endnent d_endnetent_r d_endpent \
919 d_endprotoent_r d_endpwent d_endpwent_r d_endsent \
920 d_endservent_r d_getgrent d_getgrent_r d_getgrgid_r \
921 d_getgrnam_r d_gethbyaddr d_gethent d_getsbyport \
922 d_gethostbyaddr_r d_gethostbyname_r d_gethostent_r \
923 d_getlogin_r d_getnbyaddr d_getnbyname d_getnent \
924 d_getnetbyaddr_r d_getnetbyname_r d_getnetent_r \
925 d_getpent d_getpbyname d_getpbynumber d_getprotobyname_r \
926 d_getprotobynumber_r d_getprotoent_r d_getpwent \
927 d_getpwent_r d_getpwnam_r d_getpwuid_r d_getsent \
928 d_getservbyname_r d_getservbyport_r d_getservent_r \
929 d_getspnam_r d_getsbyname
930 # d_gethbyname
931 do
932 PERL_CONFIGURE="$PERL_CONFIGURE -U$sym"
933 done
934 }
935
936 This mostly gains space when linking staticaly, as the functions
937 will liekly not be linked in. The gain for dynamically-linked
938 binaries is smaller.
939
940 Also, this leaves "gethostbyname" in - not only is it actually used
941 often, the Socket module also exposes it, so leaving it out usually
942 gains little. Why Socket exposes a C function that is in the core
943 already is anybody's guess.
944
945 AUTHOR
946 Marc Lehmann <schmorp@schmorp.de>
947 http://software.schmorp.de/pkg/staticperl.html
948