apxs.in revision cadc09f9ce8c99fa7cff9b469b4b32cff59894fa
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#!/usr/local/bin/perl
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# ====================================================================
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd#
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# Copyright (c) 2000 The Apache Software Foundation. All rights
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# reserved.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# Redistribution and use in source and binary forms, with or without
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# modification, are permitted provided that the following conditions
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc# are met:
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd#
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.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
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#
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.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
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.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
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#
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# <http://www.apache.org/>.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd##
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## apxs -- APache eXtenSion tool
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Written by Ralf S. Engelschall <rse@apache.org>
6c4ef4a72d9897e53365b94103f4bd819fd0d3acnd##
25ed62dce99fb4e35a6e8df83b948f877db22393nd
25ed62dce99fb4e35a6e8df83b948f877db22393ndrequire 5.003;
25ed62dce99fb4e35a6e8df83b948f877db22393nduse strict;
25ed62dce99fb4e35a6e8df83b948f877db22393ndpackage apxs;
25ed62dce99fb4e35a6e8df83b948f877db22393nd
25ed62dce99fb4e35a6e8df83b948f877db22393nd##
25ed62dce99fb4e35a6e8df83b948f877db22393nd## Configuration
25ed62dce99fb4e35a6e8df83b948f877db22393nd##
25ed62dce99fb4e35a6e8df83b948f877db22393nd
25ed62dce99fb4e35a6e8df83b948f877db22393ndmy $CFG_TARGET = '@TARGET@'; # substituted via Makefile.tmpl
25ed62dce99fb4e35a6e8df83b948f877db22393ndmy $CFG_CC = '@CC@'; # 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
ba1761b7cdc483fa8460f183a95b520e789a161and
ba1761b7cdc483fa8460f183a95b520e789a161and##
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Cleanup the above stuff
ba1761b7cdc483fa8460f183a95b520e789a161and##
ba1761b7cdc483fa8460f183a95b520e789a161and$CFG_CFLAGS =~ s|^\s+||;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd$CFG_CFLAGS =~ s|\s+$||;
ba1761b7cdc483fa8460f183a95b520e789a161and$CFG_CFLAGS =~ s|\s+`.+apaci`||;
ba1761b7cdc483fa8460f183a95b520e789a161and
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd##
ba1761b7cdc483fa8460f183a95b520e789a161and## parse argument line
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd##
ba1761b7cdc483fa8460f183a95b520e789a161and
ba1761b7cdc483fa8460f183a95b520e789a161and# defaults for parameters
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_n = '';
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $opt_g = '';
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_c = 0;
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_o = '';
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy @opt_D = ();
ba1761b7cdc483fa8460f183a95b520e789a161andmy @opt_I = ();
ba1761b7cdc483fa8460f183a95b520e789a161andmy @opt_L = ();
ba1761b7cdc483fa8460f183a95b520e789a161andmy @opt_l = ();
ba1761b7cdc483fa8460f183a95b520e789a161andmy @opt_W = ();
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy @opt_S = ();
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_e = 0;
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_i = 0;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndmy $opt_a = 0;
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_A = 0;
ba1761b7cdc483fa8460f183a95b520e789a161andmy $opt_q = 0;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
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.
ba1761b7cdc483fa8460f183a95b520e789a161andsub Getopts {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my ($argumentative, @ARGV) = @_;
ba1761b7cdc483fa8460f183a95b520e789a161and my (@args, $first, $rest, $pos);
ba1761b7cdc483fa8460f183a95b520e789a161and my ($errs) = 0;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd local ($_);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe local ($[) = 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
ba1761b7cdc483fa8460f183a95b520e789a161and @args = split( / */, $argumentative);
ba1761b7cdc483fa8460f183a95b520e789a161and while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd ($first, $rest) = ($1,$2);
1723928efa40774afc394d9e6b2b974c1f49330dnd if ($_ =~ m|^--$|) {
1723928efa40774afc394d9e6b2b974c1f49330dnd shift(@ARGV);
ba1761b7cdc483fa8460f183a95b520e789a161and last;
ba1761b7cdc483fa8460f183a95b520e789a161and }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd $pos = index($argumentative,$first);
ba1761b7cdc483fa8460f183a95b520e789a161and if($pos >= $[) {
ba1761b7cdc483fa8460f183a95b520e789a161and if($args[$pos+1] eq ':') {
22d5d84393d960a2027f472036f3fee15d7dbce9nd shift(@ARGV);
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen if($rest eq '') {
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen unless (@ARGV) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
ba1761b7cdc483fa8460f183a95b520e789a161and ++$errs;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf $rest = shift(@ARGV);
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf eval "\$opt_$first = \$rest;";
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf elsif ($args[$pos+1] eq '+') {
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf shift(@ARGV);
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if($rest eq '') {
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf unless (@ARGV) {
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
bed3c2e56e8f3328e780200466b9d009093db468sf ++$errs;
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd $rest = shift(@ARGV);
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd eval "push(\@opt_$first, \$rest);";
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf else {
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf eval "\$opt_$first = 1";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if($rest eq '') {
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf shift(@ARGV);
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd else {
7e9d90004f580231e0376880710dc25408950ab9rbowen $ARGV[0] = "-$rest";
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf }
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf }
aa2ff7f8e8477e2b9d20dc2e72737d6bd5145465sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf else {
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "apxs:Error: Unknown option: $first\n";
909ce17e2bd0faef7b1c294f2307f009793fd493nd ++$errs;
acf65805923cf80834c39689cc0e2a8e7201c186sf if($rest ne '') {
acf65805923cf80834c39689cc0e2a8e7201c186sf $ARGV[0] = "-$rest";
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf else {
89507e27e4d31a7e97f258994e4ba3904de47652nd shift(@ARGV);
acf65805923cf80834c39689cc0e2a8e7201c186sf }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
acf65805923cf80834c39689cc0e2a8e7201c186sf }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd return ($errs == 0, @ARGV);
acf65805923cf80834c39689cc0e2a8e7201c186sf}
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
acf65805923cf80834c39689cc0e2a8e7201c186sfsub usage {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR " apxs -q [-S <var>=<val>] <query> ...\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 " [-Wl,<flags>] <files> ...\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";
acf65805923cf80834c39689cc0e2a8e7201c186sf exit(1);
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd}
acf65805923cf80834c39689cc0e2a8e7201c186sf
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# option handling
acf65805923cf80834c39689cc0e2a8e7201c186sfmy $rc;
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
acf65805923cf80834c39689cc0e2a8e7201c186sf&usage if ($rc == 0);
acf65805923cf80834c39689cc0e2a8e7201c186sf&usage if ($#ARGV == -1 and not $opt_g);
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
acf65805923cf80834c39689cc0e2a8e7201c186sf# argument handling
acf65805923cf80834c39689cc0e2a8e7201c186sfmy @args = @ARGV;
acf65805923cf80834c39689cc0e2a8e7201c186sfmy $name = 'unknown';
acf65805923cf80834c39689cc0e2a8e7201c186sf$name = $opt_n if ($opt_n ne '');
acf65805923cf80834c39689cc0e2a8e7201c186sf
acf65805923cf80834c39689cc0e2a8e7201c186sfif (@opt_S) {
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($opt_S);
acf65805923cf80834c39689cc0e2a8e7201c186sf foreach $opt_S (@opt_S) {
acf65805923cf80834c39689cc0e2a8e7201c186sf if ($opt_S =~ m/^([^=]+)=(.*)$/) {
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($var) = $1;
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($val) = $2;
acf65805923cf80834c39689cc0e2a8e7201c186sf my $oldval = eval "\$CFG_$var";
89507e27e4d31a7e97f258994e4ba3904de47652nd
acf65805923cf80834c39689cc0e2a8e7201c186sf unless ($var and $oldval) {
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf print STDERR "apxs:Error: no config variable $var\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf &usage;
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf
acf65805923cf80834c39689cc0e2a8e7201c186sf eval "\$CFG_${var}=\"${val}\"";
acf65805923cf80834c39689cc0e2a8e7201c186sf } else {
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "apxs:Error: malformatted -S option\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf &usage;
acf65805923cf80834c39689cc0e2a8e7201c186sf }
89f151d6b9775dd1ae53958d5986ffc7cb8fbba6kess }
acf65805923cf80834c39689cc0e2a8e7201c186sf}
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
acf65805923cf80834c39689cc0e2a8e7201c186sf##
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf## Initial shared object support check
acf65805923cf80834c39689cc0e2a8e7201c186sf##
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sfif (not -x "$CFG_SBINDIR/$CFG_TARGET") {
4044e4b6cb07cf7fa8e90676fafffe543c1d439bjim print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
89f151d6b9775dd1ae53958d5986ffc7cb8fbba6kess exit(1);
acf65805923cf80834c39689cc0e2a8e7201c186sf}
bf876fa45c212a18d7aa07504e872cf63a0c247cndif (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
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";
89f151d6b9775dd1ae53958d5986ffc7cb8fbba6kess exit(1);
89f151d6b9775dd1ae53958d5986ffc7cb8fbba6kess}
acf65805923cf80834c39689cc0e2a8e7201c186sf
89f151d6b9775dd1ae53958d5986ffc7cb8fbba6kess##
acf65805923cf80834c39689cc0e2a8e7201c186sf## Operation
acf65805923cf80834c39689cc0e2a8e7201c186sf##
d0828c8a321dc5e9ea60550f052294669c08cf93jim
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);
acf65805923cf80834c39689cc0e2a8e7201c186sf
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);
bc525661d031758c0a4e771543372b4869ca86aand exit(1);
65a611af7093423efb91e5794b8887a527d4cf63trawick }
65a611af7093423efb91e5794b8887a527d4cf63trawick }
65a611af7093423efb91e5794b8887a527d4cf63trawick}
65a611af7093423efb91e5794b8887a527d4cf63trawick
65a611af7093423efb91e5794b8887a527d4cf63trawickif ($opt_g) {
65a611af7093423efb91e5794b8887a527d4cf63trawick ##
acf65805923cf80834c39689cc0e2a8e7201c186sf ## SAMPLE MODULE SOURCE GENERATION
acf65805923cf80834c39689cc0e2a8e7201c186sf ##
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
acf65805923cf80834c39689cc0e2a8e7201c186sf if (-d $name) {
6fe26506780e73be2a412d758af77fafdf03291and print STDERR "apxs:Error: Directory `$name' already exists. Remove first\n";
6fe26506780e73be2a412d758af77fafdf03291and exit(1);
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf
acf65805923cf80834c39689cc0e2a8e7201c186sf my $data = join('', <DATA>);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd $data =~ s|%NAME%|$name|sg;
acf65805923cf80834c39689cc0e2a8e7201c186sf $data =~ s|%TARGET%|$CFG_TARGET|sg;
cd6c8de3bedcc401ee230159b0439fa20f44488etakashi
acf65805923cf80834c39689cc0e2a8e7201c186sf my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
cd6c8de3bedcc401ee230159b0439fa20f44488etakashi
cd6c8de3bedcc401ee230159b0439fa20f44488etakashi print STDERR "Creating [DIR] $name\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf system("mkdir $name");
bf7a66e941926dc62fd3e0a2b5ba3420ffdc2eb6sf print STDERR "Creating [FILE] $name/Makefile\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd open(FP, ">${name}/Makefile") || die;
acf65805923cf80834c39689cc0e2a8e7201c186sf print FP $mkf;
acf65805923cf80834c39689cc0e2a8e7201c186sf close(FP);
acf65805923cf80834c39689cc0e2a8e7201c186sf print STDERR "Creating [FILE] $name/mod_$name.c\n";
acf65805923cf80834c39689cc0e2a8e7201c186sf open(FP, ">${name}/mod_${name}.c") || die;
acf65805923cf80834c39689cc0e2a8e7201c186sf print FP $src;
acf65805923cf80834c39689cc0e2a8e7201c186sf close(FP);
bf7a66e941926dc62fd3e0a2b5ba3420ffdc2eb6sf
acf65805923cf80834c39689cc0e2a8e7201c186sf exit(0);
acf65805923cf80834c39689cc0e2a8e7201c186sf}
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
acf65805923cf80834c39689cc0e2a8e7201c186sf
acf65805923cf80834c39689cc0e2a8e7201c186sfif ($opt_q) {
acf65805923cf80834c39689cc0e2a8e7201c186sf ##
acf65805923cf80834c39689cc0e2a8e7201c186sf ## QUERY INFORMATION
acf65805923cf80834c39689cc0e2a8e7201c186sf ##
acf65805923cf80834c39689cc0e2a8e7201c186sf
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $result = '';
acf65805923cf80834c39689cc0e2a8e7201c186sf my $arg;
acf65805923cf80834c39689cc0e2a8e7201c186sf foreach $arg (@args) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $ok = 0;
acf65805923cf80834c39689cc0e2a8e7201c186sf my $name;
acf65805923cf80834c39689cc0e2a8e7201c186sf foreach $name (qw(
acf65805923cf80834c39689cc0e2a8e7201c186sf TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
acf65805923cf80834c39689cc0e2a8e7201c186sf PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak )) {
acf65805923cf80834c39689cc0e2a8e7201c186sf if ($arg eq $name or $arg eq lc($name)) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $val = eval "\$CFG_$name";
acf65805923cf80834c39689cc0e2a8e7201c186sf $result .= "${val}::";
acf65805923cf80834c39689cc0e2a8e7201c186sf $ok = 1;
282b62d8e9a4edbc2da22ba2d876ec94afc48084nd }
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf if (not $ok) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
acf65805923cf80834c39689cc0e2a8e7201c186sf exit(1);
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf $result =~ s|::$||;
acf65805923cf80834c39689cc0e2a8e7201c186sf $result =~ s|::| |;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print $result;
acf65805923cf80834c39689cc0e2a8e7201c186sf}
acf65805923cf80834c39689cc0e2a8e7201c186sf
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndif ($opt_c) {
acf65805923cf80834c39689cc0e2a8e7201c186sf ##
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd ## SHARED OBJECT COMPILATION
acf65805923cf80834c39689cc0e2a8e7201c186sf ##
acf65805923cf80834c39689cc0e2a8e7201c186sf
dd2f29c187db35e7635ce67a83dddceb75be87a4minfrin # split files into sources and objects
acf65805923cf80834c39689cc0e2a8e7201c186sf my @srcs = ();
dd2f29c187db35e7635ce67a83dddceb75be87a4minfrin my @objs = ();
acf65805923cf80834c39689cc0e2a8e7201c186sf my $f;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd foreach $f (@args) {
45d66a3a49ac14b7f18cd4d733c1947801b55172sf if ($f =~ m|\.c$|) {
acf65805923cf80834c39689cc0e2a8e7201c186sf push(@srcs, $f);
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen }
acf65805923cf80834c39689cc0e2a8e7201c186sf else {
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen push(@objs, $f);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen }
acf65805923cf80834c39689cc0e2a8e7201c186sf
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen # determine output file
acf65805923cf80834c39689cc0e2a8e7201c186sf my $dso_file;
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen if ($opt_o eq '') {
acf65805923cf80834c39689cc0e2a8e7201c186sf if ($#srcs > -1) {
acf65805923cf80834c39689cc0e2a8e7201c186sf $dso_file = $srcs[0];
acf65805923cf80834c39689cc0e2a8e7201c186sf $dso_file =~ s|\.[^.]+$|.so|;
acf65805923cf80834c39689cc0e2a8e7201c186sf }
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton elsif ($#objs > -1) {
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton $dso_file = $objs[0];
a1ceb0cd0152edea3c72f4d9dcb352bae6ef273fjorton $dso_file =~ s|\.[^.]+$|.so|;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $dso_file = "mod_unknown.so";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $dso_file = $opt_o;
f4cbda69df0490c6deaacb8d04f103d200ddd183nd }
f4cbda69df0490c6deaacb8d04f103d200ddd183nd
f4cbda69df0490c6deaacb8d04f103d200ddd183nd # create compilation commands
c1621f589e6e26efc55db89e59c9f445580856cctrawick my @cmds = ();
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $opt = '';
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my ($opt_Wc, $opt_I, $opt_D);
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $opt_Wc (@opt_W) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $opt_I (@opt_I) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= "-I$opt_I ";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $opt_D (@opt_D) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= "-D$opt_D ";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $s;
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $s (@srcs) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $o = $s;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $o =~ s|\.c$|.o|;
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
0237f43ab925775250e266e479d0a337ff374a4btakashi unshift(@objs, $o);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
0237f43ab925775250e266e479d0a337ff374a4btakashi
c1621f589e6e26efc55db89e59c9f445580856cctrawick # create link command
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
0237f43ab925775250e266e479d0a337ff374a4btakashi my $o;
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $o (@objs) {
0237f43ab925775250e266e479d0a337ff374a4btakashi $cmd .= " $o";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt = '';
0237f43ab925775250e266e479d0a337ff374a4btakashi my ($opt_Wl, $opt_L, $opt_l);
a1d62218cdb0efd0f02da1b54fd3eda91a681d98nd foreach $opt_Wl (@opt_W) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if($CFG_LD_SHLIB ne "gcc") {
49acc6accb4061182ef84dc991aaa346ad01a8ecsf $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
c1621f589e6e26efc55db89e59c9f445580856cctrawick } else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= " -W$opt_Wl";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $opt_L (@opt_L) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= " -L$opt_L";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $opt_l (@opt_l) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $opt .= " -l$opt_l";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick $cmd .= $opt;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $cmd .= " $CFG_LIBS_SHLIB";
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@cmds, $cmd);
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick # execute the commands
c1621f589e6e26efc55db89e59c9f445580856cctrawick &execute_cmds(@cmds);
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick # allow one-step compilation and installation
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if ($opt_i or $opt_e) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick @args = ( $dso_file );
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding}
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawickif ($opt_i or $opt_e) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding ##
604c89126c27104f659d7a51b0113e3bd435faf8fielding ## SHARED OBJECT INSTALLATION
604c89126c27104f659d7a51b0113e3bd435faf8fielding ##
604c89126c27104f659d7a51b0113e3bd435faf8fielding
c1621f589e6e26efc55db89e59c9f445580856cctrawick # determine installation commands
c1621f589e6e26efc55db89e59c9f445580856cctrawick # and corresponding LoadModule/AddModule directives
c1621f589e6e26efc55db89e59c9f445580856cctrawick my @lmd = ();
c1621f589e6e26efc55db89e59c9f445580856cctrawick my @amd = ();
c1621f589e6e26efc55db89e59c9f445580856cctrawick my @cmds = ();
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $f;
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coar foreach $f (@args) {
6c4ef4a72d9897e53365b94103f4bd819fd0d3acnd if ($f !~ m|\.so$|) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick print STDERR "apxs:Error: file $f is not a shared object\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick exit(1);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $t = $f;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $t =~ s|^.+/([^/]+)$|$1|;
22d5d84393d960a2027f472036f3fee15d7dbce9nd if ($opt_i) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
c1621f589e6e26efc55db89e59c9f445580856cctrawick push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen }
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick # determine module symbolname and filename
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $filename = '';
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd if ($name eq 'unknown') {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $name = '';
1462ff536f1b939bb337766b2056109c29664c4erbowen my $base = $f;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $base =~ s|\.[^.]+$||;
1462ff536f1b939bb337766b2056109c29664c4erbowen if (-f "$base.c") {
c1621f589e6e26efc55db89e59c9f445580856cctrawick open(FP, "<$base.c");
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $content = join('', <FP>);
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen close(FP);
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $name = "$1";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd $filename = "$base.c";
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename =~ s|^[^/]+/||;
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($name eq '') {
8559a67073808d84d85bb5dd552d4247caafe709sf if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
8559a67073808d84d85bb5dd552d4247caafe709sf $name = "$1";
8559a67073808d84d85bb5dd552d4247caafe709sf $filename = $base;
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename =~ s|^[^/]+/||;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf if ($name eq '') {
8559a67073808d84d85bb5dd552d4247caafe709sf print "apxs:Error: Sorry, cannot determine bootstrap symbol name\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick print "apxs:Error: Please specify one with option `-n'\n";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd exit(1);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($filename eq '') {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $filename = "mod_${name}.c";
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
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));
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick # execute the commands
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd &execute_cmds(@cmds);
c1621f589e6e26efc55db89e59c9f445580856cctrawick
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 exit(1);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
efb3a31a4ca193ac8629a4c039d481c29171d6e0sf
c1621f589e6e26efc55db89e59c9f445580856cctrawick open(FP, "<$CFG_SYSCONFDIR/$CFG_TARGET.conf") || die;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd my $content = join('', <FP>);
c1621f589e6e26efc55db89e59c9f445580856cctrawick close(FP);
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
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";
c1621f589e6e26efc55db89e59c9f445580856cctrawick exit(1);
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $lmd;
3565dbca9832b5199154ec8de294f24582fbd73end my $c = '';
c1621f589e6e26efc55db89e59c9f445580856cctrawick $c = '#' if ($opt_A);
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $lmd (@lmd) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $what = $opt_A ? "preparing" : "activating";
c1621f589e6e26efc55db89e59c9f445580856cctrawick if ($content !~ m|\n#?\s*$lmd|) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
c1621f589e6e26efc55db89e59c9f445580856cctrawick } else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick $lmd =~ m|LoadModule\s+(.+?)_module.*|;
604c89126c27104f659d7a51b0113e3bd435faf8fielding print STDERR "[$what module `$1' in $CFG_SYSCONFDIR/$CFG_TARGET.conf]\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick my $amd;
c1621f589e6e26efc55db89e59c9f445580856cctrawick foreach $amd (@amd) {
c96324066bcd1916e5378ee8a2bbef93ae5824c6nd if ($content !~ m|\n#?\s*$amd|) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd } else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
01d52afd5ea497df24826737569291294d5dfa04rbowen }
01d52afd5ea497df24826737569291294d5dfa04rbowen }
c1621f589e6e26efc55db89e59c9f445580856cctrawick if (@lmd or @amd) {
c1621f589e6e26efc55db89e59c9f445580856cctrawick if (open(FP, ">$CFG_SYSCONFDIR/$CFG_TARGET.conf.new")) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd print FP $content;
c1621f589e6e26efc55db89e59c9f445580856cctrawick close(FP);
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 && " .
b43f840409794ed298e8634f6284741f193b6c4ftakashi "rm $CFG_SYSCONFDIR/$CFG_TARGET.conf.new");
c1621f589e6e26efc55db89e59c9f445580856cctrawick } else {
c1621f589e6e26efc55db89e59c9f445580856cctrawick print STDERR "unable to open configuration file\n";
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
c1621f589e6e26efc55db89e59c9f445580856cctrawick }
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd }
c1621f589e6e26efc55db89e59c9f445580856cctrawick}
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick##EOF##
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl__DATA__
c1621f589e6e26efc55db89e59c9f445580856cctrawick##
c1621f589e6e26efc55db89e59c9f445580856cctrawick## Makefile -- Build procedure for sample %NAME% Apache module
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd## Autogenerated via ``apxs -n %NAME% -g''.
c1621f589e6e26efc55db89e59c9f445580856cctrawick##
c1621f589e6e26efc55db89e59c9f445580856cctrawick
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the used tools
c1621f589e6e26efc55db89e59c9f445580856cctrawickAPXS=apxs
c1621f589e6e26efc55db89e59c9f445580856cctrawickAPACHECTL=apachectl
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick# additional defines, includes and libraries
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#DEF=-Dmy_define=my_value
c1621f589e6e26efc55db89e59c9f445580856cctrawick#INC=-Imy/include/dir
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#LIB=-Lmy/lib/dir -lmylib
c1621f589e6e26efc55db89e59c9f445580856cctrawick
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the default target
c1621f589e6e26efc55db89e59c9f445580856cctrawickall: mod_%NAME%.so
0193f13df922db31ff281e3e5ce9632fe42bac87sf
c1621f589e6e26efc55db89e59c9f445580856cctrawick# compile the shared object file
c1621f589e6e26efc55db89e59c9f445580856cctrawickmod_%NAME%.so: mod_%NAME%.c
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
c1621f589e6e26efc55db89e59c9f445580856cctrawick
a5a2e98043365d3f5a8bb3c3cdfc252a4f11bf02nd# install the shared object file into Apache
c1621f589e6e26efc55db89e59c9f445580856cctrawickinstall: all
c1621f589e6e26efc55db89e59c9f445580856cctrawick $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
c1621f589e6e26efc55db89e59c9f445580856cctrawick# cleanup
c1621f589e6e26efc55db89e59c9f445580856cctrawickclean:
c1621f589e6e26efc55db89e59c9f445580856cctrawick -rm -f mod_%NAME%.o mod_%NAME%.so
c1621f589e6e26efc55db89e59c9f445580856cctrawick
c1621f589e6e26efc55db89e59c9f445580856cctrawick# simple test
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndtest: reload
c1621f589e6e26efc55db89e59c9f445580856cctrawick lynx -mime_header http://localhost/%NAME%
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
c1621f589e6e26efc55db89e59c9f445580856cctrawick# install and activate shared object by reloading Apache to
c1621f589e6e26efc55db89e59c9f445580856cctrawick# force a reload of the shared object file
c1621f589e6e26efc55db89e59c9f445580856cctrawickreload: install restart
c1621f589e6e26efc55db89e59c9f445580856cctrawick
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd# the general Apache start/restart/stop
c1621f589e6e26efc55db89e59c9f445580856cctrawick# procedures
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndstart:
c1621f589e6e26efc55db89e59c9f445580856cctrawick $(APACHECTL) start
c1621f589e6e26efc55db89e59c9f445580856cctrawickrestart:
c1621f589e6e26efc55db89e59c9f445580856cctrawick $(APACHECTL) restart
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60ndstop:
c1621f589e6e26efc55db89e59c9f445580856cctrawick $(APACHECTL) stop
898711b68797304101de0882fa576c8908acfae6nd
898711b68797304101de0882fa576c8908acfae6nd-=#=-
c1621f589e6e26efc55db89e59c9f445580856cctrawick/*
c1621f589e6e26efc55db89e59c9f445580856cctrawick** mod_%NAME%.c -- Apache sample %NAME% module
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd** [Autogenerated via ``apxs -n %NAME% -g'']
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
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**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** $ apxs -c -i mod_%NAME%.c
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** Then activate it in Apache's %TARGET%.conf file for instance
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd** for the URL /%NAME% in as follows:
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** # %TARGET%.conf
c1621f589e6e26efc55db89e59c9f445580856cctrawick** LoadModule %NAME%_module libexec/mod_%NAME%.so
c1621f589e6e26efc55db89e59c9f445580856cctrawick** <Location /%NAME%>
c1621f589e6e26efc55db89e59c9f445580856cctrawick** SetHandler %NAME%
c1621f589e6e26efc55db89e59c9f445580856cctrawick** </Location>
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** Then after restarting Apache via
2a0b626c070fea0a68a071a4160ff695eb4731dand**
2a0b626c070fea0a68a071a4160ff695eb4731dand** $ apachectl restart
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
2a0b626c070fea0a68a071a4160ff695eb4731dand** you immediately can request the URL /%NAME and watch for the
c1621f589e6e26efc55db89e59c9f445580856cctrawick** output of this module. This can be achieved for instance via:
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** $ lynx -mime_header http://localhost/%NAME%
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd** The output should be similar to the following one:
c1621f589e6e26efc55db89e59c9f445580856cctrawick**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** HTTP/1.1 200 OK
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd** Date: Tue, 31 Mar 1998 14:42:22 GMT
c1621f589e6e26efc55db89e59c9f445580856cctrawick** Server: Apache/1.3.4 (Unix)
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd** Connection: close
c1621f589e6e26efc55db89e59c9f445580856cctrawick** Content-Type: text/html
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd**
c1621f589e6e26efc55db89e59c9f445580856cctrawick** The sample page from mod_%NAME%.c
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd*/
c1621f589e6e26efc55db89e59c9f445580856cctrawick
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#include "httpd.h"
c1621f589e6e26efc55db89e59c9f445580856cctrawick#include "http_config.h"
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd#include "http_protocol.h"
c1621f589e6e26efc55db89e59c9f445580856cctrawick#include "ap_config.h"
c1621f589e6e26efc55db89e59c9f445580856cctrawick
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd/* The sample content handler */
c1621f589e6e26efc55db89e59c9f445580856cctrawickstatic int %NAME%_handler(request_rec *r)
1723928efa40774afc394d9e6b2b974c1f49330dnd{
1723928efa40774afc394d9e6b2b974c1f49330dnd r->content_type = "text/html";
1723928efa40774afc394d9e6b2b974c1f49330dnd ap_send_http_header(r);
1723928efa40774afc394d9e6b2b974c1f49330dnd if (!r->header_only)
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd ap_rputs("The sample page from mod_%NAME%.c\n", r);
1723928efa40774afc394d9e6b2b974c1f49330dnd return OK;
1723928efa40774afc394d9e6b2b974c1f49330dnd}
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
1723928efa40774afc394d9e6b2b974c1f49330dnd/* Dispatch list of content handlers */
1723928efa40774afc394d9e6b2b974c1f49330dndstatic const handler_rec %NAME%_handlers[] = {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd { "%NAME%", %NAME%_handler },
1723928efa40774afc394d9e6b2b974c1f49330dnd { NULL, NULL }
1723928efa40774afc394d9e6b2b974c1f49330dnd};
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen/* Dispatch list for API hooks */
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sfmodule MODULE_VAR_EXPORT %NAME%_module = {
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen STANDARD_MODULE_STUFF,
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* module initializer */
e83cd73f10044371dd9dfa5f46b6d7d5c585fe54sf NULL, /* create per-dir config structures */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* merge per-dir config structures */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* create per-server config structures */
49acc6accb4061182ef84dc991aaa346ad01a8ecsf NULL, /* merge per-server config structures */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* table of config file commands */
c819c19c2f1ffbf3a3f12a4070cc6c3f4ea2a6f2sf %NAME%_handlers, /* [#8] MIME-typed-dispatched handlers */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#1] URI to filename translation */
cef8c32664f99ed33838dd0bde26051c4b71af1bsf NULL, /* [#4] validate user id from request */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#5] check if the user is ok _here_ */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#3] check access by host address */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#6] determine MIME type */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#7] pre-run fixups */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* [#9] log a transaction */
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier NULL, /* [#2] header parser */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* child_init */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen NULL, /* child_exit */
63befe0983261d711e62457b380e24ecc3b7b79etrawick NULL /* [#0] post read-request */
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen};
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen
0bd1ddab48139fbbe68f4e257fe669dc19f58fe9rbowen