… | |
… | |
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 instmod 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 |
… | |
… | |
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 | |
… | |
… | |
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<staticperl::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 | |
… | |
… | |
871 | =item C<STATICPERL> |
901 | =item C<STATICPERL> |
872 | |
902 | |
873 | The directory where staticperl stores all its files |
903 | The directory where staticperl stores all its files |
874 | (default: F<~/.staticperl>). |
904 | (default: F<~/.staticperl>). |
875 | |
905 | |
876 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
906 | =item C<DLCACHE> |
877 | |
907 | |
878 | Usually set to C<1> to make modules "less inquisitive" during their |
908 | The path to a directory (will be created if it doesn't exist) where |
879 | installation, you can set any environment variable you want - some modules |
909 | downloaded perl sources are being cached, to avoid downloading them |
880 | (such as L<Coro> or L<EV>) use environment variables for further tweaking. |
910 | again. The default is empty, which means there is no cache. |
881 | |
911 | |
882 | =item C<PERL_VERSION> |
912 | =item C<PERL_VERSION> |
883 | |
913 | |
884 | The perl version to install - default is currently C<5.12.3>, but C<5.8.9> |
914 | 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 |
915 | 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). |
916 | about as big as 5.12.3). |
|
|
917 | |
|
|
918 | =item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... |
|
|
919 | |
|
|
920 | Usually set to C<1> to make modules "less inquisitive" during their |
|
|
921 | installation. You can set (and export!) any environment variable you want |
|
|
922 | - some modules (such as L<Coro> or L<EV>) use environment variables for |
|
|
923 | further tweaking. |
887 | |
924 | |
888 | =item C<PERL_PREFIX> |
925 | =item C<PERL_PREFIX> |
889 | |
926 | |
890 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
927 | The prefix where perl gets installed (default: F<$STATICPERL/perl>), |
891 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
928 | i.e. where the F<bin> and F<lib> subdirectories will end up. |
… | |
… | |
911 | the top of the F<staticperl> script for more info on these, and use a |
948 | the top of the F<staticperl> script for more info on these, and use a |
912 | F<~/.staticperlrc> to override them. |
949 | F<~/.staticperlrc> to override them. |
913 | |
950 | |
914 | Most of the variables override (or modify) the corresponding F<Configure> |
951 | Most of the variables override (or modify) the corresponding F<Configure> |
915 | variable, except C<PERL_CCFLAGS>, which gets appended. |
952 | variable, except C<PERL_CCFLAGS>, which gets appended. |
|
|
953 | |
|
|
954 | You should have a look near the beginning of the F<staticperl> script - |
|
|
955 | staticperl tries to default C<PERL_OPTIMIZE> to some psace-saving options |
|
|
956 | suitable for newer gcc versions. For other compilers or older versions you |
|
|
957 | need to adjust these, for example, in your F<~/.staticperlrc>. |
916 | |
958 | |
917 | =back |
959 | =back |
918 | |
960 | |
919 | =head4 Variables you probably I<do not want> to override |
961 | =head4 Variables you probably I<do not want> to override |
920 | |
962 | |
… | |
… | |
1099 | |
1141 | |
1100 | =back |
1142 | =back |
1101 | |
1143 | |
1102 | =head1 RUNTIME FUNCTIONALITY |
1144 | =head1 RUNTIME FUNCTIONALITY |
1103 | |
1145 | |
1104 | Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which |
1146 | Binaries created with C<mkbundle>/C<mkperl> contain extra functionality, |
1105 | are required to access the bundled perl sources, but might be useful for |
1147 | mostly related to the extra files bundled in the binary (the virtual |
1106 | other purposes. |
1148 | filesystem). All of this data is statically compiled into the binary, and |
|
|
1149 | accessing means copying it from a read-only section of your binary. Data |
|
|
1150 | pages in this way is usually freed by the operating system, as it isn't |
|
|
1151 | use more the onace. |
|
|
1152 | |
|
|
1153 | =head2 VIRTUAL FILESYSTEM |
|
|
1154 | |
|
|
1155 | Every bundle has a virtual filesystem. The only information stored in it |
|
|
1156 | is the path and contents of each file that was bundled. |
|
|
1157 | |
|
|
1158 | =head3 LAYOUT |
|
|
1159 | |
|
|
1160 | Any path starting with an ampersand (F<&>) or exclamation mark (F<!>) are |
|
|
1161 | reserved by F<staticperl>. They must only be used as described in this |
|
|
1162 | section. |
|
|
1163 | |
|
|
1164 | =over 4 |
|
|
1165 | |
|
|
1166 | =item ! |
|
|
1167 | |
|
|
1168 | All files that typically cannot be loaded from memory (such as dynamic |
|
|
1169 | objects or shared libraries), but have to reside in the filesystem, are |
|
|
1170 | prefixed with F<!>. Typically these files get written out to some |
|
|
1171 | (semi-)temporary directory shortly after program startup, or before being |
|
|
1172 | used. |
|
|
1173 | |
|
|
1174 | =item !boot |
|
|
1175 | |
|
|
1176 | The bootstrap file, if specified during bundling. |
|
|
1177 | |
|
|
1178 | =item !auto/ |
|
|
1179 | |
|
|
1180 | Shared objects or dlls corresponding to dynamically-linked perl extensions |
|
|
1181 | are stored with an F<!auto/> prefix. |
|
|
1182 | |
|
|
1183 | =item !lib/ |
|
|
1184 | |
|
|
1185 | External shared libraries are stored in this directory. |
|
|
1186 | |
|
|
1187 | =item any letter |
|
|
1188 | |
|
|
1189 | Any path starting with a letter is a perl library file. For example, |
|
|
1190 | F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and |
|
|
1191 | F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">. |
|
|
1192 | |
|
|
1193 | Obviously, module names shouldn't start with any other characters than |
|
|
1194 | letters :) |
|
|
1195 | |
|
|
1196 | =back |
|
|
1197 | |
|
|
1198 | =head3 FUNCTIONS |
|
|
1199 | |
|
|
1200 | =over 4 |
|
|
1201 | |
|
|
1202 | =item $file = staticperl::find $path |
|
|
1203 | |
|
|
1204 | Returns the data associated with the given C<$path> |
|
|
1205 | (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>). |
|
|
1206 | |
|
|
1207 | Returns C<undef> if the file isn't embedded. |
|
|
1208 | |
|
|
1209 | =item @paths = staticperl::list |
|
|
1210 | |
|
|
1211 | Returns the list of all paths embedded in this binary. |
|
|
1212 | |
|
|
1213 | =back |
|
|
1214 | |
|
|
1215 | =head2 EXTRA FEATURES |
1107 | |
1216 | |
1108 | In addition, for the embedded loading of perl files to work, F<staticperl> |
1217 | In addition, for the embedded loading of perl files to work, F<staticperl> |
1109 | overrides the C<@INC> array. |
1218 | overrides the C<@INC> array. |
1110 | |
|
|
1111 | =over 4 |
|
|
1112 | |
|
|
1113 | =item $file = staticperl::find $path |
|
|
1114 | |
|
|
1115 | Returns the data associated with the given C<$path> |
|
|
1116 | (e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically |
|
|
1117 | the UNIX path relative to the perl library directory. |
|
|
1118 | |
|
|
1119 | Returns C<undef> if the file isn't embedded. |
|
|
1120 | |
|
|
1121 | =item @paths = staticperl::list |
|
|
1122 | |
|
|
1123 | Returns the list of all paths embedded in this binary. |
|
|
1124 | |
|
|
1125 | =back |
|
|
1126 | |
1219 | |
1127 | =head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT |
1220 | =head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT |
1128 | |
1221 | |
1129 | To make truly static (Linux-) libraries, you might want to have a look at |
1222 | To make truly static (Linux-) libraries, you might want to have a look at |
1130 | buildroot (L<http://buildroot.uclibc.org/>). |
1223 | buildroot (L<http://buildroot.uclibc.org/>). |
… | |
… | |
1139 | good experiences with GCC 4.4.x but not GCC 4.5. |
1232 | good experiences with GCC 4.4.x but not GCC 4.5. |
1140 | |
1233 | |
1141 | To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections |
1234 | To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections |
1142 | -finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386> |
1235 | -finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386> |
1143 | doesn't decrease codesize much, but it makes the file much more |
1236 | doesn't decrease codesize much, but it makes the file much more |
1144 | compressible. |
1237 | compressible (and the execution a lot slower...). |
1145 | |
1238 | |
1146 | If you don't need Coro or threads, you can go with "linuxthreads.old" (or |
1239 | If you don't need Coro or threads, you can go with "linuxthreads.old" (or |
1147 | no thread support). For Coro, it is highly recommended to switch to a |
1240 | no thread support). For Coro, it is highly recommended to switch to a |
1148 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
1241 | uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 |
1149 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
1242 | snapshot) and enable NPTL, otherwise Coro needs to be configured with the |
… | |
… | |
1151 | twice the address space needed for stacks). |
1244 | twice the address space needed for stacks). |
1152 | |
1245 | |
1153 | If you use C<linuxthreads.old>, then you should also be aware that |
1246 | If you use C<linuxthreads.old>, then you should also be aware that |
1154 | uClibc shares C<errno> between all threads when statically linking. See |
1247 | uClibc shares C<errno> between all threads when statically linking. See |
1155 | L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a |
1248 | L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a |
1156 | workaround (And L<https://bugs.uclibc.org/2089> for discussion). |
1249 | workaround (and L<https://bugs.uclibc.org/2089> for discussion). |
1157 | |
1250 | |
1158 | C<ccache> support is also recommended, especially if you want |
1251 | C<ccache> support is also recommended, especially if you want |
1159 | to play around with buildroot options. Enabling the C<miniperl> |
1252 | to play around with buildroot options. Enabling the C<miniperl> |
1160 | package will probably enable all options required for a successful |
1253 | package will probably enable all options required for a successful |
1161 | perl build. F<staticperl> itself additionally needs either C<wget> |
1254 | perl build. F<staticperl> itself additionally needs either C<wget> |
… | |
… | |
1169 | it from working properly in a chroot - either use dash (and link it to |
1262 | it from working properly in a chroot - either use dash (and link it to |
1170 | F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's |
1263 | F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's |
1171 | built-in ash shell. |
1264 | built-in ash shell. |
1172 | |
1265 | |
1173 | Finally, you need F</dev/null> inside the chroot for many scripts to work |
1266 | Finally, you need F</dev/null> inside the chroot for many scripts to work |
1174 | - F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will |
1267 | - either F<cp /dev/null output/target/dev> or bind-mounting your F</dev> |
1175 | both provide this. |
1268 | will provide this. |
1176 | |
1269 | |
1177 | After you have compiled and set up your buildroot target, you can copy |
1270 | After you have compiled and set up your buildroot target, you can copy |
1178 | F<staticperl> from the C<App::Staticperl> distribution or from your |
1271 | F<staticperl> from the C<App::Staticperl> distribution or from your |
1179 | perl f<bin> directory (if you installed it) into the F<output/target> |
1272 | perl F<bin> directory (if you installed it) into the F<output/target> |
1180 | filesystem, chroot inside and run it. |
1273 | filesystem, chroot inside and run it. |
1181 | |
1274 | |
1182 | =head1 RECIPES / SPECIFIC MODULES |
1275 | =head1 RECIPES / SPECIFIC MODULES |
1183 | |
1276 | |
1184 | This section contains some common(?) recipes and information about |
1277 | This section contains some common(?) recipes and information about |
… | |
… | |
1222 | C<"AnyEvent/Util/uts46data.pl">. |
1315 | C<"AnyEvent/Util/uts46data.pl">. |
1223 | |
1316 | |
1224 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1317 | Or you can use C<--usepacklists> and specify C<-MAnyEvent> to include |
1225 | everything. |
1318 | everything. |
1226 | |
1319 | |
|
|
1320 | =item Cairo |
|
|
1321 | |
|
|
1322 | See Glib, same problem, same solution. |
|
|
1323 | |
1227 | =item Carp |
1324 | =item Carp |
1228 | |
1325 | |
1229 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1326 | Carp had (in older versions of perl) a dependency on L<Carp::Heavy>. As of |
1230 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1327 | perl 5.12.2 (maybe earlier), this dependency no longer exists. |
1231 | |
1328 | |
1232 | =item Config |
1329 | =item Config |
1233 | |
1330 | |
1234 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1331 | The F<perl -V> switch (as well as many modules) needs L<Config>, which in |
1235 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1332 | turn might need L<"Config_heavy.pl">. Including the latter gives you |
1236 | both. |
1333 | both. |
|
|
1334 | |
|
|
1335 | =item Glib |
|
|
1336 | |
|
|
1337 | Glib literally requires Glib to be installed already to build - it tries |
|
|
1338 | to fake this by running Glib out of the build directory before being |
|
|
1339 | built. F<staticperl> tries to work around this by forcing C<MAN1PODS> and |
|
|
1340 | C<MAN3PODS> to be empty via the C<PERL_MM_OPT> environment variable. |
|
|
1341 | |
|
|
1342 | =item Gtk2 |
|
|
1343 | |
|
|
1344 | See Pango, same problems, same solution. |
|
|
1345 | |
|
|
1346 | =item Pango |
|
|
1347 | |
|
|
1348 | In addition to the C<MAN3PODS> problem in Glib, Pango also routes around |
|
|
1349 | L<ExtUtils::MakeMaker> by compiling its files on its own. F<staticperl> |
|
|
1350 | tries to patch L<ExtUtils::MM_Unix> to route around Pango. |
1237 | |
1351 | |
1238 | =item Term::ReadLine::Perl |
1352 | =item Term::ReadLine::Perl |
1239 | |
1353 | |
1240 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1354 | Also needs L<Term::ReadLine::readline>, or C<--usepacklists>. |
1241 | |
1355 | |