App-Staticperl

 view release on metacpan or  search on metacpan

mkbundle  view on Meta::CPAN

}

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,
      "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;

# required for @INC loading, unfortunately
trace_module "PerlIO::scalar";



( run in 0.486 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )