ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.pod
Revision: 1.12
Committed: Tue Dec 7 13:23:07 2010 UTC (13 years, 5 months ago) by root
Branch: MAIN
Changes since 1.11: +16 -5 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.8 staticperl - perl, libc, 100 modules, all in one 500kb file
4 root 1.1
5     =head1 SYNOPSIS
6    
7     staticperl help # print the embedded documentation
8     staticperl fetch # fetch and unpack perl sources
9     staticperl configure # fetch and then configure perl
10     staticperl build # configure and then build perl
11     staticperl install # build and then install perl
12     staticperl clean # clean most intermediate files (restart at configure)
13     staticperl distclean # delete everything installed by this script
14     staticperl cpan # invoke CPAN shell
15     staticperl instmod path... # install unpacked modules
16     staticperl instcpan modulename... # install modules from CPAN
17     staticperl mkbundle <bundle-args...> # see documentation
18     staticperl mkperl <bundle-args...> # see documentation
19    
20     Typical Examples:
21    
22     staticperl install # fetch, configure, build and install perl
23     staticperl cpan # run interactive cpan shell
24     staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V
25     staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http
26     # build a perl with the above modules linked in
27    
28     =head1 DESCRIPTION
29    
30     This script helps you creating single-file perl interpreters, or embedding
31 root 1.3 a perl interpreter in your applications. Single-file means that it is
32     fully self-contained - no separate shared objects, no autoload fragments,
33     no .pm or .pl files are needed. And when linking statically, you can
34     create (or embed) a single file that contains perl interpreter, libc, all
35     the modules you need and all the libraries you need.
36 root 1.1
37 root 1.8 With F<uClibc> and F<upx> on x86, you can create a single 500kb binary
38     that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO,
39     Coro and so on. Or any other choice of modules.
40 root 1.1
41 root 1.3 The created files do not need write access to the file system (like PAR
42 root 1.1 does). In fact, since this script is in many ways similar to PAR::Packer,
43     here are the differences:
44    
45     =over 4
46    
47     =item * The generated executables are much smaller than PAR created ones.
48    
49     Shared objects and the perl binary contain a lot of extra info, while
50     the static nature of F<staticperl> allows the linker to remove all
51     functionality and meta-info not required by the final executable. Even
52     extensions statically compiled into perl at build time will only be
53     present in the final executable when needed.
54    
55     In addition, F<staticperl> can strip perl sources much more effectively
56     than PAR.
57    
58     =item * The generated executables start much faster.
59    
60     There is no need to unpack files, or even to parse Zip archives (which is
61     slow and memory-consuming business).
62    
63     =item * The generated executables don't need a writable filesystem.
64    
65     F<staticperl> loads all required files directly from memory. There is no
66     need to unpack files into a temporary directory.
67    
68     =item * More control over included files.
69    
70 root 1.3 PAR tries to be maintenance and hassle-free - it tries to include more
71     files than necessary to make sure everything works out of the box. The
72     extra files (such as the unicode database) can take substantial amounts of
73     memory and file size.
74 root 1.1
75     With F<staticperl>, the burden is mostly with the developer - only direct
76     compile-time dependencies and L<AutoLoader> are handled automatically.
77     This means the modules to include often need to be tweaked manually.
78    
79     =item * PAR works out of the box, F<staticperl> does not.
80    
81     Maintaining your own custom perl build can be a pain in the ass, and while
82     F<staticperl> tries to make this easy, it still requires a custom perl
83     build and possibly fiddling with some modules. PAR is likely to produce
84     results faster.
85    
86     =back
87    
88     =head1 HOW DOES IT WORK?
89    
90     Simple: F<staticperl> downloads, compile and installs a perl version of
91     your choice in F<~/.staticperl>. You can add extra modules either by
92     letting F<staticperl> install them for you automatically, or by using CPAN
93     and doing it interactively. This usually takes 5-10 minutes, depending on
94 root 1.3 the speed of your computer and your internet connection.
95 root 1.1
96     It is possible to do program development at this stage, too.
97    
98     Afterwards, you create a list of files and modules you want to include,
99 root 1.3 and then either build a new perl binary (that acts just like a normal perl
100 root 1.1 except everything is compiled in), or you create bundle files (basically C
101     sources you can use to embed all files into your project).
102    
103     This step is very fast (a few seconds if PPI is not used for stripping,
104     more seconds otherwise, as PPI is very slow), and can be tweaked and
105     repeated as often as necessary.
106    
107     =head1 THE F<STATICPERL> SCRIPT
108    
109     This module installs a script called F<staticperl> into your perl
110     binary directory. The script is fully self-contained, and can be used
111     without perl (for example, in an uClibc chroot environment). In fact,
112     it can be extracted from the C<App::Staticperl> distribution tarball as
113     F<bin/staticperl>, without any installation.
114    
115     F<staticperl> interprets the first argument as a command to execute,
116     optionally followed by any parameters.
117    
118     There are two command categories: the "phase 1" commands which deal with
119     installing perl and perl modules, and the "phase 2" commands, which deal
120     with creating binaries and bundle files.
121    
122     =head2 PHASE 1 COMMANDS: INSTALLING PERL
123    
124     The most important command is F<install>, which does basically
125     everything. The default is to download and install perl 5.12.2 and a few
126     modules required by F<staticperl> itself, but all this can (and should) be
127     changed - see L<CONFIGURATION>, below.
128    
129     The command
130    
131     staticperl install
132    
133     Is normally all you need: It installs the perl interpreter in
134     F<~/.staticperl/perl>. It downloads, configures, builds and installs the
135     perl interpreter if required.
136    
137     Most of the following commands simply run one or more steps of this
138     sequence.
139    
140 root 1.3 To force recompilation or reinstallation, you need to run F<staticperl
141 root 1.1 distclean> first.
142    
143     =over 4
144    
145     =item F<staticperl fetch>
146    
147     Runs only the download and unpack phase, unless this has already happened.
148    
149     =item F<staticperl configure>
150    
151     Configures the unpacked perl sources, potentially after downloading them first.
152    
153     =item F<staticperl build>
154    
155     Builds the configured perl sources, potentially after automatically
156     configuring them.
157    
158     =item F<staticperl install>
159    
160 root 1.3 Wipes the perl installation directory (usually F<~/.staticperl/perl>) and
161     installs the perl distribution, potentially after building it first.
162 root 1.1
163     =item F<staticperl cpan> [args...]
164    
165 root 1.3 Starts an interactive CPAN shell that you can use to install further
166     modules. Installs the perl first if necessary, but apart from that,
167 root 1.1 no magic is involved: you could just as well run it manually via
168     F<~/.staticperl/perl/bin/cpan>.
169    
170     Any additional arguments are simply passed to the F<cpan> command.
171    
172     =item F<staticperl instcpan> module...
173    
174     Tries to install all the modules given and their dependencies, using CPAN.
175    
176     Example:
177    
178     staticperl instcpan EV AnyEvent::HTTPD Coro
179    
180     =item F<staticperl instsrc> directory...
181    
182     In the unlikely case that you have unpacked perl modules around and want
183 root 1.3 to install from these instead of from CPAN, you can do this using this
184 root 1.1 command by specifying all the directories with modules in them that you
185     want to have built.
186    
187     =item F<staticperl clean>
188    
189 root 1.12 Deletes the perl source directory (and potentially cleans up other
190     intermediate files). This can be used to clean up files only needed for
191     building perl, without removing the installed perl interpreter, or to
192     force a re-build from scratch.
193    
194     At the moment, it doesn't delete downloaded tarballs.
195 root 1.1
196     =item F<staticperl distclean>
197    
198     This wipes your complete F<~/.staticperl> directory. Be careful with this,
199     it nukes your perl download, perl sources, perl distribution and any
200     installed modules. It is useful if you wish to start over "from scratch"
201     or when you want to uninstall F<staticperl>.
202    
203     =back
204    
205     =head2 PHASE 2 COMMANDS: BUILDING PERL BUNDLES
206    
207     Building (linking) a new F<perl> binary is handled by a separate
208     script. To make it easy to use F<staticperl> from a F<chroot>, the script
209     is embedded into F<staticperl>, which will write it out and call for you
210     with any arguments you pass:
211    
212     staticperl mkbundle mkbundle-args...
213    
214     In the oh so unlikely case of something not working here, you
215 root 1.2 can run the script manually as well (by default it is written to
216 root 1.1 F<~/.staticperl/mkbundle>).
217    
218     F<mkbundle> is a more conventional command and expect the argument
219 root 1.3 syntax commonly used on UNIX clones. For example, this command builds
220 root 1.1 a new F<perl> binary and includes F<Config.pm> (for F<perl -V>),
221     F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd>
222     in this distribution):
223    
224     # first make sure we have perl and the required modules
225     staticperl instcpan AnyEvent::HTTPD
226    
227     # now build the perl
228     staticperl mkperl -M'"Config_heavy.pl"' -MAnyEvent::Impl::Perl \
229     -MAnyEvent::HTTPD -MURI::http \
230     --add 'eg/httpd httpd.pm'
231    
232     # finally, invoke it
233     ./perl -Mhttpd
234    
235     As you can see, things are not quite as trivial: the L<Config> module has
236     a hidden dependency which is not even a perl module (F<Config_heavy.pl>),
237     L<AnyEvent> needs at least one event loop backend that we have to
238 root 1.3 specify manually (here L<AnyEvent::Impl::Perl>), and the F<URI> module
239 root 1.1 (required by L<AnyEvent::HTTPD>) implements various URI schemes as extra
240     modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need
241 root 1.3 to include that module. I found out about these dependencies by carefully
242     watching any error messages about missing modules...
243 root 1.1
244     =head3 OPTION PROCESSING
245    
246 root 1.3 All options can be given as arguments on the command line (typically
247     using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since
248     specifying a lot of modules can make the command line very cumbersome,
249 root 1.1 you can put all long options into a "bundle specification file" (with or
250     without C<--> prefix) and specify this bundle file instead.
251    
252     For example, the command given earlier could also look like this:
253    
254     staticperl mkperl httpd.bundle
255    
256     And all options could be in F<httpd.bundle>:
257    
258     use "Config_heavy.pl"
259     use AnyEvent::Impl::Perl
260     use AnyEvent::HTTPD
261     use URI::http
262     add eg/httpd httpd.pm
263    
264 root 1.2 All options that specify modules or files to be added are processed in the
265 root 1.3 order given on the command line (that affects the C<--use> and C<--eval>
266 root 1.2 options at the moment).
267    
268 root 1.1 =head3 MKBUNDLE OPTIONS
269    
270     =over 4
271    
272 root 1.2 =item --verbose | -v
273    
274     Increases the verbosity level by one (the default is C<1>).
275    
276     =item --quiet | -q
277    
278     Decreases the verbosity level by one.
279    
280     =item --strip none|pod|ppi
281    
282     Specify the stripping method applied to reduce the file of the perl
283     sources included.
284    
285     The default is C<pod>, which uses the L<Pod::Strip> module to remove all
286 root 1.3 pod documentation, which is very fast and reduces file size a lot.
287 root 1.2
288     The C<ppi> method uses L<PPI> to parse and condense the perl sources. This
289 root 1.3 saves a lot more than just L<Pod::Strip>, and is generally safer, but
290     is also a lot slower, so is best used for production builds. Note that
291     this method doesn't optimise for raw file size, but for best compression
292     (that means that the uncompressed file size is a bit larger, but the files
293     compress better, e.g. with F<upx>).
294 root 1.2
295 root 1.9 Last not least, if you need accurate line numbers in error messages,
296     or in the unlikely case where C<pod> is too slow, or some module gets
297     mistreated, you can specify C<none> to not mangle included perl sources in
298     any way.
299 root 1.2
300     =item --perl
301    
302     After writing out the bundle files, try to link a new perl interpreter. It
303     will be called F<perl> and will be left in the current working
304     directory. The bundle files will be removed.
305    
306 root 1.3 This switch is automatically used when F<staticperl> is invoked with the
307 root 1.2 C<mkperl> command (instead of C<mkbundle>):
308    
309     # build a new ./perl with only common::sense in it - very small :)
310     staticperl mkperl -Mcommon::sense
311    
312     =item --use module | -Mmodule
313    
314     Include the named module and all direct dependencies. This is done by
315     C<require>'ing the module in a subprocess and tracing which other modules
316     and files it actually loads. If the module uses L<AutoLoader>, then all
317     splitfiles will be included as well.
318    
319     Example: include AnyEvent and AnyEvent::Impl::Perl.
320    
321     staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl
322    
323     Sometimes you want to load old-style "perl libraries" (F<.pl> files), or
324     maybe other weirdly named files. To do that, you need to quote the name in
325 root 1.3 single or double quotes. When given on the command line, you probably need
326 root 1.2 to quote once more to avoid your shell interpreting it. Common cases that
327     need this are F<Config_heavy.pl> and F<utf8_heavy.pl>.
328    
329     Example: include the required files for F<perl -V> to work in all its
330     glory (F<Config.pm> is included automatically by this).
331    
332     # bourne shell
333     staticperl mkbundle --use '"Config_heavy.pl"'
334    
335     # bundle specification file
336     use "Config_heavy.pl"
337    
338     The C<-Mmodule> syntax is included as an alias that might be easier to
339     remember than C<use>. Or maybe it confuses people. Time will tell. Or
340     maybe not. Argh.
341    
342     =item --eval "perl code" | -e "perl code"
343    
344     Sometimes it is easier (or necessary) to specify dependencies using perl
345     code, or maybe one of the modules you use need a special use statement. In
346     that case, you can use C<eval> to execute some perl snippet or set some
347     variables or whatever you need. All files C<require>'d or C<use>'d in the
348     script are included in the final bundle.
349    
350     Keep in mind that F<mkbundle> will only C<require> the modules named
351     by the C<--use> option, so do not expect the symbols from modules you
352 root 1.3 C<--use>'d earlier on the command line to be available.
353 root 1.2
354     Example: force L<AnyEvent> to detect a backend and therefore include it
355     in the final bundle.
356    
357     staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect'
358    
359     # or like this
360     staticperl mkbundle -MAnyEvent --eval 'use AnyEvent; AnyEvent::detect'
361    
362     Example: use a separate "bootstrap" script that C<use>'s lots of modules
363     and include this in the final bundle, to be executed automatically.
364    
365     staticperl mkbundle --eval 'do "bootstrap"' --boot bootstrap
366    
367     =item --boot filename
368    
369     Include the given file in the bundle and arrange for it to be executed
370     (using a C<require>) before anything else when the new perl is
371     initialised. This can be used to modify C<@INC> or anything else before
372 root 1.3 the perl interpreter executes scripts given on the command line (or via
373 root 1.2 C<-e>). This works even in an embedded interpreter.
374    
375     =item --add "file" | --add "file alias"
376    
377     Adds the given (perl) file into the bundle (and optionally call it
378     "alias"). This is useful to include any custom files into the bundle.
379    
380     Example: embed the file F<httpd> as F<httpd.pm> when creating the bundle.
381    
382     staticperl mkperl --add "httpd httpd.pm"
383    
384     It is also a great way to add any custom modules:
385    
386     # specification file
387     add file1 myfiles/file1
388     add file2 myfiles/file2
389     add file3 myfiles/file3
390    
391 root 1.10 =item --binadd "file" | --add "file alias"
392    
393     Just like C<--add>, except that it treats the file as binary and adds it
394     without any processing.
395    
396     You should probably add a C</> prefix to avoid clashing with embedded
397     perl files (whose paths do not start with C</>), and/or use a special
398     directory, such as C</res/name>.
399    
400     You can later get a copy of these files by calling C<staticperl::find
401     "alias">.
402    
403 root 1.2 =item --static
404    
405     When C<--perl> is also given, link statically instead of dynamically. The
406     default is to link the new perl interpreter fully dynamic (that means all
407     perl modules are linked statically, but all external libraries are still
408     referenced dynamically).
409    
410     Keep in mind that Solaris doesn't support static linking at all, and
411     systems based on GNU libc don't really support it in a usable fashion
412     either. Try uClibc if you want to create fully statically linked
413     executables, or try the C<--staticlibs> option to link only some libraries
414     statically.
415    
416     =item any other argument
417    
418     Any other argument is interpreted as a bundle specification file, which
419     supports most long options (without extra quoting), one option per line.
420 root 1.1
421     =back
422    
423     =head2 F<STATCPERL> CONFIGURATION AND HOOKS
424    
425 root 1.2 During (each) startup, F<staticperl> tries to source the following shell
426     files in order:
427    
428     /etc/staticperlrc
429     ~/.staticperlrc
430     $STATICPERL/rc
431    
432     They can be used to override shell variables, or define functions to be
433     called at specific phases.
434    
435     Note that the last file is erased during F<staticperl distclean>, so
436     generally should not be used.
437    
438     =head3 CONFIGURATION VARIABLES
439    
440     =head4 Variables you I<should> override
441    
442     =over 4
443    
444     =item C<EMAIL>
445    
446     The e-mail address of the person who built this binary. Has no good
447     default, so should be specified by you.
448    
449     =item C<CPAN>
450    
451     The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>).
452    
453 root 1.6 =item C<EXTRA_MODULES>
454 root 1.2
455 root 1.6 Additional modules installed during F<staticperl install>. Here you can
456     set which modules you want have to installed from CPAN.
457 root 1.2
458 root 1.11 Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO.
459 root 1.2
460 root 1.11 EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO"
461 root 1.2
462 root 1.6 Note that you can also use a C<postinstall> hook to achieve this, and
463     more.
464 root 1.2
465 root 1.11 =back
466    
467     =head4 Variables you might I<want> to override
468    
469     =over 4
470    
471     =item C<STATICPERL>
472    
473     The directory where staticperl stores all its files
474     (default: F<~/.staticperl>).
475    
476 root 1.6 =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ...
477 root 1.2
478     Usually set to C<1> to make modules "less inquisitive" during their
479     installation, you can set any environment variable you want - some modules
480     (such as L<Coro> or L<EV>) use environment variables for further tweaking.
481    
482 root 1.11 =item C<PERL_VERSION>
483 root 1.6
484 root 1.11 The perl version to install - default is currently C<5.12.2>, but C<5.8.9>
485     is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is
486     about as big as 5.12.2).
487 root 1.2
488 root 1.11 =item C<PERL_PREFIX>
489 root 1.2
490 root 1.6 The prefix where perl gets installed (default: F<$STATICPERL/perl>),
491     i.e. where the F<bin> and F<lib> subdirectories will end up.
492 root 1.2
493 root 1.10 =item C<PERL_CONFIGURE>
494    
495     Additional Configure options - these are simply passed to the perl
496     Configure script. For example, if you wanted to enable dynamic loading,
497     you could pass C<-Dusedl>. To enable ithreads (Why would you want that
498     insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads>
499     and so on.
500    
501     More commonly, you would either activate 64 bit integer support
502     (C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to
503     reduce filesize further.
504    
505 root 1.6 =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS>
506 root 1.2
507 root 1.6 These flags are passed to perl's F<Configure> script, and are generally
508     optimised for small size (at the cost of performance). Since they also
509     contain subtle workarounds around various build issues, changing these
510     usually requires understanding their default values - best look at the top
511     of the F<staticperl> script for more info on these.
512 root 1.2
513     =back
514    
515 root 1.5 =head4 Variables you probably I<do not want> to override
516 root 1.2
517     =over 4
518    
519     =item C<MKBUNDLE>
520    
521     Where F<staticperl> writes the C<mkbundle> command to
522     (default: F<$STATICPERL/mkbundle>).
523    
524     =item C<STATICPERL_MODULES>
525    
526     Additional modules needed by C<mkbundle> - should therefore not be changed
527     unless you know what you are doing.
528    
529     =back
530    
531     =head3 OVERRIDABLE HOOKS
532    
533     In addition to environment variables, it is possible to provide some
534     shell functions that are called at specific times. To provide your own
535 root 1.3 commands, just define the corresponding function.
536 root 1.2
537     Example: install extra modules from CPAN and from some directories
538     at F<staticperl install> time.
539    
540     postinstall() {
541 root 1.4 rm -rf lib/threads* # weg mit Schaden
542 root 1.2 instcpan IO::AIO EV
543     instsrc ~/src/AnyEvent
544     instsrc ~/src/XML-Sablotron-1.0100001
545 root 1.4 instcpan Anyevent::AIO AnyEvent::HTTPD
546 root 1.2 }
547    
548     =over 4
549    
550 root 1.12 =item preconfigure
551    
552     Called just before running F<./Configur> in the perl source
553     directory. Current working directory is the perl source directory.
554    
555     This can be used to set any C<PERL_xxx> variables, which might be costly
556     to compute.
557    
558 root 1.2 =item postconfigure
559    
560     Called after configuring, but before building perl. Current working
561     directory is the perl source directory.
562    
563 root 1.12 Could be used to tailor/patch config.sh (followed by F<sh Configure -S>)
564     or do any other modifications.
565 root 1.2
566     =item postbuild
567    
568     Called after building, but before installing perl. Current working
569     directory is the perl source directory.
570    
571     I have no clue what this could be used for - tell me.
572    
573     =item postinstall
574    
575     Called after perl and any extra modules have been installed in C<$PREFIX>,
576     but before setting the "installation O.K." flag.
577    
578     The current working directory is C<$PREFIX>, but maybe you should not rely
579     on that.
580    
581     This hook is most useful to customise the installation, by deleting files,
582     or installing extra modules using the C<instcpan> or C<instsrc> functions.
583    
584     The script must return with a zero exit status, or the installation will
585     fail.
586    
587     =back
588 root 1.1
589 root 1.9 =head1 ANATOMY OF A BUNDLE
590    
591     When not building a new perl binary, C<mkbundle> will leave a number of
592     files in the current working directory, which can be used to embed a perl
593     interpreter in your program.
594    
595     Intimate knowledge of L<perlembed> and preferably some experience with
596     embedding perl is highly recommended.
597    
598     C<mkperl> (or the C<--perl> option) basically does this to link the new
599     interpreter (it also adds a main program to F<bundle.>):
600    
601     $Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts)
602    
603     =over 4
604    
605     =item bundle.h
606    
607     A header file that contains the prototypes of the few symbols "exported"
608     by bundle.c, and also exposes the perl headers to the application.
609    
610     =over 4
611    
612     =item staticperl_init ()
613    
614     Initialises the perl interpreter. You can use the normal perl functions
615     after calling this function, for example, to define extra functions or
616     to load a .pm file that contains some initialisation code, or the main
617     program function:
618    
619     XS (xsfunction)
620     {
621     dXSARGS;
622    
623     // now we have items, ST(i) etc.
624     }
625    
626     static void
627     run_myapp(void)
628     {
629     staticperl_init ();
630     newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
631     eval_pv ("require myapp::main", 1); // executes "myapp/main.pm"
632     }
633    
634     =item staticperl_xs_init (pTHX)
635    
636     Sometimes you need direct control over C<perl_parse> and C<perl_run>, in
637     which case you do not want to use C<staticperl_init> but call them on your
638     own.
639    
640     Then you need this function - either pass it directly as the C<xs_init>
641     function to C<perl_parse>, or call it from your own C<xs_init> function.
642    
643     =item staticperl_cleanup ()
644    
645     In the unlikely case that you want to destroy the perl interpreter, here
646     is the corresponding function.
647    
648     =item PerlInterpreter *staticperl
649    
650     The perl interpreter pointer used by staticperl. Not normally so useful,
651     but there it is.
652    
653     =back
654    
655     =item bundle.ccopts
656    
657     Contains the compiler options required to compile at least F<bundle.c> and
658     any file that includes F<bundle.h> - you should probably use it in your
659     C<CFLAGS>.
660    
661     =item bundle.ldopts
662    
663     The linker options needed to link the final program.
664    
665     =back
666    
667     =head1 RUNTIME FUNCTIONALITY
668    
669     Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which
670     are required to access the bundled perl sources, but might be useful for
671     other purposes.
672    
673     In addition, for the embedded loading of perl files to work, F<staticperl>
674     overrides the C<@INC> array.
675    
676     =over 4
677    
678     =item $file = staticperl::find $path
679    
680     Returns the data associated with the given C<$path>
681     (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically
682     the UNIX path relative to the perl library directory.
683    
684     Returns C<undef> if the file isn't embedded.
685    
686     =item @paths = staticperl::list
687    
688     Returns the list of all paths embedded in this binary.
689    
690     =back
691    
692     =head1 FULLY STATIC BINARIES - BUILDROOT
693    
694 root 1.10 To make truly static (Linux-) libraries, you might want to have a look at
695 root 1.9 buildroot (L<http://buildroot.uclibc.org/>).
696    
697     Buildroot is primarily meant to set up a cross-compile environment (which
698     is not so useful as perl doesn't quite like cross compiles), but it can also compile
699     a chroot environment where you can use F<staticperl>.
700    
701     To do so, download buildroot, and enable "Build options => development
702     files in target filesystem" and optionally "Build options => gcc
703     optimization level (optimize for size)". At the time of writing, I had
704     good experiences with GCC 4.4.x but not GCC 4.5.
705    
706     To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections
707     -finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386>
708     doesn't decrease codesize much, but it makes the file much more
709     compressible.
710    
711     If you don't need Coro or threads, you can go with "linuxthreads.old" (or
712     no thread support). For Coro, it is highly recommended to switch to a
713     uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201
714     snapshot) and enable NPTL, otherwise Coro needs to be configured with the
715     ultra-slow pthreads backend to work around linuxthreads bugs (it also uses
716     twice the address space needed for stacks).
717    
718 root 1.10 If you use C<linuxthreads.old>, then you should also be aware that
719     uClibc shares C<errno> between all threads when statically linking. See
720     L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a
721     workaround (And L<https://bugs.uclibc.org/2089> for discussion).
722    
723 root 1.11 C<ccache> support is also recommended, especially if you want
724     to play around with buildroot options. Enabling the C<miniperl>
725     package will probably enable all options required for a successful
726     perl build. F<staticperl> itself additionally needs either C<wget>
727     (recommended, for CPAN) or C<curl>.
728 root 1.9
729     As for shells, busybox should provide all that is needed, but the default
730     busybox configuration doesn't include F<comm> which is needed by perl -
731     either make a custom busybox config, or compile coreutils.
732    
733     For the latter route, you might find that bash has some bugs that keep
734     it from working properly in a chroot - either use dash (and link it to
735     F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's
736     built-in ash shell.
737    
738     Finally, you need F</dev/null> inside the chroot for many scripts to work
739     - F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will
740     both provide this.
741    
742     After you have compiled and set up your buildroot target, you can copy
743     F<staticperl> from the C<App::Staticperl> distribution or from your
744     perl f<bin> directory (if you installed it) into the F<output/target>
745     filesystem, chroot inside and run it.
746    
747 root 1.1 =head1 AUTHOR
748    
749     Marc Lehmann <schmorp@schmorp.de>
750     http://software.schmorp.de/pkg/staticperl.html