apxs.in revision 4fd6031d2fe03e3e6bcacb23afac6f5034a2843c
#!@perlbin@ -w
# ====================================================================
# The Apache Software License, Version 1.1
#
# Copyright (c) 2000-2002 The Apache Software Foundation. All rights
# reserved.
#
# 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
# 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
#
require 5.003;
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;
# 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
##
#allow apxs to be run from the source tree, before installation
}
exit 1;
}
exit 1;
}
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)" if defined $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)" if defined $val;
$result .= ";;";
$ok = 1;
}
if (not $ok) {
error("Invalid query string `$arg'");
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) = @_;
foreach $cmd (@cmds) {
notice($cmd);
if ($rc) {
exit 1 ;
}
}
}
if ($opt_g) {
##
## SAMPLE MODULE SOURCE GENERATION
##
if (-d $name) {
exit(1);
}
$data =~ s|%TARGET%|$CFG_TARGET|sg;
$data =~ s|%INSTALLBUILDDIR%|$installbuilddir|sg;
exit(0);
}
##
## QUERY INFORMATION
##
}
##
## SHARED OBJECT COMPILATION
##
# split files into sources and objects
my $f;
if ($f =~ m|\.c$|) {
}
else {
}
}
# determine output file
my $dso_file;
}
}
else {
}
}
else {
}
# create compilation commands
}
}
}
my $s;
my $mod;
my $slo = $s;
my $lo = $s;
my $la = $s;
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");
}
# create link command
my $o;
my $lo;
}
} else {
}
}
}
}
push(@cmds, "$installbuilddir/libtool $ltflags --mode=link $CFG_CC -o $dso_file -rpath $CFG_LIBEXECDIR -module -avoid-version $opt $lo");
# execute the commands
# allow one-step compilation and installation
}
}
##
## SHARED OBJECT INSTALLATION
##
# determine installation commands
# and corresponding LoadModule/AddModule directives
my $f;
if ($f !~ m#(\.so$|\.la$)#) {
exit(1);
}
my $t = $f;
$t =~ s|^.+/([^/]+)$|$1|;
}
# determine module symbolname and filename
my $base = $f;
$base =~ s|\.[^.]+$||;
$filename =~ s|^[^/]+/||;
}
}
$filename =~ s|^[^/]+/||;
}
}
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"));
push(@amd, sprintf("AddModule %s", $filename));
}
# 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.");
exit(1);
}
my $lmd;
my $c = '';
$c = '#' if ($opt_A);
foreach $lmd (@lmd) {
} else {
}
$lmd =~ m|LoadModule\s+(.+?)_module.*|;
}
my $amd;
} else {
}
}
} else {
}
}
}
}
sub error{
}
sub notice{
}
##EOF##
##
## Makefile -- Build procedure for sample %NAME% Apache module
## Autogenerated via ``apxs -n %NAME% -g''.
##
builddir=.
# the used tools
# additional defines, includes and libraries
#DEFS=-Dmy_define=my_value
# the default target
# install the shared object file into Apache
# cleanup
# 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
# procedures
stop:
-=#=-
-=#=-
/*
**
** by running:
**
** $ apxs -c -i mod_%NAME%.c
**
**
** # %TARGET%.conf
** SetHandler %NAME%
** </Location>
**
** Then after restarting Apache via
**
**
**
** $ lynx -mime_header http://localhost/%NAME%
**
**
** Connection: close
**
*/
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
static int %NAME%_handler(request_rec *r)
{
return DECLINED;
}
if (!r->header_only)
return OK;
}
static void %NAME%_register_hooks(apr_pool_t *p)
{
}
%NAME%_register_hooks /* register hooks */
};