#!/bin/sh ############################################################################# # configuration to fill in (or to replace in your .staticperlrc) STATICPERL=~/.staticperl CPAN=https://mirror.netcologne.de/cpan # which mirror to use BACKPAN=https://backpan.perl.org/ EMAIL="read the documentation " DLCACHE= # perl build variables MAKE=make PERL_VERSION=http://stableperl.schmorp.de/dist/latest.tar.gz # 5.12.5 and 5.8.9 are good choices for small builds PERL_CC=cc PERL_CONFIGURE="" # additional Configure arguments PERL_CCFLAGS="-g -DPERL_DISABLE_PMC -DPERL_ARENA_SIZE=16376 -DNO_PERL_MALLOC_ENV -D_GNU_SOURCE -DNDEBUG" PERL_OPTIMIZE="-Os" # -Os -ffunction-sections -fdata-sections -finline-limit=8 -ffast-math" ARCH="$(uname -m)" #case "$ARCH" in # i*86 | x86_64 | amd64 ) # PERL_OPTIMIZE="$PERL_OPTIMIZE -mpush-args -mno-inline-stringops-dynamically -mno-align-stringops -mno-ieee-fp" # x86/amd64 # case "$ARCH" in # i*86 ) # PERL_OPTIMIZE="$PERL_OPTIMIZE -fomit-frame-pointer -march=pentium3 -mtune=i386" # x86 only # ;; # esac # ;; #esac # -Wl,--gc-sections makes it impossible to check for undefined references # for some reason so we need to patch away the "-no" after Configure and before make :/ # --allow-multiple-definition exists to work around uclibc's pthread static linking bug #PERL_LDFLAGS="-Wl,--no-gc-sections -Wl,--allow-multiple-definition" PERL_LDFLAGS= PERL_LIBS="-lm -lcrypt" # perl loves to add lotsa crap itself # some configuration options for modules PERL_MM_USE_DEFAULT=1 PERL_MM_OPT="MAN1PODS= MAN3PODS=" #CORO_INTERFACE=p # needed without nptl on x86, due to bugs in linuxthreads - very slow #EV_EXTRA_DEFS='-DEV_FEATURES=4+8+16+64 -DEV_USE_SELECT=0 -DEV_USE_POLL=1 -DEV_USE_EPOLL=1 -DEV_NO_LOOPS -DEV_COMPAT3=0' export PERL_MM_USE_DEFAULT PERL_MM_OPT # which extra modules to install by default from CPAN that are # required by mkbundle STATICPERL_MODULES="ExtUtils::MakeMaker ExtUtils::CBuilder common::sense Pod::Strip PPI PPI::XS Pod::Usage" # which extra modules you might want to install EXTRA_MODULES="" # overridable functions preconfigure() { : ; } patchconfig() { : ; } postconfigure() { : ; } postbuild() { : ; } postcpanconfig() { : ; } postinstall() { : ; } # now source user config, if any if [ "$STATICPERLRC" ]; then . "$STATICPERLRC" else [ -r /etc/staticperlrc ] && . /etc/staticperlrc [ -r ~/.staticperlrc ] && . ~/.staticperlrc [ -r "$STATICPERL/rc" ] && . "$STATICPERL/rc" fi ############################################################################# # support # work around ExtUtils::CBuilder and others export CC="$PERL_CC" export CFLAGS="$PERL_CFLAGS" export LD="$PERL_CC" export LDFLAGS="$PERL_LDFLAGS" unset LIBS PERL_PREFIX="${PERL_PREFIX:=$STATICPERL/perl}" # where the perl gets installed unset PERL PERL5OPT PERL5LIB PERLLIB PERL_UNICODE PERLIO PERLIO_DEBUG PERL_MB_OPT LC_ALL=C; export LC_ALL # just to be on the safe side # prepend PATH - not required by staticperl itself, but might make # life easier when working in e.g. "staticperl cpan / look" PATH="$PERL_PREFIX/perl/bin:$PATH" # set version in a way that Makefile.PL can extract VERSION=VERSION; eval \ $VERSION="1.46" fatal() { printf -- "\nFATAL: %s\n\n" "$*" >&2 exit 1 } verbose() { printf -- "%s\n" "$*" } verblock() { verbose verbose "***" while read line; do verbose "*** $line" done verbose "***" verbose } rcd() { cd "$1" || fatal "$1: cannot enter" } trace() { prefix="$1"; shift # "$@" 2>&1 | while read line; do # echo "$prefix: $line" # done "$@" } trap wait 0 ############################################################################# # clean distclean() { verblock </dev/null 2>&1; } \ || wget -O $PERLTAR~ "$PERLURL" \ || curl -f >$PERLTAR~ "$PERLURL" \ || fatal "$URL: unable to download" rm -f $PERLTAR mv $PERLTAR~ $PERLTAR if [ "$DLCACHE" ]; then mkdir -p "$DLCACHE" cp $PERLTAR "$DLCACHE"/$PERLTAR~$$~ && \ mv "$DLCACHE"/$PERLTAR~$$~ "$DLCACHE"/$PERLTAR fi fi verblock < "$2~" || fatal "error while running sed" rm -f "$2" mv "$2~" "$2" } configure_failure() { cat </dev/null 2>&1 sedreplace '/^#define SITELIB/d' config_h.SH # I hate them for this grep -q -- -fstack-protector Configure && \ sedreplace 's/-fstack-protector/-fno-stack-protector/g' Configure # what did that bloke think grep -q -- usedl=.define hints/darwin.sh && \ sedreplace '/^usedl=.define.;$/d' hints/darwin.sh preconfigure || fatal "preconfigure hook failed" # trace configure \ sh Configure -Duselargefiles \ -Uuse64bitint \ -Dusemymalloc=n \ -Uusedl \ -Uusethreads \ -Uuseithreads \ -Uusemultiplicity \ -Uusesfio \ -Uuseshrplib \ -Uinstallusrbinperl \ -A ccflags=" $PERL_CCFLAGS" \ -Dcc="$PERL_CC" \ -Doptimize="$PERL_OPTIMIZE" \ -Dldflags="$PERL_LDFLAGS" \ -Dlibs="$PERL_LIBS" \ -Dprefix="$PERL_PREFIX" \ -Dbin="$PERL_PREFIX/bin" \ -Dprivlib="$PERL_PREFIX/lib" \ -Darchlib="$PERL_PREFIX/lib" \ -Uusevendorprefix \ -Dsitelib="$PERL_PREFIX/lib" \ -Dsitearch="$PERL_PREFIX/lib" \ -Uman1dir \ -Uman3dir \ -Usiteman1dir \ -Usiteman3dir \ -Dpager=/usr/bin/less \ -Demail="$EMAIL" \ -Dcf_email="$EMAIL" \ -Dcf_by="$EMAIL" \ $PERL_CONFIGURE \ -Duseperlio \ -Uversiononly \ -dE || configure_failure sedreplace ' s/-Wl,--no-gc-sections/-Wl,--gc-sections/g s/ *-fno-stack-protector */ /g ' config.sh patchconfig || fatal "patchconfig hook failed" sh Configure -S || fatal "Configure -S failed" postconfigure || fatal "postconfigure hook failed" : > staticstamp.configure ) || exit } write_shellscript() { { echo "#!/bin/sh" echo "STATICPERL=\"$STATICPERL\"" echo "PERL_PREFIX=\"$PERL_PREFIX\"" echo "MAKE=\"$MAKE\"" cat } >"$PERL_PREFIX/bin/$1" chmod 755 "$PERL_PREFIX/bin/$1" } build() { ( configure rcd "$STATICPERL/src/perl" verblock < "$PERL_PREFIX/staticstamp.postinstall" fi } install() { ( if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then build verblock <stacksize <<'EOSS' #! perl mkdir "lib", 0777; mkdir "lib/Storable", 0777; open my $fh, ">lib/Storable/Limit.pm" or die; syswrite $fh, < "$cache~"; then echo echo "*** FATAL: error while patching $path" echo else rm -f "$path" mv "$cache~" "$path" cp "$path" "$cache" fi fi fi } # patch CPAN::HandleConfig.pm to always include _our_ MyConfig.pm, # not the one in the users homedirectory, to avoid clobbering his. patch CPAN/HandleConfig.pm cpan_handleconfig_pm ' 1i\ use CPAN::MyConfig; # patched by staticperl ' # patch ExtUtils::MM_Unix to always search blib for modules # when building a perl - this works around Pango/Gtk2 being misdetected # as not being an XS module. patch ExtUtils/MM_Unix.pm mm_unix_pm ' /^sub staticmake/,/^}/ s/if (@{$self->{C}}) {/if (@{$self->{C}} or $self->{NAME} =~ m%^(Pango|Gtk2)$%) { # patched by staticperl/ ' # patch ExtUtils::Miniperl to always add DynaLoader # this is required for dynamic loading in static perls, # and static loading in dynamic perls, when rebuilding a new perl. # Why this patch is necessray I don't understand. Yup. patch ExtUtils/Miniperl.pm extutils_miniperl.pm ' /^sub writemain/ a\ push @_, "DynaLoader"; # patched by staticperl ' # ExtUtils::CBuilder always tries to link shared libraries # even on systems without shared library support. From the same # source as Module::Build, so no wonder it's broken beyond fixing. # and since so many dependent modules are even worse, # we hardwire to 0 to get their pure-perl versions. patch ExtUtils/CBuilder/Base.pm extutils_cbuilder_base.pm ' /^sub have_compiler/ a\ return 0; # patched by staticperl ' end_of_patch_postinstall # immediately use it "$PERL_PREFIX/bin/SP-patch-postinstall" # help to trick CPAN into avoiding ~/.cpan completely echo 1 >"$PERL_PREFIX/lib/CPAN/MyConfig.pm" # we call cpan with -MCPAN::MyConfig in this script, which # is strictly unnecessary as we have to patch CPAN anyway, # so consider it "for good measure". "$PERL_PREFIX"/bin/perl -MCPAN::MyConfig -MCPAN -e ' CPAN::Shell->o (conf => urllist => push => "'"$CPAN"'"); CPAN::Shell->o (conf => urllist => push => "'"$BACKPAN"'"); CPAN::Shell->o (conf => pushy_https => "0"); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); CPAN::Shell->o (conf => q); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan"); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/build"); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/prefs"); CPAN::Shell->o (conf => q , "'"$STATICPERL"'/cpan/histfile"); CPAN::Shell->o (conf => q, "'"$STATICPERL"'/cpan/sources"); CPAN::Shell->o (conf => q, "MAP_TARGET=perl"); CPAN::Shell->o (conf => q, "'"$PERL_PREFIX"'/bin/SP-make-make"); CPAN::Shell->o (conf => q, "'"$PERL_PREFIX"'/bin/SP-make-install-make"); CPAN::Shell->o (conf => q, q); CPAN::Shell->o (conf => q, q); CPAN::Shell->o (conf => q, q<0>); CPAN::Shell->o (conf => q, q<0>); CPAN::Shell->o (conf => q, q); CPAN::Shell->o (conf => q); ' || fatal "error while initialising CPAN" postcpanconfig : > "$PERL_PREFIX/staticstamp.install" fi _postinstall ) || exit } import() { ( IMPORT="$1" rcd "$STATICPERL" if ! [ -e "$PERL_PREFIX/staticstamp.install" ]; then verblock < "$PERL_PREFIX/.import" : > "$PERL_PREFIX/staticstamp.install" fi _postinstall ) || exit } ############################################################################# # install a module from CPAN instcpan() { [ $NOCHECK_INSTALL ] || install verblock < $_) for @ARGV' -- "$@" | tee "$STATICPERL/instcpan.log" if grep -q " -- NOT OK\$" "$STATICPERL/instcpan.log"; then fatal "failure while installing modules from CPAN ($*)" fi rm -f "$STATICPERL/instcpan.log" } ############################################################################# # install a module from unpacked sources instsrc() { [ $NOCHECK_INSTALL ] || install verblock </dev/null 2>&1 "$MAKE" distclean >/dev/null 2>&1 "$PERL_PREFIX"/bin/perl Makefile.PL || fatal "$mod: error running Makefile.PL" "$MAKE" || fatal "$mod: error building module" "$PERL_PREFIX"/bin/SP-make-install-make install || fatal "$mod: error installing module" "$MAKE" distclean >/dev/null 2>&1 exit 0 ) || exit $? done } ############################################################################# # main podusage() { echo if [ -e "$PERL_PREFIX/bin/perl" ]; then "$PERL_PREFIX/bin/perl" -MPod::Usage -e \ 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 2>/dev/null && exit fi # try whatever perl we can find perl -MPod::Usage -e \ 'pod2usage -input => *STDIN, -output => *STDOUT, -verbose => '$1', -exitval => 0, -noperldoc => 1' <"$0" \ 2>/dev/null && exit fatal "displaying documentation requires a working perl - try '$0 install' to build one in a safe location" } usage() { podusage 0 } catmkbundle() { { read dummy echo "#!$PERL_PREFIX/bin/perl" cat } <<'end_of_mkbundle' #!/opt/bin/perl ############################################################################# # cannot load modules till after the tracer BEGIN block our $VERBOSE = 1; our $STRIP = "pod"; # none, pod or ppi our $COMPRESS = "lzf"; our $KEEPNL = 0; our $UNISTRIP = 1; # always on, try to strip unicore swash data our $PERL = 0; our $APP; our $VERIFY = 0; our $STATIC = 0; our $PACKLIST = 0; our $IGNORE_ENV = 0; our $ALLOW_DYNAMIC = 0; our $HAVE_DYNAMIC; # maybe useful? our $EXTRA_CFLAGS = ""; our $EXTRA_LDFLAGS = ""; our $EXTRA_LIBS = ""; # TODO: at least with lzf, OPTIMIZE_SIZE sesm to be a win? (also, does not respect KEEPNL) our $OPTIMISE_SIZE = 0; # optimise for raw file size instead of for compression? our $CACHE; our $CACHEVER = 2; # do not change unless you know what you are doing my $PREFIX = "bundle"; my $PACKAGE = "static"; my %pm; my %pmbin; my @libs; my @static_ext; my $extralibs; my @staticlibs; my @incext; @ARGV or die "$0: use 'staticperl help' (or read the sources of staticperl)\n"; # remove "." from @INC - staticperl.sh does it for us, but be on the safe side BEGIN { @INC = grep !/^\.$/, @INC } $|=1; our ($TRACER_W, $TRACER_R); sub find_incdir($) { for (@INC) { next if ref; return $_ if -e "$_/$_[0]"; } undef } sub find_inc($) { my $dir = find_incdir $_[0]; return "$dir/$_[0]" if defined $dir; undef } BEGIN { # create a loader process to detect @INC requests before we load any modules my ($W_TRACER, $R_TRACER); # used by tracer pipe $R_TRACER, $TRACER_W or die "pipe: $!"; pipe $TRACER_R, $W_TRACER or die "pipe: $!"; unless (fork) { close $TRACER_R; close $TRACER_W; my $pkg = "pkg000000"; unshift @INC, sub { my $dir = find_incdir $_[1] or return; syswrite $W_TRACER, "-\n$dir\n$_[1]\n"; open my $fh, "<:raw:perlio", "$dir/$_[1]" or warn "ERROR: $dir/$_[1]: $!\n"; $fh }; while (<$R_TRACER>) { if (/use (.*)$/) { my $mod = $1; my $eval; if ($mod =~ /^'.*'$/ or $mod =~ /^".*"$/) { $eval = "require $mod"; } elsif ($mod =~ y%/.%%) { $eval = "require q\x00$mod\x00"; } else { my $pkg = ++$pkg; $eval = "{ package $pkg; use $mod; }"; } eval $eval; warn "ERROR: $@ (while loading '$mod')\n" if $@; } elsif (/eval (.*)$/) { my $eval = $1; eval $eval; warn "ERROR: $@ (in '$eval')\n" if $@; } syswrite $W_TRACER, "\n"; } exit 0; } } # module loading is now safe sub trace_parse { for (;;) { <$TRACER_R> =~ /^-$/ or last; my $dir = <$TRACER_R>; chomp $dir; my $name = <$TRACER_R>; chomp $name; $pm{$name} = "$dir/$name"; print "+ found potential dependency $name\n" if $VERBOSE >= 3; } } sub trace_module { print "tracing module $_[0]\n" if $VERBOSE >= 2; syswrite $TRACER_W, "use $_[0]\n"; trace_parse; } sub trace_eval { print "tracing eval $_[0]\n" if $VERBOSE >= 2; syswrite $TRACER_W, "eval $_[0]\n"; trace_parse; } sub trace_finish { close $TRACER_W; close $TRACER_R; } ############################################################################# # now we can use modules use common::sense; use Config; use Digest::MD5; sub cache($$$) { my ($variant, $src, $filter) = @_; if (length $CACHE and 2048 <= length $src and defined $variant) { my $file = "$CACHE/" . Digest::MD5::md5_hex "$CACHEVER\x00$variant\x00$src"; if (open my $fh, "<:raw:perlio", $file) { print "using cache for $file\n" if $VERBOSE >= 7; local $/; return <$fh>; } $src = $filter->($src); print "creating cache entry $file\n" if $VERBOSE >= 8; if (open my $fh, ">:raw:perlio", "$file~") { if ((syswrite $fh, $src) == length $src) { close $fh; rename "$file~", $file; } } return $src; } $filter->($src) } sub dump_string { my ($fh, $data) = @_; if (length $data) { if ($^O eq "MSWin32") { # 16 bit system, strings can't be longer than 64k. seriously. print $fh "{\n"; for ( my $ofs = 0; length (my $substr = substr $data, $ofs, 20); $ofs += 20 ) { $substr = join ",", map ord, split //, $substr; print $fh " $substr,\n"; } print $fh " 0 }\n"; } else { for ( my $ofs = 0; length (my $substr = substr $data, $ofs, 80); $ofs += 80 ) { $substr =~ s/([^\x20-\x21\x23-\x5b\x5d-\x7e])/sprintf "\\%03o", ord $1/ge; $substr =~ s/\?/\\?/g; # trigraphs... print $fh " \"$substr\"\n"; } } } else { print $fh " \"\"\n"; } } ############################################################################# sub glob2re { for (quotemeta $_[0]) { s/\\\*/\x00/g; s/\x00\x00/.*/g; s/\x00/[^\/]*/g; s/\\\?/[^\/]/g; $_ = s/^\\\/// ? "^$_\$" : "(?:^|/)$_\$"; s/(?: \[\^\/\] | \. ) \*\$$//x; return qr<$_>s } } our %INCSKIP = ( "unicore/TestProp.pl" => undef, # 3.5MB of insanity, apparently just some testcase ); sub get_dirtree { my $root = shift; my @tree; my $skip; my $scan; $scan = sub { for (sort do { opendir my $fh, $_[0] or return; readdir $fh }) { next if /^\./; my $path = "$_[0]/$_"; if (-d "$path/.") { $scan->($path); } else { $path = substr $path, $skip; push @tree, $path unless exists $INCSKIP{$path}; } } }; $root =~ s/\/$//; $skip = 1 + length $root; $scan->($root); \@tree } my $inctrees; sub get_inctrees { unless ($inctrees) { my %inctree; $inctree{$_} ||= [$_, get_dirtree $_] # entries in @INC are often duplicates for @INC; $inctrees = [values %inctree]; } @$inctrees } ############################################################################# sub cmd_boot { $pm{"!boot"} = $_[0]; } sub cmd_add { $_[0] =~ /^(.*?)(?:\s+(\S+))?$/ or die "$_[0]: cannot parse"; my $file = $1; my $as = defined $2 ? $2 : $1; $pm{$as} = $file; $pmbin{$as} = 1 if $_[1]; } sub cmd_staticlib { push @staticlibs, $_ for split /\s+/, $_[0]; } sub cmd_include { push @incext, [$_[1], glob2re $_[0]]; } sub cmd_incglob { my ($pattern) = @_; $pattern = glob2re $pattern; for (get_inctrees) { my ($dir, $files) = @$_; $pm{$_} = "$dir/$_" for grep /$pattern/ && /\.(pl|pm)$/, @$files; } } sub parse_argv; sub cmd_file { open my $fh, "<", $_[0] or die "$_[0]: $!\n"; local @ARGV; while (<$fh>) { chomp; next unless /\S/; next if /^\s*#/; s/^\s*-*/--/; my ($cmd, $args) = split / /, $_, 2; push @ARGV, $cmd; push @ARGV, $args if defined $args; } parse_argv; } use Getopt::Long; sub parse_argv { GetOptions "perl" => \$PERL, "app=s" => \$APP, "verbose|v" => sub { ++$VERBOSE }, "quiet|q" => sub { --$VERBOSE }, "strip=s" => \$STRIP, "keepnl" => \$KEEPNL, "compress=s" => \$COMPRESS, "cache=s" => \$CACHE, # internal option "eval|e=s" => sub { trace_eval $_[1] }, "use|M=s" => sub { trace_module $_[1] }, "boot=s" => sub { cmd_boot $_[1] }, "add=s" => sub { cmd_add $_[1], 0 }, "addbin=s" => sub { cmd_add $_[1], 1 }, "incglob=s" => sub { cmd_incglob $_[1] }, "include|i=s" => sub { cmd_include $_[1], 1 }, "exclude|x=s" => sub { cmd_include $_[1], 0 }, "usepacklists!" => \$PACKLIST, "static!" => \$STATIC, "staticlib=s" => sub { cmd_staticlib $_[1] }, "allow-dynamic!" => \$ALLOW_DYNAMIC, "ignore-env" => \$IGNORE_ENV, "extra-cflags=s" => \$EXTRA_CFLAGS, "extra-ldflags=s" => \$EXTRA_LDFLAGS, "extra-libs=s" => \$EXTRA_LIBS, "<>" => sub { cmd_file $_[0] }, or exit 1; } Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); parse_argv; die "cannot specify both --app and --perl\n" if $PERL and defined $APP; die "--compress must be either none or lzf\n" unless $COMPRESS =~ /^(?:none|lzf)\z/; # required for @INC loading, unfortunately trace_module "PerlIO::scalar"; ############################################################################# # apply include/exclude { my %pmi; for (@incext) { my ($inc, $glob) = @$_; my @match = grep /$glob/, keys %pm; if ($inc) { # include @pmi{@match} = delete @pm{@match}; print "applying include $glob - protected ", (scalar @match), " files.\n" if $VERBOSE >= 5; } else { # exclude delete @pm{@match}; print "applying exclude $glob - removed ", (scalar @match), " files.\n" if $VERBOSE >= 5; } } my @pmi = keys %pmi; @pm{@pmi} = delete @pmi{@pmi}; } ############################################################################# # scan for AutoLoader, static archives and other dependencies sub scan_al { my ($auto, $autodir) = @_; my $ix = "$autodir/autosplit.ix"; print "processing autoload index for '$auto'\n" if $VERBOSE >= 6; $pm{"$auto/autosplit.ix"} = $ix; open my $fh, "<:perlio", $ix or die "$ix: $!"; my $package; while (<$fh>) { if (/^\s*sub\s+ ([^[:space:];]+) \s* (?:\([^)]*\))? \s*;?\s*$/x) { my $al = "auto/$package/$1.al"; my $inc = find_inc $al; defined $inc or die "$al: autoload file not found, but should be there.\n"; $pm{$al} = $inc; print "found autoload function '$al'\n" if $VERBOSE >= 6; } elsif (/^\s*package\s+([^[:space:];]+)\s*;?\s*$/) { ($package = $1) =~ s/::/\//g; } elsif (/^\s*(?:#|1?\s*;?\s*$)/) { # nop } else { warn "WARNING: $ix: unparsable line, please report: $_"; } } } for my $pm (keys %pm) { if ($pm =~ /^(.*)\.pm$/) { my $auto = "auto/$1"; my $autodir = find_inc $auto; if (defined $autodir && -d $autodir) { # AutoLoader scan_al $auto, $autodir if -f "$autodir/autosplit.ix"; # extralibs.ld if (open my $fh, "<:perlio", "$autodir/extralibs.ld") { print "found extralibs for $pm\n" if $VERBOSE >= 6; local $/; $extralibs .= " " . <$fh>; } $pm =~ /([^\/]+).pm$/ or die "$pm: unable to match last component"; my $base = $1; # static ext if (-f "$autodir/$base$Config{_a}") { print "found static archive for $pm\n" if $VERBOSE >= 3; push @libs, "$autodir/$base$Config{_a}"; push @static_ext, $pm; } # dynamic object if (-f "$autodir/$base.$Config{dlext}") { if ($ALLOW_DYNAMIC) { my $as = "!$auto/$base.$Config{dlext}"; $pm{$as} = "$autodir/$base.$Config{dlext}"; $pmbin{$as} = 1; $HAVE_DYNAMIC = 1; print "+ added dynamic object $as\n" if $VERBOSE >= 3; } else { die "ERROR: found shared object '$autodir/$base.$Config{dlext}' but --allow-dynamic not given, aborting.\n" } } if ($PACKLIST && open my $fh, "<:perlio", "$autodir/.packlist") { print "found .packlist for $pm\n" if $VERBOSE >= 3; while (<$fh>) { chomp; s/ .*$//; # newer-style .packlists might contain key=value pairs # only include certain files (.al, .ix, .pm, .pl) if (/\.(pm|pl|al|ix)$/) { for my $inc (@INC) { # in addition, we only add files that are below some @INC path $inc =~ s/\/*$/\//; if ($inc eq substr $_, 0, length $inc) { my $base = substr $_, length $inc; $pm{$base} = $_; print "+ added .packlist dependency $base\n" if $VERBOSE >= 3; } last; } } } } } } } ############################################################################# print "processing bundle files (try more -v power if you get bored waiting here)...\n" if $VERBOSE >= 1; my $compress = sub { shift }; if ($COMPRESS eq "lzf") { require Compress::LZF; $compress = sub { Compress::LZF::compress_best (shift) }; } my $data; my @index; my @order = sort { length $a <=> length $b or $a cmp $b } keys %pm; # sorting by name - better compression, but needs more metadata # sorting by length - faster lookup # usually, the metadata overhead beats the loss through compression for my $pm (@order) { my $path = $pm{$pm}; 128 > length $pm or die "ERROR: $pm: path too long (only 128 octets supported)\n"; my $src = ref $path ? $$path : do { open my $pm, "<:raw:perlio", $path or die "$path: $!"; local $/; <$pm> }; my $size = length $src; unless ($pmbin{$pm}) { # only do this unless the file is binary if ($pm =~ /^auto\/POSIX\/[^\/]+\.al$/) { if ($src =~ /^ unimpl \"/m) { print "$pm: skipping (raises runtime error only).\n" if $VERBOSE >= 3; next; } } $src = cache "$STRIP,$UNISTRIP,$KEEPNL,$OPTIMISE_SIZE,$COMPRESS", $src, sub { if ($UNISTRIP && $pm =~ /^unicore\/.*\.pl$/) { print "applying unicore stripping $pm\n" if $VERBOSE >= 6; # special stripping for unicore swashes and properties # much more could be done by going binary $src =~ s{ (^return\ <<'END';\n) (.*?\n) (END(?:\n|\Z)) }{ my ($pre, $data, $post) = ($1, $2, $3); for ($data) { s/^([0-9a-fA-F]+)\t([0-9a-fA-F]+)\t/sprintf "%X\t%X", hex $1, hex $2/gem if $OPTIMISE_SIZE; # s{ # ^([0-9a-fA-F]+)\t([0-9a-fA-F]*)\t # }{ # # ww - smaller filesize, UU - compress better # pack "C0UU", # hex $1, # length $2 ? (hex $2) - (hex $1) : 0 # }gemx; s/#.*\n/\n/mg; s/\s+\n/\n/mg; } "$pre$data$post" }smex; } if ($STRIP =~ /ppi/i) { require PPI; # PPI (quite correctly) treats pod in __DATA__ as data, not pod, so # we don't have to work around Opcode.pm, as with Pod::Strip if (my $ppi = PPI::Document->new (\$src)) { for my $node ( @{ $ppi->find (PPI::Token::Comment::) }, @{ $ppi->find (PPI::Token::Pod::) } ) { if ($KEEPNL) { $node->{content} =~ s/[^\n]//g; $node->insert_after (PPI::Token::Whitespace->new ("\n")) if length $node->{content}; } $node->delete; } # prune END stuff for (my $last = $ppi->last_element; $last; ) { my $prev = $last->previous_token; if ($last->isa (PPI::Token::Whitespace::)) { $last->delete; } elsif ($last->isa (PPI::Statement::End::)) { $last->delete; last; } elsif ($last->isa (PPI::Token::Pod::)) { $last->delete; } elsif ($last->isa (PPI::Token::Comment::)) { $last->delete; } else { last; } $last = $prev; } # prune some but not all insignificant whitespace for my $ws (@{ $ppi->find (PPI::Token::Whitespace::) }) { my $prev = $ws->previous_token; my $next = $ws->next_token; if (!$prev || !$next) { $ws->delete; } else { if ($next->isa (PPI::Token::Whitespace::)) { # push this whitespace data into the next node $next->{content} = "$ws->{content}$next->{content}"; $ws->{content} = ""; } elsif ( ( $next->isa (PPI::Token::Operator::) && $next->{content} =~ /^(?:,|=|!|!=|==|=>)$/ # no ., because of digits. == float or $prev->isa (PPI::Token::Operator::) && $prev->{content} =~ /^(?:,|=|\.|!|!=|==|=>)$/ or $prev->isa (PPI::Token::Structure::) or ($OPTIMISE_SIZE && ($prev->isa (PPI::Token::Word::) && (PPI::Token::Symbol:: eq ref $next || $next->isa (PPI::Structure::Block::) || $next->isa (PPI::Structure::List::) || $next->isa (PPI::Structure::Condition::))) ) ) # perl has some idiotic warning about nonexisting operators (Reverse %s operator) # also catch "= ~" && !( $prev->isa (PPI::Token::Operator::) && $prev->{content} eq "=" && $next->isa (PPI::Token::Operator::) && $next->{content} =~ /[+\-\~]/ ) ) { if ($KEEPNL) { $ws->{content} =~ s/[^\n]//g; } else { $ws->{content} = ''; } } else { if ($KEEPNL) { $ws->{content} =~ s/[^\n]//g; $ws->{content} ||= ' '; # keep at least one space } else { $ws->{content} = ' '; } } } } # prune whitespace around blocks if ($OPTIMISE_SIZE) { # these usually decrease size, but decrease compressability more for my $struct (PPI::Structure::Block::, PPI::Structure::Condition::) { for my $node (@{ $ppi->find ($struct) }) { my $n1 = $node->first_token; my $n2 = $n1->previous_token; $n1->delete if $n1->isa (PPI::Token::Whitespace::); $n2->delete if $n2 && $n2->isa (PPI::Token::Whitespace::); my $n1 = $node->last_token; my $n2 = $n1->next_token; $n1->delete if $n1->isa (PPI::Token::Whitespace::); $n2->delete if $n2 && $n2->isa (PPI::Token::Whitespace::); } } for my $node (@{ $ppi->find (PPI::Structure::List::) }) { my $n1 = $node->first_token; $n1->delete if $n1->isa (PPI::Token::Whitespace::); my $n1 = $node->last_token; $n1->delete if $n1->isa (PPI::Token::Whitespace::); } } # reformat qw() lists which often have lots of whitespace for my $node (@{ $ppi->find (PPI::Token::QuoteLike::Words::) }) { if ($node->{content} =~ /^qw(.)(.*)(.)$/s) { my ($a, $qw, $b) = ($1, $2, $3); $qw =~ s/^\s+//; $qw =~ s/\s+$//; $qw =~ s/\s+/ /g; $node->{content} = "qw$a$qw$b"; } } $src = $ppi->serialize; } else { warn "WARNING: $pm{$pm}: PPI failed to parse this file\n"; } } elsif ($STRIP =~ /pod/i && $pm ne "Opcode.pm") { # opcode parses its own pod require Pod::Strip; my $stripper = Pod::Strip->new; my $out; $stripper->output_string (\$out); $stripper->parse_string_document ($src) or die; $src = $out; } if ($VERIFY && $pm =~ /\.pm$/ && $pm ne "Opcode.pm") { if (open my $fh, "-|") { <$fh>; } else { eval "#line 1 \"$pm\"\n$src" or warn "\n\n\n$pm\n\n$src\n$@\n\n\n"; exit 0; } } $src }; # if ($pm eq "Opcode.pm") { # open my $fh, ">x" or die; print $fh $src;#d# # exit 1; # } } $src = $compress->($src); print "adding $pm (original size $size, stored size ", length $src, ")\n" if $VERBOSE >= 2; push @index, ((length $pm) << 25) | length $data; $data .= $pm . $src; } length $data < 2**25 or die "ERROR: bundle too large (only 32MB supported)\n"; my $varpfx = "bundle"; ############################################################################# # output print "generating $PREFIX.h... " if $VERBOSE >= 1; { open my $fh, ">", "$PREFIX.h" or die "$PREFIX.h: $!\n"; print $fh < #include #include /* public API */ EXTERN_C PerlInterpreter *staticperl; EXTERN_C void staticperl_xs_init (pTHX); EXTERN_C void staticperl_init (XSINIT_t xs_init); /* argument can be 0 */ EXTERN_C void staticperl_cleanup (void); EOF } print "\n" if $VERBOSE >= 1; ############################################################################# # output print "generating $PREFIX.c... " if $VERBOSE >= 1; open my $fh, ">", "$PREFIX.c" or die "$PREFIX.c: $!\n"; print $fh <= 3 # define lzf_movsb(dst, src, len) \ asm ("rep movsb" \ : "=D" (dst), "=S" (src), "=c" (len) \ : "0" (dst), "1" (src), "2" (len)); #endif static unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len) { U8 const *ip = (const U8 *)in_data; U8 *op = (U8 *)out_data; U8 const *const in_end = ip + in_len; U8 *const out_end = op + out_len; do { unsigned int ctrl = *ip++; if (ctrl < (1 << 5)) /* literal run */ { ctrl++; if (op + ctrl > out_end) return 0; #ifdef lzf_movsb lzf_movsb (op, ip, ctrl); #else while (ctrl--) *op++ = *ip++; #endif } else /* back reference */ { unsigned int len = ctrl >> 5; U8 *ref = op - ((ctrl & 0x1f) << 8) - 1; if (len == 7) len += *ip++; ref -= *ip++; if (op + len + 2 > out_end) return 0; if (ref < (U8 *)out_data) return 0; len += 2; #ifdef lzf_movsb lzf_movsb (op, ref, len); #else do *op++ = *ref++; while (--len); #endif } } while (ip < in_end); return op - (U8 *)out_data; } static SV * static_to_sv (const char *ptr, STRLEN len) { SV *res; const U8 *p = (const U8 *)ptr; if (len == 0) /* empty */ res = newSVpvn ("", 0); else if (*p == 0) /* not compressed */ res = newSVpvn (p + 1, len - 1); else /* lzf compressed, with UTF-8-encoded original size in front */ { STRLEN ulenlen; UV ulen = utf8n_to_uvchr (p, len, &ulenlen, 0); p += ulenlen; len -= ulenlen; res = NEWSV (0, ulen); sv_upgrade (res, SVt_PV); SvPOK_only (res); lzf_decompress (p, len, SvPVX (res), ulen); SvCUR_set (res, ulen); } return res; } EOF } else { print $fh <bootstrap; @INC = $perlio_inc; D } else { D # PerlIO::scalar not available, use slower method D @INC = sub { D # always check if PerlIO::scalar might now be available D if (defined &PerlIO::scalar::bootstrap) { D # switch to the faster perlio_inc hook D @INC = map { $_ == $_[0] ? $perlio_inc : $_ } @INC; D goto &$perlio_inc; D } D D my $data = find "$_[1]" D or return; D D $INC{$_[1]} = "$inc_prefix$_[1]"; D D sub { D $data =~ /\G([^\n]*\n?)/g D or return; D D $_ = $1; D 1 D } D }; D } } '; $bootstrap .= "require '!boot';" if exists $pm{"!boot"}; if ($HAVE_DYNAMIC) { $bootstrap =~ s/^D/ /mg; } else { $bootstrap =~ s/^D.*$//mg; } $bootstrap =~ s/#.*$//mg; $bootstrap =~ s/\s+/ /g; $bootstrap =~ s/(\W) /$1/g; $bootstrap =~ s/ (\W)/$1/g; print $fh "const char bootstrap [] = "; dump_string $fh, $bootstrap; print $fh ";\n\n"; print $fh <> 1; U32 idx = $varpfx\_index [m]; int comp = namelen - (idx >> 25); if (!comp) { int ofs = idx & 0x1FFFFFFU; comp = memcmp (name, $varpfx\_data + ofs, namelen); if (!comp) { /* found */ int ofs2 = $varpfx\_index [m + 1] & 0x1FFFFFFU; ofs += namelen; res = static_to_sv ($varpfx\_data + ofs, ofs2 - ofs); goto found; } } if (comp < 0) r = m - 1; else l = m + 1; } XSRETURN (0); found: ST (0) = sv_2mortal (res); } XSRETURN (1); } /* list all files in the bundle */ XS(list) { dXSARGS; if (items != 0) Perl_croak (aTHX_ "Usage: $PACKAGE\::list"); { int i; EXTEND (SP, $varpfx\_count); for (i = 0; i < $varpfx\_count; ++i) { U32 idx = $varpfx\_index [i]; PUSHs (sv_2mortal (newSVpvn ($varpfx\_data + (idx & 0x1FFFFFFU), idx >> 25))); } } XSRETURN ($varpfx\_count); } #ifdef STATICPERL_BUNDLE_INCLUDE #include STATICPERL_BUNDLE_INCLUDE #endif EOF ############################################################################# # xs_init print $fh <= 1; ############################################################################# # libs, cflags my $ccopts; { print "generating $PREFIX.ccopts... " if $VERBOSE >= 1; $ccopts = "$Config{ccflags} $Config{optimize} $Config{cppflags} -I$Config{archlibexp}/CORE $EXTRA_CFLAGS"; $ccopts =~ s/([\(\)])/\\$1/g; open my $fh, ">$PREFIX.ccopts" or die "$PREFIX.ccopts: $!"; print $fh $ccopts; print "$ccopts\n\n" if $VERBOSE >= 1; } my $ldopts; { print "generating $PREFIX.ldopts... "; $ldopts = $STATIC ? "-static " : ""; $ldopts .= "$Config{ccdlflags} $Config{ldflags} $EXTRA_LDFLAGS @libs $Config{archlibexp}/CORE/$Config{libperl} $Config{perllibs} $EXTRA_LIBS"; my %seen; $ldopts .= " $_" for reverse grep !$seen{$_}++, reverse +($extralibs =~ /(\S+)/g); for (@staticlibs) { $ldopts =~ s/(^|\s) (-l\Q$_\E) ($|\s)/$1-Wl,-Bstatic $2 -Wl,-Bdynamic$3/gx; } $ldopts =~ s/([\(\)])/\\$1/g; open my $fh, ">$PREFIX.ldopts" or die "$PREFIX.ldopts: $!"; print $fh $ldopts; print "$ldopts\n\n" if $VERBOSE >= 1; } if ($PERL or defined $APP) { $APP = "perl" unless defined $APP; my $build = "$Config{cc} $ccopts -o \Q$APP\E$Config{_exe} bundle.c $ldopts"; print "build $APP...\n" if $VERBOSE >= 1; print "$build\n" if $VERBOSE >= 2; system $build; unlink "$PREFIX.$_" for qw(ccopts ldopts c h); print "\n" if $VERBOSE >= 1; } end_of_mkbundle } bundle() { MKBUNDLE="${MKBUNDLE:=$PERL_PREFIX/bin/SP-mkbundle}" catmkbundle >"$MKBUNDLE~" || fatal "$MKBUNDLE~: cannot create" chmod 755 "$MKBUNDLE~" && mv "$MKBUNDLE~" "$MKBUNDLE" CACHE="$STATICPERL/cache" mkdir -p "$CACHE" "$PERL_PREFIX/bin/perl" -- "$MKBUNDLE" --cache "$CACHE" "$@" } if [ $# -gt 0 ]; then while [ $# -gt 0 ]; do mkdir -p "$STATICPERL" || fatal "$STATICPERL: cannot create" mkdir -p "$PERL_PREFIX" || fatal "$PERL_PREFIX: cannot create" command="${1#--}"; shift case "$command" in version ) echo "staticperl version $VERSION" ;; fetch | configure | build | install | clean | realclean | distclean ) ( "$command" ) || exit ;; import ) ( import "$1" ) || exit shift ;; instsrc ) ( instsrc "$@" ) || exit exit ;; instcpan ) ( instcpan "$@" ) || exit exit ;; perl ) ( install ) || exit exec "$PERL_PREFIX/bin/perl" "$@" exit ;; cpan ) ( install ) || exit PERL="$PERL_PREFIX/bin/perl" export PERL exec "$PERL_PREFIX/bin/cpan" "$@" exit ;; mkbundle ) ( install ) || exit bundle "$@" exit ;; mkperl ) ( install ) || exit bundle --perl "$@" exit ;; mkapp ) ( install ) || exit bundle --app "$@" exit ;; help ) podusage 2 ;; * ) exec 1>&2 echo echo "Unknown command: $command" podusage 0 ;; esac done else usage fi exit 0 =head1 NAME staticperl - perl, libc, 100 modules, all in one standalone 500kb file =head1 SYNOPSIS staticperl help # print the embedded documentation staticperl fetch # fetch and unpack perl sources staticperl configure # fetch and then configure perl staticperl build # configure and then build perl staticperl install # build and then install perl staticperl clean # clean most intermediate files (restart at configure) staticperl distclean # delete everything installed by this script staticperl perl ... # invoke the perlinterpreter staticperl cpan # invoke CPAN shell staticperl instsrc path... # install unpacked modules staticperl instcpan modulename... # install modules from CPAN staticperl mkbundle # see documentation staticperl mkperl # see documentation staticperl mkapp appname # see documentation Typical Examples: staticperl install # fetch, configure, build and install perl staticperl cpan # run interactive cpan shell staticperl mkperl -MConfig_heavy.pl # build a perl that supports -V staticperl mkperl -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI -MURI::http # build a perl with the above modules linked in staticperl mkapp myapp --boot mainprog mymodules # build a binary "myapp" from mainprog and mymodules =head1 DESCRIPTION This script helps you to create single-file perl interpreters or applications, or embedding a perl interpreter in your applications. Single-file means that it is fully self-contained - no separate shared objects, no autoload fragments, no .pm or .pl files are needed. And when linking statically, you can create (or embed) a single file that contains perl interpreter, libc, all the modules you need, all the libraries you need and of course your actual program. With F and F on x86, you can create a single 500kb binary that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, Coro and so on. Or any other choice of modules (and some other size :). To see how this turns out, you can try out smallperl and bigperl, two pre-built static and compressed perl binaries with many and even more modules: just follow the links at L. The created files do not need write access to the file system (like PAR does). In fact, since this script is in many ways similar to PAR::Packer, here are the differences: =over 4 =item * The generated executables are much smaller than PAR created ones. Shared objects and the perl binary contain a lot of extra info, while the static nature of F allows the linker to remove all functionality and meta-info not required by the final executable. Even extensions statically compiled into perl at build time will only be present in the final executable when needed. In addition, F can strip perl sources much more effectively than PAR. =item * The generated executables start much faster. There is no need to unpack files, or even to parse Zip archives (which is slow and memory-consuming business). =item * The generated executables don't need a writable filesystem. F loads all required files directly from memory. There is no need to unpack files into a temporary directory. =item * More control over included files, more burden. PAR tries to be maintenance and hassle-free - it tries to include more files than necessary to make sure everything works out of the box. It mostly succeeds at this, but he extra files (such as the unicode database) can take substantial amounts of memory and file size. With F, the burden is mostly with the developer - only direct compile-time dependencies and L are handled automatically. This means the modules to include often need to be tweaked manually. All this does not preclude more permissive modes to be implemented in the future, but right now, you have to resolve hidden dependencies manually. =item * PAR works out of the box, F does not. Maintaining your own custom perl build can be a pain in the ass, and while F tries to make this easy, it still requires a custom perl build and possibly fiddling with some modules. PAR is likely to produce results faster. Ok, PAR never has worked for me out of the box, and for some people, F does work out of the box, as they don't count "fiddling with module use lists" against it, but nevertheless, F is certainly a bit more difficult to use. =back =head1 HOW DOES IT WORK? Simple: F downloads, compile and installs a perl version of your choice in F<~/.staticperl>. You can add extra modules either by letting F install them for you automatically, or by using CPAN and doing it interactively. This usually takes 5-10 minutes, depending on the speed of your computer and your internet connection. It is possible to do program development at this stage, too. Afterwards, you create a list of files and modules you want to include, and then either build a new perl binary (that acts just like a normal perl except everything is compiled in), or you create bundle files (basically C sources you can use to embed all files into your project). This step is very fast (a few seconds if PPI is not used for stripping, or the stripped files are in the cache), and can be tweaked and repeated as often as necessary. =head1 THE F SCRIPT This module installs a script called F into your perl binary directory. The script is fully self-contained, and can be used without perl (for example, in an uClibc/dietlibc/musl chroot environment). In fact, it can be extracted from the C distribution tarball as F, without any installation. The newest (possibly alpha) version can also be downloaded from L. F interprets the first argument as a command to execute, optionally followed by any parameters. There are two command categories: the "phase 1" commands which deal with installing perl and perl modules, and the "phase 2" commands, which deal with creating binaries and bundle files. =head2 PHASE 1 COMMANDS: INSTALLING PERL The most important command is F, which does basically everything. The default is to download and install perl 5.12.3 and a few modules required by F itself, but all this can (and should) be changed - see L, below. The command staticperl install is normally all you need: It installs the perl interpreter in F<~/.staticperl/perl>. It downloads, configures, builds and installs the perl interpreter if required. Most of the following F subcommands simply run one or more steps of this sequence. If it fails, then most commonly because the compiler options I selected are not supported by your compiler - either edit the F script yourself or create F<~/.staticperl> shell script where your set working C etc. variables. To force recompilation or reinstallation, you need to run F first. =over 4 =item F Prints some info about the version of the F script you are using. =item F Runs only the download and unpack phase, unless this has already happened. =item F Configures the unpacked perl sources, potentially after downloading them first. =item F Builds the configured perl sources, potentially after automatically configuring them. =item F Wipes the perl installation directory (usually F<~/.staticperl/perl>) and installs the perl distribution, potentially after building it first. =item F [args...] Invokes the compiled perl interpreter with the given arguments. Basically the same as starting perl directly (usually via F<~/.staticperl/bin/perl>), but beats typing the path sometimes. Example: check that the Gtk2 module is installed and loadable. staticperl perl -MGtk2 -e0 =item F [args...] Starts an interactive CPAN shell that you can use to install further modules. Installs the perl first if necessary, but apart from that, no magic is involved: you could just as well run it manually via F<~/.staticperl/perl/bin/cpan>, except that F additionally sets the environment variable C<$PERL> to the path of the perl interpreter, which is handy in subshells. Any additional arguments are simply passed to the F command. =item F module... Tries to install all the modules given and their dependencies, using CPAN. Example: staticperl instcpan EV AnyEvent::HTTPD Coro =item F directory... In the unlikely case that you have unpacked perl modules around and want to install from these instead of from CPAN, you can do this using this command by specifying all the directories with modules in them that you want to have built. =item F Deletes the perl source directory (and potentially cleans up other intermediate files). This can be used to clean up files only needed for building perl, without removing the installed perl interpreter. At the moment, it doesn't delete downloaded tarballs. The exact semantics of this command will probably change. =item F This wipes your complete F<~/.staticperl> directory. Be careful with this, it nukes your perl download, perl sources, perl distribution and any installed modules. It is useful if you wish to start over "from scratch" or when you want to uninstall F. =back =head2 PHASE 2 COMMANDS: BUILDING PERL BUNDLES Building (linking) a new F binary is handled by a separate script. To make it easy to use F from a F, the script is embedded into F, which will write it out and call for you with any arguments you pass: staticperl mkbundle mkbundle-args... In the oh so unlikely case of something not working here, you can run the script manually as well (by default it is written to F<~/.staticperl/mkbundle>). F is a more conventional command and expect the argument syntax commonly used on UNIX clones. For example, this command builds a new F binary and includes F (for F), F, F and a custom F script (from F in this distribution): # first make sure we have perl and the required modules staticperl instcpan AnyEvent::HTTPD # now build the perl staticperl mkperl -MConfig_heavy.pl -MAnyEvent::Impl::Perl \ -MAnyEvent::HTTPD -MURI::http \ --add 'eg/httpd httpd.pm' # finally, invoke it ./perl -Mhttpd As you can see, things are not quite as trivial: the L module has a hidden dependency which is not even a perl module (F), L needs at least one event loop backend that we have to specify manually (here L), and the F module (required by L) implements various URI schemes as extra modules - since L only needs C URIs, we only need to include that module. I found out about these dependencies by carefully watching any error messages about missing modules... Instead of building a new perl binary, you can also build a standalone application: # build the app staticperl mkapp app --boot eg/httpd \ -MAnyEvent::Impl::Perl -MAnyEvent::HTTPD -MURI::http # run it ./app Here are the three phase 2 commands: =over 4 =item F args... The "default" bundle command - it interprets the given bundle options and writes out F, F, F and F files, useful for embedding. =item F args... Creates a bundle just like F (in fact, it's the same as invoking F args...), but then compiles and links a new perl interpreter that embeds the created bundle, then deletes all intermediate files. =item F filename args... Does the same as F (in fact, it's the same as invoking F filename args...), but then compiles and links a new standalone application that simply initialises the perl interpreter. The difference to F is that the standalone application does not act like a perl interpreter would - in fact, by default it would just do nothing and exit immediately, so you should specify some code to be executed via the F<--boot> option. =back =head3 OPTION PROCESSING All options can be given as arguments on the command line (typically using long (e.g. C<--verbose>) or short option (e.g. C<-v>) style). Since specifying a lot of options can make the command line very long and unwieldy, you can put all long options into a "bundle specification file" (one option per line, with or without C<--> prefix) and specify this bundle file instead. For example, the command given earlier to link a new F could also look like this: staticperl mkperl httpd.bundle With all options stored in the F file (one option per line, everything after the option is an argument): use "Config_heavy.pl" use AnyEvent::Impl::Perl use AnyEvent::HTTPD use URI::http add eg/httpd httpd.pm All options that specify modules or files to be added are processed in the order given on the command line. =head3 BUNDLE CREATION WORKFLOW / STATICPERL MKBUNDLE OPTIONS F works by first assembling a list of candidate files and modules to include, then filtering them by include/exclude patterns. The remaining modules (together with their direct dependencies, such as link libraries and L files) are then converted into bundle files suitable for embedding. F can then optionally build a new perl interpreter or a standalone application. =over 4 =item Step 0: Generic argument processing. The following options influence F itself. =over 4 =item C<--verbose> | C<-v> Increases the verbosity level by one (the default is C<1>). =item C<--quiet> | C<-q> Decreases the verbosity level by one. =item any other argument Any other argument is interpreted as a bundle specification file, which supports all options (without extra quoting), one option per line, in the format C