… | |
… | |
9 | staticperl configure # fetch and then configure perl |
9 | staticperl configure # fetch and then configure perl |
10 | staticperl build # configure and then build perl |
10 | staticperl build # configure and then build perl |
11 | staticperl install # build and then install perl |
11 | staticperl install # build and then install perl |
12 | staticperl clean # clean most intermediate files (restart at configure) |
12 | staticperl clean # clean most intermediate files (restart at configure) |
13 | staticperl distclean # delete everything installed by this script |
13 | staticperl distclean # delete everything installed by this script |
|
|
14 | staticperl perl ... # invoke the perlinterpreter |
14 | staticperl cpan # invoke CPAN shell |
15 | staticperl cpan # invoke CPAN shell |
15 | staticperl instmod path... # install unpacked modules |
16 | staticperl instmod path... # install unpacked modules |
16 | staticperl instcpan modulename... # install modules from CPAN |
17 | staticperl instcpan modulename... # install modules from CPAN |
17 | staticperl mkbundle <bundle-args...> # see documentation |
18 | staticperl mkbundle <bundle-args...> # see documentation |
18 | staticperl mkperl <bundle-args...> # see documentation |
19 | staticperl mkperl <bundle-args...> # see documentation |
… | |
… | |
20 | |
21 | |
21 | Typical Examples: |
22 | Typical Examples: |
22 | |
23 | |
23 | staticperl install # fetch, configure, build and install perl |
24 | staticperl install # fetch, configure, build and install perl |
24 | staticperl cpan # run interactive cpan shell |
25 | staticperl cpan # run interactive cpan shell |
25 | staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V |
26 | staticperl mkperl -MConfig_heavy.pl # build a perl that supports -V |
26 | staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http |
27 | staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http |
27 | # build a perl with the above modules linked in |
28 | # build a perl with the above modules linked in |
28 | staticperl mkapp myapp --boot mainprog mymodules |
29 | staticperl mkapp myapp --boot mainprog mymodules |
29 | # build a binary "myapp" from mainprog and mymodules |
30 | # build a binary "myapp" from mainprog and mymodules |
30 | |
31 | |
… | |
… | |
139 | with creating binaries and bundle files. |
140 | with creating binaries and bundle files. |
140 | |
141 | |
141 | =head2 PHASE 1 COMMANDS: INSTALLING PERL |
142 | =head2 PHASE 1 COMMANDS: INSTALLING PERL |
142 | |
143 | |
143 | The most important command is F<install>, which does basically |
144 | The most important command is F<install>, which does basically |
144 | everything. The default is to download and install perl 5.12.2 and a few |
145 | everything. The default is to download and install perl 5.12.3 and a few |
145 | modules required by F<staticperl> itself, but all this can (and should) be |
146 | modules required by F<staticperl> itself, but all this can (and should) be |
146 | changed - see L<CONFIGURATION>, below. |
147 | changed - see L<CONFIGURATION>, below. |
147 | |
148 | |
148 | The command |
149 | The command |
149 | |
150 | |
… | |
… | |
185 | |
186 | |
186 | =item F<staticperl install> |
187 | =item F<staticperl install> |
187 | |
188 | |
188 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
189 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
189 | installs the perl distribution, potentially after building it first. |
190 | installs the perl distribution, potentially after building it first. |
|
|
191 | |
|
|
192 | =item F<staticperl perl> [args...] |
|
|
193 | |
|
|
194 | Invokes the compiled perl interpreter with the given args. Basically the |
|
|
195 | same as starting perl directly (usually via F<~/.staticperl/bin/perl>), |
|
|
196 | but beats typing the path sometimes. |
|
|
197 | |
|
|
198 | Example: check that the Gtk2 module is installed and loadable. |
|
|
199 | |
|
|
200 | staticperl perl -MGtk2 -e0 |
190 | |
201 | |
191 | =item F<staticperl cpan> [args...] |
202 | =item F<staticperl cpan> [args...] |
192 | |
203 | |
193 | Starts an interactive CPAN shell that you can use to install further |
204 | Starts an interactive CPAN shell that you can use to install further |
194 | modules. Installs the perl first if necessary, but apart from that, |
205 | modules. Installs the perl first if necessary, but apart from that, |
… | |
… | |
252 | |
263 | |
253 | # first make sure we have perl and the required modules |
264 | # first make sure we have perl and the required modules |
254 | staticperl instcpan AnyEvent::HTTPD |
265 | staticperl instcpan AnyEvent::HTTPD |
255 | |
266 | |
256 | # now build the perl |
267 | # now build the perl |
257 | staticperl mkperl -M'"Config_heavy.pl"' -MAnyEvent::Impl::Perl \ |
268 | staticperl mkperl -MConfig_heavy.pl -MAnyEvent::Impl::Perl \ |
258 | -MAnyEvent::HTTPD -MURI::http \ |
269 | -MAnyEvent::HTTPD -MURI::http \ |
259 | --add 'eg/httpd httpd.pm' |
270 | --add 'eg/httpd httpd.pm' |
260 | |
271 | |
261 | # finally, invoke it |
272 | # finally, invoke it |
262 | ./perl -Mhttpd |
273 | ./perl -Mhttpd |
… | |
… | |
381 | |
392 | |
382 | =over 4 |
393 | =over 4 |
383 | |
394 | |
384 | =item C<--use> F<module> | C<-M>F<module> |
395 | =item C<--use> F<module> | C<-M>F<module> |
385 | |
396 | |
386 | Include the named module and trace direct dependencies. This is done by |
397 | Include the named module or perl library and trace direct |
387 | C<require>'ing the module in a subprocess and tracing which other modules |
398 | dependencies. This is done by loading the module in a subprocess and |
388 | and files it actually loads. |
399 | tracing which other modules and files it actually loads. |
389 | |
400 | |
390 | Example: include AnyEvent and AnyEvent::Impl::Perl. |
401 | Example: include AnyEvent and AnyEvent::Impl::Perl. |
391 | |
402 | |
392 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
403 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
393 | |
404 | |
394 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), |
405 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
395 | or maybe other weirdly named files. To do that, you need to quote |
406 | maybe other weirdly named files. To support this, the C<--use> option |
396 | the name in single or double quotes (this is because F<staticperl> |
407 | actually tries to do what you mean, depending on the string you specify: |
397 | I<literally> just adds the string after the C<require> - which acts |
408 | |
398 | different when confronted with quoted vs. unquoted strings). When given on |
409 | =over 4 |
399 | the command line, you probably need to quote once more to avoid your shell |
410 | |
400 | interpreting it. Common cases that need this are F<Config_heavy.pl> and |
411 | =item a possibly valid module name, e.g. F<common::sense>, F<Carp>, |
401 | F<utf8_heavy.pl>. |
412 | F<Coro::Mysql>. |
|
|
413 | |
|
|
414 | If the string contains no quotes, no F</> and no F<.>, then C<--use> |
|
|
415 | assumes that it is a normal module name. It will create a new package and |
|
|
416 | evaluate a C<use module> in it, i.e. it will load the package and do a |
|
|
417 | default import. |
|
|
418 | |
|
|
419 | The import step is done because many modules trigger more dependencies |
|
|
420 | when something is imported than without. |
|
|
421 | |
|
|
422 | =item anything that contains F</> or F<.> characters, |
|
|
423 | e.g. F<utf8_heavy.pl>, F<Module/private/data.pl>. |
|
|
424 | |
|
|
425 | The string will be quoted and passed to require, as if you used C<require |
|
|
426 | $module>. Nothing will be imported. |
|
|
427 | |
|
|
428 | =item "path" or 'path', e.g. C<"utf8_heavy.pl">. |
|
|
429 | |
|
|
430 | If you enclose the name into single or double quotes, then the quotes will |
|
|
431 | be removed and the resulting string will be passed to require. This syntax |
|
|
432 | is form compatibility with older versions of staticperl and should not be |
|
|
433 | used anymore. |
|
|
434 | |
|
|
435 | =back |
|
|
436 | |
|
|
437 | Example: C<use> AnyEvent::Socket, once using C<use> (importing the |
|
|
438 | symbols), and once via C<require>, not importing any symbols. The first |
|
|
439 | form is preferred as many modules load some extra dependencies when asked |
|
|
440 | to export symbols. |
|
|
441 | |
|
|
442 | staticperl mkbundle -MAnyEvent::Socket # use + import |
|
|
443 | staticperl mkbundle -MAnyEvent/Socket.pm # require only |
402 | |
444 | |
403 | Example: include the required files for F<perl -V> to work in all its |
445 | Example: include the required files for F<perl -V> to work in all its |
404 | glory (F<Config.pm> is included automatically by this). |
446 | glory (F<Config.pm> is included automatically by the dependency tracker). |
405 | |
447 | |
406 | # bourne shell |
448 | # shell command |
407 | staticperl mkbundle --use '"Config_heavy.pl"' |
449 | staticperl mkbundle -MConfig_heavy.pl |
408 | |
450 | |
409 | # bundle specification file |
451 | # bundle specification file |
410 | use "Config_heavy.pl" |
452 | use Config_heavy.pl |
411 | |
453 | |
412 | The C<-M>module syntax is included as a convenience that might be easier |
454 | The C<-M>module syntax is included as a convenience that might be easier |
413 | to remember than C<--use> - it's the same switch as perl itself uses |
455 | to remember than C<--use> - it's the same switch as perl itself uses |
414 | to load modules. Or maybe it confuses people. Time will tell. Or maybe |
456 | to load modules. Or maybe it confuses people. Time will tell. Or maybe |
415 | not. Sigh. |
457 | not. Sigh. |
… | |
… | |
420 | code, or maybe one of the modules you use need a special use statement. In |
462 | code, or maybe one of the modules you use need a special use statement. In |
421 | that case, you can use C<--eval> to execute some perl snippet or set some |
463 | that case, you can use C<--eval> to execute some perl snippet or set some |
422 | variables or whatever you need. All files C<require>'d or C<use>'d while |
464 | variables or whatever you need. All files C<require>'d or C<use>'d while |
423 | executing the snippet are included in the final bundle. |
465 | executing the snippet are included in the final bundle. |
424 | |
466 | |
425 | Keep in mind that F<mkbundle> will only C<require> the modules named |
467 | Keep in mind that F<mkbundle> will not import any symbols from the modules |
426 | by the C<--use> option, so do not expect the symbols from modules you |
468 | named by the C<--use> option, so do not expect the symbols from modules |
427 | C<--use>'d earlier on the command line to be available. |
469 | you C<--use>'d earlier on the command line to be available. |
428 | |
470 | |
429 | Example: force L<AnyEvent> to detect a backend and therefore include it |
471 | Example: force L<AnyEvent> to detect a backend and therefore include it |
430 | in the final bundle. |
472 | in the final bundle. |
431 | |
473 | |
432 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
474 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
… | |
… | |
467 | --incglob '/unicore/**.pl' |
509 | --incglob '/unicore/**.pl' |
468 | |
510 | |
469 | =item C<--add> F<file> | C<--add> "F<file> alias" |
511 | =item C<--add> F<file> | C<--add> "F<file> alias" |
470 | |
512 | |
471 | Adds the given (perl) file into the bundle (and optionally call it |
513 | Adds the given (perl) file into the bundle (and optionally call it |
472 | "alias"). The F<file> is either an absolute path or a path relative to |
514 | "alias"). The F<file> is either an absolute path or a path relative to the |
473 | the current directory. If an alias is specified, then this is the name it |
515 | current directory. If an alias is specified, then this is the name it will |
474 | will use for C<@INC> searches, otherwise the F<file> will be used as the |
516 | use for C<@INC> searches, otherwise the path F<file> will be used as the |
475 | internal name. |
517 | internal name. |
476 | |
518 | |
477 | This switch is used to include extra files into the bundle. |
519 | This switch is used to include extra files into the bundle. |
478 | |
520 | |
479 | Example: embed the file F<httpd> in the current directory as F<httpd.pm> |
521 | Example: embed the file F<httpd> in the current directory as F<httpd.pm> |
480 | when creating the bundle. |
522 | when creating the bundle. |
481 | |
523 | |
482 | staticperl mkperl --add "httpd httpd.pm" |
524 | staticperl mkperl --add "httpd httpd.pm" |
|
|
525 | |
|
|
526 | # can be accessed via "use httpd" |
|
|
527 | |
|
|
528 | Example: add a file F<initcode> from the current directory. |
|
|
529 | |
|
|
530 | staticperl mkperl --add 'initcode &initcode' |
|
|
531 | |
|
|
532 | # can be accessed via "do '&initcode'" |
483 | |
533 | |
484 | Example: add local files as extra modules in the bundle. |
534 | Example: add local files as extra modules in the bundle. |
485 | |
535 | |
486 | # specification file |
536 | # specification file |
487 | add file1 myfiles/file1.pm |
537 | add file1 myfiles/file1.pm |
… | |
… | |
497 | |
547 | |
498 | Just like C<--add>, except that it treats the file as binary and adds it |
548 | Just like C<--add>, except that it treats the file as binary and adds it |
499 | without any postprocessing (perl files might get stripped to reduce their |
549 | without any postprocessing (perl files might get stripped to reduce their |
500 | size). |
550 | size). |
501 | |
551 | |
502 | You should probably add a C</> prefix to avoid clashing with embedded perl |
552 | If you specify an alias you should probably add a C<&> prefix to avoid |
503 | files (whose paths do not start with C</>), and/or use a special directory |
553 | clashing with embedded perl files (whose paths never start with C<&>), |
504 | prefix, such as C</res/name>. |
554 | and/or use a special directory prefix, such as C<&res/name>. |
505 | |
555 | |
506 | You can later get a copy of these files by calling C<staticperl::find |
556 | You can later get a copy of these files by calling C<staticperl::find |
507 | "alias">. |
557 | "alias">. |
508 | |
558 | |
509 | An alternative way to embed binary files is to convert them to perl and |
559 | An alternative way to embed binary files is to convert them to perl and |
… | |
… | |
557 | that are added automatically. Only one (F<.packlist> files) is currently |
607 | that are added automatically. Only one (F<.packlist> files) is currently |
558 | optional and can be influenced, the others are always included: |
608 | optional and can be influenced, the others are always included: |
559 | |
609 | |
560 | =over 4 |
610 | =over 4 |
561 | |
611 | |
562 | =item C<--usepacklist> |
612 | =item C<--usepacklists> |
563 | |
613 | |
564 | Read F<.packlist> files for each distribution that happens to match a |
614 | Read F<.packlist> files for each distribution that happens to match a |
565 | module name you specified. Sounds weird, and it is, so expect semantics to |
615 | module name you specified. Sounds weird, and it is, so expect semantics to |
566 | change somehow in the future. |
616 | change somehow in the future. |
567 | |
617 | |
… | |
… | |
664 | The difference to the (mutually exclusive) C<--perl> option is that the |
714 | The difference to the (mutually exclusive) C<--perl> option is that the |
665 | binary created by this option will not try to act as a perl interpreter - |
715 | binary created by this option will not try to act as a perl interpreter - |
666 | instead it will simply initialise the perl interpreter, clean it up and |
716 | instead it will simply initialise the perl interpreter, clean it up and |
667 | exit. |
717 | exit. |
668 | |
718 | |
669 | This means that, by default, it will do nothing but burna few CPU cycles |
719 | This means that, by default, it will do nothing but burn a few CPU cycles |
670 | - for it to do something useful you I<must> add some boot code, e.g. with |
720 | - for it to do something useful you I<must> add some boot code, e.g. with |
671 | the C<--boot> option. |
721 | the C<--boot> option. |
672 | |
722 | |
673 | Example: create a standalone perl binary called F<./myexe> that will |
723 | Example: create a standalone perl binary called F<./myexe> that will |
674 | execute F<appfile> when it is started. |
724 | execute F<appfile> when it is started. |
675 | |
725 | |
676 | staticperl mkbundle --app myexe --boot appfile |
726 | staticperl mkbundle --app myexe --boot appfile |
|
|
727 | |
|
|
728 | =item C<--ignore-env> |
|
|
729 | |
|
|
730 | Generates extra code to unset some environment variables before |
|
|
731 | initialising/running perl. Perl supports a lot of environment variables |
|
|
732 | that might alter execution in ways that might be undesirablre for |
|
|
733 | standalone applications, and this option removes those known to cause |
|
|
734 | trouble. |
|
|
735 | |
|
|
736 | Specifically, these are removed: |
|
|
737 | |
|
|
738 | C<PERL_HASH_SEED_DEBUG> and C<PERL_DEBUG_MSTATS> can cause underaible |
|
|
739 | output, C<PERL5OPT>, C<PERL_DESTRUCT_LEVEL>, C<PERL_HASH_SEED> and |
|
|
740 | C<PERL_SIGNALS> can alter execution significantly, and C<PERL_UNICODE>, |
|
|
741 | C<PERLIO_DEBUG> and C<PERLIO> can affect input and output. |
|
|
742 | |
|
|
743 | The variables C<PERL_LIB> and C<PERL5_LIB> are always ignored because the |
|
|
744 | startup code used by F<staticperl> overrides C<@INC> in all cases. |
|
|
745 | |
|
|
746 | This option will not make your program more secure (unless you are |
|
|
747 | running with elevated privileges), but it will reduce the surprise effect |
|
|
748 | when a user has these environment variables set and doesn't expect your |
|
|
749 | standalone program to act like a perl interpreter. |
677 | |
750 | |
678 | =item C<--static> |
751 | =item C<--static> |
679 | |
752 | |
680 | Add C<-static> to F<bundle.ldopts>, which means a fully static (if |
753 | Add C<-static> to F<bundle.ldopts>, which means a fully static (if |
681 | supported by the OS) executable will be created. This is not immensely |
754 | supported by the OS) executable will be created. This is not immensely |
… | |
… | |
732 | =item Patterns not starting with F</> will be anchored at the end of the path. |
805 | =item Patterns not starting with F</> will be anchored at the end of the path. |
733 | |
806 | |
734 | That is, F<idna.pl> will match any file called F<idna.pl> anywhere in the |
807 | That is, F<idna.pl> will match any file called F<idna.pl> anywhere in the |
735 | hierarchy, but not any directories of the same name. |
808 | hierarchy, but not any directories of the same name. |
736 | |
809 | |
737 | =item A F<*> matches any single component. |
810 | =item A F<*> matches anything within a single path component. |
738 | |
811 | |
739 | That is, F</unicore/*.pl> would match all F<.pl> files directly inside |
812 | That is, F</unicore/*.pl> would match all F<.pl> files directly inside |
740 | C</unicore>, not any deeper level F<.pl> files. Or in other words, F<*> |
813 | C</unicore>, not any deeper level F<.pl> files. Or in other words, F<*> |
741 | will not match slashes. |
814 | will not match slashes. |
742 | |
815 | |
… | |
… | |
817 | installation, you can set any environment variable you want - some modules |
890 | installation, you can set any environment variable you want - some modules |
818 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
891 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
819 | |
892 | |
820 | =item C<PERL_VERSION> |
893 | =item C<PERL_VERSION> |
821 | |
894 | |
822 | The perl version to install - default is currently C<5.12.2>, but C<5.8.9> |
895 | The perl version to install - default is currently C<5.12.3>, but C<5.8.9> |
823 | is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is |
896 | is also a good choice (5.8.9 is much smaller than 5.12.3, while 5.10.1 is |
824 | about as big as 5.12.2). |
897 | about as big as 5.12.3). |
825 | |
898 | |
826 | =item C<PERL_PREFIX> |
899 | =item C<PERL_PREFIX> |
827 | |
900 | |
828 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
901 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
829 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
902 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
… | |
… | |
850 | F<~/.staticperlrc> to override them. |
923 | F<~/.staticperlrc> to override them. |
851 | |
924 | |
852 | Most of the variables override (or modify) the corresponding F<Configure> |
925 | Most of the variables override (or modify) the corresponding F<Configure> |
853 | variable, except C<PERL_CCFLAGS>, which gets appended. |
926 | variable, except C<PERL_CCFLAGS>, which gets appended. |
854 | |
927 | |
|
|
928 | You should have a look near the beginning of the F<staticperl> script - |
|
|
929 | staticperl tries to default C<PERL_OPTIMIZE> to some psace-saving options |
|
|
930 | suitable for newer gcc versions. For other compilers or older versions you |
|
|
931 | need to adjust these, for example, in your F<~/.staticperlrc>. |
|
|
932 | |
855 | =back |
933 | =back |
856 | |
934 | |
857 | =head4 Variables you probably I<do not want> to override |
935 | =head4 Variables you probably I<do not want> to override |
858 | |
936 | |
859 | =over 4 |
937 | =over 4 |
… | |
… | |
877 | =head3 OVERRIDABLE HOOKS |
955 | =head3 OVERRIDABLE HOOKS |
878 | |
956 | |
879 | In addition to environment variables, it is possible to provide some |
957 | In addition to environment variables, it is possible to provide some |
880 | shell functions that are called at specific times. To provide your own |
958 | shell functions that are called at specific times. To provide your own |
881 | commands, just define the corresponding function. |
959 | commands, just define the corresponding function. |
|
|
960 | |
|
|
961 | The actual order in which hooks are invoked during a full install |
|
|
962 | from scratch is C<preconfigure>, C<patchconfig>, C<postconfigure>, |
|
|
963 | C<postbuild>, C<postinstall>. |
882 | |
964 | |
883 | Example: install extra modules from CPAN and from some directories |
965 | Example: install extra modules from CPAN and from some directories |
884 | at F<staticperl install> time. |
966 | at F<staticperl install> time. |
885 | |
967 | |
886 | postinstall() { |
968 | postinstall() { |
… | |
… | |
893 | |
975 | |
894 | =over 4 |
976 | =over 4 |
895 | |
977 | |
896 | =item preconfigure |
978 | =item preconfigure |
897 | |
979 | |
898 | Called just before running F<./Configur> in the perl source |
980 | Called just before running F<./Configure> in the perl source |
899 | directory. Current working directory is the perl source directory. |
981 | directory. Current working directory is the perl source directory. |
900 | |
982 | |
901 | This can be used to set any C<PERL_xxx> variables, which might be costly |
983 | This can be used to set any C<PERL_xxx> variables, which might be costly |
902 | to compute. |
984 | to compute. |
903 | |
985 | |
|
|
986 | =item patchconfig |
|
|
987 | |
|
|
988 | Called after running F<./Configure> in the perl source directory to create |
|
|
989 | F<./config.sh>, but before running F<./Configure -S> to actually apply the |
|
|
990 | config. Current working directory is the perl source directory. |
|
|
991 | |
|
|
992 | Can be used to tailor/patch F<config.sh> or do any other modifications. |
|
|
993 | |
904 | =item postconfigure |
994 | =item postconfigure |
905 | |
995 | |
906 | Called after configuring, but before building perl. Current working |
996 | Called after configuring, but before building perl. Current working |
907 | directory is the perl source directory. |
997 | directory is the perl source directory. |
908 | |
|
|
909 | Could be used to tailor/patch config.sh (followed by F<sh Configure -S>) |
|
|
910 | or do any other modifications. |
|
|
911 | |
998 | |
912 | =item postbuild |
999 | =item postbuild |
913 | |
1000 | |
914 | Called after building, but before installing perl. Current working |
1001 | Called after building, but before installing perl. Current working |
915 | directory is the perl source directory. |
1002 | directory is the perl source directory. |
… | |
… | |
953 | A header file that contains the prototypes of the few symbols "exported" |
1040 | A header file that contains the prototypes of the few symbols "exported" |
954 | by bundle.c, and also exposes the perl headers to the application. |
1041 | by bundle.c, and also exposes the perl headers to the application. |
955 | |
1042 | |
956 | =over 4 |
1043 | =over 4 |
957 | |
1044 | |
958 | =item staticperl_init () |
1045 | =item staticperl_init (xs_init = 0) |
959 | |
1046 | |
960 | Initialises the perl interpreter. You can use the normal perl functions |
1047 | Initialises the perl interpreter. You can use the normal perl functions |
961 | after calling this function, for example, to define extra functions or |
1048 | after calling this function, for example, to define extra functions or |
962 | to load a .pm file that contains some initialisation code, or the main |
1049 | to load a .pm file that contains some initialisation code, or the main |
963 | program function: |
1050 | program function: |
… | |
… | |
970 | } |
1057 | } |
971 | |
1058 | |
972 | static void |
1059 | static void |
973 | run_myapp(void) |
1060 | run_myapp(void) |
974 | { |
1061 | { |
975 | staticperl_init (); |
1062 | staticperl_init (0); |
976 | newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
1063 | newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
977 | eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" |
1064 | eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" |
978 | } |
1065 | } |
979 | |
1066 | |
|
|
1067 | When your bootcode already wants to access some XS functions at |
|
|
1068 | compiletime, then you need to supply an C<xs_init> function pointer that |
|
|
1069 | is called as soon as perl is initialised enough to define XS functions, |
|
|
1070 | but before the preamble code is executed: |
|
|
1071 | |
|
|
1072 | static void |
|
|
1073 | xs_init (pTHX) |
|
|
1074 | { |
|
|
1075 | newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
|
|
1076 | } |
|
|
1077 | |
|
|
1078 | static void |
|
|
1079 | run_myapp(void) |
|
|
1080 | { |
|
|
1081 | staticperl_init (xs_init); |
|
|
1082 | } |
|
|
1083 | |
|
|
1084 | =item staticperl_cleanup () |
|
|
1085 | |
|
|
1086 | In the unlikely case that you want to destroy the perl interpreter, here |
|
|
1087 | is the corresponding function. |
|
|
1088 | |
980 | =item staticperl_xs_init (pTHX) |
1089 | =item staticperl_xs_init (pTHX) |
981 | |
1090 | |
982 | Sometimes you need direct control over C<perl_parse> and C<perl_run>, in |
1091 | Sometimes you need direct control over C<perl_parse> and C<perl_run>, in |
983 | which case you do not want to use C<staticperl_init> but call them on your |
1092 | which case you do not want to use C<staticperl_init> but call them on your |
984 | own. |
1093 | own. |
985 | |
1094 | |
986 | Then you need this function - either pass it directly as the C<xs_init> |
1095 | Then you need this function - either pass it directly as the C<xs_init> |
987 | function to C<perl_parse>, or call it from your own C<xs_init> function. |
1096 | function to C<perl_parse>, or call it as one of the first things from your |
988 | |
1097 | own C<xs_init> function. |
989 | =item staticperl_cleanup () |
|
|
990 | |
|
|
991 | In the unlikely case that you want to destroy the perl interpreter, here |
|
|
992 | is the corresponding function. |
|
|
993 | |
1098 | |
994 | =item PerlInterpreter *staticperl |
1099 | =item PerlInterpreter *staticperl |
995 | |
1100 | |
996 | The perl interpreter pointer used by staticperl. Not normally so useful, |
1101 | The perl interpreter pointer used by staticperl. Not normally so useful, |
997 | but there it is. |
1102 | but there it is. |
… | |
… | |
1033 | |
1138 | |
1034 | Returns the list of all paths embedded in this binary. |
1139 | Returns the list of all paths embedded in this binary. |
1035 | |
1140 | |
1036 | =back |
1141 | =back |
1037 | |
1142 | |
1038 | =head1 FULLY STATIC BINARIES - BUILDROOT |
1143 | =head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT |
1039 | |
1144 | |
1040 | To make truly static (Linux-) libraries, you might want to have a look at |
1145 | To make truly static (Linux-) libraries, you might want to have a look at |
1041 | buildroot (L<http://buildroot.uclibc.org/>). |
1146 | buildroot (L<http://buildroot.uclibc.org/>). |
1042 | |
1147 | |
1043 | Buildroot is primarily meant to set up a cross-compile environment (which |
1148 | Buildroot is primarily meant to set up a cross-compile environment (which |
… | |
… | |
1104 | |
1209 | |
1105 | Some functionality in the utf8 module, such as swash handling (used |
1210 | Some functionality in the utf8 module, such as swash handling (used |
1106 | for unicode character ranges in regexes) is implemented in the |
1211 | for unicode character ranges in regexes) is implemented in the |
1107 | C<"utf8_heavy.pl"> library: |
1212 | C<"utf8_heavy.pl"> library: |
1108 | |
1213 | |
1109 | -M'"utf8_heavy.pl"' |
1214 | -Mutf8_heavy.pl |
1110 | |
1215 | |
1111 | Many Unicode properties in turn are defined in separate modules, |
1216 | Many Unicode properties in turn are defined in separate modules, |
1112 | such as C<"unicore/Heavy.pl"> and more specific data tables such as |
1217 | such as C<"unicore/Heavy.pl"> and more specific data tables such as |
1113 | C<"unicore/To/Digit.pl"> or C<"unicore/lib/Perl/Word.pl">. These tables |
1218 | C<"unicore/To/Digit.pl"> or C<"unicore/lib/Perl/Word.pl">. These tables |
1114 | are big (7MB uncompressed, although F<staticperl> contains special |
1219 | are big (7MB uncompressed, although F<staticperl> contains special |
1115 | handling for those files), so including them on demand by your application |
1220 | handling for those files), so including them on demand by your application |
1116 | only might pay off. |
1221 | only might pay off. |
1117 | |
1222 | |
1118 | To simply include the whole unicode database, use: |
1223 | To simply include the whole unicode database, use: |
1119 | |
1224 | |
1120 | --incglob '/unicore/*.pl' |
1225 | --incglob '/unicore/**.pl' |
1121 | |
1226 | |
1122 | =item AnyEvent |
1227 | =item AnyEvent |
1123 | |
1228 | |
1124 | AnyEvent needs a backend implementation that it will load in a delayed |
1229 | AnyEvent needs a backend implementation that it will load in a delayed |
1125 | fashion. The L<AnyEvent::Impl::Perl> backend is the default choice |
1230 | fashion. The L<AnyEvent::Impl::Perl> backend is the default choice |
… | |
… | |
1130 | |
1235 | |
1131 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
1236 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
1132 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
1237 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
1133 | C<"AnyEvent/Util/uts46data.pl">. |
1238 | C<"AnyEvent/Util/uts46data.pl">. |
1134 | |
1239 | |
1135 | Or you can use C<--usepacklist> and specify C<-MAnyEvent> to include |
1240 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1136 | everything. |
1241 | everything. |
|
|
1242 | |
|
|
1243 | =item Cairo |
|
|
1244 | |
|
|
1245 | See Glib, same problem, same solution. |
1137 | |
1246 | |
1138 | =item Carp |
1247 | =item Carp |
1139 | |
1248 | |
1140 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1249 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1141 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1250 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
… | |
… | |
1144 | |
1253 | |
1145 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1254 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1146 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1255 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1147 | both. |
1256 | both. |
1148 | |
1257 | |
|
|
1258 | =item Glib |
|
|
1259 | |
|
|
1260 | Glib literally requires Glib to be installed already to build - it tries |
|
|
1261 | to fake this by running Glib out of the build directory before being |
|
|
1262 | built. F<staticperl> tries to work around this by forcing C<MAN1PODS> and |
|
|
1263 | C<MAN3PODS> to be empty via the C<PERL_MM_OPT> environment variable. |
|
|
1264 | |
|
|
1265 | =item Gtk2 |
|
|
1266 | |
|
|
1267 | See Pango, same problems, same solution. |
|
|
1268 | |
|
|
1269 | =item Pango |
|
|
1270 | |
|
|
1271 | In addition to the C<MAN3PODS> problem in Glib, Pango also routes around |
|
|
1272 | L<ExtUtils::MakeMaker> by compiling its files on its own. F<staticperl> |
|
|
1273 | tries to patch L<ExtUtils::MM_Unix> to route around Pango. |
|
|
1274 | |
1149 | =item Term::ReadLine::Perl |
1275 | =item Term::ReadLine::Perl |
1150 | |
1276 | |
1151 | Also needs L<Term::ReadLine::readline>, or C<--usepacklist>. |
1277 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1152 | |
1278 | |
1153 | =item URI |
1279 | =item URI |
1154 | |
1280 | |
1155 | URI implements schemes as separate modules - the generic URL scheme is |
1281 | URI implements schemes as separate modules - the generic URL scheme is |
1156 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
1282 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
1157 | you need to use any of these schemes, you should include these manually, |
1283 | you need to use any of these schemes, you should include these manually, |
1158 | or use C<--usepacklist>. |
1284 | or use C<--usepacklists>. |
1159 | |
1285 | |
1160 | =back |
1286 | =back |
1161 | |
1287 | |
1162 | =head2 RECIPES |
1288 | =head2 RECIPES |
1163 | |
1289 | |
1164 | =over 4 |
1290 | =over 4 |
1165 | |
1291 | |
1166 | =item Linking everything in |
1292 | =item Just link everything in |
1167 | |
1293 | |
1168 | To link just about everything installed in the perl library into a new |
1294 | To link just about everything installed in the perl library into a new |
1169 | perl, try this: |
1295 | perl, try this (the first time this runs it will take a long time, as a |
|
|
1296 | lot of files need to be parsed): |
1170 | |
1297 | |
1171 | staticperl mkperl --strip ppi --incglob '*' |
1298 | staticperl mkperl -v --strip ppi --incglob '*' |
1172 | |
1299 | |
|
|
1300 | If you don't mind the extra megabytes, this can be a very effective way of |
|
|
1301 | creating bundles without having to worry about forgetting any modules. |
|
|
1302 | |
|
|
1303 | You get even more useful variants of this method by first selecting |
|
|
1304 | everything, and then excluding stuff you are reasonable sure not to need - |
|
|
1305 | L<bigperl|http://staticperl.schmorp.de/bigperl.html> uses this approach. |
|
|
1306 | |
1173 | =item Getting rid of netdb function |
1307 | =item Getting rid of netdb functions |
1174 | |
1308 | |
1175 | The perl core has lots of netdb functions (C<getnetbyname>, C<getgrent> |
1309 | The perl core has lots of netdb functions (C<getnetbyname>, C<getgrent> |
1176 | and so on) that few applications use. You can avoid compiling them in by |
1310 | and so on) that few applications use. You can avoid compiling them in by |
1177 | putting the following fragment into a C<preconfigure> hook: |
1311 | putting the following fragment into a C<preconfigure> hook: |
1178 | |
1312 | |
… | |
… | |
1195 | do |
1329 | do |
1196 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1330 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1197 | done |
1331 | done |
1198 | } |
1332 | } |
1199 | |
1333 | |
1200 | This mostly gains space when linking staticaly, as the functions will |
1334 | This mostly gains space when linking statically, as the functions will |
1201 | likely not be linked in. The gain for dynamically-linked binaries is |
1335 | likely not be linked in. The gain for dynamically-linked binaries is |
1202 | smaller. |
1336 | smaller. |
1203 | |
1337 | |
1204 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1338 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1205 | often, the L<Socket> module also exposes it, so leaving it out usually |
1339 | often, the L<Socket> module also exposes it, so leaving it out usually |