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

Comparing App-Staticperl/staticperl.pod (file contents):
Revision 1.4 by root, Mon Dec 6 21:12:21 2010 UTC vs.
Revision 1.13 by root, Tue Dec 7 19:55:56 2010 UTC

1=head1 NAME 1=head1 NAME
2 2
3staticperl - perl, libc, 50 modules all in one 500kb file 3staticperl - 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
32fully self-contained - no separate shared objects, no autoload fragments, 32fully self-contained - no separate shared objects, no autoload fragments,
33no .pm or .pl files are needed. And when linking statically, you can 33no .pm or .pl files are needed. And when linking statically, you can
34create (or embed) a single file that contains perl interpreter, libc, all 34create (or embed) a single file that contains perl interpreter, libc, all
35the modules you need and all the libraries you need. 35the modules you need and all the libraries you need.
36 36
37With F<uClibc> and F<upx> on x86, you can create a single 500kb binary that 37With F<uClibc> and F<upx> on x86, you can create a single 500kb binary
38contains perl and 50 modules such as AnyEvent, EV, IO::AIO, Coro and so 38that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO,
39on. Or any other choice of modules. 39Coro and so on. Or any other choice of modules.
40 40
41The created files do not need write access to the file system (like PAR 41The created files do not need write access to the file system (like PAR
42does). In fact, since this script is in many ways similar to PAR::Packer, 42does). In fact, since this script is in many ways similar to PAR::Packer,
43here are the differences: 43here are the differences:
44 44
81Maintaining your own custom perl build can be a pain in the ass, and while 81Maintaining your own custom perl build can be a pain in the ass, and while
82F<staticperl> tries to make this easy, it still requires a custom perl 82F<staticperl> tries to make this easy, it still requires a custom perl
83build and possibly fiddling with some modules. PAR is likely to produce 83build and possibly fiddling with some modules. PAR is likely to produce
84results faster. 84results faster.
85 85
86Ok, PAR never has worked for me out of the box, and for some people,
87F<staticperl> does work out of the box, as they don't count "fiddling with
88module use lists" against it, but nevertheless, F<staticperl> is certainly
89a bit more difficult to use.
90
86=back 91=back
87 92
88=head1 HOW DOES IT WORK? 93=head1 HOW DOES IT WORK?
89 94
90Simple: F<staticperl> downloads, compile and installs a perl version of 95Simple: F<staticperl> downloads, compile and installs a perl version of
184command by specifying all the directories with modules in them that you 189command by specifying all the directories with modules in them that you
185want to have built. 190want to have built.
186 191
187=item F<staticperl clean> 192=item F<staticperl clean>
188 193
189Runs F<make distclean> in the perl source directory (and potentially 194Deletes the perl source directory (and potentially cleans up other
190cleans up other intermediate files). This can be used to clean up 195intermediate files). This can be used to clean up files only needed for
191intermediate files without removing the installed perl interpreter. 196building perl, without removing the installed perl interpreter, or to
197force a re-build from scratch.
198
199At the moment, it doesn't delete downloaded tarballs.
192 200
193=item F<staticperl distclean> 201=item F<staticperl distclean>
194 202
195This wipes your complete F<~/.staticperl> directory. Be careful with this, 203This wipes your complete F<~/.staticperl> directory. Be careful with this,
196it nukes your perl download, perl sources, perl distribution and any 204it nukes your perl download, perl sources, perl distribution and any
287is also a lot slower, so is best used for production builds. Note that 295is also a lot slower, so is best used for production builds. Note that
288this method doesn't optimise for raw file size, but for best compression 296this 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 297(that means that the uncompressed file size is a bit larger, but the files
290compress better, e.g. with F<upx>). 298compress better, e.g. with F<upx>).
291 299
300Last not least, if you need accurate line numbers in error messages,
292Last not least, in the unlikely case where C<pod> is too slow, or some 301or in the unlikely case where C<pod> is too slow, or some module gets
293module gets mistreated, you can specify C<none> to not mangle included 302mistreated, you can specify C<none> to not mangle included perl sources in
294perl sources in any way. 303any way.
295 304
296=item --perl 305=item --perl
297 306
298After writing out the bundle files, try to link a new perl interpreter. It 307After writing out the bundle files, try to link a new perl interpreter. It
299will be called F<perl> and will be left in the current working 308will be called F<perl> and will be left in the current working
382 # specification file 391 # specification file
383 add file1 myfiles/file1 392 add file1 myfiles/file1
384 add file2 myfiles/file2 393 add file2 myfiles/file2
385 add file3 myfiles/file3 394 add file3 myfiles/file3
386 395
396=item --binadd "file" | --add "file alias"
397
398Just like C<--add>, except that it treats the file as binary and adds it
399without any processing.
400
401You should probably add a C</> prefix to avoid clashing with embedded
402perl files (whose paths do not start with C</>), and/or use a special
403directory, such as C</res/name>.
404
405You can later get a copy of these files by calling C<staticperl::find
406"alias">.
407
387=item --static 408=item --static
388 409
389When C<--perl> is also given, link statically instead of dynamically. The 410When C<--perl> is also given, link statically instead of dynamically. The
390default is to link the new perl interpreter fully dynamic (that means all 411default is to link the new perl interpreter fully dynamic (that means all
391perl modules are linked statically, but all external libraries are still 412perl modules are linked statically, but all external libraries are still
428=item C<EMAIL> 449=item C<EMAIL>
429 450
430The e-mail address of the person who built this binary. Has no good 451The e-mail address of the person who built this binary. Has no good
431default, so should be specified by you. 452default, so should be specified by you.
432 453
433=back 454=item C<CPAN>
434 455
456The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>).
457
458=item C<EXTRA_MODULES>
459
460Additional modules installed during F<staticperl install>. Here you can
461set which modules you want have to installed from CPAN.
462
463Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO.
464
465 EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO"
466
467Note that you can also use a C<postinstall> hook to achieve this, and
468more.
469
470=back
471
435=head4 Variables you I<might want> to override 472=head4 Variables you might I<want> to override
436 473
437=over 4 474=over 4
438 475
476=item C<STATICPERL>
477
478The directory where staticperl stores all its files
479(default: F<~/.staticperl>).
480
481=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ...
482
483Usually set to C<1> to make modules "less inquisitive" during their
484installation, you can set any environment variable you want - some modules
485(such as L<Coro> or L<EV>) use environment variables for further tweaking.
486
439=item C<PERLVER> 487=item C<PERL_VERSION>
440 488
441The perl version to install - default is currently C<5.12.2>, but C<5.8.9> 489The perl version to install - default is currently C<5.12.2>, but C<5.8.9>
442is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is 490is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is
443about as big as 5.12.2). 491about as big as 5.12.2).
444 492
445=item C<CPAN> 493=item C<PERL_PREFIX>
446 494
447The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). 495The prefix where perl gets installed (default: F<$STATICPERL/perl>),
496i.e. where the F<bin> and F<lib> subdirectories will end up.
497
498=item C<PERL_CONFIGURE>
499
500Additional Configure options - these are simply passed to the perl
501Configure script. For example, if you wanted to enable dynamic loading,
502you could pass C<-Dusedl>. To enable ithreads (Why would you want that
503insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads>
504and so on.
505
506More commonly, you would either activate 64 bit integer support
507(C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to
508reduce filesize further.
448 509
449=item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> 510=item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS>
450 511
451These flags are passed to perl's F<Configure> script, and are generally 512These flags are passed to perl's F<Configure> script, and are generally
452optimised for small size (at the cost of performance). Since they also 513optimised for small size (at the cost of performance). Since they also
453contain subtle workarounds around various build issues, changing these 514contain subtle workarounds around various build issues, changing these
454usually requires understanding their default values - best look at the top 515usually requires understanding their default values - best look at the top
455of the F<staticperl> script for more info on these. 516of the F<staticperl> script for more info on these.
456 517
457=item C<STATICPERL>
458
459The directory where staticperl stores all its files
460(default: F<~/.staticperl>).
461
462=item C<PREFIX>
463
464The prefix where perl gets installed (default: F<$STATICPERL/perl>),
465i.e. where the F<bin> and F<lib> subdirectories will end up.
466
467=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, others
468
469Usually set to C<1> to make modules "less inquisitive" during their
470installation, you can set any environment variable you want - some modules
471(such as L<Coro> or L<EV>) use environment variables for further tweaking.
472
473=item C<EXTRA_MODULES>
474
475Additional modules installed during F<staticperl install>. Here you can
476set which modules you want have to installed from CPAN.
477
478Example: I really really need EV, AnyEvent, Coro and IO::AIO.
479
480 EXTRA_MODULES="EV AnyEvent Coro IO::AIO"
481
482Note that you can also use a C<postinstall> hook to achieve this, and
483more.
484
485=back 518=back
486 519
487=head4 Variables you I<probably do not want> to override 520=head4 Variables you probably I<do not want> to override
488 521
489=over 4 522=over 4
490 523
491=item C<MKBUNDLE> 524=item C<MKBUNDLE>
492 525
517 instcpan Anyevent::AIO AnyEvent::HTTPD 550 instcpan Anyevent::AIO AnyEvent::HTTPD
518 } 551 }
519 552
520=over 4 553=over 4
521 554
555=item preconfigure
556
557Called just before running F<./Configur> in the perl source
558directory. Current working directory is the perl source directory.
559
560This can be used to set any C<PERL_xxx> variables, which might be costly
561to compute.
562
522=item postconfigure 563=item postconfigure
523 564
524Called after configuring, but before building perl. Current working 565Called after configuring, but before building perl. Current working
525directory is the perl source directory. 566directory is the perl source directory.
526 567
527Could be used to tailor/patch config.sh (followed by F<./Configure -S>) or 568Could be used to tailor/patch config.sh (followed by F<sh Configure -S>)
528do any other modifications. 569or do any other modifications.
529 570
530=item postbuild 571=item postbuild
531 572
532Called after building, but before installing perl. Current working 573Called after building, but before installing perl. Current working
533directory is the perl source directory. 574directory is the perl source directory.
548The script must return with a zero exit status, or the installation will 589The script must return with a zero exit status, or the installation will
549fail. 590fail.
550 591
551=back 592=back
552 593
594=head1 ANATOMY OF A BUNDLE
595
596When not building a new perl binary, C<mkbundle> will leave a number of
597files in the current working directory, which can be used to embed a perl
598interpreter in your program.
599
600Intimate knowledge of L<perlembed> and preferably some experience with
601embedding perl is highly recommended.
602
603C<mkperl> (or the C<--perl> option) basically does this to link the new
604interpreter (it also adds a main program to F<bundle.>):
605
606 $Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts)
607
608=over 4
609
610=item bundle.h
611
612A header file that contains the prototypes of the few symbols "exported"
613by bundle.c, and also exposes the perl headers to the application.
614
615=over 4
616
617=item staticperl_init ()
618
619Initialises the perl interpreter. You can use the normal perl functions
620after calling this function, for example, to define extra functions or
621to load a .pm file that contains some initialisation code, or the main
622program function:
623
624 XS (xsfunction)
625 {
626 dXSARGS;
627
628 // now we have items, ST(i) etc.
629 }
630
631 static void
632 run_myapp(void)
633 {
634 staticperl_init ();
635 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
636 eval_pv ("require myapp::main", 1); // executes "myapp/main.pm"
637 }
638
639=item staticperl_xs_init (pTHX)
640
641Sometimes you need direct control over C<perl_parse> and C<perl_run>, in
642which case you do not want to use C<staticperl_init> but call them on your
643own.
644
645Then you need this function - either pass it directly as the C<xs_init>
646function to C<perl_parse>, or call it from your own C<xs_init> function.
647
648=item staticperl_cleanup ()
649
650In the unlikely case that you want to destroy the perl interpreter, here
651is the corresponding function.
652
653=item PerlInterpreter *staticperl
654
655The perl interpreter pointer used by staticperl. Not normally so useful,
656but there it is.
657
658=back
659
660=item bundle.ccopts
661
662Contains the compiler options required to compile at least F<bundle.c> and
663any file that includes F<bundle.h> - you should probably use it in your
664C<CFLAGS>.
665
666=item bundle.ldopts
667
668The linker options needed to link the final program.
669
670=back
671
672=head1 RUNTIME FUNCTIONALITY
673
674Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which
675are required to access the bundled perl sources, but might be useful for
676other purposes.
677
678In addition, for the embedded loading of perl files to work, F<staticperl>
679overrides the C<@INC> array.
680
681=over 4
682
683=item $file = staticperl::find $path
684
685Returns the data associated with the given C<$path>
686(e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically
687the UNIX path relative to the perl library directory.
688
689Returns C<undef> if the file isn't embedded.
690
691=item @paths = staticperl::list
692
693Returns the list of all paths embedded in this binary.
694
695=back
696
697=head1 FULLY STATIC BINARIES - BUILDROOT
698
699To make truly static (Linux-) libraries, you might want to have a look at
700buildroot (L<http://buildroot.uclibc.org/>).
701
702Buildroot is primarily meant to set up a cross-compile environment (which
703is not so useful as perl doesn't quite like cross compiles), but it can also compile
704a chroot environment where you can use F<staticperl>.
705
706To do so, download buildroot, and enable "Build options => development
707files in target filesystem" and optionally "Build options => gcc
708optimization level (optimize for size)". At the time of writing, I had
709good experiences with GCC 4.4.x but not GCC 4.5.
710
711To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections
712-finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386>
713doesn't decrease codesize much, but it makes the file much more
714compressible.
715
716If you don't need Coro or threads, you can go with "linuxthreads.old" (or
717no thread support). For Coro, it is highly recommended to switch to a
718uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201
719snapshot) and enable NPTL, otherwise Coro needs to be configured with the
720ultra-slow pthreads backend to work around linuxthreads bugs (it also uses
721twice the address space needed for stacks).
722
723If you use C<linuxthreads.old>, then you should also be aware that
724uClibc shares C<errno> between all threads when statically linking. See
725L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a
726workaround (And L<https://bugs.uclibc.org/2089> for discussion).
727
728C<ccache> support is also recommended, especially if you want
729to play around with buildroot options. Enabling the C<miniperl>
730package will probably enable all options required for a successful
731perl build. F<staticperl> itself additionally needs either C<wget>
732(recommended, for CPAN) or C<curl>.
733
734As for shells, busybox should provide all that is needed, but the default
735busybox configuration doesn't include F<comm> which is needed by perl -
736either make a custom busybox config, or compile coreutils.
737
738For the latter route, you might find that bash has some bugs that keep
739it from working properly in a chroot - either use dash (and link it to
740F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's
741built-in ash shell.
742
743Finally, you need F</dev/null> inside the chroot for many scripts to work
744- F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will
745both provide this.
746
747After you have compiled and set up your buildroot target, you can copy
748F<staticperl> from the C<App::Staticperl> distribution or from your
749perl f<bin> directory (if you installed it) into the F<output/target>
750filesystem, chroot inside and run it.
751
553=head1 AUTHOR 752=head1 AUTHOR
554 753
555 Marc Lehmann <schmorp@schmorp.de> 754 Marc Lehmann <schmorp@schmorp.de>
556 http://software.schmorp.de/pkg/staticperl.html 755 http://software.schmorp.de/pkg/staticperl.html

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines