1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | staticperl - perl, libc, 50 modules all in one 500kb file |
3 | staticperl - perl, libc, 100 modules, all in one 500kb file |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | staticperl help # print the embedded documentation |
7 | staticperl help # print the embedded documentation |
8 | staticperl fetch # fetch and unpack perl sources |
8 | staticperl fetch # fetch and unpack perl sources |
… | |
… | |
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 |
38 | contains perl and 50 modules such as AnyEvent, EV, IO::AIO, Coro and so |
38 | that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
39 | on. Or any other choice of modules. |
39 | Coro and so 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 | |
|
|
292 | Last not least, if you need accurate line numbers in error messages, |
287 | Last not least, in the unlikely case where C<pod> is too slow, or some |
293 | or in the unlikely case where C<pod> is too slow, or some module gets |
288 | module gets mistreated, you can specify C<none> to not mangle included |
294 | mistreated, you can specify C<none> to not mangle included perl sources in |
289 | perl sources in any way. |
295 | any way. |
290 | |
296 | |
291 | =item --perl |
297 | =item --perl |
292 | |
298 | |
293 | After writing out the bundle files, try to link a new perl interpreter. It |
299 | 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 |
300 | will be called F<perl> and will be left in the current working |
295 | directory. The bundle files will be removed. |
301 | directory. The bundle files will be removed. |
296 | |
302 | |
297 | This switch is automatically ued when F<staticperl> is invoked with the |
303 | This switch is automatically used when F<staticperl> is invoked with the |
298 | C<mkperl> command (instead of C<mkbundle>): |
304 | C<mkperl> command (instead of C<mkbundle>): |
299 | |
305 | |
300 | # build a new ./perl with only common::sense in it - very small :) |
306 | # build a new ./perl with only common::sense in it - very small :) |
301 | staticperl mkperl -Mcommon::sense |
307 | staticperl mkperl -Mcommon::sense |
302 | |
308 | |
… | |
… | |
311 | |
317 | |
312 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
318 | staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl |
313 | |
319 | |
314 | Sometimes you want to load old-style "perl libraries" (F<.pl> files), or |
320 | 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 |
321 | 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 |
322 | 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 |
323 | 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>. |
324 | need this are F<Config_heavy.pl> and F<utf8_heavy.pl>. |
319 | |
325 | |
320 | Example: include the required files for F<perl -V> to work in all its |
326 | Example: include the required files for F<perl -V> to work in all its |
321 | glory (F<Config.pm> is included automatically by this). |
327 | 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 |
344 | variables or whatever you need. All files C<require>'d or C<use>'d in the |
339 | script are included in the final bundle. |
345 | script are included in the final bundle. |
340 | |
346 | |
341 | Keep in mind that F<mkbundle> will only C<require> the modules named |
347 | 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 |
348 | 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. |
349 | C<--use>'d earlier on the command line to be available. |
344 | |
350 | |
345 | Example: force L<AnyEvent> to detect a backend and therefore include it |
351 | Example: force L<AnyEvent> to detect a backend and therefore include it |
346 | in the final bundle. |
352 | in the final bundle. |
347 | |
353 | |
348 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
354 | staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' |
… | |
… | |
358 | =item --boot filename |
364 | =item --boot filename |
359 | |
365 | |
360 | Include the given file in the bundle and arrange for it to be executed |
366 | 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 |
367 | (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 |
368 | 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 |
369 | the perl interpreter executes scripts given on the command line (or via |
364 | C<-e>). This works even in an embedded interpreter. |
370 | C<-e>). This works even in an embedded interpreter. |
365 | |
371 | |
366 | =item --add "file" | --add "file alias" |
372 | =item --add "file" | --add "file alias" |
367 | |
373 | |
368 | Adds the given (perl) file into the bundle (and optionally call it |
374 | Adds the given (perl) file into the bundle (and optionally call it |
… | |
… | |
376 | |
382 | |
377 | # specification file |
383 | # specification file |
378 | add file1 myfiles/file1 |
384 | add file1 myfiles/file1 |
379 | add file2 myfiles/file2 |
385 | add file2 myfiles/file2 |
380 | add file3 myfiles/file3 |
386 | add file3 myfiles/file3 |
|
|
387 | |
|
|
388 | =item --binadd "file" | --add "file alias" |
|
|
389 | |
|
|
390 | Just like C<--add>, except that it treats the file as binary and adds it |
|
|
391 | without any processing. |
|
|
392 | |
|
|
393 | You should probably add a C</> prefix to avoid clashing with embedded |
|
|
394 | perl files (whose paths do not start with C</>), and/or use a special |
|
|
395 | directory, such as C</res/name>. |
|
|
396 | |
|
|
397 | You can later get a copy of these files by calling C<staticperl::find |
|
|
398 | "alias">. |
381 | |
399 | |
382 | =item --static |
400 | =item --static |
383 | |
401 | |
384 | When C<--perl> is also given, link statically instead of dynamically. The |
402 | When C<--perl> is also given, link statically instead of dynamically. The |
385 | default is to link the new perl interpreter fully dynamic (that means all |
403 | default is to link the new perl interpreter fully dynamic (that means all |
… | |
… | |
425 | The e-mail address of the person who built this binary. Has no good |
443 | The e-mail address of the person who built this binary. Has no good |
426 | default, so should be specified by you. |
444 | default, so should be specified by you. |
427 | |
445 | |
428 | =back |
446 | =back |
429 | |
447 | |
430 | =head4 Variables you I<might want> to override |
448 | =head4 Variables you might I<want> to override |
431 | |
449 | |
432 | =over 4 |
450 | =over 4 |
433 | |
451 | |
434 | =item C<PERLVER> |
452 | =item C<PERLVER> |
435 | |
453 | |
… | |
… | |
438 | about as big as 5.12.2). |
456 | about as big as 5.12.2). |
439 | |
457 | |
440 | =item C<CPAN> |
458 | =item C<CPAN> |
441 | |
459 | |
442 | The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). |
460 | The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). |
|
|
461 | |
|
|
462 | =item C<EXTRA_MODULES> |
|
|
463 | |
|
|
464 | Additional modules installed during F<staticperl install>. Here you can |
|
|
465 | set which modules you want have to installed from CPAN. |
|
|
466 | |
|
|
467 | Example: I really really need EV, AnyEvent, Coro and IO::AIO. |
|
|
468 | |
|
|
469 | EXTRA_MODULES="EV AnyEvent Coro IO::AIO" |
|
|
470 | |
|
|
471 | Note that you can also use a C<postinstall> hook to achieve this, and |
|
|
472 | more. |
|
|
473 | |
|
|
474 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
|
|
475 | |
|
|
476 | Usually set to C<1> to make modules "less inquisitive" during their |
|
|
477 | installation, you can set any environment variable you want - some modules |
|
|
478 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
|
|
479 | |
|
|
480 | =item C<STATICPERL> |
|
|
481 | |
|
|
482 | The directory where staticperl stores all its files |
|
|
483 | (default: F<~/.staticperl>). |
|
|
484 | |
|
|
485 | =item C<PREFIX> |
|
|
486 | |
|
|
487 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
|
|
488 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
|
|
489 | |
|
|
490 | =item C<PERL_CONFIGURE> |
|
|
491 | |
|
|
492 | Additional Configure options - these are simply passed to the perl |
|
|
493 | Configure script. For example, if you wanted to enable dynamic loading, |
|
|
494 | you could pass C<-Dusedl>. To enable ithreads (Why would you want that |
|
|
495 | insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads> |
|
|
496 | and so on. |
|
|
497 | |
|
|
498 | More commonly, you would either activate 64 bit integer support |
|
|
499 | (C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to |
|
|
500 | reduce filesize further. |
443 | |
501 | |
444 | =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
502 | =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
445 | |
503 | |
446 | These flags are passed to perl's F<Configure> script, and are generally |
504 | These flags are passed to perl's F<Configure> script, and are generally |
447 | optimised for small size (at the cost of performance). Since they also |
505 | optimised for small size (at the cost of performance). Since they also |
448 | contain subtle workarounds around various build issues, changing these |
506 | contain subtle workarounds around various build issues, changing these |
449 | usually requires understanding their default values - best look at the top |
507 | usually requires understanding their default values - best look at the top |
450 | of the F<staticperl> script for more info on these. |
508 | of the F<staticperl> script for more info on these. |
451 | |
509 | |
452 | =item C<STATICPERL> |
|
|
453 | |
|
|
454 | The directory where staticperl stores all its files |
|
|
455 | (default: F<~/.staticperl>). |
|
|
456 | |
|
|
457 | =item C<PREFIX> |
|
|
458 | |
|
|
459 | The prefix where perl get's installed (default: F<$STATICPERL/perl>), |
|
|
460 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
|
|
461 | |
|
|
462 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, others |
|
|
463 | |
|
|
464 | Usually set to C<1> to make modules "less inquisitive" during their |
|
|
465 | installation, you can set any environment variable you want - some modules |
|
|
466 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
|
|
467 | |
|
|
468 | =item C<EXTRA_MODULES> |
|
|
469 | |
|
|
470 | Additional modules installed during F<staticperl install>. Here you can |
|
|
471 | set which modules you want have to installed from CPAN. |
|
|
472 | |
|
|
473 | Example: I really really need EV, AnyEvent, Coro and IO::AIO. |
|
|
474 | |
|
|
475 | EXTRA_MODULES="EV AnyEvent Coro IO::AIO" |
|
|
476 | |
|
|
477 | Note that you cna also use a C<postinstall> hook to achieve this, and |
|
|
478 | more. |
|
|
479 | |
|
|
480 | =back |
510 | =back |
481 | |
511 | |
482 | =head4 Variables you I<probably do not want> to override |
512 | =head4 Variables you probably I<do not want> to override |
483 | |
513 | |
484 | =over 4 |
514 | =over 4 |
485 | |
515 | |
486 | =item C<MKBUNDLE> |
516 | =item C<MKBUNDLE> |
487 | |
517 | |
… | |
… | |
497 | |
527 | |
498 | =head3 OVERRIDABLE HOOKS |
528 | =head3 OVERRIDABLE HOOKS |
499 | |
529 | |
500 | In addition to environment variables, it is possible to provide some |
530 | In addition to environment variables, it is possible to provide some |
501 | shell functions that are called at specific times. To provide your own |
531 | shell functions that are called at specific times. To provide your own |
502 | commands, justd efine the corresponding function. |
532 | commands, just define the corresponding function. |
503 | |
533 | |
504 | Example: install extra modules from CPAN and from some directories |
534 | Example: install extra modules from CPAN and from some directories |
505 | at F<staticperl install> time. |
535 | at F<staticperl install> time. |
506 | |
536 | |
507 | postinstall() { |
537 | postinstall() { |
508 | rm -rf lib/threads.* # weg mit Schaden |
538 | rm -rf lib/threads* # weg mit Schaden |
509 | instcpan IO::AIO EV |
539 | instcpan IO::AIO EV |
510 | instsrc ~/src/AnyEvent |
540 | instsrc ~/src/AnyEvent |
511 | instsrc ~/src/XML-Sablotron-1.0100001 |
541 | instsrc ~/src/XML-Sablotron-1.0100001 |
512 | instcpan AnyEvent::HTTPD |
542 | instcpan Anyevent::AIO AnyEvent::HTTPD |
513 | } |
543 | } |
514 | |
544 | |
515 | =over 4 |
545 | =over 4 |
516 | |
546 | |
517 | =item postconfigure |
547 | =item postconfigure |
… | |
… | |
543 | The script must return with a zero exit status, or the installation will |
573 | The script must return with a zero exit status, or the installation will |
544 | fail. |
574 | fail. |
545 | |
575 | |
546 | =back |
576 | =back |
547 | |
577 | |
|
|
578 | =head1 ANATOMY OF A BUNDLE |
|
|
579 | |
|
|
580 | When not building a new perl binary, C<mkbundle> will leave a number of |
|
|
581 | files in the current working directory, which can be used to embed a perl |
|
|
582 | interpreter in your program. |
|
|
583 | |
|
|
584 | Intimate knowledge of L<perlembed> and preferably some experience with |
|
|
585 | embedding perl is highly recommended. |
|
|
586 | |
|
|
587 | C<mkperl> (or the C<--perl> option) basically does this to link the new |
|
|
588 | interpreter (it also adds a main program to F<bundle.>): |
|
|
589 | |
|
|
590 | $Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts) |
|
|
591 | |
|
|
592 | =over 4 |
|
|
593 | |
|
|
594 | =item bundle.h |
|
|
595 | |
|
|
596 | A header file that contains the prototypes of the few symbols "exported" |
|
|
597 | by bundle.c, and also exposes the perl headers to the application. |
|
|
598 | |
|
|
599 | =over 4 |
|
|
600 | |
|
|
601 | =item staticperl_init () |
|
|
602 | |
|
|
603 | Initialises the perl interpreter. You can use the normal perl functions |
|
|
604 | after calling this function, for example, to define extra functions or |
|
|
605 | to load a .pm file that contains some initialisation code, or the main |
|
|
606 | program function: |
|
|
607 | |
|
|
608 | XS (xsfunction) |
|
|
609 | { |
|
|
610 | dXSARGS; |
|
|
611 | |
|
|
612 | // now we have items, ST(i) etc. |
|
|
613 | } |
|
|
614 | |
|
|
615 | static void |
|
|
616 | run_myapp(void) |
|
|
617 | { |
|
|
618 | staticperl_init (); |
|
|
619 | newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); |
|
|
620 | eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" |
|
|
621 | } |
|
|
622 | |
|
|
623 | =item staticperl_xs_init (pTHX) |
|
|
624 | |
|
|
625 | Sometimes you need direct control over C<perl_parse> and C<perl_run>, in |
|
|
626 | which case you do not want to use C<staticperl_init> but call them on your |
|
|
627 | own. |
|
|
628 | |
|
|
629 | Then you need this function - either pass it directly as the C<xs_init> |
|
|
630 | function to C<perl_parse>, or call it from your own C<xs_init> function. |
|
|
631 | |
|
|
632 | =item staticperl_cleanup () |
|
|
633 | |
|
|
634 | In the unlikely case that you want to destroy the perl interpreter, here |
|
|
635 | is the corresponding function. |
|
|
636 | |
|
|
637 | =item PerlInterpreter *staticperl |
|
|
638 | |
|
|
639 | The perl interpreter pointer used by staticperl. Not normally so useful, |
|
|
640 | but there it is. |
|
|
641 | |
|
|
642 | =back |
|
|
643 | |
|
|
644 | =item bundle.ccopts |
|
|
645 | |
|
|
646 | Contains the compiler options required to compile at least F<bundle.c> and |
|
|
647 | any file that includes F<bundle.h> - you should probably use it in your |
|
|
648 | C<CFLAGS>. |
|
|
649 | |
|
|
650 | =item bundle.ldopts |
|
|
651 | |
|
|
652 | The linker options needed to link the final program. |
|
|
653 | |
|
|
654 | =back |
|
|
655 | |
|
|
656 | =head1 RUNTIME FUNCTIONALITY |
|
|
657 | |
|
|
658 | Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which |
|
|
659 | are required to access the bundled perl sources, but might be useful for |
|
|
660 | other purposes. |
|
|
661 | |
|
|
662 | In addition, for the embedded loading of perl files to work, F<staticperl> |
|
|
663 | overrides the C<@INC> array. |
|
|
664 | |
|
|
665 | =over 4 |
|
|
666 | |
|
|
667 | =item $file = staticperl::find $path |
|
|
668 | |
|
|
669 | Returns the data associated with the given C<$path> |
|
|
670 | (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically |
|
|
671 | the UNIX path relative to the perl library directory. |
|
|
672 | |
|
|
673 | Returns C<undef> if the file isn't embedded. |
|
|
674 | |
|
|
675 | =item @paths = staticperl::list |
|
|
676 | |
|
|
677 | Returns the list of all paths embedded in this binary. |
|
|
678 | |
|
|
679 | =back |
|
|
680 | |
|
|
681 | =head1 FULLY STATIC BINARIES - BUILDROOT |
|
|
682 | |
|
|
683 | To make truly static (Linux-) libraries, you might want to have a look at |
|
|
684 | buildroot (L<http://buildroot.uclibc.org/>). |
|
|
685 | |
|
|
686 | Buildroot is primarily meant to set up a cross-compile environment (which |
|
|
687 | is not so useful as perl doesn't quite like cross compiles), but it can also compile |
|
|
688 | a chroot environment where you can use F<staticperl>. |
|
|
689 | |
|
|
690 | To do so, download buildroot, and enable "Build options => development |
|
|
691 | files in target filesystem" and optionally "Build options => gcc |
|
|
692 | optimization level (optimize for size)". At the time of writing, I had |
|
|
693 | good experiences with GCC 4.4.x but not GCC 4.5. |
|
|
694 | |
|
|
695 | To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections |
|
|
696 | -finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386> |
|
|
697 | doesn't decrease codesize much, but it makes the file much more |
|
|
698 | compressible. |
|
|
699 | |
|
|
700 | If you don't need Coro or threads, you can go with "linuxthreads.old" (or |
|
|
701 | no thread support). For Coro, it is highly recommended to switch to a |
|
|
702 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
|
|
703 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
|
|
704 | ultra-slow pthreads backend to work around linuxthreads bugs (it also uses |
|
|
705 | twice the address space needed for stacks). |
|
|
706 | |
|
|
707 | If you use C<linuxthreads.old>, then you should also be aware that |
|
|
708 | uClibc shares C<errno> between all threads when statically linking. See |
|
|
709 | L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a |
|
|
710 | workaround (And L<https://bugs.uclibc.org/2089> for discussion). |
|
|
711 | |
|
|
712 | C<ccache> support is also recommended, especially if you want to |
|
|
713 | play around with buildroot options. Enabling the C<miniperl> package |
|
|
714 | will probably enable all options required for a successful perl |
|
|
715 | build. F<staticperl> itself additionally needs either C<wget> or C<curl>. |
|
|
716 | |
|
|
717 | As for shells, busybox should provide all that is needed, but the default |
|
|
718 | busybox configuration doesn't include F<comm> which is needed by perl - |
|
|
719 | either make a custom busybox config, or compile coreutils. |
|
|
720 | |
|
|
721 | For the latter route, you might find that bash has some bugs that keep |
|
|
722 | it from working properly in a chroot - either use dash (and link it to |
|
|
723 | F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's |
|
|
724 | built-in ash shell. |
|
|
725 | |
|
|
726 | Finally, you need F</dev/null> inside the chroot for many scripts to work |
|
|
727 | - F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will |
|
|
728 | both provide this. |
|
|
729 | |
|
|
730 | After you have compiled and set up your buildroot target, you can copy |
|
|
731 | F<staticperl> from the C<App::Staticperl> distribution or from your |
|
|
732 | perl f<bin> directory (if you installed it) into the F<output/target> |
|
|
733 | filesystem, chroot inside and run it. |
|
|
734 | |
548 | =head1 AUTHOR |
735 | =head1 AUTHOR |
549 | |
736 | |
550 | Marc Lehmann <schmorp@schmorp.de> |
737 | Marc Lehmann <schmorp@schmorp.de> |
551 | http://software.schmorp.de/pkg/staticperl.html |
738 | http://software.schmorp.de/pkg/staticperl.html |