#!/usr/local/bin/perl -w use strict; use Getopt::Long; use File::Basename; my $ROOT = "$ENV{'HOME'}/apache"; my $VER = "httpd-2.0"; my $tmpdir = "/tmp"; my $start = 1; my $dir; my $tarpgm; # set to some tar or gtar in PATH that is GNU tar my $platform; # e.g., "i686-pc-linux-gnu"; my $logfile; if (@ARGV > 0) { GetOptions("dir=s" => \$dir, "tmpdir=s" => \$tmpdir) or die "bad options"; } if (defined($dir)) { die "--dir must specify a directory" if ! -d $dir; $VER = basename($dir); $ROOT = dirname($dir); die "fix your --dir" if ! -d $ROOT; } if (! -d $tmpdir) { die "$tmpdir is not a directory"; } $logfile = "$tmpdir/testbinbuild.log"; $platform = `$ROOT/$VER/srclib/apr/build/config.guess`; chomp($platform); $tarpgm = find_gnu_tar(); if ($tarpgm eq "") { die "I couldn't find GNU tar on your system"; } print "GNU tar: $tarpgm\n"; print "Testing binbuilds for $VER on platform $platform...\n"; chdir("$ROOT/$VER"); run_cmd("rm -f $ROOT/$VER-$platform.tar.gz"); if ($start <= 1) { run_cmd("./buildconf"); } if ($start <= 2) { if (-d "$ROOT/$VER/old-bindist") { run_cmd("rm -rf $ROOT/$VER/old-bindist"); } if (-d "$ROOT/$VER/bindist") { run_cmd("rm -rf $ROOT/$VER/bindist"); } run_cmd("build/binbuild.sh"); # OF CRITICAL IMPORTANCE!!!!!!! # WE MUST MOVE THE TEMPORARY INSTALL TREE TO A DIFFERENT PATH! # otherwise, the libraries used in the build will still exist # and any dependencies in httpd on those libraries will not # be found. By making the old path to the libraries invalid, # we'll ensure that httpd can find the new library location via # the appropriate environment variable. run_cmd("mv $ROOT/$VER/bindist $ROOT/$VER/old-bindist"); } if ($start <= 3) { run_cmd("rm -rf $tmpdir/testbinbuild-unpack"); } if ($start <= 4) { run_cmd("mkdir $tmpdir/testbinbuild-unpack"); } chdir("$tmpdir/testbinbuild-unpack"); if ($start <= 5) { run_cmd("$tarpgm -xzf $ROOT/$VER-$platform.tar.gz"); } chdir("$VER") or die "couldn't change directories to $VER"; if ($start <= 6) { run_cmd("rm -rf $tmpdir/testbinbuild-install"); run_cmd("./install-bindist.sh $tmpdir/testbinbuild-install"); } if ($start <= 7) { try_apxs_g(); try_apxs_q(); } exit(0); ########################### sub is_this_tar_ok { my ($tarpgm) = @_; my $output = `$tarpgm --version 2>/dev/null`; # We don't know of any version of GNU tar which doesn't # have the features we need. Thus there is no version # number in the check. if ($output =~ /GNU tar/) { return 1; } return 0; } sub find_gnu_tar { my @dirs = split /:/, $ENV{'PATH'}; foreach my $onedir (@dirs) { if (-e "$onedir/tar") { if (is_this_tar_ok("$onedir/tar")) { return "$onedir/tar"; } } if (-e "$onedir/gtar") { if (is_this_tar_ok("$onedir/gtar")) { return "$onedir/gtar"; } } } return ""; # error } ############################################################### sub try_apxs_q { chdir("$tmpdir/testbinbuild-install"); run_cmd("bin/apxs -q CFLAGS"); run_cmd("bin/apxs -q installbuilddir"); } sub try_apxs_g { chdir("$tmpdir/testbinbuild-install"); run_cmd("rm -rf $tmpdir/testbinbuild-install/jeff"); run_cmd("bin/apxs -g -n jeff"); chdir("jeff"); run_cmd("make"); } ############################################################### sub run_cmd { my ($cmd) = @_; my $rc; printf("*$cmd*\n"); $rc = system("$cmd >>$logfile 2>&1"); $rc &= 0xFFFF; if ($rc ne 0) { if (($rc & 0xFF) == 0) { $rc >>= 8; print STDERR "Error code $rc from command $cmd... (see $logfile)\n"; exit(1); } else { print STDERR "A signal terminated command $cmd... (see $logfile)\n"; exit(1); } } }