httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thom May <t...@planetarytramp.net>
Subject [PATCH] Fix apxs so it is relocatable...
Date Mon, 01 Apr 2002 18:41:43 GMT
Hi,
This patch addes an equivalent functionality to htppd's -d argument to apxs.
The code works in two ways - if you explicitly specify -d, it uses that,
otherwise, it first checks to see if it's in the directory specified during
the configure process, and if not it then attempts to guess what the server
root is. If all this fails, it dies.
(The code has also been slightly altered so that arguments are parsed before
config_vars.mk is read, and the output makefile uses $installbuilddir rather
than $prefix/build)
This has only been tested on linux - it works in all the test cases I've
thrown at it; but I'd apreciate testing on other archs/OSs.
Cheers,
-Thom, going to don the asbestos suit, and hide in the fallout shelter...

---

Index: support/apxs.in
===================================================================
RCS file: /home/cvspublic/httpd-2.0/support/apxs.in,v
retrieving revision 1.36
diff -u -u -r1.36 apxs.in
--- support/apxs.in	13 Mar 2002 20:48:05 -0000	1.36
+++ support/apxs.in	1 Apr 2002 17:33:09 -0000
@@ -58,36 +58,6 @@
 package apxs;
 
 ##
-##  Configuration
-##
-
-my $prefix         = "@prefix@";
-my $CFG_PREFIX     = $prefix;
-
-# read the configuration variables once
-my %config_vars = ();
-get_config_vars("$prefix/build/config_vars.mk",\%config_vars);
-
-my $exec_prefix    = get_vars("exec_prefix");
-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 $includedir     = get_vars("includedir");
-my $CFG_INCLUDEDIR = eval qq("$includedir");
-my $CFG_CC         = get_vars("CC");
-my $libexecdir     = get_vars("libexecdir");
-my $CFG_LIBEXECDIR = eval qq("$libexecdir");
-my $sbindir        = get_vars("sbindir");
-my $CFG_SBINDIR    = eval qq("$sbindir");
-my $ltflags        = $ENV{'LTFLAGS'};
-$ltflags or $ltflags = "--silent";
-
-my %internal_vars = map {$_ => 1}
-    qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
-       PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
-
-##
 ##  parse argument line
 ##
 
@@ -108,6 +78,7 @@
 my $opt_A = 0;
 my $opt_q = 0;
 my $opt_h = 0;
+my $opt_d = '';
 
 #   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
@@ -174,19 +145,19 @@
 }
 
 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 -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
+    print STDERR "Usage: apxs -d <server-root> -g [-S <var>=<val>] -n <modname>\n";
+    print STDERR "       apxs -d <server-root> -q [-S <var>=<val>] <query>
...\n";
+    print STDERR "       apxs -d -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>] <files> ...\n";
-    print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>]
<dsofile> ...\n";
-    print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>]
<dsofile> ...\n";
+    print STDERR "       apxs -d <server-root> -i [-S <var>=<val>] [-a]
[-A] [-n <modname>] <dsofile> ...\n";
+    print STDERR "       apxs -d <server-root> -e [-S <var>=<val>] [-a]
[-A] [-n <modname>] <dsofile> ...\n";
     exit(1);
 }
 
 #   option handling
 my $rc;
-($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
+($rc, @ARGV) = &Getopts("d:qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
 &usage if ($rc == 0);
 &usage if ($#ARGV == -1 and not $opt_g);
 &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not
$opt_e);
@@ -217,10 +188,74 @@
     }
 }
 
