--- App-Staticperl/staticperl.pod 2010/12/07 13:23:07 1.12 +++ App-Staticperl/staticperl.pod 2011/04/02 11:00:34 1.39 @@ -11,33 +11,42 @@ staticperl install # build and then install perl staticperl clean # clean most intermediate files (restart at configure) staticperl distclean # delete everything installed by this script + staticperl perl ... # invoke the perlinterpreter staticperl cpan # invoke CPAN shell staticperl instmod path... # install unpacked modules staticperl instcpan modulename... # install modules from CPAN staticperl mkbundle # see documentation staticperl mkperl # see documentation + staticperl mkapp appname # see documentation Typical Examples: staticperl install # fetch, configure, build and install perl staticperl cpan # run interactive cpan shell - staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V + staticperl mkperl -MConfig_heavy.pl # build a perl that supports -V staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http # build a perl with the above modules linked in + staticperl mkapp myapp --boot mainprog mymodules + # build a binary "myapp" from mainprog and mymodules =head1 DESCRIPTION -This script helps you creating single-file perl interpreters, or embedding -a perl interpreter in your applications. Single-file means that it is -fully self-contained - no separate shared objects, no autoload fragments, -no .pm or .pl files are needed. And when linking statically, you can -create (or embed) a single file that contains perl interpreter, libc, all -the modules you need and all the libraries you need. +This script helps you to create single-file perl interpreters +or applications, or embedding a perl interpreter in your +applications. Single-file means that it is fully self-contained - no +separate shared objects, no autoload fragments, no .pm or .pl files are +needed. And when linking statically, you can create (or embed) a single +file that contains perl interpreter, libc, all the modules you need, all +the libraries you need and of course your actual program. With F and F on x86, you can create a single 500kb binary that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, Coro and so on. Or any other choice of modules. +To see how this turns out, you can try out smallperl and bigperl, two +pre-built static and compressed perl binaries with many and even more +modules: just follow the links at L. + The created files do not need write access to the file system (like PAR does). In fact, since this script is in many ways similar to PAR::Packer, here are the differences: @@ -65,17 +74,21 @@ F loads all required files directly from memory. There is no need to unpack files into a temporary directory. -=item * More control over included files. +=item * More control over included files, more burden. PAR tries to be maintenance and hassle-free - it tries to include more -files than necessary to make sure everything works out of the box. The -extra files (such as the unicode database) can take substantial amounts of -memory and file size. +files than necessary to make sure everything works out of the box. It +mostly succeeds at this, but he extra files (such as the unicode database) +can take substantial amounts of memory and file size. With F, the burden is mostly with the developer - only direct compile-time dependencies and L are handled automatically. This means the modules to include often need to be tweaked manually. +All this does not preclude more permissive modes to be implemented in +the future, but right now, you have to resolve state hidden dependencies +manually. + =item * PAR works out of the box, F does not. Maintaining your own custom perl build can be a pain in the ass, and while @@ -83,6 +96,11 @@ build and possibly fiddling with some modules. PAR is likely to produce results faster. +Ok, PAR never has worked for me out of the box, and for some people, +F does work out of the box, as they don't count "fiddling with +module use lists" against it, but nevertheless, F is certainly +a bit more difficult to use. + =back =head1 HOW DOES IT WORK? @@ -100,17 +118,19 @@ except everything is compiled in), or you create bundle files (basically C sources you can use to embed all files into your project). -This step is very fast (a few seconds if PPI is not used for stripping, -more seconds otherwise, as PPI is very slow), and can be tweaked and -repeated as often as necessary. +This step is very fast (a few seconds if PPI is not used for stripping, or +the stripped files are in the cache), and can be tweaked and repeated as +often as necessary. =head1 THE F SCRIPT This module installs a script called F into your perl -binary directory. The script is fully self-contained, and can be used -without perl (for example, in an uClibc chroot environment). In fact, -it can be extracted from the C distribution tarball as -F, without any installation. +binary directory. The script is fully self-contained, and can be +used without perl (for example, in an uClibc chroot environment). In +fact, it can be extracted from the C distribution +tarball as F, without any installation. The +newest (possibly alpha) version can also be downloaded from +L. F interprets the first argument as a command to execute, optionally followed by any parameters. @@ -122,7 +142,7 @@ =head2 PHASE 1 COMMANDS: INSTALLING PERL The most important command is F, which does basically -everything. The default is to download and install perl 5.12.2 and a few +everything. The default is to download and install perl 5.12.3 and a few modules required by F itself, but all this can (and should) be changed - see L, below. @@ -130,18 +150,27 @@ staticperl install -Is normally all you need: It installs the perl interpreter in +is normally all you need: It installs the perl interpreter in F<~/.staticperl/perl>. It downloads, configures, builds and installs the perl interpreter if required. -Most of the following commands simply run one or more steps of this -sequence. +Most of the following F subcommands simply run one or more +steps of this sequence. + +If it fails, then most commonly because the compiler options I selected +are not supported by your compiler - either edit the F script +yourself or create F<~/.staticperl> shell script where your set working +C etc. variables. To force recompilation or reinstallation, you need to run F first. =over 4 +=item F + +Prints some info about the version of the F script you are using. + =item F Runs only the download and unpack phase, unless this has already happened. @@ -160,6 +189,16 @@ Wipes the perl installation directory (usually F<~/.staticperl/perl>) and installs the perl distribution, potentially after building it first. +=item F [args...] + +Invokes the compiled perl interpreter with the given args. Basically the +same as starting perl directly (usually via F<~/.staticperl/bin/perl>), +but beats typing the path sometimes. + +Example: check that the Gtk2 module is installed and loadable. + + staticperl perl -MGtk2 -e0 + =item F [args...] Starts an interactive CPAN shell that you can use to install further @@ -188,11 +227,12 @@ Deletes the perl source directory (and potentially cleans up other intermediate files). This can be used to clean up files only needed for -building perl, without removing the installed perl interpreter, or to -force a re-build from scratch. +building perl, without removing the installed perl interpreter. At the moment, it doesn't delete downloaded tarballs. +The exact semantics of this command will probably change. + =item F This wipes your complete F<~/.staticperl> directory. Be careful with this, @@ -225,7 +265,7 @@ staticperl instcpan AnyEvent::HTTPD # now build the perl - staticperl mkperl -M'"Config_heavy.pl"' -MAnyEvent::Impl::Perl \ + staticperl mkperl -MConfig_heavy.pl -MAnyEvent::Impl::Perl \ -MAnyEvent::HTTPD -MURI::http \ --add 'eg/httpd httpd.pm' @@ -241,20 +281,64 @@ to include that module. I found out about these dependencies by carefully watching any error messages about missing modules... +Instead of building a new perl binary, you can also build a standalone +application: + + # build the app + staticperl mkapp app --boot eg/httpd \ + -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http + + # run it + ./app + +Here are the three phase 2 commands: + +=over 4 + +=item F args... + +The "default" bundle command - it interprets the given bundle options and +writes out F, F, F and F +files, useful for embedding. + +=item F args... + +Creates a bundle just like F (in fact, it's the same +as invoking F args...), but then compiles and +links a new perl interpreter that embeds the created bundle, then deletes +all intermediate files. + +=item F filename args... + +Does the same as F (in fact, it's the same as +invoking F filename args...), but then compiles +and links a new standalone application that simply initialises the perl +interpreter. + +The difference to F is that the standalone application +does not act like a perl interpreter would - in fact, by default it would +just do nothing and exit immediately, so you should specify some code to +be executed via the F<--boot> option. + +=back + =head3 OPTION PROCESSING All options can be given as arguments on the command line (typically using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since -specifying a lot of modules can make the command line very cumbersome, -you can put all long options into a "bundle specification file" (with or -without C<--> prefix) and specify this bundle file instead. +specifying a lot of options can make the command line very long and +unwieldy, you can put all long options into a "bundle specification file" +(one option per line, with or without C<--> prefix) and specify this +bundle file instead. -For example, the command given earlier could also look like this: +For example, the command given earlier to link a new F could also +look like this: staticperl mkperl httpd.bundle -And all options could be in F: - +With all options stored in the F file (one option per line, +everything after the option is an argument): + use "Config_heavy.pl" use AnyEvent::Impl::Perl use AnyEvent::HTTPD @@ -262,94 +346,127 @@ add eg/httpd httpd.pm All options that specify modules or files to be added are processed in the -order given on the command line (that affects the C<--use> and C<--eval> -options at the moment). +order given on the command line. -=head3 MKBUNDLE OPTIONS +=head3 BUNDLE CREATION WORKFLOW / STATICPELR MKBUNDLE OPTIONS + +F works by first assembling a list of candidate +files and modules to include, then filtering them by include/exclude +patterns. The remaining modules (together with their direct dependencies, +such as link libraries and L files) are then converted into +bundle files suitable for embedding. F can then +optionally build a new perl interpreter or a standalone application. =over 4 -=item --verbose | -v +=item Step 0: Generic argument processing. -Increases the verbosity level by one (the default is C<1>). +The following options influence F itself. -=item --quiet | -q +=over 4 -Decreases the verbosity level by one. +=item C<--verbose> | C<-v> -=item --strip none|pod|ppi +Increases the verbosity level by one (the default is C<1>). -Specify the stripping method applied to reduce the file of the perl -sources included. +=item C<--quiet> | C<-q> -The default is C, which uses the L module to remove all -pod documentation, which is very fast and reduces file size a lot. +Decreases the verbosity level by one. -The C method uses L to parse and condense the perl sources. This -saves a lot more than just L, and is generally safer, but -is also a lot slower, so is best used for production builds. Note that -this method doesn't optimise for raw file size, but for best compression -(that means that the uncompressed file size is a bit larger, but the files -compress better, e.g. with F). +=item any other argument -Last not least, if you need accurate line numbers in error messages, -or in the unlikely case where C is too slow, or some module gets -mistreated, you can specify C to not mangle included perl sources in -any way. +Any other argument is interpreted as a bundle specification file, which +supports all options (without extra quoting), one option per line, in the +format C