… | |
… | |
26 | # build a perl with the above modules linked in |
26 | # build a perl with the above modules linked in |
27 | |
27 | |
28 | =head1 DESCRIPTION |
28 | =head1 DESCRIPTION |
29 | |
29 | |
30 | This script helps you creating single-file perl interpreters, or embedding |
30 | This script helps you creating single-file perl interpreters, or embedding |
31 | a pelr interpreter in your apps. Single-file means that it is fully |
31 | a perl interpreter in your applications. Single-file means that it is |
32 | self-contained - no separate shared objects, no autoload fragments, no .pm |
32 | fully self-contained - no separate shared objects, no autoload fragments, |
33 | or .pl files are needed. And when linking statically, you can create (or |
33 | no .pm or .pl files are needed. And when linking statically, you can |
34 | embed) a single file that contains perl interpreter, libc, all the modules |
34 | create (or embed) a single file that contains perl interpreter, libc, all |
35 | you need and all the libraries you need. |
35 | the modules you need and all the libraries you need. |
36 | |
36 | |
37 | With uclibc and upx on x86, you can create a single 500kb binary that |
37 | With F<uClibc> and F<upx> on x86, you can create a single 500kb binary that |
38 | contains perl and 50 modules such as AnyEvent, EV, IO::AIO, Coro and so |
38 | contains perl and 50 modules such as AnyEvent, EV, IO::AIO, Coro and so |
39 | on. Or any other choice of modules. |
39 | on. Or any other choice of modules. |
40 | |
40 | |
41 | The created files do not need write access to the filesystem (like PAR |
41 | The created files do not need write access to the file system (like PAR |
42 | does). In fact, since this script is in many ways similar to PAR::Packer, |
42 | does). In fact, since this script is in many ways similar to PAR::Packer, |
43 | here are the differences: |
43 | here are the differences: |
44 | |
44 | |
45 | =over 4 |
45 | =over 4 |
46 | |
46 | |
… | |
… | |
65 | F<staticperl> loads all required files directly from memory. There is no |
65 | F<staticperl> loads all required files directly from memory. There is no |
66 | need to unpack files into a temporary directory. |
66 | need to unpack files into a temporary directory. |
67 | |
67 | |
68 | =item * More control over included files. |
68 | =item * More control over included files. |
69 | |
69 | |
70 | PAR tries to be maintainance and hassle-free - it tries to include more files |
70 | PAR tries to be maintenance and hassle-free - it tries to include more |
71 | than necessary to make sure everything works out of the box. The extra files |
71 | files than necessary to make sure everything works out of the box. The |
72 | (such as the unicode database) can take substantial amounts of memory and filesize. |
72 | extra files (such as the unicode database) can take substantial amounts of |
|
|
73 | memory and file size. |
73 | |
74 | |
74 | With F<staticperl>, the burden is mostly with the developer - only direct |
75 | With F<staticperl>, the burden is mostly with the developer - only direct |
75 | compile-time dependencies and L<AutoLoader> are handled automatically. |
76 | compile-time dependencies and L<AutoLoader> are handled automatically. |
76 | This means the modules to include often need to be tweaked manually. |
77 | This means the modules to include often need to be tweaked manually. |
77 | |
78 | |
… | |
… | |
88 | |
89 | |
89 | Simple: F<staticperl> downloads, compile and installs a perl version of |
90 | Simple: F<staticperl> downloads, compile and installs a perl version of |
90 | your choice in F<~/.staticperl>. You can add extra modules either by |
91 | your choice in F<~/.staticperl>. You can add extra modules either by |
91 | letting F<staticperl> install them for you automatically, or by using CPAN |
92 | letting F<staticperl> install them for you automatically, or by using CPAN |
92 | and doing it interactively. This usually takes 5-10 minutes, depending on |
93 | and doing it interactively. This usually takes 5-10 minutes, depending on |
93 | the speed of your computer and your internet conenction. |
94 | the speed of your computer and your internet connection. |
94 | |
95 | |
95 | It is possible to do program development at this stage, too. |
96 | It is possible to do program development at this stage, too. |
96 | |
97 | |
97 | Afterwards, you create a list of files and modules you want to include, |
98 | Afterwards, you create a list of files and modules you want to include, |
98 | and then either build a new perl binary (that acts just like a normla perl |
99 | and then either build a new perl binary (that acts just like a normal perl |
99 | except everything is compiled in), or you create bundle files (basically C |
100 | except everything is compiled in), or you create bundle files (basically C |
100 | sources you can use to embed all files into your project). |
101 | sources you can use to embed all files into your project). |
101 | |
102 | |
102 | This step is very fast (a few seconds if PPI is not used for stripping, |
103 | This step is very fast (a few seconds if PPI is not used for stripping, |
103 | more seconds otherwise, as PPI is very slow), and can be tweaked and |
104 | more seconds otherwise, as PPI is very slow), and can be tweaked and |
… | |
… | |
134 | perl interpreter if required. |
135 | perl interpreter if required. |
135 | |
136 | |
136 | Most of the following commands simply run one or more steps of this |
137 | Most of the following commands simply run one or more steps of this |
137 | sequence. |
138 | sequence. |
138 | |
139 | |
139 | To force recompilation or reinstalaltion, you need to run F<staticperl |
140 | To force recompilation or reinstallation, you need to run F<staticperl |
140 | distclean> first. |
141 | distclean> first. |
141 | |
142 | |
142 | =over 4 |
143 | =over 4 |
143 | |
144 | |
144 | =item F<staticperl fetch> |
145 | =item F<staticperl fetch> |
… | |
… | |
154 | Builds the configured perl sources, potentially after automatically |
155 | Builds the configured perl sources, potentially after automatically |
155 | configuring them. |
156 | configuring them. |
156 | |
157 | |
157 | =item F<staticperl install> |
158 | =item F<staticperl install> |
158 | |
159 | |
159 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and installs |
160 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
160 | the perl distribution, potentially aftering building it first. |
161 | installs the perl distribution, potentially after building it first. |
161 | |
162 | |
162 | =item F<staticperl cpan> [args...] |
163 | =item F<staticperl cpan> [args...] |
163 | |
164 | |
164 | Starts an interactive CPAN shell that you cna use to install further |
165 | Starts an interactive CPAN shell that you can use to install further |
165 | modules. Installs the perl first if neccessary, but apart from that, |
166 | modules. Installs the perl first if necessary, but apart from that, |
166 | no magic is involved: you could just as well run it manually via |
167 | no magic is involved: you could just as well run it manually via |
167 | F<~/.staticperl/perl/bin/cpan>. |
168 | F<~/.staticperl/perl/bin/cpan>. |
168 | |
169 | |
169 | Any additional arguments are simply passed to the F<cpan> command. |
170 | Any additional arguments are simply passed to the F<cpan> command. |
170 | |
171 | |
… | |
… | |
177 | staticperl instcpan EV AnyEvent::HTTPD Coro |
178 | staticperl instcpan EV AnyEvent::HTTPD Coro |
178 | |
179 | |
179 | =item F<staticperl instsrc> directory... |
180 | =item F<staticperl instsrc> directory... |
180 | |
181 | |
181 | In the unlikely case that you have unpacked perl modules around and want |
182 | In the unlikely case that you have unpacked perl modules around and want |
182 | to install from these instead of from CPAN, you cna do this using this |
183 | to install from these instead of from CPAN, you can do this using this |
183 | command by specifying all the directories with modules in them that you |
184 | command by specifying all the directories with modules in them that you |
184 | want to have built. |
185 | want to have built. |
185 | |
186 | |
186 | =item F<staticperl clean> |
187 | =item F<staticperl clean> |
187 | |
188 | |
… | |
… | |
210 | In the oh so unlikely case of something not working here, you |
211 | In the oh so unlikely case of something not working here, you |
211 | can run the script manually as well (by default it is written to |
212 | can run the script manually as well (by default it is written to |
212 | F<~/.staticperl/mkbundle>). |
213 | F<~/.staticperl/mkbundle>). |
213 | |
214 | |
214 | F<mkbundle> is a more conventional command and expect the argument |
215 | F<mkbundle> is a more conventional command and expect the argument |
215 | syntax commonly used on unix clones. For example, this command builds |
216 | syntax commonly used on UNIX clones. For example, this command builds |
216 | a new F<perl> binary and includes F<Config.pm> (for F<perl -V>), |
217 | a new F<perl> binary and includes F<Config.pm> (for F<perl -V>), |
217 | F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd> |
218 | F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd> |
218 | in this distribution): |
219 | in this distribution): |
219 | |
220 | |
220 | # first make sure we have perl and the required modules |
221 | # first make sure we have perl and the required modules |
… | |
… | |
229 | ./perl -Mhttpd |
230 | ./perl -Mhttpd |
230 | |
231 | |
231 | As you can see, things are not quite as trivial: the L<Config> module has |
232 | As you can see, things are not quite as trivial: the L<Config> module has |
232 | a hidden dependency which is not even a perl module (F<Config_heavy.pl>), |
233 | a hidden dependency which is not even a perl module (F<Config_heavy.pl>), |
233 | L<AnyEvent> needs at least one event loop backend that we have to |
234 | L<AnyEvent> needs at least one event loop backend that we have to |
234 | specifymanually (here L<AnyEvent::Impl::Perl>), and the F<URI> module |
235 | specify manually (here L<AnyEvent::Impl::Perl>), and the F<URI> module |
235 | (required by L<AnyEvent::HTTPD>) implements various URI schemes as extra |
236 | (required by L<AnyEvent::HTTPD>) implements various URI schemes as extra |
236 | modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need |
237 | modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need |
237 | to include that module. |
238 | to include that module. I found out about these dependencies by carefully |
|
|
239 | watching any error messages about missing modules... |
238 | |
240 | |
239 | =head3 OPTION PROCESSING |
241 | =head3 OPTION PROCESSING |
240 | |
242 | |
241 | All options can be given as arguments on the commandline (typically using |
243 | All options can be given as arguments on the command line (typically |
242 | long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
244 | using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
243 | specifying a lot of modules can make the commandlien very cumbersome, |
245 | specifying a lot of modules can make the command line very cumbersome, |
244 | you can put all long options into a "bundle specification file" (with or |
246 | you can put all long options into a "bundle specification file" (with or |
245 | without C<--> prefix) and specify this bundle file instead. |
247 | without C<--> prefix) and specify this bundle file instead. |
246 | |
248 | |
247 | For example, the command given earlier could also look like this: |
249 | For example, the command given earlier could also look like this: |
248 | |
250 | |
… | |
… | |
255 | use AnyEvent::HTTPD |
257 | use AnyEvent::HTTPD |
256 | use URI::http |
258 | use URI::http |
257 | add eg/httpd httpd.pm |
259 | add eg/httpd httpd.pm |
258 | |
260 | |
259 | All options that specify modules or files to be added are processed in the |
261 | All options that specify modules or files to be added are processed in the |
260 | order given on the commandline (that affects the C<--use> and C<--eval> |
262 | order given on the command line (that affects the C<--use> and C<--eval> |
261 | options at the moment). |
263 | options at the moment). |
262 | |
264 | |
263 | =head3 MKBUNDLE OPTIONS |
265 | =head3 MKBUNDLE OPTIONS |
264 | |
266 | |
265 | =over 4 |
267 | =over 4 |
… | |
… | |
276 | |
278 | |
277 | Specify the stripping method applied to reduce the file of the perl |
279 | Specify the stripping method applied to reduce the file of the perl |
278 | sources included. |
280 | sources included. |
279 | |
281 | |
280 | The default is C<pod>, which uses the L<Pod::Strip> module to remove all |
282 | The default is C<pod>, which uses the L<Pod::Strip> module to remove all |
281 | pod documenatiton, which is very fast and reduces filesize a lot. |
283 | pod documentation, which is very fast and reduces file size a lot. |
282 | |
284 | |
283 | The C<ppi> method uses L<PPI> to parse and condense the perl sources. This |
285 | The C<ppi> method uses L<PPI> to parse and condense the perl sources. This |
284 | saves a lot more than just L<Pod::Strip>, and is generally safer, but is |
286 | saves a lot more than just L<Pod::Strip>, and is generally safer, but |
285 | also a lot slower, so is best used for production builds. |
287 | is also a lot slower, so is best used for production builds. Note that |
|
|
288 | this method doesn't optimise for raw file size, but for best compression |
|
|
289 | (that means that the uncompressed file size is a bit larger, but the files |
|
|
290 | compress better, e.g. with F<upx>). |
286 | |
291 | |
287 | Last not least, in the unlikely case where C<pod> is too slow, or some |
292 | Last not least, in the unlikely case where C<pod> is too slow, or some |
288 | module gets mistreated, you can specify C<none> to not mangle included |
293 | module gets mistreated, you can specify C<none> to not mangle included |
289 | perl sources in any way. |
294 | perl sources in any way. |
290 | |
295 | |
… | |
… | |
292 | |
297 | |
293 | After writing out the bundle files, try to link a new perl interpreter. It |
298 | After writing out the bundle files, try to link a new perl interpreter. It |
294 | will be called F<perl> and will be left in the current working |
299 | will be called F<perl> and will be left in the current working |
295 | directory. The bundle files will be removed. |
300 | directory. The bundle files will be removed. |
296 | |
301 | |
297 | This switch is automatically ued when F<staticperl> is invoked with the |
302 | This switch is automatically used when F<staticperl> is invoked with the |
298 | C<mkperl> command (instead of C<mkbundle>): |
303 | C<mkperl> command (instead of C<mkbundle>): |
299 | |
304 | |
300 | # build a new ./perl with only common::sense in it - very small :) |
305 | # build a new ./perl with only common::sense in it - very small :) |
301 | staticperl mkperl -Mcommon::sense |
306 | staticperl mkperl -Mcommon::sense |
302 | |
307 | |
… | |
… | |
311 | |
316 | |
312 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
317 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
313 | |
318 | |
314 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
319 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
315 | maybe other weirdly named files. To do that, you need to quote the name in |
320 | maybe other weirdly named files. To do that, you need to quote the name in |
316 | single or double quoutes. When given on the commandline, you probably need |
321 | single or double quotes. When given on the command line, you probably need |
317 | to quote once more to avoid your shell interpreting it. Common cases that |
322 | to quote once more to avoid your shell interpreting it. Common cases that |
318 | need this are F<Config_heavy.pl> and F<utf8_heavy.pl>. |
323 | need this are F<Config_heavy.pl> and F<utf8_heavy.pl>. |
319 | |
324 | |
320 | Example: include the required files for F<perl -V> to work in all its |
325 | Example: include the required files for F<perl -V> to work in all its |
321 | glory (F<Config.pm> is included automatically by this). |
326 | glory (F<Config.pm> is included automatically by this). |
… | |
… | |
338 | variables or whatever you need. All files C<require>'d or C<use>'d in the |
343 | variables or whatever you need. All files C<require>'d or C<use>'d in the |
339 | script are included in the final bundle. |
344 | script are included in the final bundle. |
340 | |
345 | |
341 | Keep in mind that F<mkbundle> will only C<require> the modules named |
346 | Keep in mind that F<mkbundle> will only C<require> the modules named |
342 | by the C<--use> option, so do not expect the symbols from modules you |
347 | by the C<--use> option, so do not expect the symbols from modules you |
343 | C<--use>'d earlier on the commandlien to be available. |
348 | C<--use>'d earlier on the command line to be available. |
344 | |
349 | |
345 | Example: force L<AnyEvent> to detect a backend and therefore include it |
350 | Example: force L<AnyEvent> to detect a backend and therefore include it |
346 | in the final bundle. |
351 | in the final bundle. |
347 | |
352 | |
348 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
353 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
… | |
… | |
358 | =item --boot filename |
363 | =item --boot filename |
359 | |
364 | |
360 | Include the given file in the bundle and arrange for it to be executed |
365 | Include the given file in the bundle and arrange for it to be executed |
361 | (using a C<require>) before anything else when the new perl is |
366 | (using a C<require>) before anything else when the new perl is |
362 | initialised. This can be used to modify C<@INC> or anything else before |
367 | initialised. This can be used to modify C<@INC> or anything else before |
363 | the perl interpreter executes scripts given on the commandline (or via |
368 | the perl interpreter executes scripts given on the command line (or via |
364 | C<-e>). This works even in an embedded interpreter. |
369 | C<-e>). This works even in an embedded interpreter. |
365 | |
370 | |
366 | =item --add "file" | --add "file alias" |
371 | =item --add "file" | --add "file alias" |
367 | |
372 | |
368 | Adds the given (perl) file into the bundle (and optionally call it |
373 | Adds the given (perl) file into the bundle (and optionally call it |
… | |
… | |
454 | The directory where staticperl stores all its files |
459 | The directory where staticperl stores all its files |
455 | (default: F<~/.staticperl>). |
460 | (default: F<~/.staticperl>). |
456 | |
461 | |
457 | =item C<PREFIX> |
462 | =item C<PREFIX> |
458 | |
463 | |
459 | The prefix where perl get's installed (default: F<$STATICPERL/perl>), |
464 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
460 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
465 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
461 | |
466 | |
462 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, others |
467 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, others |
463 | |
468 | |
464 | Usually set to C<1> to make modules "less inquisitive" during their |
469 | Usually set to C<1> to make modules "less inquisitive" during their |
… | |
… | |
472 | |
477 | |
473 | Example: I really really need EV, AnyEvent, Coro and IO::AIO. |
478 | Example: I really really need EV, AnyEvent, Coro and IO::AIO. |
474 | |
479 | |
475 | EXTRA_MODULES="EV AnyEvent Coro IO::AIO" |
480 | EXTRA_MODULES="EV AnyEvent Coro IO::AIO" |
476 | |
481 | |
477 | Note that you cna also use a C<postinstall> hook to achieve this, and |
482 | Note that you can also use a C<postinstall> hook to achieve this, and |
478 | more. |
483 | more. |
479 | |
484 | |
480 | =back |
485 | =back |
481 | |
486 | |
482 | =head4 Variables you I<probably do not want> to override |
487 | =head4 Variables you I<probably do not want> to override |
… | |
… | |
497 | |
502 | |
498 | =head3 OVERRIDABLE HOOKS |
503 | =head3 OVERRIDABLE HOOKS |
499 | |
504 | |
500 | In addition to environment variables, it is possible to provide some |
505 | In addition to environment variables, it is possible to provide some |
501 | shell functions that are called at specific times. To provide your own |
506 | shell functions that are called at specific times. To provide your own |
502 | commands, justd efine the corresponding function. |
507 | commands, just define the corresponding function. |
503 | |
508 | |
504 | Example: install extra modules from CPAN and from some directories |
509 | Example: install extra modules from CPAN and from some directories |
505 | at F<staticperl install> time. |
510 | at F<staticperl install> time. |
506 | |
511 | |
507 | postinstall() { |
512 | postinstall() { |