]> granicus.if.org Git - apache/blobdiff - support/apxs.in
* apxs: Make apxs use LDFLAGS from config_vars.mk in addition to
[apache] / support / apxs.in
index fe545a883d91056e8e6ff2b5bf7ad79cfb311e51..8bdc2daca0221ac28de9920399345c6e500232dd 100644 (file)
@@ -1,59 +1,21 @@
 #!@perlbin@ -w
-# ====================================================================
-# The Apache Software License, Version 1.1
 #
-# Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
-# reserved.
+# 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
 #
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in
-#    the documentation and/or other materials provided with the
-#    distribution.
-#
-# 3. The end-user documentation included with the redistribution,
-#    if any, must include the following acknowledgment:
-#       "This product includes software developed by the
-#        Apache Software Foundation (http://www.apache.org/)."
-#    Alternately, this acknowledgment may appear in the software itself,
-#    if and wherever such third-party acknowledgments normally appear.
-#
-# 4. The names "Apache" and "Apache Software Foundation" must
-#    not be used to endorse or promote products derived from this
-#    software without prior written permission. For written
-#    permission, please contact apache@apache.org.
-#
-# 5. Products derived from this software may not be called "Apache",
-#    nor may "Apache" appear in their name, without prior written
-#    permission of the Apache Software Foundation.
-#
-# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
-# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
-# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-# ====================================================================
-#
-# This software consists of voluntary contributions made by many
-# individuals on behalf of the Apache Software Foundation.  For more
-# information on the Apache Software Foundation, please see
-# <http://www.apache.org/>.
+#     http://www.apache.org/licenses/LICENSE-2.0
 #
+# 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.003;
+require 5.004;
 use strict;
 package apxs;
 
@@ -77,6 +39,8 @@ 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     = get_vars("includedir");
 my $CFG_INCLUDEDIR = eval qq("$includedir");
 my $CFG_CC         = get_vars("CC");
@@ -113,6 +77,7 @@ 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
@@ -121,7 +86,6 @@ sub Getopts {
     my ($argumentative, @ARGV) = @_;
     my $errs = 0;
     local $_;
-    local $[ = 0;
 
     my @args = split / */, $argumentative;
     while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
@@ -131,7 +95,7 @@ sub Getopts {
             last;
         }
         my $pos = index($argumentative,$first);
-        if ($pos >= $[) {
+        if ($pos >= 0) {
             if ($pos < $#args && $args[$pos+1] eq ':') {
                 shift @ARGV;
                 if ($rest eq '') {
@@ -180,7 +144,7 @@ sub Getopts {
 
 sub usage {
     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
-    print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
+    print STDERR "       apxs -q [-v] [-S <var>=<val>] [<query> ...]\n";
     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
     print STDERR "               [-Wl,<flags>] [-p] <files> ...\n";
@@ -191,9 +155,9 @@ sub usage {
 
 #   option handling
 my $rc;
-($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaAp", @ARGV);
+($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaApv", @ARGV);
 &usage if ($rc == 0);
-&usage if ($#ARGV == -1 and not $opt_g);
+&usage if ($#ARGV == -1 and not $opt_g and not $opt_q);
 &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
 
 #   argument handling
@@ -225,28 +189,11 @@ if (@opt_S) {
 ##
 ##  Initial shared object support check
 ##
-my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
-$httpd = eval qq("$httpd");
-$httpd = eval qq("$httpd");
-my $envvars = get_vars("sbindir") . "/envvars";
-$envvars = eval qq("$envvars");
-$envvars = eval qq("$envvars");
-
-#allow apxs to be run from the source tree, before installation
-if ($0 =~ m:support/apxs$:) {
-    ($httpd = $0) =~ s:support/apxs$::;
-}
-
-unless (-x "$httpd") {
-       error("$httpd not found or not executable");
-       exit 1;
-}
-
-unless (grep /mod_so/, `. $envvars && $httpd -l`) {
+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("your server binary `$httpd'.");
+    error("the server binary.");
     exit 1;
 }
 
@@ -291,7 +238,6 @@ sub get_vars {
         }
     }
     $result =~ s|;;$||;
-    $result =~ s|:| |;
     return $result;
 }
 
@@ -358,8 +304,65 @@ if ($opt_q) {
     ##
     ##  QUERY INFORMATION 
     ##
-    my $result = get_vars(@args);
-    print "$result\n";
+    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);
+            }
+    
+            foreach (@vars) {
+                printf "%-${width}s = %s\n", $_, $config_vars{$_};
+            }
+        } else {
+            # Unprettified name=value list
+            foreach (keys %config_vars) {
+                print "$_=$config_vars{$_}\n";
+            }
+        }
+    }
+}
+
+my $apr_config = get_vars("APR_CONFIG");
+
+if (! -x "$apr_config") {
+    error("$apr_config not found!");
+    exit(1);
+}
+
+my $apr_major_version = (split /\./, `$apr_config --version`)[0];
+
+my $apu_config = "";
+if ($apr_major_version < 2) {
+    $apu_config = get_vars("APU_CONFIG");
+
+    if (! -x "$apu_config") {
+        error("$apu_config not found!");
+        exit(1);
+    }
+}
+
+my $libtool = `$apr_config --apr-libtool`;
+chomp($libtool);
+
+my $apr_includedir = `$apr_config --includes`;
+chomp($apr_includedir);
+my $apu_includedir = "";
+if ($apr_major_version < 2) {
+    $apu_includedir = `$apu_config --includes`;
+    chomp($apu_includedir);
 }
 
 if ($opt_c) {
@@ -392,11 +395,12 @@ if ($opt_c) {
             $dso_file =~ s|\.[^.]+$|.la|;
         }
         else {
-            $dso_file = "mod_unknown.so";
+            $dso_file = "mod_unknown.la";
         }
     }
     else {
         $dso_file = $opt_o;
+        $dso_file =~ s|\.[^.]+$|.la|;
     }
 
     #   create compilation commands
@@ -424,7 +428,7 @@ if ($opt_c) {
         $la =~ s|\.c$|.la|;
         my $o = $s;
         $o =~ s|\.c$|.o|;
-        push(@cmds, "$installbuilddir/libtool $ltflags --mode=compile $CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c -o $lo $s && touch $slo");
+        push(@cmds, "$libtool $ltflags --mode=compile $CFG_CC $cflags -I$CFG_INCLUDEDIR $apr_includedir $apu_includedir $opt -c -o $lo $s && touch $slo");
         unshift(@objs, $lo);
     }
 
@@ -435,12 +439,9 @@ if ($opt_c) {
         $lo .= " $o";
     }
     my ($opt_Wl, $opt_L, $opt_l);
+    $opt = '';
     foreach $opt_Wl (@opt_W) {
-        if ($CFG_CC !~ m/gcc$/) {
-            $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
-        } else {
-            $opt .= " -W$opt_Wl";
-        }
+        $opt .= "$1 " if ($opt_Wl =~ m|^\s*l,(.*)$|);
     }
     foreach $opt_L (@opt_L) {
         $opt .= " -L$opt_L";
@@ -449,35 +450,26 @@ if ($opt_c) {
         $opt .= " -l$opt_l";
     }
 
-    my $apr_bindir = get_vars("APR_BINDIR");
-
-    if (! -x "$apr_bindir/apr-config") {
-        error("$apr_bindir/apr-config not found!");
-        exit(1);
-    }
-
+    my $ldflags = "$CFG_LDFLAGS";
     if ($opt_p == 1) {
-        my $apu_bindir = get_vars("APU_BINDIR");
-
-        if (! -x "$apu_bindir/apu-config") {
-            error("$apu_bindir/apu-config not found!");
-            exit(1);
-        }
         
-        my $apr_libs=`$apr_bindir/apr-config --cflags --ldflags --link-libtool --libs`;
+        my $apr_libs=`$apr_config --cflags --ldflags --link-libtool --libs`;
         chomp($apr_libs);
-        my $apu_libs=`$apu_bindir/apu-config --ldflags --link-libtool --libs`;
-        chomp($apu_libs);
+        my $apu_libs="";
+        if ($apr_major_version < 2) {
+            $apu_libs=`$apu_config --ldflags --link-libtool --libs`;
+            chomp($apu_libs);
+        }
         
         $opt .= " ".$apu_libs." ".$apr_libs;
     }
     else {
-        my $apr_ldflags=`$apr_bindir/apr-config --ldflags`;
+        my $apr_ldflags=`$apr_config --ldflags`;
         chomp($apr_ldflags);
         $opt .= " -rpath $CFG_LIBEXECDIR -module -avoid-version $apr_ldflags";
     }
 
-    push(@cmds, "$installbuilddir/libtool $ltflags --mode=link $CFG_CC -o $dso_file $opt $lo");
+    push(@cmds, "$libtool $ltflags --mode=link $CFG_CC $ldflags -o $dso_file $opt $lo");
 
     #   execute the commands
     &execute_cmds(@cmds);
@@ -499,16 +491,18 @@ if ($opt_i or $opt_e) {
     my @cmds = ();
     my $f;
     foreach $f (@args) {
-        if ($f !~ m#(\.so$|\.la$)#) {
+        #  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|;
-        $t =~ s|\.la$|\.so|;
+        #  use .so unambigiously for installed shared library modules
+        $t =~ s|\.[^./\\]+$|\.so|;
         if ($opt_i) {
            push(@cmds, "$installbuilddir/instdso.sh SH_LIBTOOL='" .
-                 "$installbuilddir/libtool' $f $CFG_LIBEXECDIR");
+                 "$libtool' $f $CFG_LIBEXECDIR");
            push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
         }
 
@@ -522,7 +516,7 @@ if ($opt_i or $opt_e) {
                 open(FP, "<$base.c");
                 my $content = join('', <FP>);
                 close(FP);
-                if ($content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
+                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|^[^/]+/||;
@@ -576,11 +570,18 @@ if ($opt_i or $opt_e) {
         $c = '#' if ($opt_A);
         foreach $lmd (@lmd) {
             my $what = $opt_A ? "preparing" : "activating";
-            if ($content !~ m|\n#?\s*$lmd|) {
+            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);
 
@@ -596,11 +597,46 @@ if ($opt_i or $opt_e) {
                 else {
                     # put our cmd after the section containing the last
                     # LoadModule.
-                    $content =~ s!\A((?:(?:^\s*(?:[^<]|<[^/]).*(?:$)\n)*^\s*</.*(?:$)\n?){$cntopen})!$1$c$lmd\n!m;
+                    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[^\n]*\n|$1$c$lmd\n|s;
+                $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]");
@@ -652,7 +688,7 @@ APACHECTL=apachectl
 all: local-shared-build
 
 #   install the shared object file into Apache 
-install: install-modules
+install: install-modules-yes
 
 #   cleanup
 clean: