new configure script thanks to Stephen Lamm (slamm@yahoo-inc.com).

git-svn-id: svn://10.0.0.236/trunk@119672 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kestes%walrus.com
2002-04-24 03:26:09 +00:00
parent c605d37992
commit c9a0f11857
2 changed files with 332 additions and 208 deletions

View File

@@ -0,0 +1,125 @@
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Tinderbox build tool.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Complete rewrite by Ken Estes:
# kestes@staff.mail.com Old work.
# kestes@reefedge.com New work.
# kestes@walrus.com Home.
# Contributor(s): Stephen Lamm (slamm@yahoo-inc.com)
# Files are processed by the perl script ./config.out as they are copied
# from the source tree to the build tree.
# Files are installed without change from the build directory into the
# tree rooted at prefix.
# Makefile Variables
#------------------------------------------------------------
# the prefix where most of the binaries will be install
prefix=@prefix@
# the directory where the cgibin files must go
cgibin_prefix=@cgibin_prefix@
# the root of the html directory
html_prefix=@html_prefix@
# where files will be built before they are installed
builddir=@builddir@
config_script=@config_script@
confdir=localconf
# Makefile Targets
#------------------------------------------------------------
all: build
ALL: all
build: make_build_dirs build_files set_build_permissions
install: build make_install_dirs install_files
clean:
@echo
@echo "----- Cleaning Build Directory-----"
@echo
rm -rf $(builddir)
# We do not accidently wish to edit to the 'binary' version of these
# files so ensure the build dir copies are not writable.
set_build_permissions:
@echo
@echo "----- Setting Build directory permissions -----"
find $(builddir) -type f | xargs chmod 444
find $(builddir)/bin -type f | xargs chmod 555
find $(builddir)/test -type f -name 'gen*' | xargs chmod 555
find $(builddir)/clientbin -type f | xargs chmod 555
compile_all_code: build
@echo
@echo "----- Testing if perl can compile code -----"
find $(builddir) -type f | \
egrep -v -i "readme|\.gif|/test/|addimage.cgi|images.pm|bustagestats.cgi|Storable.pm" | \
xargs -l perl -T -c
compile_bin_code: build
@echo
@echo "----- Testing if perl can compile all files in the bin directory -----"
find $(builddir)/bin -type f | \
egrep -v -i "readme|\.gif|/test/|addimage.cgi|images.pm|bustagestats.cgi|Storable.pm" | \
xargs -l perl -T -c
gen_test: compile_bin_code
rm -rf $(html_prefix)
perl $(builddir)/test/genbuilds.tst
perl $(builddir)/test/gennotices.tst
perl $(builddir)/test/genbugs.tst
$(builddir)/bin/tinder.cgi --daemon-mode
link_test:
find $(builddir) -type f -print | \
egrep -v -i "test|mage" | \
xargs egrep -i "<a +href"
STAGE_FILE := \
tb2StageFile() { \
source=$$1; \
target=$$2; \
if [ -f $$target ]; then chmod +w $$target; fi; \
perl $(config_script) < $$source > $$target; \
chmod -w $$target; \
echo "Staging $$source" 2>&1; \
}; tb2StageFile
INSTALL_FILE := \
tb2InstallFile() { \
source=$$1; \
target=$$2; \
if [ -f $$target ]; then chmod +w $$target; fi; \
echo "Install $$source -> $$target" 2>&1; \
cp -p $$source $$target; \
}; tb2InstallFile
# Automated file list is generated after this line
#------------------------------------------------------------

View File

