… | |
… | |
389 | |
389 | |
390 | Example: include AnyEvent and AnyEvent::Impl::Perl. |
390 | Example: include AnyEvent and AnyEvent::Impl::Perl. |
391 | |
391 | |
392 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
392 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
393 | |
393 | |
394 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
394 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), |
395 | maybe other weirdly named files. To do that, you need to quote the name in |
395 | or maybe other weirdly named files. To do that, you need to quote |
396 | single or double quotes. When given on the command line, you probably need |
396 | the name in single or double quotes (this is because F<staticperl> |
397 | to quote once more to avoid your shell interpreting it. Common cases that |
397 | I<literally> just adds the string after the C<require> - which acts |
398 | need this are F<Config_heavy.pl> and F<utf8_heavy.pl>. |
398 | different when confronted with quoted vs. unquoted strings). When given on |
|
|
399 | the command line, you probably need to quote once more to avoid your shell |
|
|
400 | interpreting it. Common cases that need this are F<Config_heavy.pl> and |
|
|
401 | F<utf8_heavy.pl>. |
399 | |
402 | |
400 | Example: include the required files for F<perl -V> to work in all its |
403 | Example: include the required files for F<perl -V> to work in all its |
401 | glory (F<Config.pm> is included automatically by this). |
404 | glory (F<Config.pm> is included automatically by this). |
402 | |
405 | |
403 | # bourne shell |
406 | # bourne shell |
404 | staticperl mkbundle --use '"Config_heavy.pl"' |
407 | staticperl mkbundle --use '"Config_heavy.pl"' |
405 | |
408 | |
406 | # bundle specification file |
409 | # bundle specification file |
407 | use "Config_heavy.pl" |
410 | use "Config_heavy.pl" |
408 | |
411 | |
409 | The C<-M>module syntax is included as an alias that might be easier to |
412 | The C<-M>module syntax is included as a convenience that might be easier |
410 | remember than C<--use>. Or maybe it confuses people. Time will tell. Or |
413 | 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 |
411 | maybe not. Sigh. |
415 | not. Sigh. |
412 | |
416 | |
413 | =item C<--eval> "perl code" | C<-e> "perl code" |
417 | =item C<--eval> "perl code" | C<-e> "perl code" |
414 | |
418 | |
415 | Sometimes it is easier (or necessary) to specify dependencies using perl |
419 | Sometimes it is easier (or necessary) to specify dependencies using perl |
416 | code, or maybe one of the modules you use need a special use statement. In |
420 | code, or maybe one of the modules you use need a special use statement. In |
… | |
… | |
455 | This is very useful to include "everything": |
459 | This is very useful to include "everything": |
456 | |
460 | |
457 | --incglob '*' |
461 | --incglob '*' |
458 | |
462 | |
459 | It is also useful for including perl libraries, or trees of those, such as |
463 | It is also useful for including perl libraries, or trees of those, such as |
460 | the unicode database files needed by some perl builtins, the regex engine |
464 | the unicode database files needed by some perl built-ins, the regex engine |
461 | and other modules. |
465 | and other modules. |
462 | |
466 | |
463 | --incglob '/unicore/**.pl' |
467 | --incglob '/unicore/**.pl' |
464 | |
468 | |
465 | =item C<--add> F<file> | C<--add> "F<file> alias" |
469 | =item C<--add> F<file> | C<--add> "F<file> alias" |
466 | |
470 | |
467 | Adds the given (perl) file into the bundle (and optionally call it |
471 | Adds the given (perl) file into the bundle (and optionally call it |
468 | "alias"). The F<file> is either an absolute path or a path relative to |
472 | "alias"). The F<file> is either an absolute path or a path relative to |
469 | the current directory. If an alias is specified, then this is the name it |
473 | the current directory. If an alias is specified, then this is the name it |
470 | will use for C<@INC> searches, otherfile the F<file> will be used as the |
474 | will use for C<@INC> searches, otherwise the F<file> will be used as the |
471 | internal name. |
475 | internal name. |
472 | |
476 | |
473 | This switch is used to include extra files into the bundle. |
477 | This switch is used to include extra files into the bundle. |
474 | |
478 | |
475 | Example: embed the file F<httpd> in the current directory as F<httpd.pm> |
479 | Example: embed the file F<httpd> in the current directory as F<httpd.pm> |
… | |
… | |
518 | |
522 | |
519 | =item Step 2: filter all files using C<--include> and C<--exclude> options. |
523 | =item Step 2: filter all files using C<--include> and C<--exclude> options. |
520 | |
524 | |
521 | After all candidate files and modules are added, they are I<filtered> |
525 | After all candidate files and modules are added, they are I<filtered> |
522 | by a combination of C<--include> and C<--exclude> patterns (there is an |
526 | by a combination of C<--include> and C<--exclude> patterns (there is an |
523 | implicit C<--include **> at the end, so if no filters are specified, all |
527 | implicit C<--include *> at the end, so if no filters are specified, all |
524 | files are included). |
528 | files are included). |
525 | |
529 | |
526 | All that this step does is potentially reduce the number of files that are |
530 | All that this step does is potentially reduce the number of files that are |
527 | to be included - no new files are added during this step. |
531 | to be included - no new files are added during this step. |
528 | |
532 | |
… | |
… | |
553 | that are added automatically. Only one (F<.packlist> files) is currently |
557 | that are added automatically. Only one (F<.packlist> files) is currently |
554 | optional and can be influenced, the others are always included: |
558 | optional and can be influenced, the others are always included: |
555 | |
559 | |
556 | =over 4 |
560 | =over 4 |
557 | |
561 | |
558 | =item C<--usepacklist> |
562 | =item C<--usepacklists> |
559 | |
563 | |
560 | Read F<.packlist> files for each distribution that happens to match a |
564 | Read F<.packlist> files for each distribution that happens to match a |
561 | module name you specified. Sounds weird, and it is, so expect semantics to |
565 | module name you specified. Sounds weird, and it is, so expect semantics to |
562 | change somehow in the future. |
566 | change somehow in the future. |
563 | |
567 | |
… | |
… | |
631 | Last not least, if you need accurate line numbers in error messages, |
635 | Last not least, if you need accurate line numbers in error messages, |
632 | or in the unlikely case where C<pod> is too slow, or some module gets |
636 | or in the unlikely case where C<pod> is too slow, or some module gets |
633 | mistreated, you can specify C<none> to not mangle included perl sources in |
637 | mistreated, you can specify C<none> to not mangle included perl sources in |
634 | any way. |
638 | any way. |
635 | |
639 | |
636 | =item --perl |
640 | =item C<--perl> |
637 | |
641 | |
638 | After writing out the bundle files, try to link a new perl interpreter. It |
642 | After writing out the bundle files, try to link a new perl interpreter. It |
639 | will be called F<perl> and will be left in the current working |
643 | will be called F<perl> and will be left in the current working |
640 | directory. The bundle files will be removed. |
644 | directory. The bundle files will be removed. |
641 | |
645 | |
… | |
… | |
646 | it will be even smaller than the standard perl interpreter as none of the |
650 | it will be even smaller than the standard perl interpreter as none of the |
647 | modules of the base distribution (such as L<Fcntl>) will be included. |
651 | modules of the base distribution (such as L<Fcntl>) will be included. |
648 | |
652 | |
649 | staticperl mkperl -Mcommon::sense |
653 | staticperl mkperl -Mcommon::sense |
650 | |
654 | |
651 | =item --app name |
655 | =item C<--app> F<name> |
652 | |
656 | |
653 | After writing out the bundle files, try to link a new standalone |
657 | After writing out the bundle files, try to link a new standalone |
654 | program. It will be called C<name>, and the bundle files get removed after |
658 | program. It will be called C<name>, and the bundle files get removed after |
655 | linking it. |
659 | linking it. |
656 | |
660 | |
… | |
… | |
669 | Example: create a standalone perl binary called F<./myexe> that will |
673 | Example: create a standalone perl binary called F<./myexe> that will |
670 | execute F<appfile> when it is started. |
674 | execute F<appfile> when it is started. |
671 | |
675 | |
672 | staticperl mkbundle --app myexe --boot appfile |
676 | staticperl mkbundle --app myexe --boot appfile |
673 | |
677 | |
674 | =item --static |
678 | =item C<--static> |
675 | |
679 | |
676 | Add C<-static> to F<bundle.ldopts>, which means a fully static (if |
680 | Add C<-static> to F<bundle.ldopts>, which means a fully static (if |
677 | supported by the OS) executable will be created. This is not immensely |
681 | supported by the OS) executable will be created. This is not immensely |
678 | useful when just creating the bundle files, but is most useful when |
682 | useful when just creating the bundle files, but is most useful when |
679 | linking a binary with the C<--perl> or C<--app> options. |
683 | linking a binary with the C<--perl> or C<--app> options. |
… | |
… | |
686 | systems based on GNU libc don't really support it in a very usable |
690 | systems based on GNU libc don't really support it in a very usable |
687 | fashion either. Try uClibc if you want to create fully statically linked |
691 | fashion either. Try uClibc if you want to create fully statically linked |
688 | executables, or try the C<--staticlib> option to link only some libraries |
692 | executables, or try the C<--staticlib> option to link only some libraries |
689 | statically. |
693 | statically. |
690 | |
694 | |
691 | =item --staticlib libname |
695 | =item C<--staticlib> libname |
692 | |
696 | |
693 | When not linking fully statically, this option allows you to link specific |
697 | When not linking fully statically, this option allows you to link specific |
694 | libraries statically. What it does is simply replace all occurances of |
698 | libraries statically. What it does is simply replace all occurrences of |
695 | C<-llibname> with the GCC-specific C<-Wl,-Bstatic -llibname -Wl,-Bdynamic> |
699 | C<-llibname> with the GCC-specific C<-Wl,-Bstatic -llibname -Wl,-Bdynamic> |
696 | option. |
700 | option. |
697 | |
701 | |
698 | This will have no effect unless the library is actually linked against, |
702 | This will have no effect unless the library is actually linked against, |
699 | specifically, C<--staticlib> will not link against the named library |
703 | specifically, C<--staticlib> will not link against the named library |
700 | unless it would be linked against anyway. |
704 | unless it would be linked against anyway. |
701 | |
705 | |
702 | Example: link libcrypt statically into the binary. |
706 | Example: link libcrypt statically into the final binary. |
703 | |
707 | |
704 | staticperl mkperl -MIO::AIO --staticlib crypt |
708 | staticperl mkperl -MIO::AIO --staticlib crypt |
705 | |
709 | |
706 | # ldopts might now contain: |
710 | # ldopts might now contain: |
707 | # -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread |
711 | # -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread |
… | |
… | |
728 | =item Patterns not starting with F</> will be anchored at the end of the path. |
732 | =item Patterns not starting with F</> will be anchored at the end of the path. |
729 | |
733 | |
730 | That is, F<idna.pl> will match any file called F<idna.pl> anywhere in the |
734 | That is, F<idna.pl> will match any file called F<idna.pl> anywhere in the |
731 | hierarchy, but not any directories of the same name. |
735 | hierarchy, but not any directories of the same name. |
732 | |
736 | |
733 | =item A F<*> matches any single component. |
737 | =item A F<*> matches anything within a single path component. |
734 | |
738 | |
735 | That is, F</unicore/*.pl> would match all F<.pl> files directly inside |
739 | That is, F</unicore/*.pl> would match all F<.pl> files directly inside |
736 | C</unicore>, not any deeper level F<.pl> files. Or in other words, F<*> |
740 | C</unicore>, not any deeper level F<.pl> files. Or in other words, F<*> |
737 | will not match slashes. |
741 | will not match slashes. |
738 | |
742 | |
… | |
… | |
1029 | |
1033 | |
1030 | Returns the list of all paths embedded in this binary. |
1034 | Returns the list of all paths embedded in this binary. |
1031 | |
1035 | |
1032 | =back |
1036 | =back |
1033 | |
1037 | |
1034 | =head1 FULLY STATIC BINARIES - BUILDROOT |
1038 | =head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT |
1035 | |
1039 | |
1036 | To make truly static (Linux-) libraries, you might want to have a look at |
1040 | To make truly static (Linux-) libraries, you might want to have a look at |
1037 | buildroot (L<http://buildroot.uclibc.org/>). |
1041 | buildroot (L<http://buildroot.uclibc.org/>). |
1038 | |
1042 | |
1039 | Buildroot is primarily meant to set up a cross-compile environment (which |
1043 | Buildroot is primarily meant to set up a cross-compile environment (which |
… | |
… | |
1111 | handling for those files), so including them on demand by your application |
1115 | handling for those files), so including them on demand by your application |
1112 | only might pay off. |
1116 | only might pay off. |
1113 | |
1117 | |
1114 | To simply include the whole unicode database, use: |
1118 | To simply include the whole unicode database, use: |
1115 | |
1119 | |
1116 | --incglob '/unicore/*.pl' |
1120 | --incglob '/unicore/**.pl' |
1117 | |
1121 | |
1118 | =item AnyEvent |
1122 | =item AnyEvent |
1119 | |
1123 | |
1120 | AnyEvent needs a backend implementation that it will load in a delayed |
1124 | AnyEvent needs a backend implementation that it will load in a delayed |
1121 | fashion. The L<AnyEvent::Impl::Perl> backend is the default choice |
1125 | fashion. The L<AnyEvent::Impl::Perl> backend is the default choice |
… | |
… | |
1126 | |
1130 | |
1127 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
1131 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
1128 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
1132 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
1129 | C<"AnyEvent/Util/uts46data.pl">. |
1133 | C<"AnyEvent/Util/uts46data.pl">. |
1130 | |
1134 | |
1131 | Or you can use C<--usepacklist> and specify C<-MAnyEvent> to include |
1135 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1132 | everything. |
1136 | everything. |
1133 | |
1137 | |
1134 | =item Carp |
1138 | =item Carp |
1135 | |
1139 | |
1136 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1140 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
… | |
… | |
1142 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1146 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1143 | both. |
1147 | both. |
1144 | |
1148 | |
1145 | =item Term::ReadLine::Perl |
1149 | =item Term::ReadLine::Perl |
1146 | |
1150 | |
1147 | Also needs L<Term::ReadLine::readline>, or C<--usepacklist>. |
1151 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1148 | |
1152 | |
1149 | =item URI |
1153 | =item URI |
1150 | |
1154 | |
1151 | URI implements schemes as separate modules - the generic URL scheme is |
1155 | URI implements schemes as separate modules - the generic URL scheme is |
1152 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
1156 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
1153 | you need to use any of these schemes, you should include these manually, |
1157 | you need to use any of these schemes, you should include these manually, |
1154 | or use C<--usepacklist>. |
1158 | or use C<--usepacklists>. |
1155 | |
1159 | |
1156 | =back |
1160 | =back |
1157 | |
1161 | |
1158 | =head2 RECIPES |
1162 | =head2 RECIPES |
1159 | |
1163 | |
1160 | =over 4 |
1164 | =over 4 |
1161 | |
1165 | |
1162 | =item Linking everything in |
1166 | =item Just link everything in |
1163 | |
1167 | |
1164 | To link just about everything installed in the perl library into a new |
1168 | To link just about everything installed in the perl library into a new |
1165 | perl, try this: |
1169 | perl, try this (the first time this runs it will take a long time, as a |
|
|
1170 | lot of files need to be parsed): |
1166 | |
1171 | |
1167 | staticperl mkperl --strip ppi --incglob '*' |
1172 | staticperl mkperl -v --strip ppi --incglob '*' |
1168 | |
1173 | |
|
|
1174 | If you don't mind the extra megabytes, this can be a very effective way of |
|
|
1175 | creating bundles without having to worry about forgetting any modules. |
|
|
1176 | |
|
|
1177 | You get even more useful variants of this method by first selecting |
|
|
1178 | everything, and then excluding stuff you are reasonable sure not to need - |
|
|
1179 | L<bigperl|http://staticperl.schmorp.de/bigperl.html> uses this approach. |
|
|
1180 | |
1169 | =item Getting rid of netdb function |
1181 | =item Getting rid of netdb functions |
1170 | |
1182 | |
1171 | The perl core has lots of netdb functions (C<getnetbyname>, C<getgrent> |
1183 | The perl core has lots of netdb functions (C<getnetbyname>, C<getgrent> |
1172 | and so on) that few applications use. You can avoid compiling them in by |
1184 | and so on) that few applications use. You can avoid compiling them in by |
1173 | putting the following fragment into a C<preconfigure> hook: |
1185 | putting the following fragment into a C<preconfigure> hook: |
1174 | |
1186 | |
… | |
… | |
1191 | do |
1203 | do |
1192 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1204 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1193 | done |
1205 | done |
1194 | } |
1206 | } |
1195 | |
1207 | |
1196 | This mostly gains space when linking staticaly, as the functions will |
1208 | This mostly gains space when linking statically, as the functions will |
1197 | likely not be linked in. The gain for dynamically-linked binaries is |
1209 | likely not be linked in. The gain for dynamically-linked binaries is |
1198 | smaller. |
1210 | smaller. |
1199 | |
1211 | |
1200 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1212 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1201 | often, the L<Socket> module also exposes it, so leaving it out usually |
1213 | often, the L<Socket> module also exposes it, so leaving it out usually |