=head1 NAME staticperl - perl, libc, 50 modules all in one 500kb file =head1 SYNOPSIS staticperl help # print the embedded documentation staticperl fetch # fetch and unpack perl sources staticperl configure # fetch and then configure perl staticperl build # configure and then build perl 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 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 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 -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http # build a perl with the above modules linked in =head1 DESCRIPTION This script helps you creating single-file perl interpreters, or embedding a pelr interpreter in your apps. 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. With uclibc and upx on x86, you can create a single 500kb binary that contains perl and 50 modules such as AnyEvent, EV, IO::AIO, Coro and so on. Or any other choice of modules. The created files do not need write access to the filesystem (like PAR does). In fact, since this script is in many ways similar to PAR::Packer, here are the differences: =over 4 =item * The generated executables are much smaller than PAR created ones. Shared objects and the perl binary contain a lot of extra info, while the static nature of F allows the linker to remove all functionality and meta-info not required by the final executable. Even extensions statically compiled into perl at build time will only be present in the final executable when needed. In addition, F can strip perl sources much more effectively than PAR. =item * The generated executables start much faster. There is no need to unpack files, or even to parse Zip archives (which is slow and memory-consuming business). =item * The generated executables don't need a writable filesystem. 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. PAR tries to be maintainance 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 filesize. 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. =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 F tries to make this easy, it still requires a custom perl build and possibly fiddling with some modules. PAR is likely to produce results faster. =back =head1 HOW DOES IT WORK? Simple: F downloads, compile and installs a perl version of your choice in F<~/.staticperl>. You can add extra modules either by letting F install them for you automatically, or by using CPAN and doing it interactively. This usually takes 5-10 minutes, depending on the speed of your computer and your internet conenction. It is possible to do program development at this stage, too. Afterwards, you create a list of files and modules you want to include, and then either build a new perl binary (that acts just like a normla perl 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. =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. F interprets the first argument as a command to execute, optionally followed by any parameters. There are two command categories: the "phase 1" commands which deal with installing perl and perl modules, and the "phase 2" commands, which deal with creating binaries and bundle files. =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 modules required by F itself, but all this can (and should) be changed - see L, below. The command staticperl install 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. To force recompilation or reinstalaltion, you need to run F first. =over 4 =item F Runs only the download and unpack phase, unless this has already happened. =item F Configures the unpacked perl sources, potentially after downloading them first. =item F Builds the configured perl sources, potentially after automatically configuring them. =item F Wipes the perl installation directory (usually F<~/.staticperl/perl>) and installs the perl distribution, potentially aftering building it first. =item F [args...] Starts an interactive CPAN shell that you cna use to install further modules. Installs the perl first if neccessary, but apart from that, no magic is involved: you could just as well run it manually via F<~/.staticperl/perl/bin/cpan>. Any additional arguments are simply passed to the F command. =item F module... Tries to install all the modules given and their dependencies, using CPAN. Example: staticperl instcpan EV AnyEvent::HTTPD Coro =item F directory... In the unlikely case that you have unpacked perl modules around and want to install from these instead of from CPAN, you cna do this using this command by specifying all the directories with modules in them that you want to have built. =item F Runs F in the perl source directory (and potentially cleans up other intermediate files). This can be used to clean up intermediate files without removing the installed perl interpreter. =item F This wipes your complete F<~/.staticperl> directory. Be careful with this, it nukes your perl download, perl sources, perl distribution and any installed modules. It is useful if you wish to start over "from scratch" or when you want to uninstall F. =back =head2 PHASE 2 COMMANDS: BUILDING PERL BUNDLES Building (linking) a new F binary is handled by a separate script. To make it easy to use F from a F, the script is embedded into F, which will write it out and call for you with any arguments you pass: staticperl mkbundle mkbundle-args... In the oh so unlikely case of something not working here, you cna run the script manually as well (by default it is written to F<~/.staticperl/mkbundle>). F is a more conventional command and expect the argument syntax commonly used on unix clones. For example, this command builds a new F binary and includes F (for F), F, F and a custom F script (from F in this distribution): # first make sure we have perl and the required modules staticperl instcpan AnyEvent::HTTPD # now build the perl staticperl mkperl -M'"Config_heavy.pl"' -MAnyEvent::Impl::Perl \ -MAnyEvent::HTTPD -MURI::http \ --add 'eg/httpd httpd.pm' # finally, invoke it ./perl -Mhttpd As you can see, things are not quite as trivial: the L module has a hidden dependency which is not even a perl module (F), L needs at least one event loop backend that we have to specifymanually (here L), and the F module (required by L) implements various URI schemes as extra modules - since L only needs C URIs, we only need to include that module. =head3 OPTION PROCESSING All options can be given as arguments on the commandline (typically using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since specifying a lot of modules can make the commandlien very cumbersome, you can put all long options into a "bundle specification file" (with or without C<--> prefix) and specify this bundle file instead. For example, the command given earlier could also look like this: staticperl mkperl httpd.bundle And all options could be in F: use "Config_heavy.pl" use AnyEvent::Impl::Perl use AnyEvent::HTTPD use URI::http add eg/httpd httpd.pm =head3 MKBUNDLE OPTIONS =over 4 "strip=s" => \$STRIP, "verbose|v" => sub { ++$VERBOSE }, "quiet|q" => sub { --$VERBOSE }, "perl" => \$PERL, "eval=s" => sub { trace_eval $_[1] }, "use|M=s" => sub { trace_module $_[1] }, "boot=s" => sub { cmd_boot $_[1] }, "add=s" => sub { cmd_add $_[1] }, "static" => sub { $STATIC = 1 }, "<>" => sub { cmd_file $_[1] }, =back =head2 F CONFIGURATION AND HOOKS #TODO =head1 AUTHOR Marc Lehmann http://software.schmorp.de/pkg/staticperl.html