home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / BuildOptions.pm < prev    next >
Encoding:
Perl POD Document  |  2004-07-23  |  6.6 KB  |  233 lines

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