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.2 by root, Mon Dec 6 20:53:44 2010 UTC vs.
Revision 1.12 by root, Tue Dec 7 13:23:07 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
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
30This script helps you creating single-file perl interpreters, or embedding 30This script helps you creating single-file perl interpreters, or embedding
31a pelr interpreter in your apps. Single-file means that it is fully 31a perl interpreter in your applications. Single-file means that it is
32self-contained - no separate shared objects, no autoload fragments, no .pm 32fully self-contained - no separate shared objects, no autoload fragments,
33or .pl files are needed. And when linking statically, you can create (or 33no .pm or .pl files are needed. And when linking statically, you can
34embed) a single file that contains perl interpreter, libc, all the modules 34create (or embed) a single file that contains perl interpreter, libc, all
35you need and all the libraries you need. 35the modules you need and all the libraries you need.
36 36
37With uclibc and 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 filesystem (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
45=over 4 45=over 4
46 46
65F<staticperl> loads all required files directly from memory. There is no 65F<staticperl> loads all required files directly from memory. There is no
66need to unpack files into a temporary directory. 66need 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
70PAR tries to be maintainance and hassle-free - it tries to include more files 70PAR tries to be maintenance and hassle-free - it tries to include more
71than necessary to make sure everything works out of the box. The extra files 71files 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. 72extra files (such as the unicode database) can take substantial amounts of
73memory and file size.
73 74
74With F<staticperl>, the burden is mostly with the developer - only direct 75With F<staticperl>, the burden is mostly with the developer - only direct
75compile-time dependencies and L<AutoLoader> are handled automatically. 76compile-time dependencies and L<AutoLoader> are handled automatically.
76This means the modules to include often need to be tweaked manually. 77This means the modules to include often need to be tweaked manually.
77 78
88 89
89Simple: F<staticperl> downloads, compile and installs a perl version of 90Simple: F<staticperl> downloads, compile and installs a perl version of
90your choice in F<~/.staticperl>. You can add extra modules either by 91your choice in F<~/.staticperl>. You can add extra modules either by
91letting F<staticperl> install them for you automatically, or by using CPAN 92letting F<staticperl> install them for you automatically, or by using CPAN
92and doing it interactively. This usually takes 5-10 minutes, depending on 93and doing it interactively. This usually takes 5-10 minutes, depending on
93the speed of your computer and your internet conenction. 94the speed of your computer and your internet connection.
94 95
95It is possible to do program development at this stage, too. 96It is possible to do program development at this stage, too.
96 97
97Afterwards, you create a list of files and modules you want to include, 98Afterwards, you create a list of files and modules you want to include,
98and then either build a new perl binary (that acts just like a normla perl 99and then either build a new perl binary (that acts just like a normal perl
99except everything is compiled in), or you create bundle files (basically C 100except everything is compiled in), or you create bundle files (basically C
100sources you can use to embed all files into your project). 101sources you can use to embed all files into your project).
101 102
102This step is very fast (a few seconds if PPI is not used for stripping, 103This step is very fast (a few seconds if PPI is not used for stripping,
103more seconds otherwise, as PPI is very slow), and can be tweaked and 104more seconds otherwise, as PPI is very slow), and can be tweaked and
134perl interpreter if required. 135perl interpreter if required.
135 136
136Most of the following commands simply run one or more steps of this 137Most of the following commands simply run one or more steps of this
137sequence. 138sequence.
138 139
139To force recompilation or reinstalaltion, you need to run F<staticperl 140To force recompilation or reinstallation, you need to run F<staticperl
140distclean> first. 141distclean> first.
141 142
142=over 4 143=over 4
143 144
144=item F<staticperl fetch> 145=item F<staticperl fetch>
154Builds the configured perl sources, potentially after automatically 155Builds the configured perl sources, potentially after automatically
155configuring them. 156configuring them.
156 157
157=item F<staticperl install> 158=item F<staticperl install>
158 159
159Wipes the perl installation directory (usually F<~/.staticperl/perl>) and installs 160Wipes the perl installation directory (usually F<~/.staticperl/perl>) and
160the perl distribution, potentially aftering building it first. 161installs the perl distribution, potentially after building it first.
161 162
162=item F<staticperl cpan> [args...] 163=item F<staticperl cpan> [args...]
163 164
164Starts an interactive CPAN shell that you cna use to install further 165Starts an interactive CPAN shell that you can use to install further
165modules. Installs the perl first if neccessary, but apart from that, 166modules. Installs the perl first if necessary, but apart from that,
166no magic is involved: you could just as well run it manually via 167no magic is involved: you could just as well run it manually via
167F<~/.staticperl/perl/bin/cpan>. 168F<~/.staticperl/perl/bin/cpan>.
168 169
169Any additional arguments are simply passed to the F<cpan> command. 170Any 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
181In the unlikely case that you have unpacked perl modules around and want 182In the unlikely case that you have unpacked perl modules around and want
182to install from these instead of from CPAN, you cna do this using this 183to install from these instead of from CPAN, you can do this using this
183command by specifying all the directories with modules in them that you 184command by specifying all the directories with modules in them that you
184want to have built. 185want to have built.
185 186
186=item F<staticperl clean> 187=item F<staticperl clean>
187 188
188Runs F<make distclean> in the perl source directory (and potentially 189Deletes the perl source directory (and potentially cleans up other
189cleans up other intermediate files). This can be used to clean up 190intermediate files). This can be used to clean up files only needed for
190intermediate files without removing the installed perl interpreter. 191building perl, without removing the installed perl interpreter, or to
192force a re-build from scratch.
193
194At the moment, it doesn't delete downloaded tarballs.
191 195
192=item F<staticperl distclean> 196=item F<staticperl distclean>
193 197
194This wipes your complete F<~/.staticperl> directory. Be careful with this, 198This wipes your complete F<~/.staticperl> directory. Be careful with this,
195it nukes your perl download, perl sources, perl distribution and any 199it nukes your perl download, perl sources, perl distribution and any
210In the oh so unlikely case of something not working here, you 214In the oh so unlikely case of something not working here, you
211can run the script manually as well (by default it is written to 215can run the script manually as well (by default it is written to
212F<~/.staticperl/mkbundle>). 216F<~/.staticperl/mkbundle>).
213 217
214F<mkbundle> is a more conventional command and expect the argument 218F<mkbundle> is a more conventional command and expect the argument
215syntax commonly used on unix clones. For example, this command builds 219syntax commonly used on UNIX clones. For example, this command builds
216a new F<perl> binary and includes F<Config.pm> (for F<perl -V>), 220a new F<perl> binary and includes F<Config.pm> (for F<perl -V>),
217F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd> 221F<AnyEvent::HTTPD>, F<URI> and a custom F<httpd> script (from F<eg/httpd>
218in this distribution): 222in this distribution):
219 223
220 # first make sure we have perl and the required modules 224 # first make sure we have perl and the required modules
229 ./perl -Mhttpd 233 ./perl -Mhttpd
230 234
231As you can see, things are not quite as trivial: the L<Config> module has 235As you can see, things are not quite as trivial: the L<Config> module has
232a hidden dependency which is not even a perl module (F<Config_heavy.pl>), 236a hidden dependency which is not even a perl module (F<Config_heavy.pl>),
233L<AnyEvent> needs at least one event loop backend that we have to 237L<AnyEvent> needs at least one event loop backend that we have to
234specifymanually (here L<AnyEvent::Impl::Perl>), and the F<URI> module 238specify manually (here L<AnyEvent::Impl::Perl>), and the F<URI> module
235(required by L<AnyEvent::HTTPD>) implements various URI schemes as extra 239(required by L<AnyEvent::HTTPD>) implements various URI schemes as extra
236modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need 240modules - since L<AnyEvent::HTTPD> only needs C<http> URIs, we only need
237to include that module. 241to include that module. I found out about these dependencies by carefully
242watching any error messages about missing modules...
238 243
239=head3 OPTION PROCESSING 244=head3 OPTION PROCESSING
240 245
241All options can be given as arguments on the commandline (typically using 246All options can be given as arguments on the command line (typically
242long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since 247using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since
243specifying a lot of modules can make the commandlien very cumbersome, 248specifying a lot of modules can make the command line very cumbersome,
244you can put all long options into a "bundle specification file" (with or 249you can put all long options into a "bundle specification file" (with or
245without C<--> prefix) and specify this bundle file instead. 250without C<--> prefix) and specify this bundle file instead.
246 251
247For example, the command given earlier could also look like this: 252For example, the command given earlier could also look like this:
248 253
255 use AnyEvent::HTTPD 260 use AnyEvent::HTTPD
256 use URI::http 261 use URI::http
257 add eg/httpd httpd.pm 262 add eg/httpd httpd.pm
258 263
259All options that specify modules or files to be added are processed in the 264All options that specify modules or files to be added are processed in the
260order given on the commandline (that affects the C<--use> and C<--eval> 265order given on the command line (that affects the C<--use> and C<--eval>
261options at the moment). 266options at the moment).
262 267
263=head3 MKBUNDLE OPTIONS 268=head3 MKBUNDLE OPTIONS
264 269
265=over 4 270=over 4
276 281
277Specify the stripping method applied to reduce the file of the perl 282Specify the stripping method applied to reduce the file of the perl
278sources included. 283sources included.
279 284
280The default is C<pod>, which uses the L<Pod::Strip> module to remove all 285The default is C<pod>, which uses the L<Pod::Strip> module to remove all
281pod documenatiton, which is very fast and reduces filesize a lot. 286pod documentation, which is very fast and reduces file size a lot.
282 287
283The C<ppi> method uses L<PPI> to parse and condense the perl sources. This 288The C<ppi> method uses L<PPI> to parse and condense the perl sources. This
284saves a lot more than just L<Pod::Strip>, and is generally safer, but is 289saves a lot more than just L<Pod::Strip>, and is generally safer, but
285also a lot slower, so is best used for production builds. 290is also a lot slower, so is best used for production builds. Note that
291this method doesn't optimise for raw file size, but for best compression
292(that means that the uncompressed file size is a bit larger, but the files
293compress better, e.g. with F<upx>).
286 294
295Last not least, if you need accurate line numbers in error messages,
287Last not least, in the unlikely case where C<pod> is too slow, or some 296or in the unlikely case where C<pod> is too slow, or some module gets
288module gets mistreated, you can specify C<none> to not mangle included 297mistreated, you can specify C<none> to not mangle included perl sources in
289perl sources in any way. 298any way.
290 299
291=item --perl 300=item --perl
292 301
293After writing out the bundle files, try to link a new perl interpreter. It 302After writing out the bundle files, try to link a new perl interpreter. It
294will be called F<perl> and will be left in the current working 303will be called F<perl> and will be left in the current working
295directory. The bundle files will be removed. 304directory. The bundle files will be removed.
296 305
297This switch is automatically ued when F<staticperl> is invoked with the 306This switch is automatically used when F<staticperl> is invoked with the
298C<mkperl> command (instead of C<mkbundle>): 307C<mkperl> command (instead of C<mkbundle>):
299 308
300 # build a new ./perl with only common::sense in it - very small :) 309 # build a new ./perl with only common::sense in it - very small :)
301 staticperl mkperl -Mcommon::sense 310 staticperl mkperl -Mcommon::sense
302 311
311 320
312 staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl 321 staticperl mkbundle --use AnyEvent --use AnyEvent::Impl::Perl
313 322
314Sometimes you want to load old-style "perl libraries" (F<.pl> files), or 323Sometimes you want to load old-style "perl libraries" (F<.pl> files), or
315maybe other weirdly named files. To do that, you need to quote the name in 324maybe other weirdly named files. To do that, you need to quote the name in
316single or double quoutes. When given on the commandline, you probably need 325single or double quotes. When given on the command line, you probably need
317to quote once more to avoid your shell interpreting it. Common cases that 326to quote once more to avoid your shell interpreting it. Common cases that
318need this are F<Config_heavy.pl> and F<utf8_heavy.pl>. 327need this are F<Config_heavy.pl> and F<utf8_heavy.pl>.
319 328
320Example: include the required files for F<perl -V> to work in all its 329Example: include the required files for F<perl -V> to work in all its
321glory (F<Config.pm> is included automatically by this). 330glory (F<Config.pm> is included automatically by this).
338variables or whatever you need. All files C<require>'d or C<use>'d in the 347variables or whatever you need. All files C<require>'d or C<use>'d in the
339script are included in the final bundle. 348script are included in the final bundle.
340 349
341Keep in mind that F<mkbundle> will only C<require> the modules named 350Keep in mind that F<mkbundle> will only C<require> the modules named
342by the C<--use> option, so do not expect the symbols from modules you 351by the C<--use> option, so do not expect the symbols from modules you
343C<--use>'d earlier on the commandlien to be available. 352C<--use>'d earlier on the command line to be available.
344 353
345Example: force L<AnyEvent> to detect a backend and therefore include it 354Example: force L<AnyEvent> to detect a backend and therefore include it
346in the final bundle. 355in the final bundle.
347 356
348 staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect' 357 staticperl mkbundle --eval 'use AnyEvent; AnyEvent::detect'
358=item --boot filename 367=item --boot filename
359 368
360Include the given file in the bundle and arrange for it to be executed 369Include 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 370(using a C<require>) before anything else when the new perl is
362initialised. This can be used to modify C<@INC> or anything else before 371initialised. This can be used to modify C<@INC> or anything else before
363the perl interpreter executes scripts given on the commandline (or via 372the perl interpreter executes scripts given on the command line (or via
364C<-e>). This works even in an embedded interpreter. 373C<-e>). This works even in an embedded interpreter.
365 374
366=item --add "file" | --add "file alias" 375=item --add "file" | --add "file alias"
367 376
368Adds the given (perl) file into the bundle (and optionally call it 377Adds the given (perl) file into the bundle (and optionally call it
376 385
377 # specification file 386 # specification file
378 add file1 myfiles/file1 387 add file1 myfiles/file1
379 add file2 myfiles/file2 388 add file2 myfiles/file2
380 add file3 myfiles/file3 389 add file3 myfiles/file3
390
391=item --binadd "file" | --add "file alias"
392
393Just like C<--add>, except that it treats the file as binary and adds it
394without any processing.
395
396You should probably add a C</> prefix to avoid clashing with embedded
397perl files (whose paths do not start with C</>), and/or use a special
398directory, such as C</res/name>.
399
400You can later get a copy of these files by calling C<staticperl::find
401"alias">.
381 402
382=item --static 403=item --static
383 404
384When C<--perl> is also given, link statically instead of dynamically. The 405When C<--perl> is also given, link statically instead of dynamically. The
385default is to link the new perl interpreter fully dynamic (that means all 406default is to link the new perl interpreter fully dynamic (that means all
423=item C<EMAIL> 444=item C<EMAIL>
424 445
425The e-mail address of the person who built this binary. Has no good 446The e-mail address of the person who built this binary. Has no good
426default, so should be specified by you. 447default, so should be specified by you.
427 448
428=back 449=item C<CPAN>
429 450
451The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>).
452
453=item C<EXTRA_MODULES>
454
455Additional modules installed during F<staticperl install>. Here you can
456set which modules you want have to installed from CPAN.
457
458Example: I really really need EV, AnyEvent, Coro and AnyEvent::AIO.
459
460 EXTRA_MODULES="EV AnyEvent Coro AnyEvent::AIO"
461
462Note that you can also use a C<postinstall> hook to achieve this, and
463more.
464
465=back
466
430=head4 Variables you I<might want> to override 467=head4 Variables you might I<want> to override
431 468
432=over 4 469=over 4
433 470
471=item C<STATICPERL>
472
473The directory where staticperl stores all its files
474(default: F<~/.staticperl>).
475
476=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ...
477
478Usually set to C<1> to make modules "less inquisitive" during their
479installation, you can set any environment variable you want - some modules
480(such as L<Coro> or L<EV>) use environment variables for further tweaking.
481
434=item C<PERLVER> 482=item C<PERL_VERSION>
435 483
436The perl version to install - default is currently C<5.12.2>, but C<5.8.9> 484The perl version to install - default is currently C<5.12.2>, but C<5.8.9>
437is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is 485is also a good choice (5.8.9 is much smaller than 5.12.2, while 5.10.1 is
438about as big as 5.12.2). 486about as big as 5.12.2).
439 487
440=item C<CPAN> 488=item C<PERL_PREFIX>
441 489
442The URL of the CPAN mirror to use (e.g. L<http://mirror.netcologne.de/cpan/>). 490The prefix where perl gets installed (default: F<$STATICPERL/perl>),
491i.e. where the F<bin> and F<lib> subdirectories will end up.
492
493=item C<PERL_CONFIGURE>
494
495Additional Configure options - these are simply passed to the perl
496Configure script. For example, if you wanted to enable dynamic loading,
497you could pass C<-Dusedl>. To enable ithreads (Why would you want that
498insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads>
499and so on.
500
501More commonly, you would either activate 64 bit integer support
502(C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to
503reduce filesize further.
443 504
444=item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> 505=item C<PERL_CPPFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS>
445 506
446These flags are passed to perl's F<Configure> script, and are generally 507These flags are passed to perl's F<Configure> script, and are generally
447optimised for small size (at the cost of performance). Since they also 508optimised for small size (at the cost of performance). Since they also
448contain subtle workarounds around various build issues, changing these 509contain subtle workarounds around various build issues, changing these
449usually requires understanding their default values - best look at the top 510usually requires understanding their default values - best look at the top
450of the F<staticperl> script for more info on these. 511of the F<staticperl> script for more info on these.
451 512
452=item C<STATICPERL>
453
454The directory where staticperl stores all its files
455(default: F<~/.staticperl>).
456
457=item C<PREFIX>
458
459The prefix where perl get's installed (default: F<$STATICPERL/perl>),
460i.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
464Usually set to C<1> to make modules "less inquisitive" during their
465installation, 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
470Additional modules installed during F<staticperl install>. Here you can
471set which modules you want have to installed from CPAN.
472
473Example: I really really need EV, AnyEvent, Coro and IO::AIO.
474
475 EXTRA_MODULES="EV AnyEvent Coro IO::AIO"
476
477Note that you cna also use a C<postinstall> hook to achieve this, and
478more.
479
480=back 513=back
481 514
482=head4 Variables you I<probably do not want> to override 515=head4 Variables you probably I<do not want> to override
483 516
484=over 4 517=over 4
485 518
486=item C<MKBUNDLE> 519=item C<MKBUNDLE>
487 520
497 530
498=head3 OVERRIDABLE HOOKS 531=head3 OVERRIDABLE HOOKS
499 532
500In addition to environment variables, it is possible to provide some 533In addition to environment variables, it is possible to provide some
501shell functions that are called at specific times. To provide your own 534shell functions that are called at specific times. To provide your own
502commands, justd efine the corresponding function. 535commands, just define the corresponding function.
503 536
504Example: install extra modules from CPAN and from some directories 537Example: install extra modules from CPAN and from some directories
505at F<staticperl install> time. 538at F<staticperl install> time.
506 539
507 postinstall() { 540 postinstall() {
508 rm -rf lib/threads.* # weg mit Schaden 541 rm -rf lib/threads* # weg mit Schaden
509 instcpan IO::AIO EV 542 instcpan IO::AIO EV
510 instsrc ~/src/AnyEvent 543 instsrc ~/src/AnyEvent
511 instsrc ~/src/XML-Sablotron-1.0100001 544 instsrc ~/src/XML-Sablotron-1.0100001
512 instcpan AnyEvent::HTTPD 545 instcpan Anyevent::AIO AnyEvent::HTTPD
513 } 546 }
514 547
515=over 4 548=over 4
549
550=item preconfigure
551
552Called just before running F<./Configur> in the perl source
553directory. Current working directory is the perl source directory.
554
555This can be used to set any C<PERL_xxx> variables, which might be costly
556to compute.
516 557
517=item postconfigure 558=item postconfigure
518 559
519Called after configuring, but before building perl. Current working 560Called after configuring, but before building perl. Current working
520directory is the perl source directory. 561directory is the perl source directory.
521 562
522Could be used to tailor/patch config.sh (followed by F<./Configure -S>) or 563Could be used to tailor/patch config.sh (followed by F<sh Configure -S>)
523do any other modifications. 564or do any other modifications.
524 565
525=item postbuild 566=item postbuild
526 567
527Called after building, but before installing perl. Current working 568Called after building, but before installing perl. Current working
528directory is the perl source directory. 569directory is the perl source directory.
543The script must return with a zero exit status, or the installation will 584The script must return with a zero exit status, or the installation will
544fail. 585fail.
545 586
546=back 587=back
547 588
589=head1 ANATOMY OF A BUNDLE
590
591When not building a new perl binary, C<mkbundle> will leave a number of
592files in the current working directory, which can be used to embed a perl
593interpreter in your program.
594
595Intimate knowledge of L<perlembed> and preferably some experience with
596embedding perl is highly recommended.
597
598C<mkperl> (or the C<--perl> option) basically does this to link the new
599interpreter (it also adds a main program to F<bundle.>):
600
601 $Config{cc} $(cat bundle.ccopts) -o perl bundle.c $(cat bundle.ldopts)
602
603=over 4
604
605=item bundle.h
606
607A header file that contains the prototypes of the few symbols "exported"
608by bundle.c, and also exposes the perl headers to the application.
609
610=over 4
611
612=item staticperl_init ()
613
614Initialises the perl interpreter. You can use the normal perl functions
615after calling this function, for example, to define extra functions or
616to load a .pm file that contains some initialisation code, or the main
617program function:
618
619 XS (xsfunction)
620 {
621 dXSARGS;
622
623 // now we have items, ST(i) etc.
624 }
625
626 static void
627 run_myapp(void)
628 {
629 staticperl_init ();
630 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
631 eval_pv ("require myapp::main", 1); // executes "myapp/main.pm"
632 }
633
634=item staticperl_xs_init (pTHX)
635
636Sometimes you need direct control over C<perl_parse> and C<perl_run>, in
637which case you do not want to use C<staticperl_init> but call them on your
638own.
639
640Then you need this function - either pass it directly as the C<xs_init>
641function to C<perl_parse>, or call it from your own C<xs_init> function.
642
643=item staticperl_cleanup ()
644
645In the unlikely case that you want to destroy the perl interpreter, here
646is the corresponding function.
647
648=item PerlInterpreter *staticperl
649
650The perl interpreter pointer used by staticperl. Not normally so useful,
651but there it is.
652
653=back
654
655=item bundle.ccopts
656
657Contains the compiler options required to compile at least F<bundle.c> and
658any file that includes F<bundle.h> - you should probably use it in your
659C<CFLAGS>.
660
661=item bundle.ldopts
662
663The linker options needed to link the final program.
664
665=back
666
667=head1 RUNTIME FUNCTIONALITY
668
669Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which
670are required to access the bundled perl sources, but might be useful for
671other purposes.
672
673In addition, for the embedded loading of perl files to work, F<staticperl>
674overrides the C<@INC> array.
675
676=over 4
677
678=item $file = staticperl::find $path
679
680Returns the data associated with the given C<$path>
681(e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically
682the UNIX path relative to the perl library directory.
683
684Returns C<undef> if the file isn't embedded.
685
686=item @paths = staticperl::list
687
688Returns the list of all paths embedded in this binary.
689
690=back
691
692=head1 FULLY STATIC BINARIES - BUILDROOT
693
694To make truly static (Linux-) libraries, you might want to have a look at
695buildroot (L<http://buildroot.uclibc.org/>).
696
697Buildroot is primarily meant to set up a cross-compile environment (which
698is not so useful as perl doesn't quite like cross compiles), but it can also compile
699a chroot environment where you can use F<staticperl>.
700
701To do so, download buildroot, and enable "Build options => development
702files in target filesystem" and optionally "Build options => gcc
703optimization level (optimize for size)". At the time of writing, I had
704good experiences with GCC 4.4.x but not GCC 4.5.
705
706To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections
707-finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386>
708doesn't decrease codesize much, but it makes the file much more
709compressible.
710
711If you don't need Coro or threads, you can go with "linuxthreads.old" (or
712no thread support). For Coro, it is highly recommended to switch to a
713uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201
714snapshot) and enable NPTL, otherwise Coro needs to be configured with the
715ultra-slow pthreads backend to work around linuxthreads bugs (it also uses
716twice the address space needed for stacks).
717
718If you use C<linuxthreads.old>, then you should also be aware that
719uClibc shares C<errno> between all threads when statically linking. See
720L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a
721workaround (And L<https://bugs.uclibc.org/2089> for discussion).
722
723C<ccache> support is also recommended, especially if you want
724to play around with buildroot options. Enabling the C<miniperl>
725package will probably enable all options required for a successful
726perl build. F<staticperl> itself additionally needs either C<wget>
727(recommended, for CPAN) or C<curl>.
728
729As for shells, busybox should provide all that is needed, but the default
730busybox configuration doesn't include F<comm> which is needed by perl -
731either make a custom busybox config, or compile coreutils.
732
733For the latter route, you might find that bash has some bugs that keep
734it from working properly in a chroot - either use dash (and link it to
735F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's
736built-in ash shell.
737
738Finally, you need F</dev/null> inside the chroot for many scripts to work
739- F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will
740both provide this.
741
742After you have compiled and set up your buildroot target, you can copy
743F<staticperl> from the C<App::Staticperl> distribution or from your
744perl f<bin> directory (if you installed it) into the F<output/target>
745filesystem, chroot inside and run it.
746
548=head1 AUTHOR 747=head1 AUTHOR
549 748
550 Marc Lehmann <schmorp@schmorp.de> 749 Marc Lehmann <schmorp@schmorp.de>
551 http://software.schmorp.de/pkg/staticperl.html 750 http://software.schmorp.de/pkg/staticperl.html

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines