apxs.in revision cadc09f9ce8c99fa7cff9b469b4b32cff59894fa
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# ====================================================================
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# Copyright (c) 2000 The Apache Software Foundation. All rights
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# reserved.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# Redistribution and use in source and binary forms, with or without
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# modification, are permitted provided that the following conditions
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# notice, this list of conditions and the following disclaimer in
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the documentation and/or other materials provided with the
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen# 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd# if any, must include the following acknowledgment:
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# "This product includes software developed by the
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# Apache Software Foundation (http://www.apache.org/)."
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd# if and wherever such third-party acknowledgments normally appear.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# 4. The names "Apache" and "Apache Software Foundation" must
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# not be used to endorse or promote products derived from this
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# software without prior written permission. For written
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# permission, please contact apache@apache.org.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end# 5. Products derived from this software may not be called "Apache",
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen# nor may "Apache" appear in their name, without prior written
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen# permission of the Apache Software Foundation.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem# DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# SUCH DAMAGE.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# ====================================================================
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# This software consists of voluntary contributions made by many
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# individuals on behalf of the Apache Software Foundation. For more
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# information on the Apache Software Foundation, please see
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## apxs -- APache eXtenSion tool
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Written by Ralf S. Engelschall <rse@apache.org>
25ed62dce99fb4e35a6e8df83b948f877db22393ndrequire 5.003;
25ed62dce99fb4e35a6e8df83b948f877db22393nd## Configuration
25ed62dce99fb4e35a6e8df83b948f877db22393ndmy $CFG_TARGET = '@TARGET@'; # substituted via Makefile.tmpl
25ed62dce99fb4e35a6e8df83b948f877db22393ndmy $CFG_CFLAGS = '@CFLAGS@'; # substituted via Makefile.tmpl
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $CFG_CFLAGS_SHLIB = '@CFLAGS_SHLIB@'; # substituted via Makefile.tmpl
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $CFG_LD_SHLIB = '@LD_SHLIB@'; # substituted via Makefile.tmpl
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowenmy $CFG_LDFLAGS_SHLIB = '@LDFLAGS_MOD_SHLIB@'; # substituted via Makefile.tmpl
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowenmy $CFG_LIBS_SHLIB = '@LIBS_SHLIB@'; # substituted via Makefile.tmpl
c3ed174bff42ea3c139df9010d93d94316f3a5abigalicmy $CFG_PREFIX = '@prefix@'; # substituted via APACI install
ba1761b7cdc483fa8460f183a95b520e789a161andmy $CFG_SBINDIR = '@sbindir@'; # substituted via APACI install
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $CFG_INCLUDEDIR = '@includedir@'; # substituted via APACI install
ba1761b7cdc483fa8460f183a95b520e789a161andmy $CFG_LIBEXECDIR = '@libexecdir@'; # substituted via APACI install
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $CFG_SYSCONFDIR = '@sysconfdir@'; # substituted via APACI install
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Cleanup the above stuff
ba1761b7cdc483fa8460f183a95b520e789a161and## parse argument line
ba1761b7cdc483fa8460f183a95b520e789a161and# defaults for parameters
ba1761b7cdc483fa8460f183a95b520e789a161and# this subroutine is derived from Perl's getopts.pl with the enhancement of
ba1761b7cdc483fa8460f183a95b520e789a161and# the "+" metacharater at the format string to allow a list to be build by
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# subsequent occurance of the same option.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR " apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR " [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR " apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR " apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# option handling
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
acf65805923cf80834c39689cc0e2a8e7201c186sf&usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
acf65805923cf80834c39689cc0e2a8e7201c186sf# argument handling
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf## Initial shared object support check
4044e4b6cb07cf7fa8e90676fafffe543c1d439bjim print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "apxs:Error: Sorry, no shared object support for Apache\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR "apxs:Error: available under your platform. Make sure\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "apxs:Error: the Apache module mod_so is compiled into\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "apxs:Error: your server binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf## Operation
d0828c8a321dc5e9ea60550f052294669c08cf93jim# helper function for executing a list of
acf65805923cf80834c39689cc0e2a8e7201c186sf# system command with return code checks
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndsub execute_cmds {
acf65805923cf80834c39689cc0e2a8e7201c186sf my (@cmds) = @_;
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($cmd, $rc);
abde5157296f0b860f7551d8a80fa5dffa20e6cajim foreach $cmd (@cmds) {
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "$cmd\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf $rc = system("$cmd");
acf65805923cf80834c39689cc0e2a8e7201c186sf if ($rc != 0) {
bc525661d031758c0a4e771543372b4869ca86aand printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc << 8);
65a611af7093423efb91e5794b8887a527d4cf63trawickif ($opt_g) {
acf65805923cf80834c39689cc0e2a8e7201c186sf ## SAMPLE MODULE SOURCE GENERATION
acf65805923cf80834c39689cc0e2a8e7201c186sf if (-d $name) {
6fe26506780e73be2a412d758af77fafdf03291and print STDERR "apxs:Error: Directory `$name' already exists. Remove first\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf my $data = join('', <DATA>);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd $data =~ s|%NAME%|$name|sg;
acf65805923cf80834c39689cc0e2a8e7201c186sf $data =~ s|%TARGET%|$CFG_TARGET|sg;
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
acf65805923cf80834c39689cc0e2a8e7201c186sf close(FP);
acf65805923cf80834c39689cc0e2a8e7201c186sf close(FP);
acf65805923cf80834c39689cc0e2a8e7201c186sf ## QUERY INFORMATION
acf65805923cf80834c39689cc0e2a8e7201c186sf foreach $arg (@args) {
acf65805923cf80834c39689cc0e2a8e7201c186sf foreach $name (qw(
acf65805923cf80834c39689cc0e2a8e7201c186sf TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
acf65805923cf80834c39689cc0e2a8e7201c186sf PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
acf65805923cf80834c39689cc0e2a8e7201c186sf if (not $ok) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
acf65805923cf80834c39689cc0e2a8e7201c186sf $result =~ s|::$||;
acf65805923cf80834c39689cc0e2a8e7201c186sf $result =~ s|::| |;
acf65805923cf80834c39689cc0e2a8e7201c186sf $dso_file =~ s|\.[^.]+$|.so|;
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton $dso_file =~ s|\.[^.]+$|.so|;
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $o = $s;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $o =~ s|\.c$|.o|;
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
c1621f589e6e26efc55db89e59c9f445580856cctrawick print STDERR "apxs:Error: file $f is not a shared object\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $t = $f;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $base =~ s|\.[^.]+$||;
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename =~ s|^[^/]+/||;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename =~ s|^[^/]+/||;
8559a67073808d84d85bb5dd552d4247caafe709sf print "apxs:Error: Sorry, cannot determine bootstrap symbol name\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick print "apxs:Error: Please specify one with option `-n'\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($filename eq '') {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename = "mod_${name}.c";
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $dir = $CFG_LIBEXECDIR;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $dir =~ s|^$CFG_PREFIX/?||;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $dir =~ s|(.)$|$1/|;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@amd, sprintf("AddModule %s", $filename));
c1621f589e6e26efc55db89e59c9f445580856cctrawick # execute the commands
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd &execute_cmds(@cmds);
c1621f589e6e26efc55db89e59c9f445580856cctrawick # activate module via LoadModule/AddModule directive
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if ($opt_a or $opt_A) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick if (not -f "$CFG_SYSCONFDIR/$CFG_TARGET.conf") {
c1621f589e6e26efc55db89e59c9f445580856cctrawick print "apxs:Error: Config file $CFG_SYSCONFDIR/$CFG_TARGET.conf not found\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $content = join('', <FP>);
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($content !~ m|\n#?\s*LoadModule\s+|) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick print STDERR "apxs:Error: Activation failed for custom $CFG_SYSCONFDIR/$CFG_TARGET.conf file.\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
3565dbca9832b5199154ec8de294f24582fbd73end my $c = '';
c1621f589e6e26efc55db89e59c9f445580856cctrawick $c = '#' if ($opt_A);
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $lmd (@lmd) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($content !~ m|\n#?\s*$lmd|) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $lmd =~ m|LoadModule\s+(.+?)_module.*|;
604c89126c27104f659d7a51b0113e3bd435faf8fielding print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
c1621f589e6e26efc55db89e59c9f445580856cctrawick if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick system("cp $CFG_SYSCONFDIR/$CFG_TARGET.conf $CFG_SYSCONFDIR/$CFG_TARGET.conf.bak && " .
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar "cp $CFG_SYSCONFDIR/$CFG_TARGET.conf.new $CFG_SYSCONFDIR/$CFG_TARGET.conf && " .
c1621f589e6e26efc55db89e59c9f445580856cctrawick## Makefile -- Build procedure for sample %NAME% Apache module
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Autogenerated via ``apxs -n %NAME% -g''.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the used tools
c1621f589e6e26efc55db89e59c9f445580856cctrawick# additional defines, includes and libraries
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#DEF=-Dmy_define=my_value
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#LIB=-Lmy/lib/dir -lmylib
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the default target
c1621f589e6e26efc55db89e59c9f445580856cctrawick# compile the shared object file
a5a2e98043365d3f5a8bb3c3cdfc252a4f11bf02nd# install the shared object file into Apache
c1621f589e6e26efc55db89e59c9f445580856cctrawick# simple test
c1621f589e6e26efc55db89e59c9f445580856cctrawick# install and activate shared object by reloading Apache to
c1621f589e6e26efc55db89e59c9f445580856cctrawick# force a reload of the shared object file
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the general Apache start/restart/stop
c1621f589e6e26efc55db89e59c9f445580856cctrawick# procedures
c1621f589e6e26efc55db89e59c9f445580856cctrawick** To play with this sample module first compile it into a
c1621f589e6e26efc55db89e59c9f445580856cctrawick** DSO file and install it into Apache's libexec directory
c1621f589e6e26efc55db89e59c9f445580856cctrawick** by running:
c1621f589e6e26efc55db89e59c9f445580856cctrawick** $ apxs -c -i mod_%NAME%.c
c1621f589e6e26efc55db89e59c9f445580856cctrawick** Then activate it in Apache's %TARGET%.conf file for instance
2a0b626c070fea0a68a071a4160ff695eb4731dand** you immediately can request the URL /%NAME and watch for the
c1621f589e6e26efc55db89e59c9f445580856cctrawick** output of this module. This can be achieved for instance via:
c819c19c2f1ffbf3a3f12a4070cc6c3f4ea2a6f2sf %NAME%_handlers, /* [#8] MIME-typed-dispatched handlers */