@@ -1,7 +1,5 @@
#!/bin/sh
#!/usr/bin/perl -w
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
@@ -24,270 +22,271 @@
# kestes@staff.mail.com Old work.
# kestes@reefedge.com New work.
# kestes@walrus.com Home.
# Contributor(s):
# Contributor(s): Stephen Lamm (slamm@yahoo-inc.com)
use Cwd;
use Getopt::Long;
use File::Basename;
use File::Find;
# Users can set these variables or accept the defaults. These
# variables can either be set in configure (like in gnu configure) or
# overridden in the makefile.
# I do not wish to bother writing a command line parser in shell and
# configure can not easily be extended to handle other directories.
sub usage {
my $usage=<<EOF;
usage: $0 [options]
Common options:
--prefix=[path] Where to install most files
(default: '$prefix')
--cgibin-prefix=[path] Where to install cgi scripts
(default: '$cgibin_prefix')
--html-prefix=[path] Where to install html files
(default: '$html_prefix')
Other options:
--help | -h This usage text
--perl=[path] Full path to perl executable (on target
machine if different from perl on build
machine).
(default: '$perl_cmd')
--perl-flags=[flags] How to run the scripts
(default: '$perl_flags')
--build-dir=[path] Directory to construct the binaries
(default: '$builddir')
--config-script=[name] File to get the configuration options
(default: '$config_script')
: ${prefix:=/home/tinderbox}
: ${cgibin_prefix:="/var/www/cgi-bin/tinderbox"}
: ${htmldir:="/home/httpd/html/tinderbox"}
EOF
: ${perl_flags:='-T'}
print STDERR $usage;
exit 0;
}
# set default variables
$help = 0;
$prefix = '/home/tinderbox';
$cgibin_prefix = '/var/www/cgi-bin/tinderbox';
$html_prefix = '/home/httpd/html/tinderbox';
# null string means use 'which' to find default
$perl_cmd = '';
$perl_flags = '-T';
$builddir = './build';
$config_script = './config.out';
$tinder_version = '0.09';
@replacements = qw(
prefix cgibin_prefix html_prefix
builddir config_script
);
@cmds = qw(perl);
: ${builddir:=./build} > /dev/null
Getopt::Long::config('require_order', 'auto_abbrev', 'ignore_case');
# Different versions of Unix have different requirements for echo. I
# have no intention of becoming a portable shell expert. Make the
# echo command a variable and let the users figure out what works for
# them.
GetOptions(
'help|h' => \$help,
'prefix=s' => \$prefix,
'cgibin-prefix=s' => \$cgibin_prefix,
'html-prefix=s' => \$html_prefix,
'perl=s' => \$perl_cmd,
'perl-flags=s' => \$perl_flags,
'build-dir=s' => \$builddir,
'config-script=s' => \$config_script,
) or usage();
# this is for statments which do not need '\n' interpolation
: ${echo:="/bin/echo"}
# this is for statements which need '\n' interpolation
: ${echoe:="/bin/echo -e"}
config_script='./config.out'
tinder_version='0.09'
usage() if $help;
# -------------------
# Build Makefile
# -------------------
# Build Makefile
#------------------------------------------------------------
# Build a makefile to copy our executables into place and perform
# subsitutions on them.
$echo "Building Makefile"
print STDERR "Building Makefile\n";
# build a makefile to copy our executables into place and perform
# subsitutions on them
open(MAKEFILE_IN, "<Makefile.in") or
die "Unable to open Makefile.in: $!\n";
#(cd src; find . -type f -print) | perl
( find ./src -type f -print) | \
egrep -v '/CVS/' | egrep -v '\#' | egrep -v '~' | \
perl \
-e "\$prefix = '$prefix';" \
-e "\$cgibin_prefix = '$cgibin_prefix';"\
-e "\$htmldir = '$htmldir';" \
-e "\$builddir = '$builddir';" \
-e "\$config_script='$config_script';"\
-e '
use File::Basename;
# print Makefile Header
print <<EOF1;
# Makefile automatically generated by configure
# Do not edit this file
# files are processed by the perl script ./config.out as they are copied
# from the source tree to the build tree.
# files are installed without change from the build directory into the
# tree rooted at prefix.
open(MAKEFILE, ">Makefile") or
die "Unable to open Makefile: $!\n";
# Makefile Variables
# ------------------
while (<MAKEFILE_IN>) {
# perform substitutions
# the prefix where most of the binaries will be install
prefix=$prefix
if (/@\S*@/) {
for my $replace (@replacements) {
s/\@$replace\@/eval "\$$replace"/ge;
}
}
print MAKEFILE $_;
}
# the directory where the cgibin files must go
cgibin_prefix=$cgibin_prefix
close(MAKEFILE_IN) or
die "Unable to close Makefile: $!\n";
# the root of the html directory
htmldir=$htmldir
# Add Makefile build/install rules
#------------------------------------------------------------
# where files will be built before they are installed
builddir=$builddir
# Get the list of source files
my @source_files = ();
my %install_dirs=();
my %build_dirs=();
my @build_files=();
my @install_files=();
config_script=$config_script
confdir=localconf
sub wanted_source_files {
return if /^\#/ or /~$/;
$File::Find::prune = 1, return if $_ eq 'CVS';
return unless -T $_;
push @source_files, $File::Find::name;
}
# this is for statments which do not need '\'\\\\n\'' interpolation
echo=/bin/echo
find(\&wanted_source_files, 'src');
# this is for statements which need '\'\\\\n\'' interpolation
echoe="/bin/echo -e"
for my $src_file (@source_files) {
my $build_file = $src_file;
my $install_file = $src_file;
$build_file =~ s/^src/\$(builddir)/;
# Makefile Targets
# ----------------
if ($build_file =~ m/\.cgi$/) {
$install_file = '$(cgibin_prefix)/'.basename($install_file);
} else {
$install_file =~ s/^src/\$(prefix)/;
}
all: build
ALL: all
push @build_files, $build_file;
push @install_files, $install_file;
$install_dirs{File::Basename::dirname($install_file)} = 1;
$build_dirs{File::Basename::dirname($build_file)} = 1;
build: mk_build_dirs build_files set_build_permissions
$deps=<<EOF2;
install: build mk_dest_dirs install_files
clean:
@ \$(echo) "\\n\\n-----Cleaning Build Directory-----\\n\\n"
rm -rf \$(builddir)
# We do not accidently wish to edit to the 'binary' version of these
# files so ensure the build dir copies are not writable.
set_build_permissions:
@ \$(echo) "\\n\\n-----Setting Build directory permissions-----\\n\\n"
find \$(builddir) -type f | xargs chmod 444
find \$(builddir)/bin -type f | xargs chmod 555
find \$(builddir)/test -type f -name 'gen*' | xargs chmod 555
find \$(builddir)/clientbin -type f | xargs chmod 555
compile_all_code: build
@ \$(echo) "\\n\\n-----Testing if perl can compile code-----\\n\\n"
find \$(builddir) -type f | \\
egrep -v -i "readme|\.gif|/test/|addimage.cgi|images.pm|bustagestats.cgi|Storable.pm" | \\
xargs -l perl -T -c
compile_bin_code: build
@ \$(echo) "\\n\\n-----Testing if perl can compile all files in the bin directory-----\\n\\n"
find \$(builddir)/bin -type f | \\
egrep -v -i "readme|\.gif|/test/|addimage.cgi|images.pm|bustagestats.cgi|Storable.pm" | \\
xargs -l perl -T -c
gen_test: compile_bin_code
rm -rf \$(htmldir)
perl \$(builddir)/test/genbuilds.tst
perl \$(builddir)/test/gennotices.tst
perl \$(builddir)/test/genbugs.tst
\$(builddir)/bin/tinder.cgi --daemon-mode
link_test:
find \$(builddir) -type f -print | \
egrep -v -i "test|mage" | \
xargs egrep -i "<a +href"
# Automated file list is generated after this line
# ------------------------------------------------
EOF1
;
while($_=<>) {
chomp $_;
my ($src_file) = $_;
my ($build_file) = $_;
my ($dest_file) = $_;
$build_file =~ s!\./src!\$\(builddir\)!;
if ($build_file =~ m/\.cgi$/) {
$dest_file = '\'\$\(cgibin_prefix\)/\''.basename($dest_file);
} else {
$dest_file =~ s!\./src!\$\(prefix\)!;
}
$deps=<<EOF2;
build_files: $build_file
install_files: $dest_file
install_files: $install_file
$build_file: $src_file Makefile config.out
@ if [ -f $build_file ]; then chmod +w $build_file; fi;
perl \$\(config_script\) < $src_file > $build_file;
@ chmod -w $build_file;
\@\$(STAGE_FILE) \$\< \$\@
$dest_file: $build_file
@ if [ -f $dest_file ]; then chmod +w $dest_file; fi;
cp -p $build_file $dest_file
$install_file: $build_file
\@\$(INSTALL_FILE) \$\< \$\@
EOF2
;
$deps =~ s![ \t]+$!!mg;
$deps =~ s!^ +!!mg;
$deps =~ s!^\t\t+!\t!mg;
$dest_dirs{File::Basename::dirname($dest_file)} = 1;
$build_dirs{File::Basename::dirname($build_file)} = 1;
print $deps;
};
@dest_dirs = sort keys %dest_dirs;
@build_dirs = sort keys %build_dirs;
print MAKEFILE $deps;
}
# print Makefile Footer
foreach $build_file (@build_files) {
print MAKEFILE "build_files: $build_file\n";
}
print <<EOF3;
foreach $install_file (@install_files) {
print MAKEFILE "install_files: $install_file\n";
}
DEST_DIRS = @dest_dirs
my @install_dirs = sort keys %install_dirs;
my @build_dirs = sort keys %build_dirs;
BUILD_DIRS = @build_dirs
print MAKEFILE <<EOF3;
mk_dest_dirs:
for D in \$(DEST_DIRS);do \\
mkdir -p \$\$D;\\
done
mk_build_dirs:
for D in \$(BUILD_DIRS);do \\
mkdir -p \$\$D;\\
done
make_build_dirs: @build_dirs
make_install_dirs: @install_dirs
@build_dirs:
mkdir -p \$\@
@install_dirs:
mkdir -p \$\@
EOF3
' > Makefile
# -------------------
# Build Config.out
# -------------------
# Build config.out
#------------------------------------------------------------
$echo "Building config.out"
print STDERR "Building config.out\n";
rm -rf $config_script
# this file will exist only if we have run this script before.
pwd=`/bin/pwd`
unlink($config_script);
$echoe "#!perl - this script is run from makefile with -n\n" >> $config_script
$echoe "# This script is automatically genareated by configure." >> $config_script
$echoe "# This script configures various global variables.\n" >> $config_script
my $pwd = cwd;
$echo "while (<>) {" >> $config_script
$echo >> $config_script
$echoe " # Set the library search path with suitable interposing directories." >> $config_script
$echoe " s!\#tinder_libdir\#!$prefix/local_conf',\n '$prefix/default_conf',\n '$prefix/lib',\n '$pwd/$builddir/local_conf',\n '$pwd/$builddir/default_conf',\n '$pwd/$builddir/lib!;" >> $config_script
$echo >> $config_script
$echo " s!\#prefix\#!$prefix!;" >> $config_script
$echo " s!\#cgibin_prefix\#!$cgibin_prefix!;" >> $config_script
$echo " s!\#htmldir\#!$htmldir!;" >> $config_script
$echo >> $config_script
$echo " # Use Taint Perl mode for security." >> $config_script
$echo " s!\#perlflags\#!$perl_flags!;" >> $config_script
$echo " s!\#tinder_version\#!$tinder_version!;" >> $config_script
open(CONFIG_SCRIPT, ">$config_script")
or die "Unable to open $config_script: $!\n";
# some bash seems to not interpolate the '\n' I wish I understood what
# was going on here as MY bash does fine. I will leave this here
# commeted out until I figure out what is going on.
print CONFIG_SCRIPT <<EOF4;
#!perl - this script is run from makefile with -n
# /bin/echo "\n" >> $config_script
# This script is automatically generated by configure.
# This script configures various global variables.
$echo >> $config_script
while (<>) {
# Set the library search path with suitable interposing directories.
$echoe " # Hard code various executable paths into the source for security reasons." >> $config_script
s!\#tinder_libdir\#!$prefix/local_conf',
'$prefix/default_conf',
'$prefix/lib',
'$pwd/$builddir/local_conf',
'$pwd/$builddir/default_conf',
'$pwd/$builddir/lib!;
for cmd in perl
do
full_cmd=`which $cmd 2> /dev/null `
if [ $? -ne 0 ]; then
$echo "Could not find program: $cmd"
exit 9;
fi
$echo " s!\#$cmd\#!$full_cmd!;" >> $config_script
done
s!\#prefix\#!$prefix!;
s!\#cgibin_prefix\#!$cgibin_prefix!;
s!\#html_prefix\#!$html_prefix!;
$echoe "} continue {" >> $config_script
$echoe " print or die \"-p destination: \$!\\\\n\";" >> $config_script
$echoe "}" >> $config_script
# Use Taint Perl mode for security.
s!\#perlflags\#!$perl_flags!;
s!\#tinder_version\#!$tinder_version!;
/bin/chmod +x $config_script
# Hard code various executable paths into the source for security reasons.
EOF4
for my $cmd (@cmds) {
my $variable = $cmd.'_cmd';
my $explicit_cmd = $$variable;
if ($explicit_cmd) {
# Use explicitly set command path if defined
$full_cmd = $explicit_cmd;
} else {
# Search for command in the $PATH and assume that this is in the
# same place on the machine where the files are installed.
$full_cmd=`which $cmd 2> /dev/null`;
chomp($full_cmd);
if ($? != 0) {
print STDERR "Could not find program: $cmd\n";
exit 9;
}
}
print CONFIG_SCRIPT " s!\#$cmd\#!$full_cmd!;";
}
print CONFIG_SCRIPT <<EOF5;
} continue {
print or die "-p destination: $!\n";
}
EOF5
chmod 0755, $config_script or
die "Could not 'chmod 0755, $config_script': $!\n";
exit 0;