+
+##
+##  Configuration
+##
+
+# read the configuration variables once
+my %config_vars = ();
+my $mode;
+my $working_dir;
+my $server_root;
+my $installbuilddir;
+
+if ($0 =~ /^(.*)\/apxs/){
+    $working_dir=$1;
+}
+
+if  ($opt_d ne ''){
+    $mode="rel_";
+    $server_root=$opt_d ."/";
+    $installbuilddir=$server_root . "@rel_installbuilddir@";
+}
+elsif ($working_dir eq '@exp_bindir@') {
+#if ($working_dir eq '@exp_bindir@') {
+    #we are in absolute mode
+    $installbuilddir = '@exp_installbuilddir@/';
+    $mode = "exp_";
+    $server_root='@prefix@'."/";
+}
+elsif ($working_dir =~ /(.*)@rel_bindir@/) {
+    #we are working in relative mode. 
+    #we need to calculate what the server root is,
+    #and then use that as a base to work from
+    $server_root = $1;
+    $mode = "rel_";
+    $installbuilddir=$server_root . "@rel_installbuilddir@";
+}
+else {
+    die "Can't calculate what the server root is. Please use -d\n";
+}
+
+get_config_vars("$installbuilddir/config_vars.mk",\%config_vars)||die "Can't open config_vars.mk,
$!";
+	
+my $prefix         = $server_root;
+my $CFG_PREFIX     = $prefix;
+my $exec_prefix    = $server_root.get_vars("rel_exec_prefix");
+my $progname       = get_vars("progname");
+my $CFG_TARGET     = $progname;
+my $CFG_SYSCONFDIR = $server_root.get_vars("rel_sysconfdir");
+my $CFG_CFLAGS     = join ' ', map { get_vars($_) }
+  qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
+my $includedir     = $server_root.get_vars("rel_includedir");
+my $CFG_INCLUDEDIR = eval qq("$includedir");
+my $CFG_CC         = get_vars("CC");
+my $libexecdir     = $server_root.get_vars("rel_libexecdir");
+my $CFG_LIBEXECDIR = eval qq("$libexecdir");
+my $sbindir        = $server_root.get_vars("rel_sbindir");
+my $CFG_SBINDIR    = eval qq("$sbindir");
+my $ltflags        = $ENV{'LTFLAGS'};
+$ltflags or $ltflags = "--silent";
+
+my %internal_vars = map {$_ => 1}
+    qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
+       PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
+
 ##
 ##  Initial shared object support check
 ##
-my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
+my $httpd = $sbindir . "/" . $progname;
 $httpd = eval qq("$httpd");
 $httpd = eval qq("$httpd");
 
@@ -321,6 +356,7 @@
     $data =~ s|%NAME%|$name|sg;
     $data =~ s|%TARGET%|$CFG_TARGET|sg;
     $data =~ s|%PREFIX%|$prefix|sg;
+    $data =~ s|%INSTBUILDDIR%|$installbuilddir|sg;
 
     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
 
@@ -589,7 +625,7 @@
 builddir=$(shell pwd)
 top_srcdir=%PREFIX%
 top_builddir=%PREFIX%
-include %PREFIX%/build/special.mk
+include %INSTBUILDDIR%/special.mk
 
 #   the used tools
 APXS=apxs
-- 
Thom May -> thom@planetarytramp.net

<Gman> hum, I wonder if the cargo bar is looking for staff?
<thom> gman: cargo bar sydney has an insane staff turn over rate :)
<jdub> yeah, for turning over in the morning and seeing what you've woken up with.
<hadess> jdub woke up with Gman in his bed :P


Index: support/apxs.in
===================================================================
RCS file: /home/cvspublic/httpd-2.0/support/apxs.in,v
retrieving revision 1.36
diff -u -u -r1.36 apxs.in
--- support/apxs.in	13 Mar 2002 20:48:05 -0000	1.36
+++ support/apxs.in	1 Apr 2002 17:33:09 -0000
@@ -58,36 +58,6 @@
 package apxs;
 
 ##
-##  Configuration
-##
-
-my $prefix         = "@prefix@";
-my $CFG_PREFIX     = $prefix;
-
-# read the configuration variables once
-my %config_vars = ();
-get_config_vars("$prefix/build/config_vars.mk",\%config_vars);
-
-my $exec_prefix    = get_vars("exec_prefix");
-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 $includedir     = get_vars("includedir");
-my $CFG_INCLUDEDIR = eval qq("$includedir");
-my $CFG_CC         = get_vars("CC");
-my $libexecdir     = get_vars("libexecdir");
-my $CFG_LIBEXECDIR = eval qq("$libexecdir");
-my $sbindir        = get_vars("sbindir");
-my $CFG_SBINDIR    = eval qq("$sbindir");
-my $ltflags        = $ENV{'LTFLAGS'};
-$ltflags or $ltflags = "--silent";
-
-my %internal_vars = map {$_ => 1}
-    qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
-       PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
-
-##
 ##  parse argument line
 ##
 
@@ -108,6 +78,7 @@
 my $opt_A = 0;
 my $opt_q = 0;
 my $opt_h = 0;
+my $opt_d = '';
 
 #   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
@@ -174,19 +145,19 @@
 }
 
 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 -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
