#!/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 # 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) 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. sub usage { my $usage=< \$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(); usage() if $help; # Build Makefile #------------------------------------------------------------ # Build a makefile to copy our executables into place and perform # subsitutions on them. print STDERR "Building Makefile\n"; open(MAKEFILE_IN, "Makefile") or die "Unable to open Makefile: $!\n"; while () { # perform substitutions if (/@\S*@/) { for my $replace (@replacements) { s/\@$replace\@/eval "\$$replace"/ge; } } print MAKEFILE $_; } close(MAKEFILE_IN) or die "Unable to close Makefile: $!\n"; # Add Makefile build/install rules #------------------------------------------------------------ # Get the list of source files my @source_files = (); my %install_dirs=(); my %build_dirs=(); my @build_files=(); my @install_files=(); sub wanted_source_files { $File::Find::prune = 1, return if $_ eq 'CVS'; return unless -T $_; return if /^\#/ or /~$/ or /^\./; push @source_files, $File::Find::name; } find(\&wanted_source_files, 'src'); for my $src_file (@source_files) { my $build_file = $src_file; my $install_file = $src_file; $build_file =~ s/^src/\$(builddir)/; if ($build_file =~ m/\.cgi$/) { $install_file = '$(cgibin_prefix)/'.basename($install_file); } else { $install_file =~ s/^src/\$(prefix)/; } 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; $deps=<$config_script") or die "Unable to open $config_script: $!\n"; print CONFIG_SCRIPT <) { # Set the library search path with suitable interposing directories. s!\#tinder_libdir\#!$prefix/local_conf', '$prefix/default_conf', '$prefix/lib', '$pwd/$builddir/local_conf', '$pwd/$builddir/default_conf', '$pwd/$builddir/lib!; s!\#prefix\#!$prefix!; s!\#cgibin_prefix\#!$cgibin_prefix!; s!\#html_prefix\#!$html_prefix!; # Use Taint Perl mode for security. s!\#perlflags\#!$perl_flags!; s!\#tinder_version\#!$tinder_version!; # 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 <