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