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

Comparing App-Staticperl/staticperl.pod (file contents):
Revision 1.66 by root, Fri Aug 4 03:14:33 2023 UTC vs.
Revision 1.67 by root, Fri Aug 4 03:58:52 2023 UTC

124 124
125=head1 THE F<STATICPERL> SCRIPT 125=head1 THE F<STATICPERL> SCRIPT
126 126
127This module installs a script called F<staticperl> into your perl 127This module installs a script called F<staticperl> into your perl
128binary directory. The script is fully self-contained, and can be 128binary directory. The script is fully self-contained, and can be
129used without perl (for example, in an uClibc chroot environment). In 129used without perl (for example, in an uClibc/dietlibc/musl chroot
130fact, it can be extracted from the C<App::Staticperl> distribution 130environment). In fact, it can be extracted from the C<App::Staticperl>
131tarball as F<bin/staticperl>, without any installation. The 131distribution tarball as F<bin/staticperl>, without any installation. The
132newest (possibly alpha) version can also be downloaded from 132newest (possibly alpha) version can also be downloaded from
133L<http://staticperl.schmorp.de/staticperl>. 133L<http://staticperl.schmorp.de/staticperl>.
134 134
135F<staticperl> interprets the first argument as a command to execute, 135F<staticperl> interprets the first argument as a command to execute,
136optionally followed by any parameters. 136optionally followed by any parameters.
189Wipes the perl installation directory (usually F<~/.staticperl/perl>) and 189Wipes the perl installation directory (usually F<~/.staticperl/perl>) and
190installs the perl distribution, potentially after building it first. 190installs the perl distribution, potentially after building it first.
191 191
192=item F<staticperl perl> [args...] 192=item F<staticperl perl> [args...]
193 193
194Invokes the compiled perl interpreter with the given args. Basically the 194Invokes the compiled perl interpreter with the given
195same as starting perl directly (usually via F<~/.staticperl/bin/perl>), 195arguments. Basically the same as starting perl directly (usually via
196but beats typing the path sometimes. 196F<~/.staticperl/bin/perl>), but beats typing the path sometimes.
197 197
198Example: check that the Gtk2 module is installed and loadable. 198Example: check that the Gtk2 module is installed and loadable.
199 199
200 staticperl perl -MGtk2 -e0 200 staticperl perl -MGtk2 -e0
201 201
546 my $res = do "myfiles/file3.pl"; 546 my $res = do "myfiles/file3.pl";
547 547
548=item C<--addbin> F<file> | C<--addbin> "F<file> alias" 548=item C<--addbin> F<file> | C<--addbin> "F<file> alias"
549 549
550Just like C<--add>, except that it treats the file as binary and adds it 550Just like C<--add>, except that it treats the file as binary and adds it
551without any postprocessing (perl files might get stripped to reduce their 551without any post-processing (perl files might get stripped to reduce their
552size). 552size).
553 553
554If you specify an alias you should probably add a C</> prefix to avoid 554If you specify an alias you should probably add a C</> prefix to avoid
555clashing with embedded perl files (whose paths never start with C</>), 555clashing with embedded perl files (whose paths never start with C</>),
556and/or use a special directory prefix, such as C</res/name>. 556and/or use a special directory prefix, such as C</res/name>.
583bootstrapping, at a speed cost. 583bootstrapping, at a speed cost.
584 584
585One way to deal with this is to write all files starting with F<!> into 585One way to deal with this is to write all files starting with F<!> into
586some directory and then C<unshift> that path onto C<@INC>. 586some directory and then C<unshift> that path onto C<@INC>.
587 587
588#TODO: example 588(TODO for future self: write and insert a suitable example here, if
589somebody requests it).
589 590
590=back 591=back
591 592
592=item Step 2: filter all files using C<--include> and C<--exclude> options. 593=item Step 2: filter all files using C<--include> and C<--exclude> options.
593 594
709=item C<--compress> C<none>|C<lzf> 710=item C<--compress> C<none>|C<lzf>
710 711
711Compress each included library file with C<lzf> (default), or do not 712Compress each included library file with C<lzf> (default), or do not
712compress (C<none>). LZF compression typically halves the size of the 713compress (C<none>). LZF compression typically halves the size of the
713included library data at almost no overhead, but is counterproductive if 714included library data at almost no overhead, but is counterproductive if
714you are using another compression solution such as C<UPX>, so it cna be 715you are using another compression solution such as C<UPX>, so it can be
715disabled. 716disabled.
716 717
717=item C<--perl> 718=item C<--perl>
718 719
719After writing out the bundle files, try to link a new perl interpreter. It 720After writing out the bundle files, try to link a new perl interpreter. It
754 755
755=item C<--ignore-env> 756=item C<--ignore-env>
756 757
757Generates extra code to unset some environment variables before 758Generates extra code to unset some environment variables before
758initialising/running perl. Perl supports a lot of environment variables 759initialising/running perl. Perl supports a lot of environment variables
759that might alter execution in ways that might be undesirablre for 760that might alter execution in ways that might be undesirable for
760standalone applications, and this option removes those known to cause 761standalone applications, and this option removes those known to cause
761trouble. 762trouble.
762 763
763Specifically, these are removed: 764Specifically, these are removed:
764 765
785The default is to link the new binary dynamically (that means all perl 786The default is to link the new binary dynamically (that means all perl
786modules are linked statically, but all external libraries are still 787modules are linked statically, but all external libraries are still
787referenced dynamically). 788referenced dynamically).
788 789
789Keep in mind that Solaris doesn't support static linking at all, and 790Keep in mind that Solaris doesn't support static linking at all, and
790systems based on GNU libc don't really support it in a very usable 791systems based on GNU libc don't really support it in a very usable fashion
791fashion either. Try uClibc if you want to create fully statically linked 792either. Try dietlibc or musl if you want to create fully statically linked
792executables, or try the C<--staticlib> option to link only some libraries 793executables, or try the C<--staticlib> option to link only some libraries
793statically. 794statically.
794 795
795=item C<--staticlib> libname 796=item C<--staticlib> libname
796 797
876In them you can override shell variables, or define shell functions 877In them you can override shell variables, or define shell functions
877("hooks") to be called at specific phases during installation. For 878("hooks") to be called at specific phases during installation. For
878example, you could define a C<postinstall> hook to install additional 879example, you could define a C<postinstall> hook to install additional
879modules from CPAN each time you start from scratch. 880modules from CPAN each time you start from scratch.
880 881
881If the env variable C<$STATICPERLRC> is set, then F<staticperl> will try 882If the environment variable C<$STATICPERLRC> is set, then F<staticperl>
882to source the file named with it only. Otherwise, it tries the following 883will try to source the file named with it only. Otherwise, it tries the
883shell files in order: 884following shell files in order:
884 885
885 /etc/staticperlrc 886 /etc/staticperlrc
886 ~/.staticperlrc 887 ~/.staticperlrc
887 $STATICPERL/rc 888 $STATICPERL/rc
888 889
963=item C<PERL_CONFIGURE> 964=item C<PERL_CONFIGURE>
964 965
965Additional Configure options - these are simply passed to the perl 966Additional Configure options - these are simply passed to the perl
966Configure script. For example, if you wanted to enable dynamic loading, 967Configure script. For example, if you wanted to enable dynamic loading,
967you could pass C<-Dusedl>. To enable ithreads (Why would you want that 968you could pass C<-Dusedl>. To enable ithreads (Why would you want that
968insanity? Don't! Use L<forks> instead!) you would pass C<-Duseithreads> 969insanity? Don't! Use L<Coro> or L<forks> instead!) you would pass
969and so on. 970C<-Duseithreads> and so on.
970 971
971More commonly, you would either activate 64 bit integer support 972More commonly, you would either activate 64 bit integer support
972(C<-Duse64bitint>), or disable large files support (-Uuselargefiles), to 973(C<-Duse64bitint>), or disable large files support (C<-Uuselargefiles>),
973reduce filesize further. 974to reduce file size further.
974 975
975=item C<PERL_CC>, C<PERL_CCFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS> 976=item C<PERL_CC>, C<PERL_CCFLAGS>, C<PERL_OPTIMIZE>, C<PERL_LDFLAGS>, C<PERL_LIBS>
976 977
977These flags are passed to perl's F<Configure> script, and are generally 978These flags are passed to perl's F<Configure> script, and are generally
978optimised for small size (at the cost of performance). Since they also 979optimised for small size (at the cost of performance). Since they also
982F<~/.staticperlrc> to override them. 983F<~/.staticperlrc> to override them.
983 984
984Most of the variables override (or modify) the corresponding F<Configure> 985Most of the variables override (or modify) the corresponding F<Configure>
985variable, except C<PERL_CCFLAGS>, which gets appended. 986variable, except C<PERL_CCFLAGS>, which gets appended.
986 987
987The default for C<PERL_OPTIMIZE> is C<-Os> (assuming gcc), and for 988The default for C<PERL_OPTIMIZE> is C<-Os> (assuming gcc or compatible
988C<PERL_LIBS> is C<-lm -lcrypt>, which should be good for most (but not 989compilers), and for C<PERL_LIBS> is C<-lm -lcrypt>, which should be good
989all) systems. 990for most (but not all) systems.
990 991
991For other compilers or more customised optimisation settings, you need to 992For other compilers or more customised optimisation settings, you need to
992adjust these, e.g. in your F<~/.staticperlrc>. 993adjust these, e.g. in your F<~/.staticperlrc>.
993 994
994With gcc on x86 and amd64, you can get more space-savings by using: 995With gcc on x86 and amd64, you can often get more space-savings by using:
995 996
996 -Os -ffunction-sections -fdata-sections -finline-limit=8 -mpush-args 997 -Os -ffunction-sections -fdata-sections -finline-limit=8 -mpush-args
997 -mno-inline-stringops-dynamically -mno-align-stringops 998 -mno-inline-stringops-dynamically -mno-align-stringops
998 999
999And on x86 and pentium3 and newer (basically everything you might ever 1000And on x86 and pentium3 and newer (basically everything you might ever
1000want to run on), adding these is even better for space-savings (use 1001want to run on), adding these is even better for space-savings (use
1001-mtune=core2 or something newer for much faster code, too): 1002C<-mtune=core2> or something newer for much faster code, too):
1002 1003
1003 -fomit-frame-pointer -march=pentium3 -mtune=i386 1004 -fomit-frame-pointer -march=pentium3 -mtune=i386
1004 1005
1005=back 1006=back
1006 1007
1143 staticperl_init (0); 1144 staticperl_init (0);
1144 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); 1145 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
1145 eval_pv ("require myapp::main", 1); // executes "myapp/main.pm" 1146 eval_pv ("require myapp::main", 1); // executes "myapp/main.pm"
1146 } 1147 }
1147 1148
1148When your bootcode already wants to access some XS functions at 1149When your boot code already wants to access some XS functions at compile
1149compiletime, then you need to supply an C<xs_init> function pointer that 1150time, then you need to supply an C<xs_init> function pointer that is
1150is called as soon as perl is initialised enough to define XS functions, 1151called as soon as perl is initialised enough to define XS functions, but
1151but before the preamble code is executed: 1152before the preamble code is executed:
1152 1153
1153 static void 1154 static void
1154 xs_init (pTHX) 1155 xs_init (pTHX)
1155 { 1156 {
1156 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$"); 1157 newXSproto ("myapp::xsfunction", xsfunction, __FILE__, "$$;$");
1241 1242
1242=item any letter 1243=item any letter
1243 1244
1244Any path starting with a letter is a perl library file. For example, 1245Any path starting with a letter is a perl library file. For example,
1245F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and 1246F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and
1246F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">. 1247F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">.
1247 1248
1248Obviously, module names shouldn't start with any other characters than 1249Obviously, module names shouldn't start with any other characters than
1249letters :) 1250letters :)
1250 1251
1251=back 1252=back
1296 1297
1297=over 4 1298=over 4
1298 1299
1299=item utf8 1300=item utf8
1300 1301
1301Some functionality in the utf8 module, such as swash handling (used 1302Some functionality in the C<utf8> module, such as swash handling
1302for unicode character ranges in regexes) is implemented in the 1303(used for unicode character ranges in regexes) is implemented in the
1303C<"utf8_heavy.pl"> library: 1304C<utf8_heavy.pl> library:
1304 1305
1305 -Mutf8_heavy.pl 1306 -Mutf8_heavy.pl
1306 1307
1307Many Unicode properties in turn are defined in separate modules, 1308Many Unicode properties in turn are defined in separate modules,
1308such as C<"unicore/Heavy.pl"> and more specific data tables such as 1309such as C<unicore/Heavy.pl> and more specific data tables such as
1309C<"unicore/To/Digit.pl"> or C<"unicore/lib/Perl/Word.pl">. These tables 1310C<unicore/To/Digit.pl> or C<unicore/lib/Perl/Word.pl>. These tables
1310are big (7MB uncompressed, although F<staticperl> contains special 1311are big (7MB uncompressed, although F<staticperl> contains special
1311handling for those files), so including them only on demand in your 1312handling for those files), so including them only on demand in your
1312application might pay off. 1313application might pay off.
1313 1314
1314To simply include the whole unicode database, use: 1315To simply include the whole unicode database, use:
1359 1360
1360=item Net::SSLeay 1361=item Net::SSLeay
1361 1362
1362This module hasn't been significantly updated since OpenSSL is called 1363This module hasn't been significantly updated since OpenSSL is called
1363OpenSSL, and fails to properly link against dependent libraries, most 1364OpenSSL, and fails to properly link against dependent libraries, most
1364commonly, it forgets to specify -ldl when linking. 1365commonly, it forgets to specify C<-ldl> when linking.
1365 1366
1366On GNU/Linux systems this usually goes undetected, as perl usually links 1367On GNU/Linux systems this usually goes undetected, as perl usually links
1367against -ldl itself and OpenSSL just happens to pick it up that way, by 1368against C<-ldl> itself and OpenSSL just happens to pick it up that way, by
1368chance. 1369chance.
1369 1370
1370For static builds, you either have to configure -ldl manually, or you 1371For static builds, you either have to configure C<-ldl> manually, or you
1371cna use the following snippet in your C<postinstall> hook which patches 1372can use the following snippet in your C<postinstall> hook which patches
1372Net::SSLeay after installation, which happens to work most of the time: 1373Net::SSLeay after installation, which happens to work most of the time:
1373 1374
1374 postinstall() { 1375 postinstall() {
1375 # first install it 1376 # first install it
1376 instcpan Net::SSLeay 1377 instcpan Net::SSLeay

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines