1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | staticperl - perl, libc, 100 modules, all in one 500kb file |
3 | staticperl - perl, libc, 100 modules, all in one standalone 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 |
9 | staticperl configure # fetch and then configure perl |
9 | staticperl configure # fetch and then configure perl |
10 | staticperl build # configure and then build perl |
10 | staticperl build # configure and then build perl |
11 | staticperl install # build and then install perl |
11 | staticperl install # build and then install perl |
12 | staticperl clean # clean most intermediate files (restart at configure) |
12 | staticperl clean # clean most intermediate files (restart at configure) |
13 | staticperl distclean # delete everything installed by this script |
13 | staticperl distclean # delete everything installed by this script |
|
|
14 | staticperl perl ... # invoke the perlinterpreter |
14 | staticperl cpan # invoke CPAN shell |
15 | staticperl cpan # invoke CPAN shell |
15 | staticperl instmod path... # install unpacked modules |
16 | staticperl instsrc path... # install unpacked modules |
16 | staticperl instcpan modulename... # install modules from CPAN |
17 | staticperl instcpan modulename... # install modules from CPAN |
17 | staticperl mkbundle <bundle-args...> # see documentation |
18 | staticperl mkbundle <bundle-args...> # see documentation |
18 | staticperl mkperl <bundle-args...> # see documentation |
19 | staticperl mkperl <bundle-args...> # see documentation |
19 | staticperl mkapp appname <bundle-args...> # see documentation |
20 | staticperl mkapp appname <bundle-args...> # see documentation |
20 | |
21 | |
… | |
… | |
38 | file that contains perl interpreter, libc, all the modules you need, all |
39 | file that contains perl interpreter, libc, all the modules you need, all |
39 | the libraries you need and of course your actual program. |
40 | the libraries you need and of course your actual program. |
40 | |
41 | |
41 | With F<uClibc> and F<upx> on x86, you can create a single 500kb binary |
42 | With F<uClibc> and F<upx> on x86, you can create a single 500kb binary |
42 | that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
43 | that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, |
43 | Coro and so on. Or any other choice of modules. |
44 | Coro and so on. Or any other choice of modules (and some other size :). |
44 | |
45 | |
45 | To see how this turns out, you can try out smallperl and bigperl, two |
46 | To see how this turns out, you can try out smallperl and bigperl, two |
46 | pre-built static and compressed perl binaries with many and even more |
47 | pre-built static and compressed perl binaries with many and even more |
47 | modules: just follow the links at L<http://staticperl.schmorp.de/>. |
48 | modules: just follow the links at L<http://staticperl.schmorp.de/>. |
48 | |
49 | |
… | |
… | |
83 | With F<staticperl>, the burden is mostly with the developer - only direct |
84 | With F<staticperl>, the burden is mostly with the developer - only direct |
84 | compile-time dependencies and L<AutoLoader> are handled automatically. |
85 | compile-time dependencies and L<AutoLoader> are handled automatically. |
85 | This means the modules to include often need to be tweaked manually. |
86 | This means the modules to include often need to be tweaked manually. |
86 | |
87 | |
87 | All this does not preclude more permissive modes to be implemented in |
88 | All this does not preclude more permissive modes to be implemented in |
88 | the future, but right now, you have to resolve state hidden dependencies |
89 | the future, but right now, you have to resolve hidden dependencies |
89 | manually. |
90 | manually. |
90 | |
91 | |
91 | =item * PAR works out of the box, F<staticperl> does not. |
92 | =item * PAR works out of the box, F<staticperl> does not. |
92 | |
93 | |
93 | Maintaining your own custom perl build can be a pain in the ass, and while |
94 | Maintaining your own custom perl build can be a pain in the ass, and while |
… | |
… | |
186 | =item F<staticperl install> |
187 | =item F<staticperl install> |
187 | |
188 | |
188 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
189 | Wipes the perl installation directory (usually F<~/.staticperl/perl>) and |
189 | installs the perl distribution, potentially after building it first. |
190 | installs the perl distribution, potentially after building it first. |
190 | |
191 | |
|
|
192 | =item F<staticperl perl> [args...] |
|
|
193 | |
|
|
194 | Invokes the compiled perl interpreter with the given args. Basically the |
|
|
195 | same as starting perl directly (usually via F<~/.staticperl/bin/perl>), |
|
|
196 | but beats typing the path sometimes. |
|
|
197 | |
|
|
198 | Example: check that the Gtk2 module is installed and loadable. |
|
|
199 | |
|
|
200 | staticperl perl -MGtk2 -e0 |
|
|
201 | |
191 | =item F<staticperl cpan> [args...] |
202 | =item F<staticperl cpan> [args...] |
192 | |
203 | |
193 | Starts an interactive CPAN shell that you can use to install further |
204 | Starts an interactive CPAN shell that you can use to install further |
194 | modules. Installs the perl first if necessary, but apart from that, |
205 | modules. Installs the perl first if necessary, but apart from that, |
195 | no magic is involved: you could just as well run it manually via |
206 | no magic is involved: you could just as well run it manually via |
196 | F<~/.staticperl/perl/bin/cpan>. |
207 | F<~/.staticperl/perl/bin/cpan>, except that F<staticperl> additionally |
|
|
208 | sets the environment variable C<$PERL> to the path of the perl |
|
|
209 | interpreter, which is handy in subshells. |
197 | |
210 | |
198 | Any additional arguments are simply passed to the F<cpan> command. |
211 | Any additional arguments are simply passed to the F<cpan> command. |
199 | |
212 | |
200 | =item F<staticperl instcpan> module... |
213 | =item F<staticperl instcpan> module... |
201 | |
214 | |
… | |
… | |
335 | add eg/httpd httpd.pm |
348 | add eg/httpd httpd.pm |
336 | |
349 | |
337 | All options that specify modules or files to be added are processed in the |
350 | All options that specify modules or files to be added are processed in the |
338 | order given on the command line. |
351 | order given on the command line. |
339 | |
352 | |
340 | =head3 BUNDLE CREATION WORKFLOW / STATICPELR MKBUNDLE OPTIONS |
353 | =head3 BUNDLE CREATION WORKFLOW / STATICPERL MKBUNDLE OPTIONS |
341 | |
354 | |
342 | F<staticperl mkbundle> works by first assembling a list of candidate |
355 | F<staticperl mkbundle> works by first assembling a list of candidate |
343 | files and modules to include, then filtering them by include/exclude |
356 | files and modules to include, then filtering them by include/exclude |
344 | patterns. The remaining modules (together with their direct dependencies, |
357 | patterns. The remaining modules (together with their direct dependencies, |
345 | such as link libraries and L<AutoLoader> files) are then converted into |
358 | such as link libraries and L<AutoLoader> files) are then converted into |
… | |
… | |
530 | # then later, in perl, use |
543 | # then later, in perl, use |
531 | use myfiles::file1; |
544 | use myfiles::file1; |
532 | require myfiles::file2; |
545 | require myfiles::file2; |
533 | my $res = do "myfiles/file3.pl"; |
546 | my $res = do "myfiles/file3.pl"; |
534 | |
547 | |
535 | =item C<--binadd> F<file> | C<--add> "F<file> alias" |
548 | =item C<--addbin> F<file> | C<--addbin> "F<file> alias" |
536 | |
549 | |
537 | Just like C<--add>, except that it treats the file as binary and adds it |
550 | Just like C<--add>, except that it treats the file as binary and adds it |
538 | without any postprocessing (perl files might get stripped to reduce their |
551 | without any postprocessing (perl files might get stripped to reduce their |
539 | size). |
552 | size). |
540 | |
553 | |
541 | If you specify an alias you should probably add a C<&> prefix to avoid |
554 | If you specify an alias you should probably add a C</> prefix to avoid |
542 | clashing with embedded perl files (whose paths never start with C<&>), |
555 | clashing with embedded perl files (whose paths never start with C</>), |
543 | and/or use a special directory prefix, such as C<&res/name>. |
556 | and/or use a special directory prefix, such as C</res/name>. |
544 | |
557 | |
545 | You can later get a copy of these files by calling C<staticperl::find |
558 | You can later get a copy of these files by calling C<static::find |
546 | "alias">. |
559 | "alias">. |
547 | |
560 | |
548 | An alternative way to embed binary files is to convert them to perl and |
561 | An alternative way to embed binary files is to convert them to perl and |
549 | use C<do> to get the contents - this method is a bit cumbersome, but works |
562 | use C<do> to get the contents - this method is a bit cumbersome, but works |
550 | both inside and outside of a staticperl bundle: |
563 | both inside and outside of a staticperl bundle, without extra ado: |
551 | |
564 | |
552 | # a "binary" file, call it "bindata.pl" |
565 | # a "binary" file, call it "bindata.pl" |
553 | <<'SOME_MARKER' |
566 | <<'SOME_MARKER' |
554 | binary data NOT containing SOME_MARKER |
567 | binary data NOT containing SOME_MARKER |
555 | SOME_MARKER |
568 | SOME_MARKER |
556 | |
569 | |
557 | # load the binary |
570 | # load the binary |
558 | chomp (my $data = do "bindata.pl"); |
571 | chomp (my $data = do "bindata.pl"); |
|
|
572 | |
|
|
573 | =item C<--allow-dynamic> |
|
|
574 | |
|
|
575 | By default, when F<mkbundle> hits a dynamic perl extension (e.g. a F<.so> |
|
|
576 | or F<.dll> file), it will stop with a fatal error. |
|
|
577 | |
|
|
578 | When this option is enabled, F<mkbundle> packages the shared |
|
|
579 | object into the bundle instead, with a prefix of F<!> |
|
|
580 | (e.g. F<!auto/List/Util/Util.so>). What you do with that is currently up |
|
|
581 | to you, F<staticperl> has no special support for this at the moment, apart |
|
|
582 | from working around the lack of availability of F<PerlIO::scalar> while |
|
|
583 | bootstrapping, at a speed cost. |
|
|
584 | |
|
|
585 | One way to deal with this is to write all files starting with F<!> into |
|
|
586 | some directory and then C<unshift> that path onto C<@INC>. |
|
|
587 | |
|
|
588 | #TODO: example |
559 | |
589 | |
560 | =back |
590 | =back |
561 | |
591 | |
562 | =item Step 2: filter all files using C<--include> and C<--exclude> options. |
592 | =item Step 2: filter all files using C<--include> and C<--exclude> options. |
563 | |
593 | |
… | |
… | |
722 | standalone applications, and this option removes those known to cause |
752 | standalone applications, and this option removes those known to cause |
723 | trouble. |
753 | trouble. |
724 | |
754 | |
725 | Specifically, these are removed: |
755 | Specifically, these are removed: |
726 | |
756 | |
727 | C<PERL_HASH_SEED_DEBUG> and C<PERL_DEBUG_MSTATS> can cause underaible |
757 | C<PERL_HASH_SEED_DEBUG> and C<PERL_DEBUG_MSTATS> can cause undesirable |
728 | output, C<PERL5OPT>, C<PERL_DESTRUCT_LEVEL>, C<PERL_HASH_SEED> and |
758 | output, C<PERL5OPT>, C<PERL_DESTRUCT_LEVEL>, C<PERL_HASH_SEED> and |
729 | C<PERL_SIGNALS> can alter execution significantly, and C<PERL_UNICODE>, |
759 | C<PERL_SIGNALS> can alter execution significantly, and C<PERL_UNICODE>, |
730 | C<PERLIO_DEBUG> and C<PERLIO> can affect input and output. |
760 | C<PERLIO_DEBUG> and C<PERLIO> can affect input and output. |
731 | |
761 | |
732 | The variables C<PERL_LIB> and C<PERL5_LIB> are always ignored because the |
762 | The variables C<PERL_LIB> and C<PERL5_LIB> are always ignored because the |
… | |
… | |
770 | staticperl mkperl -MIO::AIO --staticlib crypt |
800 | staticperl mkperl -MIO::AIO --staticlib crypt |
771 | |
801 | |
772 | # ldopts might now contain: |
802 | # ldopts might now contain: |
773 | # -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread |
803 | # -lm -Wl,-Bstatic -lcrypt -Wl,-Bdynamic -lpthread |
774 | |
804 | |
|
|
805 | =item C<--extra-cflags> string |
|
|
806 | |
|
|
807 | Specifies extra compiler flags, used when compiling the bundle file. The |
|
|
808 | flags are appended to all the existing flags, so can be sued to override |
|
|
809 | settings. |
|
|
810 | |
|
|
811 | =item C<--extra-ldflags> string |
|
|
812 | |
|
|
813 | Specifies extra linker flags, used when linking the bundle. |
|
|
814 | |
|
|
815 | =item C<--extra-libs> string |
|
|
816 | |
|
|
817 | Extra linker flags, appended at the end when linking. The difference to |
|
|
818 | C<--extra-ldflags> is that the ldflags are appended to the flags, before |
|
|
819 | the objects and libraries, and the extra libs are added at the end. |
|
|
820 | |
775 | =back |
821 | =back |
776 | |
822 | |
777 | =back |
823 | =back |
778 | |
824 | |
779 | =head3 EXTENDED GLOB PATTERNS |
825 | =head3 EXTENDED GLOB PATTERNS |
… | |
… | |
871 | =item C<STATICPERL> |
917 | =item C<STATICPERL> |
872 | |
918 | |
873 | The directory where staticperl stores all its files |
919 | The directory where staticperl stores all its files |
874 | (default: F<~/.staticperl>). |
920 | (default: F<~/.staticperl>). |
875 | |
921 | |
|
|
922 | =item C<DLCACHE> |
|
|
923 | |
|
|
924 | The path to a directory (will be created if it doesn't exist) where |
|
|
925 | downloaded perl sources are being cached, to avoid downloading them |
|
|
926 | again. The default is empty, which means there is no cache. |
|
|
927 | |
|
|
928 | =item C<PERL_VERSION> |
|
|
929 | |
|
|
930 | The perl version to install - C<5.12.5> is a good choice for small builds, |
|
|
931 | but C<5.8.9> is also a good choice (5.8.9 is much smaller than 5.12.5), if |
|
|
932 | it builds on your system. |
|
|
933 | |
|
|
934 | You can also set this variable to the absolute URL of a tarball (F<.tar>, |
|
|
935 | F<.tar.gz>, F<.tar.bz2>, F<.tar.lzma> or F<.tar.xz>), or to the absolute |
|
|
936 | path of an unpacked perl source tree, which will be copied. |
|
|
937 | |
|
|
938 | The default is currently |
|
|
939 | F<http://stableperl.schmorp.de/dist/latest.tar.gz>, i.e. the latest |
|
|
940 | stableperl release. |
|
|
941 | |
876 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
942 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
877 | |
943 | |
878 | Usually set to C<1> to make modules "less inquisitive" during their |
944 | Usually set to C<1> to make modules "less inquisitive" during their |
879 | installation, you can set any environment variable you want - some modules |
945 | installation. You can set (and export!) any environment variable you want |
880 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
946 | - some modules (such as L<Coro> or L<EV>) use environment variables for |
881 | |
947 | further tweaking. |
882 | =item C<PERL_VERSION> |
|
|
883 | |
|
|
884 | The perl version to install - default is currently C<5.12.3>, but C<5.8.9> |
|
|
885 | is also a good choice (5.8.9 is much smaller than 5.12.3, while 5.10.1 is |
|
|
886 | about as big as 5.12.3). |
|
|
887 | |
948 | |
888 | =item C<PERL_PREFIX> |
949 | =item C<PERL_PREFIX> |
889 | |
950 | |
890 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
951 | The directory where perl gets installed (default: F<$STATICPERL/perl>), |
891 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
952 | i.e. where the F<bin> and F<lib> subdirectories will end up. Previous |
|
|
953 | contents will be removed on installation. |
892 | |
954 | |
893 | =item C<PERL_CONFIGURE> |
955 | =item C<PERL_CONFIGURE> |
894 | |
956 | |
895 | Additional Configure options - these are simply passed to the perl |
957 | Additional Configure options - these are simply passed to the perl |
896 | Configure script. For example, if you wanted to enable dynamic loading, |
958 | Configure script. For example, if you wanted to enable dynamic loading, |
… | |
… | |
912 | F<~/.staticperlrc> to override them. |
974 | F<~/.staticperlrc> to override them. |
913 | |
975 | |
914 | Most of the variables override (or modify) the corresponding F<Configure> |
976 | Most of the variables override (or modify) the corresponding F<Configure> |
915 | variable, except C<PERL_CCFLAGS>, which gets appended. |
977 | variable, except C<PERL_CCFLAGS>, which gets appended. |
916 | |
978 | |
|
|
979 | The default for C<PERL_OPTIMIZE> is C<-Os> (assuming gcc), and for |
|
|
980 | C<PERL_LIBS> is C<-lm -lcrypt>, which should be good for most (but not |
|
|
981 | all) systems. |
|
|
982 | |
|
|
983 | For other compilers or more customised optimisation settings, you need to |
|
|
984 | adjust these, e.g. in your F<~/.staticperlrc>. |
|
|
985 | |
|
|
986 | With gcc on x86 and amd64, you can get more space-savings by using: |
|
|
987 | |
|
|
988 | -Os -ffunction-sections -fdata-sections -finline-limit=8 -mpush-args |
|
|
989 | -mno-inline-stringops-dynamically -mno-align-stringops |
|
|
990 | |
|
|
991 | And on x86 and pentium3 and newer (basically everything you might ever |
|
|
992 | want to run on), adding these is even better for space-savings (use |
|
|
993 | -mtune=core2 or something newer for much faster code, too): |
|
|
994 | |
|
|
995 | -fomit-frame-pointer -march=pentium3 -mtune=i386 |
|
|
996 | |
917 | =back |
997 | =back |
918 | |
998 | |
919 | =head4 Variables you probably I<do not want> to override |
999 | =head4 Variables you probably I<do not want> to override |
920 | |
1000 | |
921 | =over 4 |
1001 | =over 4 |
… | |
… | |
939 | =head3 OVERRIDABLE HOOKS |
1019 | =head3 OVERRIDABLE HOOKS |
940 | |
1020 | |
941 | In addition to environment variables, it is possible to provide some |
1021 | In addition to environment variables, it is possible to provide some |
942 | shell functions that are called at specific times. To provide your own |
1022 | shell functions that are called at specific times. To provide your own |
943 | commands, just define the corresponding function. |
1023 | commands, just define the corresponding function. |
|
|
1024 | |
|
|
1025 | The actual order in which hooks are invoked during a full install |
|
|
1026 | from scratch is C<preconfigure>, C<patchconfig>, C<postconfigure>, |
|
|
1027 | C<postbuild>, C<postinstall>. |
944 | |
1028 | |
945 | Example: install extra modules from CPAN and from some directories |
1029 | Example: install extra modules from CPAN and from some directories |
946 | at F<staticperl install> time. |
1030 | at F<staticperl install> time. |
947 | |
1031 | |
948 | postinstall() { |
1032 | postinstall() { |
… | |
… | |
955 | |
1039 | |
956 | =over 4 |
1040 | =over 4 |
957 | |
1041 | |
958 | =item preconfigure |
1042 | =item preconfigure |
959 | |
1043 | |
960 | Called just before running F<./Configur> in the perl source |
1044 | Called just before running F<./Configure> in the perl source |
961 | directory. Current working directory is the perl source directory. |
1045 | directory. Current working directory is the perl source directory. |
962 | |
1046 | |
963 | This can be used to set any C<PERL_xxx> variables, which might be costly |
1047 | This can be used to set any C<PERL_xxx> variables, which might be costly |
964 | to compute. |
1048 | to compute. |
965 | |
1049 | |
|
|
1050 | =item patchconfig |
|
|
1051 | |
|
|
1052 | Called after running F<./Configure> in the perl source directory to create |
|
|
1053 | F<./config.sh>, but before running F<./Configure -S> to actually apply the |
|
|
1054 | config. Current working directory is the perl source directory. |
|
|
1055 | |
|
|
1056 | Can be used to tailor/patch F<config.sh> or do any other modifications. |
|
|
1057 | |
966 | =item postconfigure |
1058 | =item postconfigure |
967 | |
1059 | |
968 | Called after configuring, but before building perl. Current working |
1060 | Called after configuring, but before building perl. Current working |
969 | directory is the perl source directory. |
1061 | directory is the perl source directory. |
970 | |
1062 | |
971 | Could be used to tailor/patch config.sh (followed by F<sh Configure -S>) |
|
|
972 | or do any other modifications. |
|
|
973 | |
|
|
974 | =item postbuild |
1063 | =item postbuild |
975 | |
1064 | |
976 | Called after building, but before installing perl. Current working |
1065 | Called after building, but before installing perl. Current working |
977 | directory is the perl source directory. |
1066 | directory is the perl source directory. |
978 | |
1067 | |
979 | I have no clue what this could be used for - tell me. |
1068 | I have no clue what this could be used for - tell me. |
|
|
1069 | |
|
|
1070 | =item postcpanconfig |
|
|
1071 | |
|
|
1072 | Called just after CPAN has been configured, but before it has been used to |
|
|
1073 | install anything. You can further change the configuration like this: |
|
|
1074 | |
|
|
1075 | "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' |
|
|
1076 | CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); |
|
|
1077 | ' || fatal "error while initialising CPAN in postcpanconfig" |
980 | |
1078 | |
981 | =item postinstall |
1079 | =item postinstall |
982 | |
1080 | |
983 | Called after perl and any extra modules have been installed in C<$PREFIX>, |
1081 | Called after perl and any extra modules have been installed in C<$PREFIX>, |
984 | but before setting the "installation O.K." flag. |
1082 | but before setting the "installation O.K." flag. |
… | |
… | |
1090 | |
1188 | |
1091 | =back |
1189 | =back |
1092 | |
1190 | |
1093 | =head1 RUNTIME FUNCTIONALITY |
1191 | =head1 RUNTIME FUNCTIONALITY |
1094 | |
1192 | |
1095 | Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which |
1193 | Binaries created with C<mkbundle>/C<mkperl> contain extra functionality, |
1096 | are required to access the bundled perl sources, but might be useful for |
1194 | mostly related to the extra files bundled in the binary (the virtual |
1097 | other purposes. |
1195 | filesystem). All of this data is statically compiled into the binary, and |
|
|
1196 | accessing means copying it from a read-only section of your binary. Data |
|
|
1197 | pages in this way are usually freed by the operating system, as they aren't |
|
|
1198 | used more then once. |
|
|
1199 | |
|
|
1200 | =head2 VIRTUAL FILESYSTEM |
|
|
1201 | |
|
|
1202 | Every bundle has a virtual filesystem. The only information stored in it |
|
|
1203 | is the path and contents of each file that was bundled. |
|
|
1204 | |
|
|
1205 | =head3 LAYOUT |
|
|
1206 | |
|
|
1207 | Any paths starting with an ampersand (F<&>) or exclamation mark (F<!>) are |
|
|
1208 | reserved by F<staticperl>. They must only be used as described in this |
|
|
1209 | section. |
|
|
1210 | |
|
|
1211 | =over 4 |
|
|
1212 | |
|
|
1213 | =item ! |
|
|
1214 | |
|
|
1215 | All files that typically cannot be loaded from memory (such as dynamic |
|
|
1216 | objects or shared libraries), but have to reside in the filesystem, are |
|
|
1217 | prefixed with F<!>. Typically these files get written out to some |
|
|
1218 | (semi-)temporary directory shortly after program startup, or before being |
|
|
1219 | used. |
|
|
1220 | |
|
|
1221 | =item !boot |
|
|
1222 | |
|
|
1223 | The bootstrap file, if specified during bundling. |
|
|
1224 | |
|
|
1225 | =item !auto/ |
|
|
1226 | |
|
|
1227 | Shared objects or dlls corresponding to dynamically-linked perl extensions |
|
|
1228 | are stored with an F<!auto/> prefix. |
|
|
1229 | |
|
|
1230 | =item !lib/ |
|
|
1231 | |
|
|
1232 | External shared libraries are stored in this directory. |
|
|
1233 | |
|
|
1234 | =item any letter |
|
|
1235 | |
|
|
1236 | Any path starting with a letter is a perl library file. For example, |
|
|
1237 | F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and |
|
|
1238 | F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">. |
|
|
1239 | |
|
|
1240 | Obviously, module names shouldn't start with any other characters than |
|
|
1241 | letters :) |
|
|
1242 | |
|
|
1243 | =back |
|
|
1244 | |
|
|
1245 | =head3 FUNCTIONS |
|
|
1246 | |
|
|
1247 | =over 4 |
|
|
1248 | |
|
|
1249 | =item $file = static::find $path |
|
|
1250 | |
|
|
1251 | Returns the data associated with the given C<$path> |
|
|
1252 | (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>). |
|
|
1253 | |
|
|
1254 | Returns C<undef> if the file isn't embedded. |
|
|
1255 | |
|
|
1256 | =item @paths = static::list |
|
|
1257 | |
|
|
1258 | Returns the list of all paths embedded in this binary. |
|
|
1259 | |
|
|
1260 | =back |
|
|
1261 | |
|
|
1262 | =head2 EXTRA FEATURES |
1098 | |
1263 | |
1099 | In addition, for the embedded loading of perl files to work, F<staticperl> |
1264 | In addition, for the embedded loading of perl files to work, F<staticperl> |
1100 | overrides the C<@INC> array. |
1265 | overrides the C<@INC> array. |
1101 | |
1266 | |
1102 | =over 4 |
1267 | =head1 FULLY STATIC BINARIES - ALPINE LINUX |
1103 | |
1268 | |
1104 | =item $file = staticperl::find $path |
1269 | This section once contained a way to build fully static (including |
|
|
1270 | uClibc) binaries with buildroot. Unfortunately, buildroot no longer |
|
|
1271 | supports a compiler, so I recommend using alpine linux instead |
|
|
1272 | (L<http://alpinelinux.org/>). Get yourself a VM (e.g. with qemu), run an |
|
|
1273 | older alpine linux verison in it (e.g. 2.4), copy staticperl inside and |
|
|
1274 | use it. |
1105 | |
1275 | |
1106 | Returns the data associated with the given C<$path> |
1276 | The reason you might want an older alpine linux is that uClibc can be |
1107 | (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically |
1277 | quite dependent on kernel versions, so the newest version of alpine linux |
1108 | the UNIX path relative to the perl library directory. |
1278 | might need a newer kernel then you might want for, if you plan to run your |
1109 | |
1279 | binaries on on other kernels. |
1110 | Returns C<undef> if the file isn't embedded. |
|
|
1111 | |
|
|
1112 | =item @paths = staticperl::list |
|
|
1113 | |
|
|
1114 | Returns the list of all paths embedded in this binary. |
|
|
1115 | |
|
|
1116 | =back |
|
|
1117 | |
|
|
1118 | =head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT |
|
|
1119 | |
|
|
1120 | To make truly static (Linux-) libraries, you might want to have a look at |
|
|
1121 | buildroot (L<http://buildroot.uclibc.org/>). |
|
|
1122 | |
|
|
1123 | Buildroot is primarily meant to set up a cross-compile environment (which |
|
|
1124 | is not so useful as perl doesn't quite like cross compiles), but it can also compile |
|
|
1125 | a chroot environment where you can use F<staticperl>. |
|
|
1126 | |
|
|
1127 | To do so, download buildroot, and enable "Build options => development |
|
|
1128 | files in target filesystem" and optionally "Build options => gcc |
|
|
1129 | optimization level (optimize for size)". At the time of writing, I had |
|
|
1130 | good experiences with GCC 4.4.x but not GCC 4.5. |
|
|
1131 | |
|
|
1132 | To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections |
|
|
1133 | -finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386> |
|
|
1134 | doesn't decrease codesize much, but it makes the file much more |
|
|
1135 | compressible. |
|
|
1136 | |
|
|
1137 | If you don't need Coro or threads, you can go with "linuxthreads.old" (or |
|
|
1138 | no thread support). For Coro, it is highly recommended to switch to a |
|
|
1139 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
|
|
1140 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
|
|
1141 | ultra-slow pthreads backend to work around linuxthreads bugs (it also uses |
|
|
1142 | twice the address space needed for stacks). |
|
|
1143 | |
|
|
1144 | If you use C<linuxthreads.old>, then you should also be aware that |
|
|
1145 | uClibc shares C<errno> between all threads when statically linking. See |
|
|
1146 | L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a |
|
|
1147 | workaround (And L<https://bugs.uclibc.org/2089> for discussion). |
|
|
1148 | |
|
|
1149 | C<ccache> support is also recommended, especially if you want |
|
|
1150 | to play around with buildroot options. Enabling the C<miniperl> |
|
|
1151 | package will probably enable all options required for a successful |
|
|
1152 | perl build. F<staticperl> itself additionally needs either C<wget> |
|
|
1153 | (recommended, for CPAN) or C<curl>. |
|
|
1154 | |
|
|
1155 | As for shells, busybox should provide all that is needed, but the default |
|
|
1156 | busybox configuration doesn't include F<comm> which is needed by perl - |
|
|
1157 | either make a custom busybox config, or compile coreutils. |
|
|
1158 | |
|
|
1159 | For the latter route, you might find that bash has some bugs that keep |
|
|
1160 | it from working properly in a chroot - either use dash (and link it to |
|
|
1161 | F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's |
|
|
1162 | built-in ash shell. |
|
|
1163 | |
|
|
1164 | Finally, you need F</dev/null> inside the chroot for many scripts to work |
|
|
1165 | - F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will |
|
|
1166 | both provide this. |
|
|
1167 | |
|
|
1168 | After you have compiled and set up your buildroot target, you can copy |
|
|
1169 | F<staticperl> from the C<App::Staticperl> distribution or from your |
|
|
1170 | perl f<bin> directory (if you installed it) into the F<output/target> |
|
|
1171 | filesystem, chroot inside and run it. |
|
|
1172 | |
1280 | |
1173 | =head1 RECIPES / SPECIFIC MODULES |
1281 | =head1 RECIPES / SPECIFIC MODULES |
1174 | |
1282 | |
1175 | This section contains some common(?) recipes and information about |
1283 | This section contains some common(?) recipes and information about |
1176 | problems with some common modules or perl constructs that require extra |
1284 | problems with some common modules or perl constructs that require extra |
… | |
… | |
1190 | |
1298 | |
1191 | Many Unicode properties in turn are defined in separate modules, |
1299 | Many Unicode properties in turn are defined in separate modules, |
1192 | such as C<"unicore/Heavy.pl"> and more specific data tables such as |
1300 | such as C<"unicore/Heavy.pl"> and more specific data tables such as |
1193 | C<"unicore/To/Digit.pl"> or C<"unicore/lib/Perl/Word.pl">. These tables |
1301 | C<"unicore/To/Digit.pl"> or C<"unicore/lib/Perl/Word.pl">. These tables |
1194 | are big (7MB uncompressed, although F<staticperl> contains special |
1302 | are big (7MB uncompressed, although F<staticperl> contains special |
1195 | handling for those files), so including them on demand by your application |
1303 | handling for those files), so including them only on demand in your |
1196 | only might pay off. |
1304 | application might pay off. |
1197 | |
1305 | |
1198 | To simply include the whole unicode database, use: |
1306 | To simply include the whole unicode database, use: |
1199 | |
1307 | |
1200 | --incglob '/unicore/**.pl' |
1308 | --incglob '/unicore/**.pl' |
1201 | |
1309 | |
… | |
… | |
1213 | C<"AnyEvent/Util/uts46data.pl">. |
1321 | C<"AnyEvent/Util/uts46data.pl">. |
1214 | |
1322 | |
1215 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1323 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1216 | everything. |
1324 | everything. |
1217 | |
1325 | |
|
|
1326 | =item Cairo |
|
|
1327 | |
|
|
1328 | See Glib, same problem, same solution. |
|
|
1329 | |
1218 | =item Carp |
1330 | =item Carp |
1219 | |
1331 | |
1220 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1332 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1221 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1333 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1222 | |
1334 | |
1223 | =item Config |
1335 | =item Config |
1224 | |
1336 | |
1225 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1337 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1226 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1338 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1227 | both. |
1339 | both. |
|
|
1340 | |
|
|
1341 | =item Glib |
|
|
1342 | |
|
|
1343 | Glib literally requires Glib to be installed already to build - it tries |
|
|
1344 | to fake this by running Glib out of the build directory before being |
|
|
1345 | built. F<staticperl> tries to work around this by forcing C<MAN1PODS> and |
|
|
1346 | C<MAN3PODS> to be empty via the C<PERL_MM_OPT> environment variable. |
|
|
1347 | |
|
|
1348 | =item Gtk2 |
|
|
1349 | |
|
|
1350 | See Pango, same problems, same solution. |
|
|
1351 | |
|
|
1352 | =item Net::SSLeay |
|
|
1353 | |
|
|
1354 | This module hasn't been significantly updated since OpenSSL is called |
|
|
1355 | OpenSSL, and fails to properly link against dependent libraries, most |
|
|
1356 | commonly, it forgets to specify -ldl when linking. |
|
|
1357 | |
|
|
1358 | On GNU/Linux systems this usually goes undetected, as perl usually links |
|
|
1359 | against -ldl itself and OpenSSL just happens to pick it up that way, by |
|
|
1360 | chance. |
|
|
1361 | |
|
|
1362 | For static builds, you either have to configure -ldl manually, or you |
|
|
1363 | cna use the following snippet in your C<postinstall> hook which patches |
|
|
1364 | Net::SSLeay after installation, which happens to work most of the time: |
|
|
1365 | |
|
|
1366 | postinstall() { |
|
|
1367 | # first install it |
|
|
1368 | instcpan Net::SSLeay |
|
|
1369 | # then add -ldl for future linking |
|
|
1370 | chmod u+w "$PERL_PREFIX"/lib/auto/Net/SSLeay/extralibs.ld |
|
|
1371 | echo " -ldl" >>"$PERL_PREFIX"/lib/auto/Net/SSLeay/extralibs.ld |
|
|
1372 | } |
|
|
1373 | |
|
|
1374 | =item Pango |
|
|
1375 | |
|
|
1376 | In addition to the C<MAN3PODS> problem in Glib, Pango also routes around |
|
|
1377 | L<ExtUtils::MakeMaker> by compiling its files on its own. F<staticperl> |
|
|
1378 | tries to patch L<ExtUtils::MM_Unix> to route around Pango. |
1228 | |
1379 | |
1229 | =item Term::ReadLine::Perl |
1380 | =item Term::ReadLine::Perl |
1230 | |
1381 | |
1231 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1382 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1232 | |
1383 | |
… | |
… | |
1294 | gains little. Why Socket exposes a C function that is in the core already |
1445 | gains little. Why Socket exposes a C function that is in the core already |
1295 | is anybody's guess. |
1446 | is anybody's guess. |
1296 | |
1447 | |
1297 | =back |
1448 | =back |
1298 | |
1449 | |
|
|
1450 | =head1 ADDITIONAL RESOURCES |
|
|
1451 | |
|
|
1452 | Some guy has made a repository on github |
|
|
1453 | (L<https://github.com/gh0stwizard/staticperl-modules>) with some modules |
|
|
1454 | patched to build with staticperl. |
|
|
1455 | |
1299 | =head1 AUTHOR |
1456 | =head1 AUTHOR |
1300 | |
1457 | |
1301 | Marc Lehmann <schmorp@schmorp.de> |
1458 | Marc Lehmann <schmorp@schmorp.de> |
1302 | http://software.schmorp.de/pkg/staticperl.html |
1459 | http://software.schmorp.de/pkg/staticperl.html |
|
|
1460 | |