ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/README
Revision: 1.9
Committed: Wed Dec 15 00:18:04 2010 UTC (15 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-0_912
Changes since 1.8: +23 -9 lines
Log Message:
0.912

File Contents

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