ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.pod
(Generate patch)

Comparing App-Staticperl/staticperl.pod (file contents):
Revision 1.27 by root, Tue Dec 21 19:32:34 2010 UTC vs.
Revision 1.31 by root, Thu Dec 23 14:16:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines