… | |
… | |
40 | |
40 | |
41 | With F<uClibc> and F<upx> on x86, you can create a single 500kb binary |
41 | With F<uClibc> and F<upx> on x86, you can create a single 500kb binary |
42 | that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
42 | that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
43 | Coro and so on. Or any other choice of modules. |
43 | Coro and so on. Or any other choice of modules. |
44 | |
44 | |
|
|
45 | To see how this turns out, you can try out smallperl and bigperl, two |
|
|
46 | pre-built static and compressed perl binaries with many and even more |
|
|
47 | modules: just follow the links at L<http://staticperl.schmorp.de/>. |
|
|
48 | |
45 | The created files do not need write access to the file system (like PAR |
49 | The created files do not need write access to the file system (like PAR |
46 | does). In fact, since this script is in many ways similar to PAR::Packer, |
50 | does). In fact, since this script is in many ways similar to PAR::Packer, |
47 | here are the differences: |
51 | here are the differences: |
48 | |
52 | |
49 | =over 4 |
53 | =over 4 |
… | |
… | |
118 | often as necessary. |
122 | often as necessary. |
119 | |
123 | |
120 | =head1 THE F<STATICPERL> SCRIPT |
124 | =head1 THE F<STATICPERL> SCRIPT |
121 | |
125 | |
122 | This module installs a script called F<staticperl> into your perl |
126 | This module installs a script called F<staticperl> into your perl |
123 | binary directory. The script is fully self-contained, and can be used |
127 | binary directory. The script is fully self-contained, and can be |
124 | without perl (for example, in an uClibc chroot environment). In fact, |
128 | used without perl (for example, in an uClibc chroot environment). In |
125 | it can be extracted from the C<App::Staticperl> distribution tarball as |
129 | fact, it can be extracted from the C<App::Staticperl> distribution |
126 | F<bin/staticperl>, without any installation. |
130 | tarball as F<bin/staticperl>, without any installation. The |
|
|
131 | newest (possibly alpha) version can also be downloaded from |
|
|
132 | L<http://staticperl.schmorp.de/staticperl>. |
127 | |
133 | |
128 | F<staticperl> interprets the first argument as a command to execute, |
134 | F<staticperl> interprets the first argument as a command to execute, |
129 | optionally followed by any parameters. |
135 | optionally followed by any parameters. |
130 | |
136 | |
131 | There are two command categories: the "phase 1" commands which deal with |
137 | There are two command categories: the "phase 1" commands which deal with |
… | |
… | |
141 | |
147 | |
142 | The command |
148 | The command |
143 | |
149 | |
144 | staticperl install |
150 | staticperl install |
145 | |
151 | |
146 | Is normally all you need: It installs the perl interpreter in |
152 | is normally all you need: It installs the perl interpreter in |
147 | F<~/.staticperl/perl>. It downloads, configures, builds and installs the |
153 | F<~/.staticperl/perl>. It downloads, configures, builds and installs the |
148 | perl interpreter if required. |
154 | perl interpreter if required. |
149 | |
155 | |
150 | Most of the following commands simply run one or more steps of this |
156 | Most of the following F<staticperl> subcommands simply run one or more |
151 | sequence. |
157 | steps of this sequence. |
|
|
158 | |
|
|
159 | If it fails, then most commonly because the compiler options I selected |
|
|
160 | are not supported by your compiler - either edit the F<staticperl> script |
|
|
161 | yourself or create F<~/.staticperl> shell script where your set working |
|
|
162 | C<PERL_CCFLAGS> etc. variables. |
152 | |
163 | |
153 | To force recompilation or reinstallation, you need to run F<staticperl |
164 | To force recompilation or reinstallation, you need to run F<staticperl |
154 | distclean> first. |
165 | distclean> first. |
155 | |
166 | |
156 | =over 4 |
167 | =over 4 |
|
|
168 | |
|
|
169 | =item F<staticperl version> |
|
|
170 | |
|
|
171 | Prints some info about the version of the F<staticperl> script you are using. |
157 | |
172 | |
158 | =item F<staticperl fetch> |
173 | =item F<staticperl fetch> |
159 | |
174 | |
160 | Runs only the download and unpack phase, unless this has already happened. |
175 | Runs only the download and unpack phase, unless this has already happened. |
161 | |
176 | |
… | |
… | |
199 | |
214 | |
200 | =item F<staticperl clean> |
215 | =item F<staticperl clean> |
201 | |
216 | |
202 | Deletes the perl source directory (and potentially cleans up other |
217 | Deletes the perl source directory (and potentially cleans up other |
203 | intermediate files). This can be used to clean up files only needed for |
218 | intermediate files). This can be used to clean up files only needed for |
204 | building perl, without removing the installed perl interpreter, or to |
219 | building perl, without removing the installed perl interpreter. |
205 | force a re-build from scratch. |
|
|
206 | |
220 | |
207 | At the moment, it doesn't delete downloaded tarballs. |
221 | At the moment, it doesn't delete downloaded tarballs. |
|
|
222 | |
|
|
223 | The exact semantics of this command will probably change. |
208 | |
224 | |
209 | =item F<staticperl distclean> |
225 | =item F<staticperl distclean> |
210 | |
226 | |
211 | This wipes your complete F<~/.staticperl> directory. Be careful with this, |
227 | This wipes your complete F<~/.staticperl> directory. Be careful with this, |
212 | it nukes your perl download, perl sources, perl distribution and any |
228 | it nukes your perl download, perl sources, perl distribution and any |
… | |
… | |
262 | -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http |
278 | -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http |
263 | |
279 | |
264 | # run it |
280 | # run it |
265 | ./app |
281 | ./app |
266 | |
282 | |
|
|
283 | Here are the three phase 2 commands: |
|
|
284 | |
|
|
285 | =over 4 |
|
|
286 | |
|
|
287 | =item F<staticperl mkbundle> args... |
|
|
288 | |
|
|
289 | The "default" bundle command - it interprets the given bundle options and |
|
|
290 | writes out F<bundle.h>, F<bundle.c>, F<bundle.ccopts> and F<bundle.ldopts> |
|
|
291 | files, useful for embedding. |
|
|
292 | |
|
|
293 | =item F<staticperl mkperl> args... |
|
|
294 | |
|
|
295 | Creates a bundle just like F<staticperl mkbundle> (in fact, it's the same |
|
|
296 | as invoking F<staticperl mkbundle --perl> args...), but then compiles and |
|
|
297 | links a new perl interpreter that embeds the created bundle, then deletes |
|
|
298 | all intermediate files. |
|
|
299 | |
|
|
300 | =item F<staticperl mkapp> filename args... |
|
|
301 | |
|
|
302 | Does the same as F<staticperl mkbundle> (in fact, it's the same as |
|
|
303 | invoking F<staticperl mkbundle --app> filename args...), but then compiles |
|
|
304 | and links a new standalone application that simply initialises the perl |
|
|
305 | interpreter. |
|
|
306 | |
|
|
307 | The difference to F<staticperl mkperl> is that the standalone application |
|
|
308 | does not act like a perl interpreter would - in fact, by default it would |
|
|
309 | just do nothing and exit immediately, so you should specify some code to |
|
|
310 | be executed via the F<--boot> option. |
|
|
311 | |
|
|
312 | =back |
|
|
313 | |
267 | =head3 OPTION PROCESSING |
314 | =head3 OPTION PROCESSING |
268 | |
315 | |
269 | All options can be given as arguments on the command line (typically |
316 | All options can be given as arguments on the command line (typically |
270 | using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
317 | using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
271 | specifying a lot of modules can make the command line very cumbersome, |
318 | specifying a lot of modules can make the command line very cumbersome, you |
272 | you can put all long options into a "bundle specification file" (with or |
319 | can put all long options into a "bundle specification file" (one option |
273 | without C<--> prefix) and specify this bundle file instead. |
320 | per line, with or without C<--> prefix) and specify this bundle file |
|
|
321 | instead. |
274 | |
322 | |
275 | For example, the command given earlier could also look like this: |
323 | For example, the command given earlier could also look like this: |
276 | |
324 | |
277 | staticperl mkperl httpd.bundle |
325 | staticperl mkperl httpd.bundle |
278 | |
326 | |
… | |
… | |
283 | use AnyEvent::HTTPD |
331 | use AnyEvent::HTTPD |
284 | use URI::http |
332 | use URI::http |
285 | add eg/httpd httpd.pm |
333 | add eg/httpd httpd.pm |
286 | |
334 | |
287 | All options that specify modules or files to be added are processed in the |
335 | All options that specify modules or files to be added are processed in the |
288 | order given on the command line (that affects the C<--use> and C<--eval> |
336 | order given on the command line. |
289 | options at the moment). |
|
|
290 | |
337 | |
291 | =head3 PACKAGE SELECTION WORKFLOW |
338 | =head3 PACKAGE SELECTION WORKFLOW |
292 | |
339 | |
293 | F<staticperl mkbundle> has a number of options to control package |
340 | F<staticperl mkbundle> has a number of options to control package |
294 | selection. This section describes how they interact with each other. Also, |
341 | selection. This section describes how they interact with each other. Also, |
… | |
… | |
311 | |
358 | |
312 | All this step does is potentially reduce the number of files already |
359 | All this step does is potentially reduce the number of files already |
313 | selected or found in phase 1. |
360 | selected or found in phase 1. |
314 | |
361 | |
315 | =item 3. find all modules (== F<.pm> files), gather their static archives |
362 | =item 3. find all modules (== F<.pm> files), gather their static archives |
316 | (F<.a>) and AutoLoader splitfiles (F<.ix> and F<.al> files) and find any |
363 | (F<.a>) and AutoLoader splitfiles (F<.ix> and F<.al> files), find any |
317 | extra libraries they need for linking (F<extralibs.ld>). |
364 | extra libraries they need for linking (F<extralibs.ld>) and optionally |
|
|
365 | evaluate any F<.packlist> files. |
318 | |
366 | |
319 | This step is required to link against XS extensions and also adds files |
367 | This step is required to link against XS extensions and also adds files |
320 | required for L<AutoLoader> to do it's job. |
368 | required for L<AutoLoader> to do it's job. |
321 | |
369 | |
322 | =back |
370 | =back |
… | |
… | |
453 | (using a C<require>) before anything else when the new perl is |
501 | (using a C<require>) before anything else when the new perl is |
454 | initialised. This can be used to modify C<@INC> or anything else before |
502 | initialised. This can be used to modify C<@INC> or anything else before |
455 | the perl interpreter executes scripts given on the command line (or via |
503 | the perl interpreter executes scripts given on the command line (or via |
456 | C<-e>). This works even in an embedded interpreter. |
504 | C<-e>). This works even in an embedded interpreter. |
457 | |
505 | |
|
|
506 | =item --usepacklist |
|
|
507 | |
|
|
508 | Read F<.packlist> files for each distribution that happens to match a |
|
|
509 | module name you specified. Sounds weird, and it is, so expect semantics to |
|
|
510 | change somehow in the future. |
|
|
511 | |
|
|
512 | The idea is that most CPAN distributions have a F<.pm> file that matches |
|
|
513 | the name of the distribution (which is rather reasonable after all). |
|
|
514 | |
|
|
515 | If this switch is enabled, then if any of the F<.pm> files that have been |
|
|
516 | selected match an install distribution, then all F<.pm>, F<.pl>, F<.al> |
|
|
517 | and F<.ix> files installed by this distribution are also included. |
|
|
518 | |
|
|
519 | For example, using this switch, when the L<URI> module is specified, then |
|
|
520 | all L<URI> submodules that have been installed via the CPAN distribution |
|
|
521 | are included as well, so you don't have to manually specify them. |
|
|
522 | |
458 | =item --incglob pattern |
523 | =item --incglob pattern |
459 | |
524 | |
460 | This goes through all library directories and tries to match any F<.pm> |
525 | This goes through all library directories and tries to match any F<.pm> |
461 | and F<.pl> files against the extended glob pattern (see below). If a file |
526 | and F<.pl> files against the extended glob pattern (see below). If a file |
462 | matches, it is added. This switch will automatically detect L<AutoLoader> |
527 | matches, it is added. This switch will automatically detect L<AutoLoader> |
… | |
… | |
589 | |
654 | |
590 | =back |
655 | =back |
591 | |
656 | |
592 | =head2 F<STATICPERL> CONFIGURATION AND HOOKS |
657 | =head2 F<STATICPERL> CONFIGURATION AND HOOKS |
593 | |
658 | |
594 | During (each) startup, F<staticperl> tries to source the following shell |
659 | During (each) startup, F<staticperl> tries to source some shell files to |
|
|
660 | allow you to fine-tune/override configuration settings. |
|
|
661 | |
|
|
662 | In them you can override shell variables, or define shell functions |
|
|
663 | ("hooks") to be called at specific phases during installation. For |
|
|
664 | example, you could define a C<postinstall> hook to install additional |
|
|
665 | modules from CPAN each time you start from scratch. |
|
|
666 | |
|
|
667 | If the env variable C<$STATICPERLRC> is set, then F<staticperl> will try |
|
|
668 | to source the file named with it only. Otherwise, it tries the following |
595 | files in order: |
669 | shell files in order: |
596 | |
670 | |
597 | /etc/staticperlrc |
671 | /etc/staticperlrc |
598 | ~/.staticperlrc |
672 | ~/.staticperlrc |
599 | $STATICPERL/rc |
673 | $STATICPERL/rc |
600 | |
|
|
601 | They can be used to override shell variables, or define functions to be |
|
|
602 | called at specific phases. |
|
|
603 | |
674 | |
604 | Note that the last file is erased during F<staticperl distclean>, so |
675 | Note that the last file is erased during F<staticperl distclean>, so |
605 | generally should not be used. |
676 | generally should not be used. |
606 | |
677 | |
607 | =head3 CONFIGURATION VARIABLES |
678 | =head3 CONFIGURATION VARIABLES |
… | |
… | |
669 | |
740 | |
670 | More commonly, you would either activate 64 bit integer support |
741 | More commonly, you would either activate 64 bit integer support |
671 | (C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to |
742 | (C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to |
672 | reduce filesize further. |
743 | reduce filesize further. |
673 | |
744 | |
674 | =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
745 | =item C<PERL_CC>, C<PERL_CCFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
675 | |
746 | |
676 | These flags are passed to perl's F<Configure> script, and are generally |
747 | These flags are passed to perl's F<Configure> script, and are generally |
677 | optimised for small size (at the cost of performance). Since they also |
748 | optimised for small size (at the cost of performance). Since they also |
678 | contain subtle workarounds around various build issues, changing these |
749 | contain subtle workarounds around various build issues, changing these |
679 | usually requires understanding their default values - best look at the top |
750 | usually requires understanding their default values - best look at |
680 | of the F<staticperl> script for more info on these. |
751 | the top of the F<staticperl> script for more info on these, and use a |
|
|
752 | F<~/.staticperlrc> to override them. |
|
|
753 | |
|
|
754 | Most of the variables override (or modify) the corresponding F<Configure> |
|
|
755 | variable, except C<PERL_CCFLAGS>, which gets appended. |
681 | |
756 | |
682 | =back |
757 | =back |
683 | |
758 | |
684 | =head4 Variables you probably I<do not want> to override |
759 | =head4 Variables you probably I<do not want> to override |
685 | |
760 | |
686 | =over 4 |
761 | =over 4 |
|
|
762 | |
|
|
763 | =item C<MAKE> |
|
|
764 | |
|
|
765 | The make command to use - default is C<make>. |
687 | |
766 | |
688 | =item C<MKBUNDLE> |
767 | =item C<MKBUNDLE> |
689 | |
768 | |
690 | Where F<staticperl> writes the C<mkbundle> command to |
769 | Where F<staticperl> writes the C<mkbundle> command to |
691 | (default: F<$STATICPERL/mkbundle>). |
770 | (default: F<$STATICPERL/mkbundle>). |
… | |
… | |
953 | |
1032 | |
954 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
1033 | If you want to handle IRIs or IDNs (L<AnyEvent::Util> punycode and idn |
955 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
1034 | functions), you also need to include C<"AnyEvent/Util/idna.pl"> and |
956 | C<"AnyEvent/Util/uts46data.pl">. |
1035 | C<"AnyEvent/Util/uts46data.pl">. |
957 | |
1036 | |
|
|
1037 | Or you can use C<--usepacklist> and specify C<-MAnyEvent> to include |
|
|
1038 | everything. |
|
|
1039 | |
958 | =item Carp |
1040 | =item Carp |
959 | |
1041 | |
960 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1042 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
961 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1043 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
962 | |
1044 | |
… | |
… | |
966 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1048 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
967 | both. |
1049 | both. |
968 | |
1050 | |
969 | =item Term::ReadLine::Perl |
1051 | =item Term::ReadLine::Perl |
970 | |
1052 | |
971 | Also needs L<Term::ReadLine::readline>. |
1053 | Also needs L<Term::ReadLine::readline>, or C<--usepacklist>. |
972 | |
1054 | |
973 | =item URI |
1055 | =item URI |
974 | |
1056 | |
975 | URI implements schemes as separate modules - the generic URL scheme is |
1057 | URI implements schemes as separate modules - the generic URL scheme is |
976 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
1058 | implemented in L<URI::_generic>, HTTP is implemented in L<URI::http>. If |
977 | you need to use any of these schemes, you should include these manually. |
1059 | you need to use any of these schemes, you should include these manually, |
|
|
1060 | or use C<--usepacklist>. |
978 | |
1061 | |
979 | =back |
1062 | =back |
980 | |
1063 | |
981 | =head2 RECIPES |
1064 | =head2 RECIPES |
982 | |
1065 | |
… | |
… | |
1015 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1098 | PERL_CONFIGURE="$PERL_CONFIGURE -U$sym" |
1016 | done |
1099 | done |
1017 | } |
1100 | } |
1018 | |
1101 | |
1019 | This mostly gains space when linking staticaly, as the functions will |
1102 | This mostly gains space when linking staticaly, as the functions will |
1020 | liekly not be linked in. The gain for dynamically-linked binaries is |
1103 | likely not be linked in. The gain for dynamically-linked binaries is |
1021 | smaller. |
1104 | smaller. |
1022 | |
1105 | |
1023 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1106 | Also, this leaves C<gethostbyname> in - not only is it actually used |
1024 | often, the L<Socket> module also exposes it, so leaving it out usually |
1107 | often, the L<Socket> module also exposes it, so leaving it out usually |
1025 | gains little. Why Socket exposes a C function that is in the core already |
1108 | gains little. Why Socket exposes a C function that is in the core already |