apxs.in revision db43a02f2c91324255a26dd82c49c3d7956ef062
#!@perlbin@ -w
#
# 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
#
#
# 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;
##
## Configuration
##
my %config_vars = ();
my $installbuilddir = "@exp_installbuilddir@";
# read the configuration variables once
my $CFG_PREFIX = $prefix;
my %internal_vars = map {$_ => 1}
##
## parse argument line
##
# defaults for parameters
my $opt_c = 0;
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 $errs = 0;
local $_;
local $[ = 0;
my @args = split / */, $argumentative;
if ($_ =~ m|^--$|) {
shift @ARGV;
last;
}
shift @ARGV;
$errs++;
}
}
}
shift @ARGV;
$errs++;
}
}
}
else {
}
else {
}
}
}
else {
$errs++;
}
else {
}
}
}
}
sub usage {
exit(1);
}
# option handling
my $rc;
# argument handling
&usage;
}
eval "\$CFG_${var}=\"${val}\"";
} else {
&usage;
}
}
}
##
## Initial shared object support check
##
exit 1;
}
sub get_config_vars{
if (/^\s*(.*?)\s*=\s*(.*)$/){
$rh_config->{$1} = $2;
}
}
}
sub get_vars {
my $ok = 0;
my $arg;
my $val = exists $config_vars{$arg}
? $config_vars{$arg}
: $config_vars{lc $arg};
$ok = 1;
}
$ok = 1;
}
exit(1);
}
}
}
$result =~ s|;;$||;
$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);
exit 1 ;
}
}
}
if ($opt_g) {
##
## SAMPLE MODULE SOURCE GENERATION
##
if (-d $name) {
exit(1);
}
my $data = join('', <DATA>);
$data =~ s|%TARGET%|$CFG_TARGET|sg;
$data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
print FP $mkf;
close(FP);
print FP $mods;
close(FP);
print FP $src;
close(FP);
exit(0);
}
if ($opt_q) {
##
## QUERY INFORMATION
##
my $result;
if ($#args >= 0) {
$result = get_vars(@args);
} 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 $_;
}
foreach (@vars) {
}
} else {
# Unprettified name=value list
foreach (keys %config_vars) {
}
}
}
}
exit(1);
}
my $apu_config = "";
if ($apr_major_version < 2) {
exit(1);
}
}
chomp($libtool);
chomp($apr_includedir);
my $apu_includedir = "";
if ($apr_major_version < 2) {
chomp($apu_includedir);
}
if ($opt_c) {
##
## SHARED OBJECT COMPILATION
##
# split files into sources and objects
my @srcs = ();
my @objs = ();
my $f;
foreach $f (@args) {
if ($f =~ m|\.c$|) {
push(@srcs, $f);
}
else {
push(@objs, $f);
}
}
# determine output file
my $dso_file;
if ($opt_o eq '') {
if ($#srcs > -1) {
$dso_file =~ s|\.[^.]+$|.la|;
}
elsif ($#objs > -1) {
$dso_file =~ s|\.[^.]+$|.la|;
}
else {
}
}
else {
$dso_file =~ s|\.[^.]+$|.la|;
}
# create compilation commands
my @cmds = ();
my $opt = '';
foreach $opt_Wc (@opt_W) {
}
foreach $opt_I (@opt_I) {
}
foreach $opt_D (@opt_D) {
}
my $s;
my $mod;
foreach $s (@srcs) {
my $slo = $s;
$slo =~ s|\.c$|.slo|;
my $lo = $s;
$lo =~ s|\.c$|.lo|;
my $la = $s;
$la =~ s|\.c$|.la|;
my $o = $s;
$o =~ s|\.c$|.o|;
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);
}
# create link command
my $o;
my $lo;
foreach $o (@objs) {
}
$opt = '';
foreach $opt_Wl (@opt_W) {
}
foreach $opt_L (@opt_L) {
}
foreach $opt_l (@opt_l) {
}
if ($opt_p == 1) {
chomp($apr_libs);
my $apu_libs="";
if ($apr_major_version < 2) {
chomp($apu_libs);
}
}
else {
chomp($apr_ldflags);
}
# execute the commands
&execute_cmds(@cmds);
# allow one-step compilation and installation
@args = ( $dso_file );
}
}
##
## SHARED OBJECT INSTALLATION
##
# determine installation commands
# and corresponding LoadModule directive
my @lmd = ();
my @cmds = ();
my $f;
foreach $f (@args) {
if ($f !~ m#(\.so$|\.la$|\.sl$|\.dll$|\.dylib$|)#) {
exit(1);
}
my $t = $f;
$t =~ s|^.+/([^/]+)$|$1|;
# use .so unambigiously for installed shared library modules
$t =~ s|\.[^./\\]+$|\.so|;
if ($opt_i) {
}
# determine module symbolname and filename
my $filename = '';
if ($name eq 'unknown') {
$name = '';
my $base = $f;
$base =~ s|\.[^.]+$||;
my $content = join('', <FP>);
close(FP);
if ($content =~ m|.*module\s+(?:AP_MODULE_DECLARE_DATA\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
$filename =~ s|^[^/]+/||;
}
}
if ($name eq '') {
if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
$filename =~ s|^[^/]+/||;
}
}
if ($name eq '') {
exit(1);
}
}
}
my $dir = $CFG_LIBEXECDIR;
$dir =~ s|^$CFG_PREFIX/?||;
}
# execute the commands
# activate module via LoadModule/AddModule directive
exit(1);
}
exit(1);
}
my $lmd;
my $c = '';
$c = '#' if ($opt_A);
# check for open <containers>, so that the new LoadModule
# directive always appears *outside* of an <container>.
# the '()=' trick forces list context and the scalar
# assignment counts the number of list members (aka number
# of matches) then
# fine. Last LoadModule is contextless.
}
. ' closed before opened.');
exit(1);
}
else {
# put our cmd after the section containing the last
# LoadModule.
my $found =
(?:(?:
^\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 (</)
# of lines that end up with
# a closing directive) must
# be repeated $cntopen
# times. That's it.
# Simple, eh? ;-)
) # capture end
. 'sections opened and not closed.');
exit(1);
}
}
} else {
# replace already existing LoadModule line
}
}
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");
}
}
}
}
sub error{
print STDERR "apxs:Error: $_[0].\n";
}
sub notice{
print STDERR "$_[0]\n";
}
##EOF##
__DATA__
##
## Makefile -- Build procedure for sample %NAME% Apache module
## Autogenerated via ``apxs -n %NAME% -g''.
##
builddir=.
top_srcdir=%PREFIX%
top_builddir=%PREFIX%
include %INSTALLBUILDDIR%/special.mk
# the used tools
APXS=apxs
APACHECTL=apachectl
# additional defines, includes and libraries
#DEFS=-Dmy_define=my_value
# the default target
all: local-shared-build
# install the shared object file into Apache
install: install-modules-yes
# cleanup
clean:
-rm -f mod_%NAME%.o mod_%NAME%.lo mod_%NAME%.slo mod_%NAME%.la
# simple test
test: reload
lynx -mime_header http://localhost/%NAME%
# install and activate shared object by reloading Apache to
# force a reload of the shared object file
reload: install restart
# procedures
start:
$(APACHECTL) start
restart:
$(APACHECTL) restart
stop:
$(APACHECTL) stop
-=#=-
mod_%NAME%.la: mod_%NAME%.slo
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_%NAME%.lo
DISTCLEAN_TARGETS = modules.mk
shared = mod_%NAME%.la
-=#=-
/*
** mod_%NAME%.c -- Apache sample %NAME% module
** [Autogenerated via ``apxs -n %NAME% -g'']
**
** To play with this sample module first compile it into a
**
**
** for the URL /%NAME% in as follows:
**
** # %TARGET%.conf
** <Location /%NAME%>
** SetHandler %NAME%
** </Location>
**
** Then after restarting Apache via
**
** $ apachectl restart
**
** you immediately can request the URL /%NAME% and watch for the
** output of this module. This can be achieved for instance via:
**
** $ lynx -mime_header http://localhost/%NAME%
**
** The output should be similar to the following one:
**
** HTTP/1.1 200 OK
** Date: Tue, 31 Mar 1998 14:42:22 GMT
** Server: Apache/1.3.4 (Unix)
** Connection: close
**
** The sample page from mod_%NAME%.c
*/
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
/* The sample content handler */
static int %NAME%_handler(request_rec *r)
{
if (strcmp(r->handler, "%NAME%")) {
return DECLINED;
}
if (!r->header_only)
ap_rputs("The sample page from mod_%NAME%.c\n", r);
return OK;
}
static void %NAME%_register_hooks(apr_pool_t *p)
{
ap_hook_handler(%NAME%_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA %NAME%_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
NULL, /* table of config file commands */
%NAME%_register_hooks /* register hooks */
};