--- App-Staticperl/staticperl.pod 2010/12/23 14:16:25 1.31 +++ App-Staticperl/staticperl.pod 2011/03/18 19:49:04 1.38 @@ -22,7 +22,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 +141,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. @@ -254,7 +254,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,31 +383,62 @@ =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 (this is because F -I just adds the string after the C - which acts -different when confronted with quoted vs. unquoted strings). 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. +Sometimes you want to load old-style "perl libraries" (F<.pl> files), or +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 a convenience that might be easier to remember than C<--use> - it's the same switch as perl itself uses @@ -422,9 +453,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. @@ -469,9 +500,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, otherwise 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. @@ -481,6 +512,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 @@ -499,9 +538,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. @@ -666,7 +705,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. @@ -675,6 +714,29 @@ staticperl mkbundle --app myexe --boot appfile +=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 @@ -819,9 +881,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 @@ -880,6 +942,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. @@ -895,20 +961,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 @@ -955,7 +1026,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 @@ -972,25 +1043,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, @@ -1106,7 +1195,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