… | |
… | |
14 | staticperl cpan # invoke CPAN shell |
14 | staticperl cpan # invoke CPAN shell |
15 | staticperl instmod path... # install unpacked modules |
15 | staticperl instmod path... # install unpacked modules |
16 | staticperl instcpan modulename... # install modules from CPAN |
16 | staticperl instcpan modulename... # install modules from CPAN |
17 | staticperl mkbundle <bundle-args...> # see documentation |
17 | staticperl mkbundle <bundle-args...> # see documentation |
18 | staticperl mkperl <bundle-args...> # see documentation |
18 | staticperl mkperl <bundle-args...> # see documentation |
|
|
19 | staticperl mkapp appname <bundle-args...> # see documentation |
19 | |
20 | |
20 | Typical Examples: |
21 | Typical Examples: |
21 | |
22 | |
22 | staticperl install # fetch, configure, build and install perl |
23 | staticperl install # fetch, configure, build and install perl |
23 | staticperl cpan # run interactive cpan shell |
24 | staticperl cpan # run interactive cpan shell |
24 | staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V |
25 | staticperl mkperl -M '"Config_heavy.pl"' # build a perl that supports -V |
25 | staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http |
26 | staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http |
26 | # build a perl with the above modules linked in |
27 | # build a perl with the above modules linked in |
|
|
28 | staticperl mkapp myapp --boot mainprog mymodules |
|
|
29 | # build a binary "myapp" from mainprog and mymodules |
27 | |
30 | |
28 | =head1 DESCRIPTION |
31 | =head1 DESCRIPTION |
29 | |
32 | |
30 | This script helps you creating single-file perl interpreters, or embedding |
33 | This script helps you to create single-file perl interpreters |
31 | a perl interpreter in your applications. Single-file means that it is |
34 | or applications, or embedding a perl interpreter in your |
32 | fully self-contained - no separate shared objects, no autoload fragments, |
35 | applications. Single-file means that it is fully self-contained - no |
33 | no .pm or .pl files are needed. And when linking statically, you can |
36 | separate shared objects, no autoload fragments, no .pm or .pl files are |
34 | create (or embed) a single file that contains perl interpreter, libc, all |
37 | needed. And when linking statically, you can create (or embed) a single |
35 | the modules you need and all the libraries you need. |
38 | file that contains perl interpreter, libc, all the modules you need, all |
|
|
39 | the libraries you need and of course your actual program. |
36 | |
40 | |
37 | 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 |
38 | 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, |
39 | Coro and so on. Or any other choice of modules. |
43 | Coro and so on. Or any other choice of modules. |
40 | |
44 | |
… | |
… | |
81 | Maintaining your own custom perl build can be a pain in the ass, and while |
85 | Maintaining your own custom perl build can be a pain in the ass, and while |
82 | F<staticperl> tries to make this easy, it still requires a custom perl |
86 | F<staticperl> tries to make this easy, it still requires a custom perl |
83 | build and possibly fiddling with some modules. PAR is likely to produce |
87 | build and possibly fiddling with some modules. PAR is likely to produce |
84 | results faster. |
88 | results faster. |
85 | |
89 | |
|
|
90 | Ok, PAR never has worked for me out of the box, and for some people, |
|
|
91 | F<staticperl> does work out of the box, as they don't count "fiddling with |
|
|
92 | module use lists" against it, but nevertheless, F<staticperl> is certainly |
|
|
93 | a bit more difficult to use. |
|
|
94 | |
86 | =back |
95 | =back |
87 | |
96 | |
88 | =head1 HOW DOES IT WORK? |
97 | =head1 HOW DOES IT WORK? |
89 | |
98 | |
90 | Simple: F<staticperl> downloads, compile and installs a perl version of |
99 | Simple: F<staticperl> downloads, compile and installs a perl version of |
… | |
… | |
184 | command by specifying all the directories with modules in them that you |
193 | command by specifying all the directories with modules in them that you |
185 | want to have built. |
194 | want to have built. |
186 | |
195 | |
187 | =item F<staticperl clean> |
196 | =item F<staticperl clean> |
188 | |
197 | |
189 | Runs F<make distclean> in the perl source directory (and potentially |
198 | Deletes the perl source directory (and potentially cleans up other |
190 | cleans up other intermediate files). This can be used to clean up |
199 | intermediate files). This can be used to clean up files only needed for |
191 | intermediate files without removing the installed perl interpreter. |
200 | building perl, without removing the installed perl interpreter, or to |
|
|
201 | force a re-build from scratch. |
|
|
202 | |
|
|
203 | At the moment, it doesn't delete downloaded tarballs. |
192 | |
204 | |
193 | =item F<staticperl distclean> |
205 | =item F<staticperl distclean> |
194 | |
206 | |
195 | This wipes your complete F<~/.staticperl> directory. Be careful with this, |
207 | This wipes your complete F<~/.staticperl> directory. Be careful with this, |
196 | it nukes your perl download, perl sources, perl distribution and any |
208 | it nukes your perl download, perl sources, perl distribution and any |
… | |
… | |
236 | (required by L<AnyEvent::HTTPD>) implements various URI schemes as extra |
248 | (required by L<AnyEvent::HTTPD>) implements various URI schemes as extra |
237 | modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need |
249 | modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need |
238 | to include that module. I found out about these dependencies by carefully |
250 | to include that module. I found out about these dependencies by carefully |
239 | watching any error messages about missing modules... |
251 | watching any error messages about missing modules... |
240 | |
252 | |
|
|
253 | Instead of building a new perl binary, you can also build a standalone |
|
|
254 | application: |
|
|
255 | |
|
|
256 | # build the app |
|
|
257 | staticperl mkapp app --boot eg/httpd \ |
|
|
258 | -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http |
|
|
259 | |
|
|
260 | # run it |
|
|
261 | ./app |
|
|
262 | |
241 | =head3 OPTION PROCESSING |
263 | =head3 OPTION PROCESSING |
242 | |
264 | |
243 | All options can be given as arguments on the command line (typically |
265 | All options can be given as arguments on the command line (typically |
244 | using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
266 | using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since |
245 | specifying a lot of modules can make the command line very cumbersome, |
267 | specifying a lot of modules can make the command line very cumbersome, |
… | |
… | |
304 | C<mkperl> command (instead of C<mkbundle>): |
326 | C<mkperl> command (instead of C<mkbundle>): |
305 | |
327 | |
306 | # build a new ./perl with only common::sense in it - very small :) |
328 | # build a new ./perl with only common::sense in it - very small :) |
307 | staticperl mkperl -Mcommon::sense |
329 | staticperl mkperl -Mcommon::sense |
308 | |
330 | |
|
|
331 | =item --app name |
|
|
332 | |
|
|
333 | After writing out the bundle files, try to link a new standalone |
|
|
334 | program. It will be called C<name>, and the bundle files get removed after |
|
|
335 | linking it. |
|
|
336 | |
|
|
337 | The difference to the (mutually exclusive) C<--perl> option is that the |
|
|
338 | binary created by this option will not try to act as a perl interpreter - |
|
|
339 | instead it will simply initialise the perl interpreter, clean it up and |
|
|
340 | exit. |
|
|
341 | |
|
|
342 | This switch is automatically used when F<staticperl> is invoked with the |
|
|
343 | C<mkapp> command (instead of C<mkbundle>): |
|
|
344 | |
|
|
345 | To let it do something useful you I<must> add some boot code, e.g. with |
|
|
346 | the C<--boot> option. |
|
|
347 | |
|
|
348 | Example: create a standalone perl binary that will execute F<appfile> when |
|
|
349 | it is started. |
|
|
350 | |
|
|
351 | staticperl mkbundle --app myexe --boot appfile |
|
|
352 | |
309 | =item --use module | -Mmodule |
353 | =item --use module | -Mmodule |
310 | |
354 | |
311 | Include the named module and all direct dependencies. This is done by |
355 | Include the named module and all direct dependencies. This is done by |
312 | C<require>'ing the module in a subprocess and tracing which other modules |
356 | C<require>'ing the module in a subprocess and tracing which other modules |
313 | and files it actually loads. If the module uses L<AutoLoader>, then all |
357 | and files it actually loads. If the module uses L<AutoLoader>, then all |
… | |
… | |
383 | # specification file |
427 | # specification file |
384 | add file1 myfiles/file1 |
428 | add file1 myfiles/file1 |
385 | add file2 myfiles/file2 |
429 | add file2 myfiles/file2 |
386 | add file3 myfiles/file3 |
430 | add file3 myfiles/file3 |
387 | |
431 | |
|
|
432 | =item --binadd "file" | --add "file alias" |
|
|
433 | |
|
|
434 | Just like C<--add>, except that it treats the file as binary and adds it |
|
|
435 | without any processing. |
|
|
436 | |
|
|
437 | You should probably add a C</> prefix to avoid clashing with embedded |
|
|
438 | perl files (whose paths do not start with C</>), and/or use a special |
|
|
439 | directory, such as C</res/name>. |
|
|
440 | |
|
|
441 | You can later get a copy of these files by calling C<staticperl::find |
|
|
442 | "alias">. |
|
|
443 | |
388 | =item --static |
444 | =item --static |
389 | |
445 | |
390 | When C<--perl> is also given, link statically instead of dynamically. The |
446 | When C<--perl> is also given, link statically instead of dynamically. The |
391 | default is to link the new perl interpreter fully dynamic (that means all |
447 | default is to link the new perl interpreter fully dynamic (that means all |
392 | perl modules are linked statically, but all external libraries are still |
448 | perl modules are linked statically, but all external libraries are still |
… | |
… | |
403 | Any other argument is interpreted as a bundle specification file, which |
459 | Any other argument is interpreted as a bundle specification file, which |
404 | supports most long options (without extra quoting), one option per line. |
460 | supports most long options (without extra quoting), one option per line. |
405 | |
461 | |
406 | =back |
462 | =back |
407 | |
463 | |
408 | =head2 F<STATCPERL> CONFIGURATION AND HOOKS |
464 | =head2 F<STATICPERL> CONFIGURATION AND HOOKS |
409 | |
465 | |
410 | During (each) startup, F<staticperl> tries to source the following shell |
466 | During (each) startup, F<staticperl> tries to source the following shell |
411 | files in order: |
467 | files in order: |
412 | |
468 | |
413 | /etc/staticperlrc |
469 | /etc/staticperlrc |
… | |
… | |
429 | =item C<EMAIL> |
485 | =item C<EMAIL> |
430 | |
486 | |
431 | The e-mail address of the person who built this binary. Has no good |
487 | The e-mail address of the person who built this binary. Has no good |
432 | default, so should be specified by you. |
488 | default, so should be specified by you. |
433 | |
489 | |
|
|
490 | =item C<CPAN> |
|
|
491 | |
|
|
492 | The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). |
|
|
493 | |
|
|
494 | =item C<EXTRA_MODULES> |
|
|
495 | |
|
|
496 | Additional modules installed during F<staticperl install>. Here you can |
|
|
497 | set which modules you want have to installed from CPAN. |
|
|
498 | |
|
|
499 | Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO. |
|
|
500 | |
|
|
501 | EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO" |
|
|
502 | |
|
|
503 | Note that you can also use a C<postinstall> hook to achieve this, and |
|
|
504 | more. |
|
|
505 | |
434 | =back |
506 | =back |
435 | |
507 | |
436 | =head4 Variables you might I<want> to override |
508 | =head4 Variables you might I<want> to override |
437 | |
509 | |
438 | =over 4 |
510 | =over 4 |
439 | |
511 | |
|
|
512 | =item C<STATICPERL> |
|
|
513 | |
|
|
514 | The directory where staticperl stores all its files |
|
|
515 | (default: F<~/.staticperl>). |
|
|
516 | |
|
|
517 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
|
|
518 | |
|
|
519 | Usually set to C<1> to make modules "less inquisitive" during their |
|
|
520 | installation, you can set any environment variable you want - some modules |
|
|
521 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
|
|
522 | |
440 | =item C<PERLVER> |
523 | =item C<PERL_VERSION> |
441 | |
524 | |
442 | The perl version to install - default is currently C<5.12.2>, but C<5.8.9> |
525 | The perl version to install - default is currently C<5.12.2>, but C<5.8.9> |
443 | is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is |
526 | is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is |
444 | about as big as 5.12.2). |
527 | about as big as 5.12.2). |
445 | |
528 | |
446 | =item C<CPAN> |
|
|
447 | |
|
|
448 | The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). |
|
|
449 | |
|
|
450 | =item C<EXTRA_MODULES> |
|
|
451 | |
|
|
452 | Additional modules installed during F<staticperl install>. Here you can |
|
|
453 | set which modules you want have to installed from CPAN. |
|
|
454 | |
|
|
455 | Example: I really really need EV, AnyEvent, Coro and IO::AIO. |
|
|
456 | |
|
|
457 | EXTRA_MODULES="EV AnyEvent Coro IO::AIO" |
|
|
458 | |
|
|
459 | Note that you can also use a C<postinstall> hook to achieve this, and |
|
|
460 | more. |
|
|
461 | |
|
|
462 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
|
|
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<STATICPERL> |
|
|
469 | |
|
|
470 | The directory where staticperl stores all its files |
|
|
471 | (default: F<~/.staticperl>). |
|
|
472 | |
|
|
473 | =item C<PREFIX> |
529 | =item C<PERL_PREFIX> |
474 | |
530 | |
475 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
531 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
476 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
532 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
|
|
533 | |
|
|
534 | =item C<PERL_CONFIGURE> |
|
|
535 | |
|
|
536 | Additional Configure options - these are simply passed to the perl |
|
|
537 | Configure script. For example, if you wanted to enable dynamic loading, |
|
|
538 | you could pass C<-Dusedl>. To enable ithreads (Why would you want that |
|
|
539 | insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads> |
|
|
540 | and so on. |
|
|
541 | |
|
|
542 | More commonly, you would either activate 64 bit integer support |
|
|
543 | (C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to |
|
|
544 | reduce filesize further. |
477 | |
545 | |
478 | =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
546 | =item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> |
479 | |
547 | |
480 | These flags are passed to perl's F<Configure> script, and are generally |
548 | These flags are passed to perl's F<Configure> script, and are generally |
481 | optimised for small size (at the cost of performance). Since they also |
549 | optimised for small size (at the cost of performance). Since they also |
… | |
… | |
518 | instcpan Anyevent::AIO AnyEvent::HTTPD |
586 | instcpan Anyevent::AIO AnyEvent::HTTPD |
519 | } |
587 | } |
520 | |
588 | |
521 | =over 4 |
589 | =over 4 |
522 | |
590 | |
|
|
591 | =item preconfigure |
|
|
592 | |
|
|
593 | Called just before running F<./Configur> in the perl source |
|
|
594 | directory. Current working directory is the perl source directory. |
|
|
595 | |
|
|
596 | This can be used to set any C<PERL_xxx> variables, which might be costly |
|
|
597 | to compute. |
|
|
598 | |
523 | =item postconfigure |
599 | =item postconfigure |
524 | |
600 | |
525 | Called after configuring, but before building perl. Current working |
601 | Called after configuring, but before building perl. Current working |
526 | directory is the perl source directory. |
602 | directory is the perl source directory. |
527 | |
603 | |
528 | Could be used to tailor/patch config.sh (followed by F<./Configure -S>) or |
604 | Could be used to tailor/patch config.sh (followed by F<sh Configure -S>) |
529 | do any other modifications. |
605 | or do any other modifications. |
530 | |
606 | |
531 | =item postbuild |
607 | =item postbuild |
532 | |
608 | |
533 | Called after building, but before installing perl. Current working |
609 | Called after building, but before installing perl. Current working |
534 | directory is the perl source directory. |
610 | directory is the perl source directory. |
… | |
… | |
654 | |
730 | |
655 | =back |
731 | =back |
656 | |
732 | |
657 | =head1 FULLY STATIC BINARIES - BUILDROOT |
733 | =head1 FULLY STATIC BINARIES - BUILDROOT |
658 | |
734 | |
659 | To make truly static (linux-) libraries, you might want to have a look at |
735 | To make truly static (Linux-) libraries, you might want to have a look at |
660 | buildroot (L<http://buildroot.uclibc.org/>). |
736 | buildroot (L<http://buildroot.uclibc.org/>). |
661 | |
737 | |
662 | Buildroot is primarily meant to set up a cross-compile environment (which |
738 | Buildroot is primarily meant to set up a cross-compile environment (which |
663 | is not so useful as perl doesn't quite like cross compiles), but it can also compile |
739 | is not so useful as perl doesn't quite like cross compiles), but it can also compile |
664 | a chroot environment where you can use F<staticperl>. |
740 | a chroot environment where you can use F<staticperl>. |
… | |
… | |
678 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
754 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
679 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
755 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
680 | ultra-slow pthreads backend to work around linuxthreads bugs (it also uses |
756 | ultra-slow pthreads backend to work around linuxthreads bugs (it also uses |
681 | twice the address space needed for stacks). |
757 | twice the address space needed for stacks). |
682 | |
758 | |
|
|
759 | If you use C<linuxthreads.old>, then you should also be aware that |
|
|
760 | uClibc shares C<errno> between all threads when statically linking. See |
|
|
761 | L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a |
|
|
762 | workaround (And L<https://bugs.uclibc.org/2089> for discussion). |
|
|
763 | |
683 | C<ccache> support is also recommended, especially if you want to |
764 | C<ccache> support is also recommended, especially if you want |
684 | play around with buildroot options. Enabling the C<miniperl> package |
765 | to play around with buildroot options. Enabling the C<miniperl> |
685 | will probably enable all options required for a successful perl |
766 | package will probably enable all options required for a successful |
686 | build. F<staticperl> itself additionally needs either C<wget> or C<curl>. |
767 | perl build. F<staticperl> itself additionally needs either C<wget> |
|
|
768 | (recommended, for CPAN) or C<curl>. |
687 | |
769 | |
688 | As for shells, busybox should provide all that is needed, but the default |
770 | As for shells, busybox should provide all that is needed, but the default |
689 | busybox configuration doesn't include F<comm> which is needed by perl - |
771 | busybox configuration doesn't include F<comm> which is needed by perl - |
690 | either make a custom busybox config, or compile coreutils. |
772 | either make a custom busybox config, or compile coreutils. |
691 | |
773 | |