+    print STDERR "Usage: apxs -d <server-root> -g [-S <var>=<val>] -n <modname>\n";
+    print STDERR "       apxs -d <server-root> -q [-S <var>=<val>] <query>
...\n";
+    print STDERR "       apxs -d -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>] <files> ...\n";
-    print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>]
<dsofile> ...\n";
-    print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>]
<dsofile> ...\n";
+    print STDERR "       apxs -d <server-root> -i [-S <var>=<val>] [-a]
[-A] [-n <modname>] <dsofile> ...\n";
+    print STDERR "       apxs -d <server-root> -e [-S <var>=<val>] [-a]
[-A] [-n <modname>] <dsofile> ...\n";
     exit(1);
 }
 
 #   option handling
 my $rc;
-($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
+($rc, @ARGV) = &Getopts("d:qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
 &usage if ($rc == 0);
 &usage if ($#ARGV == -1 and not $opt_g);
 &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not
$opt_e);
@@ -217,10 +188,74 @@
     }
 }
 
+
+##
+##  Configuration
+##
+
+# read the configuration variables once
+my %config_vars = ();
+my $mode;
+my $working_dir;
+my $server_root;
+my $installbuilddir;
+
+if ($0 =~ /^(.*)\/apxs/){
+    $working_dir=$1;
+}
+
+if  ($opt_d ne ''){
+    $mode="rel_";
+    $server_root=$opt_d ."/";
+    $installbuilddir=$server_root . "@rel_installbuilddir@";
+}
+elsif ($working_dir eq '@exp_bindir@') {
+#if ($working_dir eq '@exp_bindir@') {
+    #we are in absolute mode
+    $installbuilddir = '@exp_installbuilddir@/';
+    $mode = "exp_";
+    $server_root='@prefix@'."/";
+}
+elsif ($working_dir =~ /(.*)@rel_bindir@/) {
+    #we are working in relative mode. 
+    #we need to calculate what the server root is,
+    #and then use that as a base to work from
+    $server_root = $1;
+    $mode = "rel_";
+    $installbuilddir=$server_root . "@rel_installbuilddir@";
+}
+else {
+    die "Can't calculate what the server root is. Please use -d\n";
+}
+
+get_config_vars("$installbuilddir/config_vars.mk",\%config_vars)||die "Can't open config_vars.mk,
$!";
+	
+my $prefix         = $server_root;
+my $CFG_PREFIX     = $prefix;
+my $exec_prefix    = $server_root.get_vars("rel_exec_prefix");
+my $progname       = get_vars("progname");
+my $CFG_TARGET     = $progname;
+my $CFG_SYSCONFDIR = $server_root.get_vars("rel_sysconfdir");
+my $CFG_CFLAGS     = join ' ', map { get_vars($_) }
+  qw(SHLTCFLAGS CFLAGS NOTEST_CPPFLAGS EXTRA_CPPFLAGS EXTRA_CFLAGS);
+my $includedir     = $server_root.get_vars("rel_includedir");
+my $CFG_INCLUDEDIR = eval qq("$includedir");
+my $CFG_CC         = get_vars("CC");
+my $libexecdir     = $server_root.get_vars("rel_libexecdir");
+my $CFG_LIBEXECDIR = eval qq("$libexecdir");
+my $sbindir        = $server_root.get_vars("rel_sbindir");
+my $CFG_SBINDIR    = eval qq("$sbindir");
+my $ltflags        = $ENV{'LTFLAGS'};
+$ltflags or $ltflags = "--silent";
+
+my %internal_vars = map {$_ => 1}
+    qw(TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
+       PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR);
+
 ##
 ##  Initial shared object support check
 ##
-my $httpd = get_vars("sbindir") . "/" . get_vars("progname");
+my $httpd = $sbindir . "/" . $progname;
 $httpd = eval qq("$httpd");
 $httpd = eval qq("$httpd");
 
@@ -321,6 +356,7 @@
     $data =~ s|%NAME%|$name|sg;
     $data =~ s|%TARGET%|$CFG_TARGET|sg;
     $data =~ s|%PREFIX%|$prefix|sg;
+    $data =~ s|%INSTBUILDDIR%|$installbuilddir|sg;
 
     my ($mkf, $mods, $src) = ($data =~ m|^(.+)-=#=-\n(.+)-=#=-\n(.+)|s);
 
@@ -589,7 +625,7 @@
 builddir=$(shell pwd)
 top_srcdir=%PREFIX%
 top_builddir=%PREFIX%
-include %PREFIX%/build/special.mk
+include %INSTBUILDDIR%/special.mk
 
 #   the used tools
 APXS=apxs

Mime
View raw message