home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / BuildOptions.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-15  |  6.0 KB  |  216 lines

  1. package ModPerl::BuildOptions;
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Apache::Build ();
  7. use Apache::TestTrace;
  8. my $param_qr = qr([\s=]+);
  9.  
  10. use constant VERBOSE => 1;
  11. use constant UNKNOWN_FATAL => 2;
  12.  
  13. use File::Spec;
  14.  
  15. sub init {
  16.     my($self, $build) = @_;
  17.  
  18.     #@ARGV should override what's in .makepl_args.mod_perl2
  19.     #but @ARGV might also override the default MP_OPTS_FILE
  20.     #so snag that first
  21.     parse($build, [grep { /^MP_OPTIONS_FILE/ } @ARGV]);
  22.     parse_file($build);
  23.     parse_argv($build);
  24.  
  25.     # if AP_PREFIX is used apxs and apr-config from the apache build
  26.     # tree won't work, so it can't co-exist with APXS and APR_CONFIG
  27.     # options
  28.     if ($build->{MP_AP_PREFIX} and $build->{MP_APXS}) {
  29.         error "You need to pass either MP_AP_PREFIX or MP_APXS, but not both";
  30.         die "\n";
  31.     }
  32.     if ($build->{MP_AP_PREFIX} and $build->{MP_APR_CONFIG}) {
  33.         error "You need to pass either MP_AP_PREFIX or MP_APR_CONFIG, " .
  34.             "but not both";
  35.         die "\n";
  36.     }
  37.  
  38.     if ($build->{MP_DEBUG} and $build->{MP_USE_GTOP} and !$build->find_gtop) {
  39.         error "Can't find libgtop, resetting MP_USE_GTOP=0";
  40.         $build->{MP_USE_GTOP} = 0;
  41.     }
  42.  
  43.     unless ($build->{MP_USE_DSO} or $build->{MP_USE_STATIC}) {
  44.         $build->{MP_USE_DSO} = $build->{MP_USE_STATIC} = 1;
  45.     }
  46.  
  47.     $build->{MP_GENERATE_XS} = 1 unless exists $build->{MP_GENERATE_XS};
  48.  
  49.     # define MP_COMPAT_1X unless explicitly told to disable it
  50.     $build->{MP_COMPAT_1X} = 1
  51.         unless exists $build->{MP_COMPAT_1X} && !$build->{MP_COMPAT_1X};
  52.  
  53. }
  54.  
  55. sub parse {
  56.     my($self, $lines, $opts) = @_;
  57.  
  58.     $opts = VERBOSE|UNKNOWN_FATAL unless defined $opts;
  59.     my $table = table();
  60.     my @unknown;
  61.     my $continue = "";
  62.  
  63.     for (@$lines) {
  64.         #XXX: this "parser" should be more robust
  65.         chomp;
  66.         s/^\s+//; s/\s+$//;
  67.         next if /^\#/ || /^$/;
  68.         last if /^__END__/;
  69.  
  70.         $_ = "$continue $_" if $continue;
  71.  
  72.         #example: +"MP_CCOPTS=-Werror" if $] >= 5.007
  73.         if (s/^\+//) {
  74.             $_ = eval $_;
  75.         }
  76.  
  77.         if (/^MP_/) {
  78.             my($key, $val) = split $param_qr, $_, 2;
  79.             $val ||= "";
  80.             $continue = $val =~ s/\\$// ? $key : "";
  81.  
  82.             if (!$table->{$key} and $opts & UNKNOWN_FATAL) {
  83.                 my $usage = usage();
  84.                 die "Unknown Option: $key\nUsage:\n$usage";
  85.             }
  86.  
  87.             if ($key eq 'MP_APXS') {
  88.                 $val = File::Spec->canonpath(File::Spec->rel2abs($val));
  89.             }
  90.  
  91.             if ($key eq 'MP_AP_PREFIX') {
  92.                 $val = File::Spec->canonpath(File::Spec->rel2abs($val));
  93.  
  94.                 if (Apache::Build::WIN32()) {
  95.                     # MP_AP_PREFIX may not contain spaces
  96.                     require Win32;
  97.                     $val = Win32::GetShortPathName($val);
  98.                 }
  99.             }
  100.  
  101.             if ($table->{$key}->{append}){
  102.                 $self->{$key} = join " ", grep $_, $self->{$key}, $val;
  103.             }
  104.             else {
  105.                 $self->{$key} = $val;
  106.             }
  107.  
  108.             print "   $key = $val\n" if $opts & VERBOSE;
  109.         }
  110.         else {
  111.             push @unknown, $_;
  112.         }
  113.     }
  114.  
  115.     return \@unknown;
  116. }
  117.  
  118. sub parse_file {
  119.     my $self = shift;
  120.  
  121.     my $fh;
  122.     my @dirs = qw(./ ../ ./. ../.);
  123.     push @dirs, "$ENV{HOME}/." if exists $ENV{HOME};
  124.     my @files = map { $_ . 'makepl_args.mod_perl2' } @dirs;
  125.     unshift @files, $self->{MP_OPTIONS_FILE} if $self->{MP_OPTIONS_FILE};
  126.  
  127.     for my $file (@files) {
  128.         if (open $fh, $file) {
  129.             $self->{MP_OPTIONS_FILE} = $file;
  130.             last;
  131.         }
  132.         $fh = undef;
  133.     }
  134.  
  135.     return unless $fh;
  136.  
  137.     print "Reading Makefile.PL args from $self->{MP_OPTIONS_FILE}\n";
  138.     my $unknowns = parse($self, [<$fh>]);
  139.     push @ARGV, @$unknowns if $unknowns;
  140.  
  141.     close $fh;
  142. }
  143.  
  144. sub parse_argv {
  145.     my $self = shift;
  146.     return unless @ARGV;
  147.  
  148.     my @args = @ARGV;
  149.     @ARGV = ();
  150.  
  151.     print "Reading Makefile.PL args from \@ARGV\n";
  152.     my $unknowns = parse($self, \@args);
  153.     push @ARGV, @$unknowns if $unknowns;
  154. }
  155.  
  156. sub usage {
  157.     my $table = table();
  158.     my @opts = map { "$_ - $table->{$_}->{val}" } sort keys %$table;
  159.     join "\n", @opts;
  160. }
  161.  
  162. sub parse_table {
  163.     my($fh) = @_;
  164.     my %table;
  165.     local $_;
  166.  
  167.     while (<$fh>) {
  168.         chomp;
  169.         s/^\s+//; s/\s+$//;
  170.         next if /^\#/ || /^$/;
  171.         last if /^__END__/;
  172.         my($key, $append, $val) = split /\s+/, $_, 3;
  173.         $table{'MP_' . $key} = { append => $append, val => $val };
  174.     }
  175.  
  176.     return \%table;
  177. }
  178.  
  179. my $Table;
  180.  
  181. sub table {
  182.     $Table ||= parse_table(\*DATA);
  183. }
  184.  
  185. 1;
  186.  
  187. # __DATA__ format:
  188. # key        append     description
  189. # where:
  190. #     key:    is the option name
  191. #     append: is whether we want to replace a default option (0)
  192. #             or append the arg to the option (1)
  193. #     desc:   description for this option
  194.  
  195. __DATA__
  196. USE_GTOP       0    Link with libgtop and enable libgtop reporting
  197. DEBUG          0    Turning on debugging (-g -lperld) and tracing
  198. MAINTAINER     0    Maintainer mode: DEBUG=1 -DAP_DEBUG -Wall ...
  199. CCOPTS         1    Add to compiler flags
  200. TRACE          0    Turn on tracing
  201. USE_DSO        0    Build mod_perl as a dso
  202. USE_STATIC     0    Build mod_perl static
  203. INST_APACHE2   0    Install *.pm relative to Apache2/ directory
  204. PROMPT_DEFAULT 0    Accept default value for all would-be prompts
  205. OPTIONS_FILE   0    Read options from given file
  206. STATIC_EXTS    0    Build Apache::*.xs as static extensions
  207. APXS           0    Path to apxs
  208. AP_PREFIX      0    Apache installation or source tree prefix
  209. APR_CONFIG     0    Path to apr-config
  210. XS_GLUE_DIR    1    Directories containing extension glue
  211. INCLUDE_DIR    1    Add directories to search for header files
  212. GENERATE_XS    0    Generate XS code based on httpd version
  213. LIBNAME        0    Name of the modperl dso library (default is  mod_perl)
  214. COMPAT_1X      0    Compile-time mod_perl 1.0 backcompat (default is  on)
  215.  
  216.