#!@perlbin@ -w
java.lang.NullPointerException # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at
java.lang.NullPointerException # http://www.apache.org/licenses/LICENSE-2.0
java.lang.NullPointerException # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
require 5.004;
use strict;
package apxs;
## ## Configuration ##
# are we building in a cross compile environment? If so, destdir contains # the base directory of the cross compiled environment, otherwise destdir # is the empty string.
my $destdir = "";
my $ddi = rindex($0, "@exp_bindir@"); if ($ddi >= 0) {
$destdir = substr($0, 0, $ddi);
}
my %config_vars = ();
my $installbuilddir = "@exp_installbuilddir@";
get_config_vars($destdir . "$installbuilddir/config_vars.mk",\%config_vars);
# read the configuration variables once
my $prefix = get_vars("prefix");
my $CFG_PREFIX = $prefix;
my $exec_prefix = get_vars("exec_prefix");
my $datadir = get_vars("datadir");
my $localstatedir = get_vars("localstatedir");
my $CFG_TARGET = get_vars("progname");
my $CFG_SYSCONFDIR = get_vars("sysconfdir");
my $CFG_CFLAGS = join ' ', map { get_vars($_) }
qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
my $CFG_LDFLAGS = join ' ', map { get_vars($_) }
qw(LDFLAGS NOTEST_LDFLAGS SH_LDFLAGS);
my $includedir = $destdir . get_vars("includedir");
my $CFG_INCLUDEDIR = eval qq("$includedir");
my $CFG_CC = get_vars("CC");
my $libexecdir = $destdir . get_vars("libexecdir");
my $CFG_LIBEXECDIR = eval qq("$libexecdir");
my $sbindir = get_vars("sbindir");
my $CFG_SBINDIR = eval qq("$sbindir");
my $ltflags = $ENV{'LTFLAGS'};
$ltflags or $ltflags = "--silent";
my %internal_vars = map {$_ => 1}
qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
## ## parse argument line ##
# defaults for parameters
my $opt_n = '';
my $opt_g = '';
my $opt_c = 0;
my $opt_o = '';
my @opt_D = ();
my @opt_I = ();
my @opt_L = ();
my @opt_l = ();
my @opt_W = ();
my @opt_S = ();
my $opt_e = 0;
my $opt_i = 0;
my $opt_a = 0;
my $opt_A = 0;
my $opt_q = 0;
my $opt_h = 0;
my $opt_p = 0;
my $opt_v = 0;
# this subroutine is derived from Perl's getopts.pl with the enhancement of # the "+" metacharacter at the format string to allow a list to be built by # subsequent occurrences of the same option.
sub Getopts {
my ($argumentative, @ARGV) = @_;
my $errs = 0;
local $_;
# option handling
my $rc;
($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaApv", @ARGV);
&usage if ($rc == 0);
&usage if ($#ARGV == -1andnot $opt_g andnot $opt_q);
&usage if (not $opt_q andnot ($opt_g and $opt_n) andnot $opt_i andnot $opt_c andnot $opt_e);
# argument handling
my @args = @ARGV;
my $name = 'unknown';
$name = $opt_n if ($opt_n ne '');
if (@opt_S) {
my ($opt_S);
foreach $opt_S (@opt_S) { if ($opt_S =~ m/^([^=]+)=(.*)$/) {
my ($var) = $1;
my ($val) = $2;
my $oldval = eval "\$CFG_$var";
unless ($var and $oldval) {
print STDERR "apxs:Error: no config variable $var\n";
&usage;
}
## ## Initial shared object support check ##
unless ("@MOD_SO_ENABLED@" eq "yes") {
error("Sorry, no shared object support for Apache");
error("available under your platform. Make sure");
error("the Apache module mod_so is compiled into");
error("the server binary."); exit1;
}
sub get_config_vars{
my ($file, $rh_config) = @_;
open IN, $file or die "cannot open $file: $!"; while (<IN>){ if (/^\s*(.*?)\s*=\s*(.*)$/){
$rh_config->{$1} = $2;
}
}
close IN;
}
sub get_vars {
my $result = '';
my $ok = 0;
my $arg;
foreach $arg (@_) { if (exists $config_vars{$arg} or exists $config_vars{lc $arg}) {
my $val = exists $config_vars{$arg}
? $config_vars{$arg}
: $config_vars{lc $arg};
$val =~ s/[()]//g;
$result .= eval "qq($val)"ifdefined $val;
$result .= ";;";
$ok = 1;
} if (not $ok) { if (exists $internal_vars{$arg} or exists $internal_vars{lc $arg}) {
my $val = exists $internal_vars{$arg} ? $arg : lc $arg;
$val = eval "\$CFG_$val";
$result .= eval "qq($val)"ifdefined $val;
$result .= ";;";
$ok = 1;
} if (not $ok) {
error("Invalid query string `$arg'"); exit(1);
}
}
}
$result =~ s|;;$||; return $result;
}
## ## Operation ##
# helper function for executing a list of # system command with return code checks
sub execute_cmds {
my (@cmds) = @_;
my ($cmd, $rc);
foreach $cmd (@cmds) {
notice($cmd);
$rc = system $cmd; if ($rc) {
error(sprintf "Command failed with rc=%d\n", $rc << 8); exit1 ;
}
}
}
if ($opt_g) { ## ## SAMPLE MODULE SOURCE GENERATION ##
if ($opt_q) { ## ## QUERY INFORMATION ##
my $result; if ($#args >= 0) {
$result = get_vars(@args);
print "$result\n";
} else { # -q without var name prints all variables and their values
# Additional -v pretty-prints output if ($opt_v) { # Variable names in alphabetic order
my @vars = sort {uc($a) cmp uc($b)} keys %config_vars;
# Make the left column as wide as the longest variable name
my $width = 0;
foreach (@vars) {
my $l = length $_;
$width = $l unless ($l <= $width);
}
# allow one-step compilation and installation if ($opt_i or $opt_e) {
@args = ( $dso_file );
}
}
if ($opt_i or $opt_e) { ## ## SHARED OBJECT INSTALLATION ##
# determine installation commands # and corresponding LoadModule directive
my @lmd = ();
my @cmds = ();
my $f;
foreach $f (@args) { # ack all potential gcc, hp/ux, win32+os2+aix and os/x extensions if ($f !~ m#(\.so$|\.la$|\.sl$|\.dll$|\.dylib$|)#) {
error("file $f is not a shared object"); exit(1);
}
my $t = $f;
$t =~ s|^.+/([^/]+)$|$1|; # use .so unambigiously for installed shared library modules
$t =~ s|\.[^./\\]+$|\.so|; if ($opt_i) {
push(@cmds, $destdir . "$installbuilddir/instdso.sh SH_LIBTOOL='" . "$libtool' $f $CFG_LIBEXECDIR");
push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
}
# determine module symbolname and filename
my $filename = ''; if ($name eq 'unknown') {
$name = '';
my $base = $f;
$base =~ s|\.[^.]+$||; if (-f "$base.c") {
open(FP, "<$base.c");
my $content = join('', <FP>);
close(FP); if ($content =~ m|.*AP_DECLARE_MODULE\s*\(\s*([a-zA-Z0-9_]+)\s*\)\s*=.*|s || $content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
$name = "$1";
$filename = "$base.c";
$filename =~ s|^[^/]+/||;
}
} if ($name eq '') { if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
$name = "$1";
$filename = $base;
$filename =~ s|^[^/]+/||;
}
} if ($name eq '') {
error("Sorry, cannot determine bootstrap symbol name");
error("Please specify one with option `-n'"); exit(1);
}
} if ($filename eq '') {
$filename = "mod_${name}.c";
}
my $dir = $CFG_LIBEXECDIR;
$dir =~ s|^$CFG_PREFIX/?||;
$dir =~ s|(.)$|$1/|;
$t =~ s|\.la$|.so|;
push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
}
# execute the commands
&execute_cmds(@cmds);
# activate module via LoadModule/AddModule directive if ($opt_a or $opt_A) { if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
error("Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found"); exit(1);
}
open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
my $content = join('', <FP>);
close(FP);
if ($content !~ m|\n#?\s*LoadModule\s+|) {
error("Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.");
error("At least one `LoadModule' directive already has to exist."); exit(1);
}
my $lmd;
my $c = '';
$c = '#'if ($opt_A);
foreach $lmd (@lmd) {
my $what = $opt_A ? "preparing" : "activating";
my $lmd_re = $lmd;
$lmd_re =~ s/\s+/\\s+/g;
if ($content !~ m|\n#?\s*$lmd_re|) { # check for open <containers>, so that the new LoadModule # directive always appears *outside* of an <container>.
my $before = ($content =~ m|^(.*\n)#?\s*LoadModule\s+[^\n]+\n|s)[0];
# the '()=' trick forces list context and the scalar # assignment counts the number of list members (aka number # of matches) then
my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
if ($cntopen == $cntclose) { # fine. Last LoadModule is contextless.
$content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|s;
}
elsif ($cntopen < $cntclose) {
error('Configuration file is not valid. There are sections'
. ' closed before opened.'); exit(1);
} else { # put our cmd after the section containing the last # LoadModule.
my $found =
$content =~ s!\A ( # string and capture start
(?:(?:
^\s* # start of conf line with a
(?:[^<]|<[^/]) # directive which does not # start with '</'
.*(?:$)\n # rest of the line. # the '$' is in parentheses # to avoid misinterpreting # the string "$\" as # perl variable.
)* # catch as much as possible # of such lines. (including # zero)
^\s*</.*(?:$)\n? # after the above, we # expect a config line with # a closing container (</)
) {$cntopen} # the whole pattern (bunch # of lines that end up with # a closing directive) must # be repeated $cntopen # times. That's it. # Simple, eh? ;-)
) # capture end
!$1$c$lmd\n!mx;
unless ($found) {
error('Configuration file is not valid. There are '
. 'sections opened and not closed.'); exit(1);
}
}
} else { # replace already existing LoadModule line
$content =~ s|^(.*\n)#?\s*$lmd_re[^\n]*\n|$1$c$lmd\n|s;
}
$lmd =~ m|LoadModule\s+(.+?)_module.*|;
notice("[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]");
} if (@lmd) { if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
print FP $content;
close(FP);
system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " . "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " . "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
} else {
notice("unable to open configuration file");
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.