--- App-Staticperl/staticperl.pod 2010/12/21 19:32:34 1.27 +++ App-Staticperl/staticperl.pod 2011/04/02 11:00:34 1.39 @@ -11,6 +11,7 @@ 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 @@ -22,7 +23,7 @@ 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 @@ -141,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. @@ -188,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 @@ -254,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' @@ -383,32 +394,67 @@ =item C<--use> F | C<-M>F -Include the named module and trace direct dependencies. This is done by -C'ing the module in a subprocess and tracing which other modules -and files it actually loads. +Include the named module or perl library and trace direct +dependencies. This is done by loading the module in a subprocess and +tracing which other modules and files it actually loads. Example: include AnyEvent and AnyEvent::Impl::Perl. staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl Sometimes you want to load old-style "perl libraries" (F<.pl> files), or -maybe other weirdly named files. To do that, you need to quote the name in -single or double quotes. When given on the command line, you probably need -to quote once more to avoid your shell interpreting it. Common cases that -need this are F and F. +maybe other weirdly named files. To support this, the C<--use> option +actually tries to do what you mean, depending on the string you specify: + +=over 4 + +=item a possibly valid module name, e.g. F, F, +F. + +If the string contains no quotes, no F and no F<.>, then C<--use> +assumes that it is a normal module name. It will create a new package and +evaluate a C in it, i.e. it will load the package and do a +default import. + +The import step is done because many modules trigger more dependencies +when something is imported than without. + +=item anything that contains F or F<.> characters, +e.g. F, F. + +The string will be quoted and passed to require, as if you used C. Nothing will be imported. + +=item "path" or 'path', e.g. C<"utf8_heavy.pl">. + +If you enclose the name into single or double quotes, then the quotes will +be removed and the resulting string will be passed to require. This syntax +is form compatibility with older versions of staticperl and should not be +used anymore. + +=back + +Example: C AnyEvent::Socket, once using C (importing the +symbols), and once via C, not importing any symbols. The first +form is preferred as many modules load some extra dependencies when asked +to export symbols. + + staticperl mkbundle -MAnyEvent::Socket # use + import + staticperl mkbundle -MAnyEvent/Socket.pm # require only Example: include the required files for F to work in all its -glory (F is included automatically by this). +glory (F is included automatically by the dependency tracker). - # bourne shell - staticperl mkbundle --use '"Config_heavy.pl"' + # shell command + staticperl mkbundle -MConfig_heavy.pl # bundle specification file - use "Config_heavy.pl" + use Config_heavy.pl -The C<-M>module syntax is included as an alias that might be easier to -remember than C<--use>. Or maybe it confuses people. Time will tell. Or -maybe not. Sigh. +The C<-M>module syntax is included as a convenience that might be easier +to remember than C<--use> - it's the same switch as perl itself uses +to load modules. Or maybe it confuses people. Time will tell. Or maybe +not. Sigh. =item C<--eval> "perl code" | C<-e> "perl code" @@ -418,9 +464,9 @@ variables or whatever you need. All files C'd or C'd while executing the snippet are included in the final bundle. -Keep in mind that F will only C the modules named -by the C<--use> option, so do not expect the symbols from modules you -C<--use>'d earlier on the command line to be available. +Keep in mind that F will not import any symbols from the modules +named by the C<--use> option, so do not expect the symbols from modules +you C<--use>'d earlier on the command line to be available. Example: force L to detect a backend and therefore include it in the final bundle. @@ -457,7 +503,7 @@ --incglob '*' It is also useful for including perl libraries, or trees of those, such as -the unicode database files needed by some perl builtins, the regex engine +the unicode database files needed by some perl built-ins, the regex engine and other modules. --incglob '/unicore/**.pl' @@ -465,9 +511,9 @@ =item C<--add> F | C<--add> "F alias" Adds the given (perl) file into the bundle (and optionally call it -"alias"). The F is either an absolute path or a path relative to -the current directory. If an alias is specified, then this is the name it -will use for C<@INC> searches, otherfile the F will be used as the +"alias"). The F is either an absolute path or a path relative to the +current directory. If an alias is specified, then this is the name it will +use for C<@INC> searches, otherwise the path F will be used as the internal name. This switch is used to include extra files into the bundle. @@ -477,6 +523,14 @@ staticperl mkperl --add "httpd httpd.pm" + # can be accessed via "use httpd" + +Example: add a file F from the current directory. + + staticperl mkperl --add 'initcode &initcode' + + # can be accessed via "do '&initcode'" + Example: add local files as extra modules in the bundle. # specification file @@ -495,9 +549,9 @@ without any postprocessing (perl files might get stripped to reduce their size). -You should probably add a C prefix to avoid clashing with embedded perl -files (whose paths do not start with C), and/or use a special directory -prefix, such as C. +If you specify an alias you should probably add a C<&> prefix to avoid +clashing with embedded perl files (whose paths never start with C<&>), +and/or use a special directory prefix, such as C<&res/name>. You can later get a copy of these files by calling C. @@ -520,7 +574,7 @@ After all candidate files and modules are added, they are I by a combination of C<--include> and C<--exclude> patterns (there is an -implicit C<--include **> at the end, so if no filters are specified, all +implicit C<--include *> at the end, so if no filters are specified, all files are included). All that this step does is potentially reduce the number of files that are @@ -555,7 +609,7 @@ =over 4 -=item C<--usepacklist> +=item C<--usepacklists> Read F<.packlist> files for each distribution that happens to match a module name you specified. Sounds weird, and it is, so expect semantics to @@ -633,7 +687,7 @@ mistreated, you can specify C to not mangle included perl sources in any way. -=item --perl +=item C<--perl> After writing out the bundle files, try to link a new perl interpreter. It will be called F and will be left in the current working @@ -648,7 +702,7 @@ staticperl mkperl -Mcommon::sense -=item --app name +=item C<--app> F After writing out the bundle files, try to link a new standalone program. It will be called C, and the bundle files get removed after @@ -662,7 +716,7 @@ instead it will simply initialise the perl interpreter, clean it up and exit. -This means that, by default, it will do nothing but burna few CPU cycles +This means that, by default, it will do nothing but burn a few CPU cycles - for it to do something useful you I add some boot code, e.g. with the C<--boot> option. @@ -671,7 +725,30 @@ staticperl mkbundle --app myexe --boot appfile -=item --static +=item C<--ignore-env> + +Generates extra code to unset some environment variables before +initialising/running perl. Perl supports a lot of environment variables +that might alter execution in ways that might be undesirablre for +standalone applications, and this option removes those known to cause +trouble. + +Specifically, these are removed: + +C and C can cause underaible +output, C, C, C and +C can alter execution significantly, and C, +C and C can affect input and output. + +The variables C and C are always ignored because the +startup code used by F overrides C<@INC> in all cases. + +This option will not make your program more secure (unless you are +running with elevated privileges), but it will reduce the surprise effect +when a user has these environment variables set and doesn't expect your +standalone program to act like a perl interpreter. + +=item C<--static> Add C<-static> to F, which means a fully static (if supported by the OS) executable will be created. This is not immensely @@ -688,10 +765,10 @@ executables, or try the C<--staticlib> option to link only some libraries statically. -=item --staticlib libname +=item C<--staticlib> libname When not linking fully statically, this option allows you to link specific -libraries statically. What it does is simply replace all occurances of +libraries statically. What it does is simply replace all occurrences of C<-llibname> with the GCC-specific C<-Wl,-Bstatic -llibname -Wl,-Bdynamic> option. @@ -699,7 +776,7 @@ specifically, C<--staticlib> will not link against the named library unless it would be linked against anyway. -Example: link libcrypt statically into the binary. +Example: link libcrypt statically into the final binary. staticperl mkperl -MIO::AIO --staticlib crypt @@ -730,7 +807,7 @@ That is, F will match any file called F anywhere in the hierarchy, but not any directories of the same name. -=item A F<*> matches any single component. +=item A F<*> matches anything within a single path component. That is, F would match all F<.pl> files directly inside C, not any deeper level F<.pl> files. Or in other words, F<*> @@ -815,9 +892,9 @@ =item C -The perl version to install - default is currently C<5.12.2>, but C<5.8.9> -is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is -about as big as 5.12.2). +The perl version to install - default is currently C<5.12.3>, but C<5.8.9> +is also a good choice (5.8.9 is much smaller than 5.12.3, while 5.10.1 is +about as big as 5.12.3). =item C @@ -876,6 +953,10 @@ shell functions that are called at specific times. To provide your own commands, just define the corresponding function. +The actual order in which hooks are invoked during a full install +from scratch is C, C, C, +C, C. + Example: install extra modules from CPAN and from some directories at F time. @@ -891,20 +972,25 @@ =item preconfigure -Called just before running F<./Configur> in the perl source +Called just before running F<./Configure> in the perl source directory. Current working directory is the perl source directory. This can be used to set any C variables, which might be costly to compute. +=item patchconfig + +Called after running F<./Configure> in the perl source directory to create +F<./config.sh>, but before running F<./Configure -S> to actually apply the +config. Current working directory is the perl source directory. + +Can be used to tailor/patch F or do any other modifications. + =item postconfigure Called after configuring, but before building perl. Current working directory is the perl source directory. -Could be used to tailor/patch config.sh (followed by F) -or do any other modifications. - =item postbuild Called after building, but before installing perl. Current working @@ -951,7 +1037,7 @@ =over 4 -=item staticperl_init () +=item staticperl_init (xs_init = 0) Initialises the perl interpreter. You can use the normal perl functions after calling this function, for example, to define extra functions or @@ -968,25 +1054,43 @@ static void run_myapp(void) { - staticperl_init (); + staticperl_init (0); newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" } -=item staticperl_xs_init (pTHX) +When your bootcode already wants to access some XS functions at +compiletime, then you need to supply an C function pointer that +is called as soon as perl is initialised enough to define XS functions, +but before the preamble code is executed: -Sometimes you need direct control over C and C, in -which case you do not want to use C but call them on your -own. + static void + xs_init (pTHX) + { + newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); + } -Then you need this function - either pass it directly as the C -function to C, or call it from your own C function. + static void + run_myapp(void) + { + staticperl_init (xs_init); + } =item staticperl_cleanup () In the unlikely case that you want to destroy the perl interpreter, here is the corresponding function. +=item staticperl_xs_init (pTHX) + +Sometimes you need direct control over C and C, in +which case you do not want to use C but call them on your +own. + +Then you need this function - either pass it directly as the C +function to C, or call it as one of the first things from your +own C function. + =item PerlInterpreter *staticperl The perl interpreter pointer used by staticperl. Not normally so useful, @@ -1031,7 +1135,7 @@ =back -=head1 FULLY STATIC BINARIES - BUILDROOT +=head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT To make truly static (Linux-) libraries, you might want to have a look at buildroot (L). @@ -1102,7 +1206,7 @@ for unicode character ranges in regexes) is implemented in the C<"utf8_heavy.pl"> library: - -M'"utf8_heavy.pl"' + -Mutf8_heavy.pl Many Unicode properties in turn are defined in separate modules, such as C<"unicore/Heavy.pl"> and more specific data tables such as @@ -1113,7 +1217,7 @@ To simply include the whole unicode database, use: - --incglob '/unicore/*.pl' + --incglob '/unicore/**.pl' =item AnyEvent @@ -1128,9 +1232,13 @@ functions), you also need to include C<"AnyEvent/Util/idna.pl"> and C<"AnyEvent/Util/uts46data.pl">. -Or you can use C<--usepacklist> and specify C<-MAnyEvent> to include +Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include everything. +=item Cairo + +See Glib, same problem, same solution. + =item Carp Carp had (in older versions of perl) a dependency on L. As of @@ -1142,16 +1250,33 @@ turn might need L<"Config_heavy.pl">. Including the latter gives you both. +=item Glib + +Glib literally requires Glib to be installed already to build - it tries +to fake this by running Glib out of the build directory before being +built. F tries to work around this by forcing C and +C to be empty via the C environment variable. + +=item Gtk2 + +See Pango, same problems, same solution. + +=item Pango + +In addition to the C problem in Glib, Pango also routes around +L by compiling its files on its own. F +tries to patch L to route around Pango. + =item Term::ReadLine::Perl -Also needs L, or C<--usepacklist>. +Also needs L, or C<--usepacklists>. =item URI URI implements schemes as separate modules - the generic URL scheme is implemented in L, HTTP is implemented in L. If you need to use any of these schemes, you should include these manually, -or use C<--usepacklist>. +or use C<--usepacklists>. =back @@ -1159,14 +1284,22 @@ =over 4 -=item Linking everything in +=item Just link everything in To link just about everything installed in the perl library into a new -perl, try this: +perl, try this (the first time this runs it will take a long time, as a +lot of files need to be parsed): + + staticperl mkperl -v --strip ppi --incglob '*' + +If you don't mind the extra megabytes, this can be a very effective way of +creating bundles without having to worry about forgetting any modules. - staticperl mkperl --strip ppi --incglob '*' +You get even more useful variants of this method by first selecting +everything, and then excluding stuff you are reasonable sure not to need - +L uses this approach. -=item Getting rid of netdb function +=item Getting rid of netdb functions The perl core has lots of netdb functions (C, C and so on) that few applications use. You can avoid compiling them in by @@ -1193,7 +1326,7 @@ done } -This mostly gains space when linking staticaly, as the functions will +This mostly gains space when linking statically, as the functions will likely not be linked in. The gain for dynamically-linked binaries is smaller.