mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Back out Bug 687511 since it doesn't work in pymake.
This commit is contained in:
parent
ceb591acdb
commit
3d9ef7dc9c
@ -56,7 +56,6 @@ endif
|
||||
DIRS += pgo
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += autoconf/test
|
||||
ifeq (Android,$(OS_TARGET))
|
||||
DIRS += mobile/sutagent/android \
|
||||
mobile/sutagent/android/watcher \
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env perl
|
||||
#! /usr/bin/env perl
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
@ -16,12 +16,10 @@
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999-2011
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Steve Lamm (slamm@netscape.com).
|
||||
# Joey Armstrong <joey@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
@ -37,63 +35,29 @@
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
# make-makefiles - Quickly create Makefiles for subdirectories.
|
||||
# Also, creates any needed subdirectories.
|
||||
#
|
||||
# usage: make-makefiles [ -t <topsrcdir> -p <print_topsrcdir> -d <depth> ] [ <subdir> | <subdir>/Makefile ] ...
|
||||
|
||||
use Benchmark;
|
||||
use Cwd;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
use File::Path qw{mkpath};
|
||||
# Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(2.0);
|
||||
#$debug = 1;
|
||||
|
||||
##--------------------##
|
||||
##---] INCLUDES [---##
|
||||
##--------------------##
|
||||
use FindBin;
|
||||
use lib $FindBin::Bin;
|
||||
use makemakefile;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
my %argv;
|
||||
|
||||
my $t0 = Benchmark->new();
|
||||
sub END
|
||||
{
|
||||
if ($argv{bench})
|
||||
{
|
||||
my $t1 = Benchmark->new();
|
||||
my $delta = timediff($t1, $t0);
|
||||
print STDERR timestr($delta), "\n";
|
||||
}
|
||||
if ($^O eq 'msys') {
|
||||
$pwdcmd = 'pwd -W';
|
||||
}
|
||||
else {
|
||||
$pwdcmd = 'pwd';
|
||||
}
|
||||
|
||||
##----------------##
|
||||
##---] MAIN [---##
|
||||
##----------------##
|
||||
umask 0;
|
||||
|
||||
my $debug = $argv{debug} || 0;
|
||||
|
||||
my $pwdcmd = ($^O eq 'msys') ? 'pwd -W' : 'pwd';
|
||||
|
||||
# Determine various tree path variables
|
||||
#
|
||||
my ($topsrcdir, $ptopsrcdir, $depth, @makefiles) = parse_arguments(@ARGV);
|
||||
($topsrcdir, $ptopsrcdir, $depth, @makefiles) = parse_arguments(@ARGV);
|
||||
|
||||
my $object_fullpath = `$pwdcmd`; # Cwd::getcwd()
|
||||
$object_fullpath = `$pwdcmd`;
|
||||
chdir $depth;
|
||||
my $object_root = `$pwdcmd`; # Cwd::getcwd()
|
||||
$object_root = `$pwdcmd`;
|
||||
chomp $object_fullpath;
|
||||
chomp $object_root;
|
||||
|
||||
@ -101,23 +65,24 @@ chomp $object_root;
|
||||
# 'make-makefile' was called. For example, if make-makefile was
|
||||
# called from "mozilla/gfx/src", then $source_subdir would be
|
||||
# "gfx/src/".
|
||||
my $source_subdir = "$object_fullpath/";
|
||||
$source_subdir = "$object_fullpath/";
|
||||
my $quoted_object_root = quotemeta($object_root);
|
||||
$source_subdir =~ s|^$quoted_object_root/||;
|
||||
|
||||
# Prefix makefiles with $source_subdir so that paths
|
||||
# will be relative to the top of the object tree.
|
||||
#
|
||||
my $makefile;
|
||||
for $makefile (@makefiles) { # dead code ?
|
||||
for $makefile (@makefiles) {
|
||||
$makefile = "$source_subdir$makefile";
|
||||
}
|
||||
|
||||
create_directories(@makefiles);
|
||||
|
||||
# Find the path to the source directory based on how 'make-makefile'
|
||||
# was invoked. The path is either relative to the object directory
|
||||
# or an absolute path.
|
||||
my $given_srcdir = find_srcdir($topsrcdir, $depth);
|
||||
my $pgiven_srcdir = find_srcdir($ptopsrcdir, $depth);
|
||||
$given_srcdir = find_srcdir($topsrcdir, $depth);
|
||||
$pgiven_srcdir = find_srcdir($ptopsrcdir, $depth);
|
||||
|
||||
if ($debug) {
|
||||
warn "object_fullpath = $object_fullpath\n";
|
||||
@ -127,21 +92,18 @@ if ($debug) {
|
||||
warn "given_srcdir = $given_srcdir\n";
|
||||
}
|
||||
|
||||
my @errors;
|
||||
my @unhandled = update_makefiles_legacy($given_srcdir, $pgiven_srcdir, @makefiles);
|
||||
push(@errors, $@) if ($@);
|
||||
@unhandled = update_makefiles($given_srcdir, $pgiven_srcdir, @makefiles);
|
||||
|
||||
run_config_status(@unhandled);
|
||||
push(@errors, $@) if ($@ && $argv{'no-warnings'});
|
||||
|
||||
exit scalar(@errors);
|
||||
|
||||
# end of Main
|
||||
############################################################
|
||||
|
||||
###########################################################################
|
||||
sub dirname {
|
||||
return $_[0] =~ /(.*)\/.*/ ? "$1" : '.';
|
||||
}
|
||||
|
||||
# find_depth: Pull the value of DEPTH out of a Makefile (or Makefile.in)
|
||||
###########################################################################
|
||||
sub find_depth {
|
||||
my $depth = '';
|
||||
open(MAKEFILE, "<$_[0]") || die "Unable to open $_[0]: $!\n";
|
||||
@ -154,115 +116,39 @@ sub find_depth {
|
||||
return $depth;
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Intent: Parse command line arguments and assign values
|
||||
###########################################################################
|
||||
sub parse_arguments {
|
||||
my @args = @_;
|
||||
my $depth = '';
|
||||
my $topsrcdir = '';
|
||||
my $ptopsrcdir;
|
||||
my @makefiles = ();
|
||||
|
||||
my @arglist = qw(badtokens! bench
|
||||
chdir=s
|
||||
debug
|
||||
depth|d=s
|
||||
enhanced
|
||||
obj=s top|t=s ptop|p=s
|
||||
src=s dst=s
|
||||
);
|
||||
unless(GetOptions(\%argv, @arglist))
|
||||
{
|
||||
my $script = join('/', $FindBin::RealBin, $FindBin::Script);
|
||||
system("perldoc $script </dev/null");
|
||||
exit
|
||||
}
|
||||
@args = @ARGV;
|
||||
|
||||
my $topsrcdir = $argv{top} || '';
|
||||
if (! $topsrcdir)
|
||||
{
|
||||
$topsrcdir = $argv{top} = getTopDir();
|
||||
while (1) {
|
||||
if ($args[0] eq '-d') {
|
||||
$depth = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} elsif ($args[0] eq '-t') {
|
||||
$topsrcdir = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} elsif ($args[0] eq '-p') {
|
||||
$ptopsrcdir = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
my $ptopsrcdir ||= $argv{ptop} || $topsrcdir || '';
|
||||
|
||||
## Init --no- switch values
|
||||
foreach my $var (qw(badtokens exclusions warnings))
|
||||
{
|
||||
$argv{"no-${var}"} = $argv{$var} || 0;
|
||||
if ($topsrcdir eq '') {
|
||||
$topsrcdir = $0; # Figure out topsrcdir based on program name.
|
||||
$topsrcdir =~ s|/?build/autoconf/.*$||;
|
||||
}
|
||||
# Propogate parsed arguments for module use [--debug, --verbose]
|
||||
while (my($k, $v) = each %argv)
|
||||
{
|
||||
$main::argv{$k} = $v;
|
||||
if ($ptopsrcdir eq '') {
|
||||
$ptopsrcdir = $topsrcdir;
|
||||
}
|
||||
|
||||
if ($argv{chdir})
|
||||
{
|
||||
chdir $argv{chdir} || die "chdir $argv{chdir} failed: $!";
|
||||
}
|
||||
|
||||
##############################################################
|
||||
## Arguments allowing make-makefile to be invoked from $topsrc
|
||||
##############################################################
|
||||
if (!$argv{top} || !$argv{obj})
|
||||
{
|
||||
}
|
||||
## Limit access to container makefiles for now
|
||||
elsif ($argv{enhanced})
|
||||
{
|
||||
my @errors;
|
||||
|
||||
## iterate over @ARGV to preserve original filename for 'unhandled'
|
||||
my @files = map{ getRelPath($_) } @ARGV;
|
||||
|
||||
my $top = getTopDir();
|
||||
my $obj = getObjDir();
|
||||
|
||||
mkdirr(map{ "$obj/$_" } @files);
|
||||
push(@errors, $@) if ($@); # legacy behavior: do not exit with status
|
||||
|
||||
my $exclude = join('/', $FindBin::RealBin, $FindBin::Script);
|
||||
$exclude .= '.excl'; # $argv{exclude}
|
||||
my %exclude = getExclusions($exclude);
|
||||
my @unhandled;
|
||||
foreach my $relpath (@files)
|
||||
{
|
||||
my $rel = join('/', $relpath, 'Makefile.in');
|
||||
my $mf = join('/', $top, $rel);
|
||||
next if ($exclude{$rel});
|
||||
print STDERR " ** relpath=[$relpath], mf=[$mf]\n" if ($main::argv{debug});
|
||||
|
||||
my $rc = updateMakefiles($relpath, {depth=>$depth, obj=>$obj, top=>$top});
|
||||
if ($@)
|
||||
{
|
||||
push(@errors, $@);
|
||||
}
|
||||
elsif ($rc eq 'badtokens')
|
||||
{
|
||||
push(@unhandled, $mf);
|
||||
}
|
||||
}
|
||||
|
||||
run_config_status(@unhandled);
|
||||
push(@errors, $@) if ($@ && $argv{'no-warnings'});
|
||||
exit scalar(@errors);
|
||||
}
|
||||
|
||||
|
||||
my $depth = $argv{depth} || '';
|
||||
if (! $depth)
|
||||
{
|
||||
foreach my $fyl (@args)
|
||||
{
|
||||
if (my $tmp = find_depth($fyl))
|
||||
{
|
||||
$depth = $tmp;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $depth) {
|
||||
if ($depth eq '') {
|
||||
# Use $(DEPTH) in the Makefile or Makefile.in to determine the depth
|
||||
if (-e "Makefile.in") {
|
||||
$depth = find_depth("Makefile.in");
|
||||
@ -280,21 +166,34 @@ sub parse_arguments {
|
||||
# Build the list of makefiles to generate
|
||||
#
|
||||
@makefiles = ();
|
||||
while (@args)
|
||||
{
|
||||
next unless my $makefile = shift @args;
|
||||
$makefile =~ s/\.in$//;
|
||||
$makefile =~ s/\/$//;
|
||||
$makefile =~ /Makefile$/
|
||||
or $makefile =~ /^\.\//
|
||||
or $makefile .= "/Makefile";
|
||||
my $makefile;
|
||||
foreach $makefile (@args) {
|
||||
$makefile =~ s/\.in$//;
|
||||
$makefile =~ s/\/$//;
|
||||
$makefile =~ /Makefile$/
|
||||
or $makefile =~ /^\.\//
|
||||
or $makefile .= "/Makefile";
|
||||
push @makefiles, "$makefile";
|
||||
}
|
||||
@makefiles = "Makefile" unless @makefiles;
|
||||
@makefiles = "Makefile" unless @args;
|
||||
|
||||
return ($topsrcdir, $ptopsrcdir, $depth, @makefiles);
|
||||
}
|
||||
|
||||
|
||||
# Create all the directories at once.
|
||||
# This can be much faster than calling mkdir() for each one.
|
||||
sub create_directories {
|
||||
my @makefiles = @_;
|
||||
my @dirs = ();
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
push @dirs, dirname($ac_file);
|
||||
}
|
||||
# Call mkdir with the directories sorted by subdir count (how many /'s)
|
||||
system "mkdir -p ". join(' ', map("\"$_\"", @dirs)) if @dirs;
|
||||
}
|
||||
|
||||
# Find the top of the source directory
|
||||
# (Assuming that the executable is in $top_srcdir/build/autoconf)
|
||||
sub find_srcdir {
|
||||
@ -315,146 +214,111 @@ sub find_srcdir {
|
||||
return $ac_given_srcdir;
|
||||
}
|
||||
|
||||
1;
|
||||
###########################################################################
|
||||
## perldoc
|
||||
###########################################################################
|
||||
__END__
|
||||
# Output the makefiles.
|
||||
#
|
||||
sub update_makefiles {
|
||||
my ($ac_given_srcdir, $pac_given_srcdir, @makefiles) = @_;
|
||||
my @unhandled=();
|
||||
|
||||
=head1 NAME
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
my $ac_dir = dirname($ac_file);
|
||||
my $ac_dots = '';
|
||||
my $ac_dir_suffix = '';
|
||||
my $srcdir = '.';
|
||||
my $top_srcdir = '.';
|
||||
|
||||
make-makefile - Generate a Makefile from a F<Makefile.in> template
|
||||
# Determine $srcdir and $top_srcdir
|
||||
#
|
||||
if ($ac_dir ne '.') {
|
||||
$ac_dir_suffix = "/$ac_dir";
|
||||
$ac_dir_suffix =~ s%^/\./%/%;
|
||||
$ac_dots = $ac_dir_suffix;
|
||||
# Remove .. components from the provided dir suffix, and
|
||||
# also the forward path components they were reversing.
|
||||
my $backtracks = $ac_dots =~ s%\.\.(/|$)%%g;
|
||||
while ($backtracks--) {
|
||||
$ac_dots =~ s%/[^/]*%%;
|
||||
}
|
||||
$ac_dots =~ s%/[^/]*%../%g;
|
||||
}
|
||||
if ($ac_given_srcdir eq '.') {
|
||||
if ($ac_dots ne '') {
|
||||
$top_srcdir = $ac_dots;
|
||||
$top_srcdir =~ s%/$%%;
|
||||
}
|
||||
} elsif ($pac_given_srcdir =~ m%^/% or $pac_given_srcdir =~ m%^.:/%) {
|
||||
$srcdir = "$pac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$pac_given_srcdir";
|
||||
} else {
|
||||
if ($debug) {
|
||||
print "ac_dots = $ac_dots\n";
|
||||
print "ac_dir_suffix = $ac_dir_suffix\n";
|
||||
}
|
||||
$srcdir = "$ac_dots$ac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$ac_dots$ac_given_srcdir";
|
||||
}
|
||||
|
||||
=head1 SYNOPSIS
|
||||
if ($debug) {
|
||||
print "ac_dir = $ac_dir\n";
|
||||
print "ac_file = $ac_file\n";
|
||||
print "ac_file_in = $ac_file_in\n";
|
||||
print "srcdir = $srcdir\n";
|
||||
print "top_srcdir = $top_srcdir\n";
|
||||
print "cwd = " . `$pwdcmd` . "\n";
|
||||
}
|
||||
|
||||
make-makefile [--top t] [--obj o] [--depth d] foo/bar/Makefile.in tans/fans/Makefile foo/bar
|
||||
# Copy the file and make substitutions.
|
||||
# @srcdir@ -> value of $srcdir
|
||||
# @top_srcdir@ -> value of $top_srcdir
|
||||
#
|
||||
if (-e $ac_file) {
|
||||
next if -M _ < -M $ac_file_in; # Next if Makefile is up-to-date.
|
||||
warn "updating $ac_file\n";
|
||||
} else {
|
||||
warn "creating $ac_file\n";
|
||||
}
|
||||
|
||||
=head1 DESCRIPTION
|
||||
open INFILE, "<$ac_file_in" or do {
|
||||
warn "$0: Cannot read $ac_file_in: No such file or directory\n";
|
||||
next;
|
||||
};
|
||||
open OUTFILE, ">$ac_file" or do {
|
||||
warn "$0: Unable to create $ac_file\n";
|
||||
next;
|
||||
};
|
||||
|
||||
Given options and makefile path arguments determine path to the template
|
||||
F<Makefile.in> beneath a source directory and path to generated F<Makefile>
|
||||
beneath $MOZ_OBJDIR. DEPTH from destination directory to the 'root' will
|
||||
also be determined. F<Makefile.in> will be read in, template strings of the
|
||||
gorm @token@ will be replaced with derived values and a generated makefile
|
||||
will be written out as F<Makefile>.
|
||||
while (<INFILE>) {
|
||||
#if (/\@[_a-zA-Z]*\@.*\@[_a-zA-Z]*\@/) {
|
||||
# #warn "Two defines on a line:$ac_file:$.:$_";
|
||||
# push @unhandled, $ac_file;
|
||||
# last;
|
||||
#}
|
||||
|
||||
Makefile DEPTH= can be determined in a few different ways:
|
||||
o The string C<DEPTH=../../..> may be embedded within F<Makefile.in>.
|
||||
o Search parent directories for F<Makefile.in> and use it to assign the child.
|
||||
s/\@srcdir\@/$srcdir/g;
|
||||
s/\@top_srcdir\@/$top_srcdir/g;
|
||||
|
||||
if (/\@[_a-zA-Z]*\@/) {
|
||||
#warn "Unknown variable:$ac_file:$.:$_";
|
||||
push @unhandled, $ac_file;
|
||||
last;
|
||||
}
|
||||
print OUTFILE;
|
||||
}
|
||||
close INFILE;
|
||||
close OUTFILE;
|
||||
}
|
||||
return @unhandled;
|
||||
}
|
||||
|
||||
=head2 Option List
|
||||
sub run_config_status {
|
||||
my @unhandled = @_;
|
||||
|
||||
=over 4
|
||||
|
||||
=item --chdir
|
||||
|
||||
Move to this directory before doing anything else
|
||||
|
||||
=item -d, --depth
|
||||
|
||||
Explicitly specify the relative path from directory containing Makefile.in
|
||||
to the top sandbox directory. memory/makefile, DEPTH=../.., js/src/config, DEPTH=..
|
||||
|
||||
=item --enhanced
|
||||
|
||||
Use alternate/simplified path construction when options --top and --obj are
|
||||
passed. This feature will be used by container makefiles to support makefile
|
||||
generation while cd'd into the sandbox top directory.
|
||||
|
||||
=item -t, --top
|
||||
|
||||
Path the root of a development sandbox.
|
||||
|
||||
=item --obj
|
||||
|
||||
Path to object directory where generated makefile will be written ($MOZ_OBJDIR).
|
||||
|
||||
=item --ptop
|
||||
|
||||
Print top source dir
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Options List DEBUG
|
||||
|
||||
=over 4
|
||||
|
||||
=item --bench
|
||||
|
||||
Enable script benchmarking, report elapsed runtime.
|
||||
|
||||
=item --debug
|
||||
|
||||
Enable script debug mode.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Options List --NO-
|
||||
|
||||
=over 4
|
||||
|
||||
=item --no-badtokens (wip)
|
||||
|
||||
Handle unexpanded @token@ makefile tokens as an error condition.
|
||||
Do not rely on system(config.status) to externally supply values.
|
||||
|
||||
=item --no-excludes
|
||||
|
||||
Ignore file entries on the exclusion list, generate everything.
|
||||
|
||||
=item --no-warnings
|
||||
|
||||
Warnings are handled as an error condition.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Examples
|
||||
|
||||
=over 4
|
||||
|
||||
=item * make-makefile -t /mozilla/nightly -d . memory/mozalloc
|
||||
|
||||
cd $MOZ_OBJDIR;
|
||||
--top and --depth are explicitly set for generting memory/mozalloc/Makefile.
|
||||
|
||||
=item * make-makefile -t /mozilla/nightly -d ../../../.. html5lib_tree_construction/Makefile
|
||||
|
||||
cd $MOZ_OBJDIR/parser/htmlparser/tests/mochitest
|
||||
|
||||
--top and --depth are explicitly set for generting a makefile from within
|
||||
a subdirectory of $MOZ_OBJDIR
|
||||
|
||||
=item * make-makefile --top /mozilla/nightly --obj /mozilla/nightly/obj memory/mozalloc
|
||||
|
||||
With --top and --obj explicitly set generate $MOZ_OBJDIR/memory/mozalloc/Makefile
|
||||
while sitting in the sandbox root.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Work In Progress
|
||||
|
||||
=over 4
|
||||
|
||||
=item --no-badtokens
|
||||
|
||||
Fail on unexpanded @foo@ makefile tokens. Any tokens that can be expanded
|
||||
directly by make-makefile will avoid config.status shell overhead.
|
||||
|
||||
=item Depth from delta(--obj, --top)
|
||||
|
||||
If DEPTH= has not been embedded within a makefile the value could
|
||||
be set directly if --top and --obj are specified and the paths overlap.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<config/rules.mk>
|
||||
|
||||
=cut
|
||||
# Run config.status with any unhandled files.
|
||||
#
|
||||
if (@unhandled) {
|
||||
$ENV{CONFIG_FILES}= join ' ', @unhandled;
|
||||
system "./config.status";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
###########################################################################
|
||||
## Intent: Exclusion list for container make builds
|
||||
###########################################################################
|
||||
|
||||
# EOF
|
@ -1,745 +0,0 @@
|
||||
package makemakefile;
|
||||
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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/MPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999-2011
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Steve Lamm (slamm@netscape.com).
|
||||
# Joey Armstrong <joey@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
# use feature 'state'; 5.10+ not available everywhere
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(2.0);
|
||||
use Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(dirname_legacy
|
||||
getConfig getDepth getRelPath getObjDir getTopDir mkdirr
|
||||
getExclusions
|
||||
run_config_status
|
||||
updateMakefiles
|
||||
update_makefiles_legacy
|
||||
);
|
||||
|
||||
##--------------------##
|
||||
##---] INCLUDES [---##
|
||||
##--------------------##
|
||||
use Cwd;
|
||||
use Cwd qw{abs_path};
|
||||
use FindBin;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
umask 0;
|
||||
my $cwd = Cwd::abs_path('.');
|
||||
my %argv;
|
||||
|
||||
|
||||
###########################################################################
|
||||
## Intent: Helper function, retrieve contents of a file with error checking
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar path to input file
|
||||
## Returns:
|
||||
## array contents of the given file
|
||||
## $@ set on error
|
||||
###########################################################################
|
||||
sub cat
|
||||
{
|
||||
my $fyl = shift || '';
|
||||
$@ = '';
|
||||
my @data;
|
||||
|
||||
local *FYL;
|
||||
if (!open(FYL, $fyl))
|
||||
{
|
||||
$@ = "open($fyl) failed: $!";
|
||||
}
|
||||
else
|
||||
{
|
||||
@data = <FYL>;
|
||||
close(FYL);
|
||||
}
|
||||
return @data;
|
||||
} # cat
|
||||
|
||||
###########################################################################
|
||||
## Intent: Return directory path for a given argument
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
## Todo:
|
||||
## o Check if function can be replaced by File::Basename::dirname()
|
||||
###########################################################################
|
||||
sub dirname_legacy
|
||||
{
|
||||
my $str = (@_ && defined($_[0])) ? shift : '';
|
||||
return $str =~ /(.*)\/.*/ ? "$1" : '.';
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Intent: Given a list of makefile paths recursively create all
|
||||
## directories between file and the root
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array A list of makefiles
|
||||
## fargs Function arguments
|
||||
## mode Filesystem mode used for directory creation
|
||||
## Returns:
|
||||
## $@ Set on error
|
||||
## 0 on success
|
||||
## -----------------------------------------------------------------------
|
||||
## Note:
|
||||
## Reporting directory creation can be enabled by the --verbose
|
||||
## command line argument.
|
||||
###########################################################################
|
||||
sub mkdirr
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_])) ? %{ (pop) } : ();
|
||||
my $mode = $fargs{mode} || 0755;
|
||||
my $verbose = $main::argv{verbose} || 0;
|
||||
$@ = '' unless ($fargs{recursive});
|
||||
$fargs{recursive} = 1;
|
||||
|
||||
my @errors;
|
||||
push(@errors, $@) if ($@);
|
||||
foreach my $path (@_)
|
||||
{
|
||||
(my $dir = $path) =~ s%/?Makefile[^/]*$%%o;
|
||||
next unless (length($dir));
|
||||
next if (-e $dir);
|
||||
mkdirr( dirname($dir), \%fargs);
|
||||
eval{ File::Path::mkpath($dir, $verbose, 0755); };
|
||||
push(@errors, $@) if ($@);
|
||||
}
|
||||
$@ = join("\n", @errors);
|
||||
return $@ ? 0 : 1;
|
||||
} # mkdirr
|
||||
|
||||
###########################################################################
|
||||
## Intent: Read in configure values and return a hash of key/value pairs
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## fargs Function arguments
|
||||
## reset clear value storage and repopulate
|
||||
## Returns:
|
||||
## hash configure data to use for makefile substitutions
|
||||
## -----------------------------------------------------------------------
|
||||
## Todo: wrapper for reading config* and run_config_status
|
||||
###########################################################################
|
||||
my %_CONFIG_; # todo: state %config; w/5.10
|
||||
sub getConfig
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_]) eq 'HASH') ? %{ (pop) } : ();
|
||||
if ($fargs{reset})
|
||||
{
|
||||
%_CONFIG_ = ();
|
||||
shift;
|
||||
}
|
||||
|
||||
#my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
#my $ac_dir = dirname_legacy($ac_file);
|
||||
#my $ac_dots = '';
|
||||
#my $ac_dir_suffix = '';
|
||||
#my $srcdir = '.';
|
||||
#my $top_srcdir = '.';
|
||||
unless (%_CONFIG_)
|
||||
{
|
||||
while (@_)
|
||||
{
|
||||
my ($k, $v) = splice(@_, 0, 2);
|
||||
$_CONFIG_{$k} = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return %_CONFIG_;
|
||||
} # getConfig
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine path depth between leaf and root directory.
|
||||
## o DEPTH= may be set by makefile content
|
||||
## o DEPTH= may be set by Makefile in a parent
|
||||
## o Manually determine by relpath form leaf to sandbox top
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar Path to makefile or directory to determine DEPTH for
|
||||
## Returns:
|
||||
## scalar Relative path from leaf to root directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub getDepth($)
|
||||
{
|
||||
my $fyl = shift || '';
|
||||
|
||||
my @path = split(m%/%o, $fyl);
|
||||
pop(@path) if ('Makefile' eq substr($path[$#path], 0, 8));
|
||||
my $depth;
|
||||
my @depth;
|
||||
|
||||
my $top = getTopDir();
|
||||
my @top = split(m%/%o, $top);
|
||||
my @pathNoTop = @path;
|
||||
splice(@pathNoTop, 0, scalar(@top));
|
||||
|
||||
SEARCH:
|
||||
while (@path)
|
||||
{
|
||||
## Search for a file containing DEPTH=../..
|
||||
foreach my $fyl ( qw{Makefile.in Makefile} )
|
||||
{
|
||||
my $path = join('/', @path, $fyl);
|
||||
local *FYL;
|
||||
if (!open(FYL, $path)) {} # NOP
|
||||
elsif (my @tmp = map{ /^\s*DEPTH\s*=\s*([\.\/]+)/o ? $1 : () } <FYL>)
|
||||
{
|
||||
$depth = join('/', @depth, shift @tmp);
|
||||
last SEARCH;
|
||||
}
|
||||
close(FYL);
|
||||
}
|
||||
pop @path;
|
||||
pop @pathNoTop;
|
||||
|
||||
if (0 == scalar(@pathNoTop))
|
||||
{
|
||||
$depth = join('/', @depth);
|
||||
last;
|
||||
}
|
||||
|
||||
## Construct path manually
|
||||
push(@depth, '..');
|
||||
}
|
||||
return $depth;
|
||||
} # getDepth
|
||||
|
||||
###########################################################################
|
||||
## Intent: Read in the exclusion file
|
||||
###########################################################################
|
||||
sub getExclusions
|
||||
{
|
||||
my $file = shift || '';
|
||||
|
||||
return () if ($main::argv{'no-exclusions'});
|
||||
|
||||
my %exclude;
|
||||
if ($file)
|
||||
{
|
||||
my @data = cat($file);
|
||||
foreach (@data)
|
||||
{
|
||||
next unless ($_);
|
||||
next if (/^\s*\#/o);
|
||||
next unless (m%/%);
|
||||
chomp;
|
||||
$exclude{$_}++;
|
||||
}
|
||||
}
|
||||
return %exclude;
|
||||
} # getExclusions
|
||||
|
||||
###########################################################################
|
||||
## Intent: Given the path to a makefile beneath either src or obj
|
||||
## derive the relative path prefix between makefile and root.
|
||||
###########################################################################
|
||||
sub getRelPath
|
||||
{
|
||||
my $path0 = shift;
|
||||
my $abspath;
|
||||
|
||||
# Determine type and orientation
|
||||
my $name = basename($path0);
|
||||
my $haveMF = ($name eq 'Makefile.in') ? 1
|
||||
: ($name eq 'Makefile') ? -1
|
||||
: 0
|
||||
;
|
||||
|
||||
####################################################
|
||||
## Prep work: form a relative path with ../ removed
|
||||
####################################################
|
||||
my $top = getTopDir();
|
||||
my $obj = getObjDir();
|
||||
## If the same Makefile will be created alongside Makefile.in
|
||||
my $topQM = quotemeta($top);
|
||||
my $objQM = quotemeta($obj);
|
||||
|
||||
if ('..' eq substr($path0, 0, 2))
|
||||
{
|
||||
my @cwd = split(m%/%, $cwd);
|
||||
my @pth = split(m%/%, $path0);
|
||||
while (@pth && $pth[0] eq '..')
|
||||
{
|
||||
pop(@cwd);
|
||||
shift @pth;
|
||||
}
|
||||
$path0 = join('/', @cwd, @pth);
|
||||
$abspath = $path0;
|
||||
}
|
||||
|
||||
if ('/' eq substr($path0, 0, 1))
|
||||
{
|
||||
$path0 =~ s%^$objQM\/?%%;
|
||||
$path0 =~ s%^$topQM\/?%%;
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## Build a list of directories to search. Input source will be one
|
||||
## of path to Makefile.in, path to Makefile, directory, file within
|
||||
## a directory or relative path from cwd.
|
||||
#######################################################################
|
||||
my @subdirs;
|
||||
my $path = (0 == $haveMF) ? $path0 : dirname($path0);
|
||||
push(@subdirs, $path); # containing directory
|
||||
push(@subdirs, dirname($path)) if (0 == $haveMF && -f $path); # Arg is file within a directory
|
||||
push(@subdirs, $cwd); # relative to pwd
|
||||
|
||||
# obj - path to generated makefile
|
||||
# top - path to Makefile.in source template
|
||||
my @prefixes = ('/' ne substr($path0, 0, 1))
|
||||
? (&getTopDir, &getObjDir)
|
||||
: ()
|
||||
;
|
||||
|
||||
ON_SAFARI:
|
||||
for my $prefix (@prefixes)
|
||||
{
|
||||
next unless ($prefix); # no command line not passed
|
||||
foreach my $subdir (@subdirs)
|
||||
{
|
||||
foreach my $mf ('Makefile.in', 'Makefile')
|
||||
{
|
||||
my $path = join('/', $prefix, $subdir, $mf);
|
||||
if (-e $path)
|
||||
{
|
||||
$name = $mf;
|
||||
$haveMF = ($mf eq 'Makefile.in') ? 1 : -1;
|
||||
$abspath = $path;
|
||||
last ON_SAFARI;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## Generated makefile does not yet exist or path is invalid.
|
||||
## Should this conditon be handled to detect non-existent Makefile.in:
|
||||
## Makefile.am => Makefile.in => Makefile but Makefile.in
|
||||
#######################################################################
|
||||
if (!$abspath && -1 == $haveMF && $obj)
|
||||
{
|
||||
$abspath = ('/' eq substr($path0, 0, 1))
|
||||
? $path0
|
||||
: join('/', $obj, $path0)
|
||||
;
|
||||
}
|
||||
|
||||
########################################################
|
||||
## If --top and/or --obj specified extract relative path
|
||||
########################################################
|
||||
my $relpath;
|
||||
if (! $abspath)
|
||||
{
|
||||
# Error, fall through
|
||||
}
|
||||
elsif (1 == $haveMF) # Makefile.in
|
||||
{
|
||||
## err w/o --top
|
||||
(my $tmp = $abspath) =~ s%^$topQM/?%%;
|
||||
$relpath = dirname($tmp) unless ($tmp eq $abspath);
|
||||
}
|
||||
elsif (-1 == $haveMF) # Makefile
|
||||
{
|
||||
## err w/o --obj
|
||||
(my $tmp = $abspath) =~ s%^$objQM/?%%;
|
||||
$relpath = dirname($tmp) unless ($tmp eq $abspath);
|
||||
}
|
||||
|
||||
$relpath ||= '';
|
||||
$relpath =~ s%/./%/%og; # filter ./
|
||||
|
||||
$@ = ($relpath) ? '' : "ERROR($path0): Unable to locate sources";
|
||||
return $relpath || '';
|
||||
} # getRelPath
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine sandbox root from script startup directory
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## _set_ optional, if passed use the given value as path
|
||||
## _reset_ clear cached directory path to reassign
|
||||
## Returns:
|
||||
## scalar - absolute path to the sandbox root directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $gtd_dir;
|
||||
sub getTopDir
|
||||
{
|
||||
if (@_) # testing override
|
||||
{
|
||||
$gtd_dir = abs_path($_[1] || '.') if ($_[0] eq '_set_');
|
||||
$gtd_dir = '' if ($_[0] eq '_reset_');
|
||||
}
|
||||
|
||||
unless ($gtd_dir)
|
||||
{
|
||||
## Set by command line
|
||||
if ($main::argv{top})
|
||||
{
|
||||
$gtd_dir = $main::argv{top};
|
||||
}
|
||||
else
|
||||
{
|
||||
my $path = abs_path($FindBin::RealBin);
|
||||
my @path = split(m%/%o, $path);
|
||||
## --2 memory/mozalloc/Makefile.in
|
||||
## --3 was this for FindBin::Script ?
|
||||
splice(@path, -2);
|
||||
$gtd_dir = join('/', @path);
|
||||
}
|
||||
}
|
||||
return $gtd_dir;
|
||||
} # getTopDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine path to MOZ_OBJDIR/object directory
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## _set_ optional testing arg, if passed re-compute cached value
|
||||
## Returns:
|
||||
## scalar - absolute path to the sandbox object directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $god_dir;
|
||||
sub getObjDir
|
||||
{
|
||||
if (@_) # testing override
|
||||
{
|
||||
if ($_[0] eq '_reset_')
|
||||
{
|
||||
$god_dir = '';
|
||||
shift;
|
||||
}
|
||||
elsif ($_[0] eq '_set_')
|
||||
{
|
||||
shift;
|
||||
my $path = $_[0] || '.';
|
||||
$god_dir = abs_path($path);
|
||||
shift;
|
||||
}
|
||||
}
|
||||
|
||||
## extract $obj from given path
|
||||
unless ($god_dir)
|
||||
{
|
||||
if ($main::argv{obj})
|
||||
{
|
||||
$god_dir = $main::argv{obj};
|
||||
}
|
||||
elsif (@_ && 'Makefile' eq substr($_, -8))
|
||||
{
|
||||
$god_dir = abs_path(shift);
|
||||
}
|
||||
else # assume we are sitting in moz_objdir
|
||||
{
|
||||
$god_dir = abs_path('.');
|
||||
}
|
||||
}
|
||||
|
||||
return $god_dir;
|
||||
} # getObjDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Generate Makefile from a given Makefile.in template
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar Relative path to a directory containing a makefile
|
||||
## fargs Hash ref of function arguments.
|
||||
## obj Absolute path to MOZ_OBJ/a destination directory
|
||||
## top Absolute path to the sandbox root
|
||||
## Returns:
|
||||
## $@ Set on error
|
||||
## scalar
|
||||
## 1 True if the makefile was updated
|
||||
## 0 Otherwise
|
||||
## badtokens - If the makefile contains unexpandable @token@ strings
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub updateMakefiles
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_])) ? %{ (pop) } : ();
|
||||
local $_;
|
||||
$@ = '';
|
||||
|
||||
my $top = $fargs{top};
|
||||
my $obj = $fargs{obj};
|
||||
|
||||
my $relpath = shift || '';
|
||||
my $src = join('/', $top, $relpath, 'Makefile.in');
|
||||
my $depth = getDepth($src);
|
||||
|
||||
my @src = cat($src);
|
||||
return 0 if ($@);
|
||||
|
||||
my $dst = join('/', $obj, $relpath, 'Makefile');
|
||||
my @dst = cat($dst);
|
||||
$@ = '';
|
||||
|
||||
my $dstD = dirname($dst);
|
||||
mkdirr($dstD);
|
||||
return 0 if ($@);
|
||||
|
||||
my %data =
|
||||
( getConfig(),
|
||||
depth => $depth,
|
||||
srcdir => join('/', $top, $relpath),
|
||||
top_srcdir => $top,
|
||||
);
|
||||
|
||||
my $line = 0;
|
||||
my @data;
|
||||
while (scalar @src)
|
||||
{
|
||||
$line++;
|
||||
$_ = shift(@src);
|
||||
|
||||
## Expand embedded @foo@
|
||||
while (/\@[^\@\s\$]+\@/go)
|
||||
{
|
||||
my $end = pos($_);
|
||||
my $val = $&;
|
||||
my $len = length($val);
|
||||
$val =~ s/^\@\s*//o;
|
||||
$val =~ s/\s*\@$//o;
|
||||
|
||||
## Identify expansions to see if we can avoid shell overhead
|
||||
if (!defined $data{$val} && !$argv{'no-badtokens'})
|
||||
{
|
||||
if (1) # warnings
|
||||
{
|
||||
print STDERR "WARNING: token $val not defined\n";
|
||||
print STDERR " line $line, src: $src\n";
|
||||
}
|
||||
return 'badtokens';
|
||||
}
|
||||
|
||||
# Insert $(error txt) makefile macros for invalid tokens
|
||||
my $val1 = defined($data{$val})
|
||||
? $data{$val}
|
||||
: "\$(error $FindBin::Script: variable ${val} is undefined)"
|
||||
;
|
||||
substr($_, ($end-$len), $len, $val1);
|
||||
}
|
||||
push(@data, $_);
|
||||
}
|
||||
|
||||
if (("@data" eq "@dst") && scalar(@data))
|
||||
{
|
||||
print "Skipping up2date makefile: $dst\n" if ($argv{verbose});
|
||||
}
|
||||
else
|
||||
{
|
||||
my $action = (scalar @dst) ? 'Updating' : 'Creating';
|
||||
print "$action makefile: $dst\n";
|
||||
|
||||
my $tmp = join('.', $dst, "tmp_$$");
|
||||
if (!open(FYL, "> $tmp"))
|
||||
{
|
||||
$@ = "open($tmp) failed: $!";
|
||||
}
|
||||
else
|
||||
{
|
||||
print FYL @data;
|
||||
close(FYL);
|
||||
|
||||
## Install the new makefile
|
||||
File::Copy::move($tmp, $dst)
|
||||
|| ($@ = "move($tmp, $dst) failed: $!");
|
||||
}
|
||||
}
|
||||
|
||||
return $@ ? 0 : 1;
|
||||
} # updateMakefiles
|
||||
|
||||
# Output the makefiles.
|
||||
#
|
||||
sub update_makefiles_legacy {
|
||||
my ($ac_given_srcdir, $pac_given_srcdir, @makefiles) = @_;
|
||||
my $debug = $main::argv{debug} || 0;
|
||||
my $pwdcmd = ($^O eq 'msys') ? 'pwd -W' : 'pwd';
|
||||
my @unhandled=();
|
||||
|
||||
my @warn;
|
||||
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
my $ac_dir = dirname_legacy($ac_file);
|
||||
my $ac_dots = '';
|
||||
my $ac_dir_suffix = '';
|
||||
my $srcdir = '.';
|
||||
my $top_srcdir = '.';
|
||||
|
||||
# Determine $srcdir and $top_srcdir
|
||||
#
|
||||
if ($ac_dir ne '.') {
|
||||
$ac_dir_suffix = "/$ac_dir";
|
||||
$ac_dir_suffix =~ s%^/\./%/%;
|
||||
$ac_dots = $ac_dir_suffix;
|
||||
# Remove .. components from the provided dir suffix, and
|
||||
# also the forward path components they were reversing.
|
||||
my $backtracks = $ac_dots =~ s%\.\.(/|$)%%g;
|
||||
while ($backtracks--) {
|
||||
$ac_dots =~ s%/[^/]*%%;
|
||||
}
|
||||
$ac_dots =~ s%/[^/]*%../%g;
|
||||
}
|
||||
if ($ac_given_srcdir eq '.') {
|
||||
if ($ac_dots ne '') {
|
||||
$top_srcdir = $ac_dots;
|
||||
$top_srcdir =~ s%/$%%;
|
||||
}
|
||||
} elsif ($pac_given_srcdir =~ m%^/% or $pac_given_srcdir =~ m%^.:/%) {
|
||||
$srcdir = "$pac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$pac_given_srcdir";
|
||||
} else {
|
||||
if ($debug) {
|
||||
print "ac_dots = $ac_dots\n";
|
||||
print "ac_dir_suffix = $ac_dir_suffix\n";
|
||||
}
|
||||
$srcdir = "$ac_dots$ac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$ac_dots$ac_given_srcdir";
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
print "ac_dir = $ac_dir\n";
|
||||
print "ac_file = $ac_file\n";
|
||||
print "ac_file_in = $ac_file_in\n";
|
||||
print "srcdir = $srcdir\n";
|
||||
print "top_srcdir = $top_srcdir\n";
|
||||
print "cwd = " . `$pwdcmd` . "\n";
|
||||
}
|
||||
|
||||
# Copy the file and make substitutions.
|
||||
# @srcdir@ -> value of $srcdir
|
||||
# @top_srcdir@ -> value of $top_srcdir
|
||||
#
|
||||
if (-e $ac_file) {
|
||||
next if -M _ < -M $ac_file_in; # Next if Makefile is up-to-date.
|
||||
warn "updating $ac_file\n";
|
||||
} else {
|
||||
warn "creating $ac_file\n";
|
||||
}
|
||||
|
||||
mkdirr(dirname($ac_file));
|
||||
|
||||
open INFILE, "<$ac_file_in" or do {
|
||||
warn "$0: Cannot read $ac_file_in: No such file or directory\n";
|
||||
next;
|
||||
};
|
||||
open OUTFILE, ">$ac_file" or do {
|
||||
warn "$0: Unable to create $ac_file\n";
|
||||
next;
|
||||
};
|
||||
|
||||
while (<INFILE>) {
|
||||
s/\@srcdir\@/$srcdir/g;
|
||||
s/\@top_srcdir\@/$top_srcdir/g;
|
||||
|
||||
if (/\@[_a-zA-Z]*\@/) {
|
||||
#warn "Unknown variable:$ac_file:$.:$_";
|
||||
push @unhandled, $ac_file;
|
||||
last;
|
||||
}
|
||||
print OUTFILE;
|
||||
}
|
||||
close INFILE;
|
||||
close OUTFILE;
|
||||
}
|
||||
return @unhandled;
|
||||
} # update_makefiles_legacy
|
||||
|
||||
###########################################################################
|
||||
## Intent: Invoke config.status for unknown makefiles to create
|
||||
## directory hierarchy for the tree.
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array an optional list of makefiles to process
|
||||
## Returns:
|
||||
## 0 on success
|
||||
## $# set on error
|
||||
## -----------------------------------------------------------------------
|
||||
## Note: Is this function needed anymore ? Undefined tokens should fail
|
||||
## at time of expansion rather than having to source config.status.
|
||||
## Also config.status could be parsed to define values and avoide the
|
||||
## shell overhead altogether.
|
||||
###########################################################################
|
||||
sub run_config_status {
|
||||
my @unhandled = @_;
|
||||
|
||||
# Run config.status with any unhandled files.
|
||||
#
|
||||
my @errors;
|
||||
if (@unhandled) {
|
||||
local $ENV{CONFIG_FILES}= join ' ', @unhandled;
|
||||
|
||||
my $conf = 'config.status';
|
||||
if (! -e $conf) # legacy behavior, warn rather than err
|
||||
{
|
||||
my $cwd = cwd();
|
||||
my $err = "$FindBin::Script ERROR: Config file $conf does not exist, cwd=$cwd";
|
||||
push(@errors, $err);
|
||||
}
|
||||
elsif (0 != system("./config.status"))
|
||||
{
|
||||
my $cwd = cwd();
|
||||
push(@errors, "config.status failed \$?=$?, \$!=$!, cwd: $cwd");
|
||||
}
|
||||
}
|
||||
$@ = join("\n", @errors);
|
||||
|
||||
## Legacy behavior: config.status problems are not fatal {yet}.
|
||||
## Display warning since caller will not be calling die.
|
||||
warn $@ if ($@ && $argv{'no-warnings'});
|
||||
return $@ ? 1 : 0;
|
||||
}
|
||||
|
||||
1;
|
@ -1,94 +0,0 @@
|
||||
# -*- makefile -*-
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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/MPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2011
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Joey Armstrong <joey@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
##################################################
|
||||
## Gather a list of tests, generate timestamp deps
|
||||
##################################################
|
||||
TS=.ts
|
||||
ifneq (,$(findstring check,$(MAKECMDGOALS)))
|
||||
allsrc = $(wildcard $(srcdir)/*)
|
||||
tests2run = $(notdir $(filter %.tpl,$(allsrc)))
|
||||
tests2run += $(notdir $(filter %.tpm,$(allsrc)))
|
||||
check_targets += $(addprefix $(TS)/,$(tests2run))
|
||||
endif
|
||||
|
||||
all_nop: # export, libs and tools are not needed
|
||||
|
||||
check:: $(TS) $(check_targets)
|
||||
|
||||
#############################################
|
||||
# Only invoke tests when sources have changed
|
||||
#############################################
|
||||
$(TS)/%: $(srcdir)/%
|
||||
$(PERL) $(srcdir)/runtest $<
|
||||
@touch $@
|
||||
|
||||
parent = $(patsubst %/,%,$(dir $(srcdir)))
|
||||
$(TS)/make-makefile.tpl: \
|
||||
$(srcdir)/make-makefile.tpl\
|
||||
$(parent)/makemakefile.pm\
|
||||
$(NULL)
|
||||
$(PERL) $(srcdir)/runtest $<
|
||||
@touch $@
|
||||
|
||||
$(TS)/makemakefile.tpm: \
|
||||
$(srcdir)/makemakefile.tpm \
|
||||
$(parent)/makemakefile.pm \
|
||||
$(NULL)
|
||||
$(PERL) $(srcdir)/runtest $<
|
||||
@touch $@
|
||||
|
||||
#####################################################
|
||||
## Extra dep needed to synchronize parallel execution
|
||||
#####################################################
|
||||
$(TS): $(TS)/.done
|
||||
$(TS)/.done:
|
||||
$(MKDIR) -p $(dir $@)
|
||||
touch $@
|
||||
|
||||
GARBAGE_DIRS += $(TS)
|
||||
|
||||
# EOF
|
@ -1,4 +0,0 @@
|
||||
jsautocfg.h: jscpucfg$(HOST_BIN_SUFFIX)
|
||||
@$(RM) $@ jsautocfg.tmp
|
||||
./jscpucfg > jsautocfg.tmp
|
||||
mv jsautocfg.tmp $@
|
@ -1,4 +0,0 @@
|
||||
jsautocfg.h: jscpucfg$(HOST_BIN_SUFFIX)
|
||||
@$(RM) $@ jsautocfg.tmp
|
||||
./jscpucfg > jsautocfg.tmp
|
||||
mv jsautocfg.tmp $@
|
@ -1,8 +0,0 @@
|
||||
###########################################################################
|
||||
## Intent: Exclusion list for container make builds
|
||||
###########################################################################
|
||||
|
||||
/dev/null
|
||||
/foo/bar
|
||||
/a/b/c
|
||||
/a/b/d
|
@ -1,436 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
###########################################################################
|
||||
## Intent: Unit test to verify make-makefile.tpl
|
||||
###########################################################################
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
#use feature 'state'; # 5.10+ not installed everywhere
|
||||
use Getopt::Long;
|
||||
|
||||
use Cwd;
|
||||
use Cwd qw{abs_path};
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
use File::Path;
|
||||
use File::Temp qw{ tempdir };
|
||||
|
||||
use Test;
|
||||
sub BEGIN { plan tests => 4 };
|
||||
my @workdirs;
|
||||
sub END { system("/bin/rm -fr @workdirs"); } # cleanup behind interrupts
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
use FindBin;
|
||||
our $VERSION = qw(1.0);
|
||||
|
||||
##------------------##
|
||||
##---] INCLUDES [---##
|
||||
##------------------##
|
||||
use FindBin;
|
||||
use lib "$FindBin::RealBin/..";
|
||||
use makemakefile;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
my %argv;
|
||||
|
||||
###########################################################################
|
||||
## Intent: Create a temp sandbox populated with sources
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array a list of file paths to copy
|
||||
## Returns:
|
||||
## $@ set on error
|
||||
## scalar path to scratch sandbox
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $root; # state $root not available
|
||||
sub createSandbox
|
||||
{
|
||||
my @errors;
|
||||
|
||||
unless ($root)
|
||||
{
|
||||
my @tmp = split(m%/%, $FindBin::RealBin);
|
||||
splice(@tmp, -3);
|
||||
$root = join('/', @tmp);
|
||||
}
|
||||
|
||||
my $work = tempdir();
|
||||
push(@workdirs, $work);
|
||||
my @dirs = map{ join('/', $work, dirname($_)) } @_;
|
||||
mkdirr(@dirs);
|
||||
push(@errors, "createSandbox: $@") if ($@);
|
||||
|
||||
foreach (@_)
|
||||
{
|
||||
## Copy sources into the temp source directory
|
||||
my $src = join('/', $root, $_);
|
||||
my $dst = join('/', $work, $_);
|
||||
unless (copy($src, $dst))
|
||||
{
|
||||
push(@errors, "copy($src, $dst) failed: $!");
|
||||
}
|
||||
}
|
||||
print STDERR "createSandbox: $work\n" if ($main::argv{debug});
|
||||
$@ = join('', map{ "$_\n" } @errors);
|
||||
$work;
|
||||
} # createSandbox
|
||||
|
||||
###########################################################################
|
||||
## Intent: wrapper to run the make-makefile command.
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array command line arguments passed to make-makefile
|
||||
## Returns:
|
||||
## array command output
|
||||
## $@ set by shell exit status, empty string on success
|
||||
## $? command shell exit status
|
||||
###########################################################################
|
||||
my $mm; # state $mm not available
|
||||
sub makemakefile
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_])) ? %{ (pop) } : ();
|
||||
$mm ||= join('/', dirname($FindBin::Bin), 'make-makefile'); # cmd in parent of test/
|
||||
my $cmd = join(' ', $mm, @_);
|
||||
print "RUNNING: $cmd\n" if ($fargs{debug});
|
||||
my @out = `$cmd 2>&1`;
|
||||
print STDERR map{ "out> $_" } @out if ($argv{verbose});
|
||||
$@ = (0 == $?) ? '' : "Command failed: $cmd\n@out";
|
||||
@out;
|
||||
} # makemakefile
|
||||
|
||||
###########################################################################
|
||||
## Intent: Helper function, display the contents of a given sandbox
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar Path to sandbox
|
||||
## Returns:
|
||||
## none
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub find_ls
|
||||
{
|
||||
my $path = shift || '';
|
||||
|
||||
# Assuming dot contributes to cryptic problems
|
||||
die "find_ls: a path is required" unless ($path);
|
||||
|
||||
my $cmd = "find $path -ls";
|
||||
print "\nRunning: $cmd\n";
|
||||
print '=' x 75, "\n";
|
||||
print `$cmd`;
|
||||
} # myls
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify make-makefile is able to digest paths and generate
|
||||
## makefiles when object directory is a child of top.
|
||||
###########################################################################
|
||||
sub check_makemakefile
|
||||
{
|
||||
my $work = createSandbox
|
||||
(
|
||||
'memory/mozalloc/Makefile.in',
|
||||
'toolkit/system/windowsproxy/Makefile.in',
|
||||
'toolkit/crashreporter/google-breakpad/src/client/Makefile.in',
|
||||
);
|
||||
|
||||
|
||||
my $workdir = createSandbox();
|
||||
my $top = $workdir;
|
||||
chdir $top;
|
||||
|
||||
my $objA = 'obj-arch-dir';
|
||||
my $obj = join('/', $top, $objA);
|
||||
|
||||
# getTopDir()
|
||||
local $main::argv{top} = $work;
|
||||
local $main::argv{obj} = $obj;
|
||||
getObjDir('_reset_');
|
||||
|
||||
my @root = split(m%/%, $FindBin::RealBin);
|
||||
splice(@root, -3);
|
||||
my $root = join('/', @root);
|
||||
my @args =
|
||||
(
|
||||
|
||||
[
|
||||
banner => "--top and --obj are impled, generate Makefile",
|
||||
rel => 'memory/mozalloc',
|
||||
cmd => join(' ',
|
||||
'--top', $top,
|
||||
'--obj', $obj,
|
||||
'memory/mozalloc/Makefile',
|
||||
),
|
||||
],
|
||||
|
||||
[
|
||||
banner => "--top and abs(obj) passed",
|
||||
rel => "toolkit/system/windowsproxy",
|
||||
cmd => join(' ',
|
||||
'--top', $top,
|
||||
"$obj/toolkit/system/windowsproxy/Makefile",
|
||||
),
|
||||
exp => "$obj/toolkit/system/windowsproxy/Makefile",
|
||||
skip => 1, #
|
||||
],
|
||||
|
||||
|
||||
[
|
||||
banner => "--obj and abs(top) passed",
|
||||
rel => "toolkit/crashreporter/google-breakpad/src/client",
|
||||
cmd => join(' ',
|
||||
'--obj', $obj,
|
||||
"$top/toolkit/crashreporter/google-breakpad/src/client/Makefile.in",
|
||||
),
|
||||
exp => "$top/toolkit/crashreporter/google-breakpad/src/client/Makefile.in",
|
||||
skip => 1, #
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
foreach (@args)
|
||||
{
|
||||
my %rec = @{ $_ };
|
||||
next if ($rec{skip});
|
||||
next unless ($rec{rel});
|
||||
|
||||
my $srcR = join('/', $top, $rec{rel});
|
||||
my $dstR = join('/', $obj, $rec{rel});
|
||||
|
||||
my $src = join('/', $top, $rec{rel}, 'Makefile.in');
|
||||
my $dst = join('/', $obj, $rec{rel}, 'Makefile');
|
||||
|
||||
# Use distinct sources to avoid cleanup overhead between tests
|
||||
die "Test source already used: $dstR" if (-d $dstR);
|
||||
|
||||
## Copy sources into the temp source directory
|
||||
my $rootR = join('/', $root, $rec{rel});
|
||||
my $rootS = join('/', $root, $rec{rel}, 'Makefile.in');
|
||||
File::Path::mkpath($srcR, 0, 0700);
|
||||
copy($rootS, $src) or die "copy($rootS, $src) failed: $!";
|
||||
|
||||
die "source does not exist: $src" unless (-e $src);
|
||||
|
||||
######################
|
||||
## Generate and verify
|
||||
######################
|
||||
print STDERR "RUNNING: $rec{banner}\n" if ($argv{debug});
|
||||
my @errs;
|
||||
makemakefile('--enhanced', $rec{cmd}, {verbose=>1});
|
||||
if ($@)
|
||||
{
|
||||
push(@errs, "\$@ should not be set: $@\n");
|
||||
}
|
||||
elsif (! -e $dst)
|
||||
{
|
||||
push(@errs, "Generated makefile does not exist: $dst, banner: $rec{banner}\n");
|
||||
}
|
||||
|
||||
ok(scalar(@errs), 0, "Errors detected:\n" . join(" $_", @errs));
|
||||
find_ls($top) if (@errs);
|
||||
}
|
||||
|
||||
} # check_makemakefile
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify make-makefile is able to digest paths and generate
|
||||
## makefiles when top/MOZ_OBJDIR are not parent/child directories
|
||||
## ---------------------------------------------------------------------------
|
||||
## Args:
|
||||
## none
|
||||
## Returns:
|
||||
## none
|
||||
## ---------------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub check_makemakefile_distinct
|
||||
{
|
||||
my $workdir = createSandbox();
|
||||
# my $workdir = tempdir();
|
||||
|
||||
###############################################
|
||||
## Now update when top/obj are not parent/child
|
||||
###############################################
|
||||
my $top = join('/', $workdir, 'top');
|
||||
my $obj = join('/', $workdir, 'obj');
|
||||
|
||||
$main::argv{top} = $top;
|
||||
$main::argv{obj} = $obj; # test afterward, using undef ?
|
||||
|
||||
my @sbxroot = split(m%/%, $FindBin::RealBin);
|
||||
splice(@sbxroot, -2);
|
||||
my $sbxroot = join('/', @sbxroot);
|
||||
|
||||
## Copy in a makefile template to to convert
|
||||
File::Path::mkpath(["$top/memory/mozalloc"], 0, 0700);
|
||||
copy("$sbxroot/memory/mozalloc/Makefile.in", "$top/memory/mozalloc/Makefile.in");
|
||||
|
||||
|
||||
# work/memory/mozalloc/Makefile.in
|
||||
|
||||
my @args =
|
||||
(
|
||||
[
|
||||
banner => '--top and --obj are distinct [1]',
|
||||
cmd => "--obj $obj memory/mozalloc/Makefile",
|
||||
exp => "$obj/memory/mozalloc/Makefile",
|
||||
],
|
||||
|
||||
[
|
||||
banner => "--top and --obj are distinct [2]",
|
||||
cmd => "--top $top memory/mozalloc/Makefile.in",
|
||||
exp => "$obj/memory/mozalloc/Makefile",
|
||||
skip => 1, # test problem: top != obj
|
||||
],
|
||||
|
||||
[
|
||||
banner => "--top and --obj are distinct [3]",
|
||||
cmd => join(' ',
|
||||
"--top $top",
|
||||
"--obj $obj",
|
||||
"memory/mozalloc/Makefile.in",
|
||||
),
|
||||
exp => "$obj/memory/mozalloc/Makefile",
|
||||
skip => 1, # test problem: top != obj
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
foreach (@args)
|
||||
{
|
||||
my %rec = @{ $_ };
|
||||
print STDERR "banner: $rec{banner}\n" if ($argv{debug});
|
||||
next if $rec{skip};
|
||||
|
||||
unlink $rec{exp};
|
||||
makemakefile('--enhanced', $rec{cmd});
|
||||
|
||||
my @errs;
|
||||
if ($@)
|
||||
{
|
||||
push(@errs, "\$@ should not be set: $@\n");
|
||||
}
|
||||
elsif (! -e $rec{exp})
|
||||
{
|
||||
push(@errs, "Makefile does not exist: $rec{exp}\n");
|
||||
}
|
||||
ok(scalar(@errs), 0, "Errors detected:\n" . join(" $_", @errs));
|
||||
}
|
||||
|
||||
} # check_makemakefile_distinct
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify legacy behavior, invoke make-makefile when cwd is
|
||||
## a subdirectory beneath MOZ_OBJDIR.
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## none
|
||||
## Returns:
|
||||
## none
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub check_makemakefile_legacy
|
||||
{
|
||||
my $work = createSandbox
|
||||
(
|
||||
'memory/mozalloc/Makefile.in',
|
||||
'parser/htmlparser/tests/mochitest/html5lib_tree_construction/Makefile.in',
|
||||
);
|
||||
|
||||
my $obj = join('/', $work, 'obj');
|
||||
mkdir $obj;
|
||||
|
||||
my @args =
|
||||
(
|
||||
{
|
||||
banner => '-t path -d dot',
|
||||
cwd => $obj,
|
||||
cmd => "-t $work -d . memory/mozalloc/Makefile",
|
||||
exp => "$obj/memory/mozalloc/Makefile",
|
||||
skip => 0,
|
||||
},
|
||||
|
||||
{
|
||||
banner => '-t path -d relpath',
|
||||
cwd => join('/', $obj, 'parser/htmlparser/tests/mochitest'),
|
||||
cmd => "-t $work -d ../../../.. html5lib_tree_construction/Makefile",
|
||||
exp => "$obj/parser/htmlparser/tests/mochitest/html5lib_tree_construction/Makefile",
|
||||
skip => 0,
|
||||
},
|
||||
);
|
||||
|
||||
foreach (@args)
|
||||
{
|
||||
my %rec = %{ $_ };
|
||||
next if ($rec{skip});
|
||||
|
||||
## make-make while sitting in $objdir
|
||||
mkdirr($rec{cwd});
|
||||
chdir $rec{cwd} || die "chdir $rec{cwd} failed; $!";
|
||||
|
||||
makemakefile($rec{cmd});
|
||||
my @errs;
|
||||
if ($@)
|
||||
{
|
||||
push(@errs, "make-makefile $rec{cmd} failed: $@");
|
||||
}
|
||||
elsif (! -e $rec{exp})
|
||||
{
|
||||
push(@errs, "generated makefile does not exist: $rec{exp}");
|
||||
}
|
||||
ok(scalar(@errs), 0, "Errors detected: @errs");
|
||||
find_ls($work) if (@errs);
|
||||
}
|
||||
chdir $FindBin::RealBin;
|
||||
} # check_makemakefile_legacy
|
||||
|
||||
###########################################################################
|
||||
## Intent: Smoke tests for the unittests module
|
||||
###########################################################################
|
||||
sub smoke
|
||||
{
|
||||
print STDERR "Running test: smoke()\n" if ($argv{debug});
|
||||
} # smoke()
|
||||
|
||||
###########################################################################
|
||||
## Intent: Intitialize global test objects and consts
|
||||
###########################################################################
|
||||
sub init
|
||||
{
|
||||
print "Running: init()\n" if ($argv{debug});
|
||||
# testplan(24, 0);
|
||||
} # init()
|
||||
|
||||
##----------------##
|
||||
##---] MAIN [---##
|
||||
##----------------##
|
||||
unless(GetOptions(\%argv,
|
||||
qw(
|
||||
debug|d
|
||||
manual
|
||||
test=s@
|
||||
verbose
|
||||
)))
|
||||
{
|
||||
print "USAGE: $0\n";
|
||||
print " --debug Enable script debug mode\n";
|
||||
print " --manual Also run disabled tests\n";
|
||||
print " --smoke Run smoke tests then exit\n";
|
||||
print " --test Run a list of tests by function name\n";
|
||||
print " --verbose Enable script verbose mode\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
init();
|
||||
smoke();
|
||||
|
||||
check_makemakefile();
|
||||
check_makemakefile_distinct();
|
||||
check_makemakefile_legacy();
|
@ -1,519 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
###########################################################################
|
||||
## Intent: Unit test to verify the makemakefile.pm module
|
||||
###########################################################################
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
#use feature 'state';
|
||||
use Getopt::Long;
|
||||
|
||||
use FindBin;
|
||||
use Cwd qw{abs_path};
|
||||
use File::Basename;
|
||||
use File::Compare;
|
||||
use File::Copy;
|
||||
use File::Temp qw{tempdir};
|
||||
|
||||
use Test;
|
||||
sub BEGIN { plan tests => 36 };
|
||||
my @workdirs;
|
||||
sub END { system("/bin/rm -fr @workdirs"); } # cleanup behind interrupts
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(1.0);
|
||||
|
||||
##------------------##
|
||||
##---] INCLUDES [---##
|
||||
##------------------##
|
||||
use FindBin;
|
||||
use lib "$FindBin::RealBin/..";
|
||||
use makemakefile;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
my %argv;
|
||||
|
||||
###########################################################################
|
||||
## Intent: Create a temp sandbox populated with sources
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array files to copy into the temporary sandbox
|
||||
## Returns:
|
||||
## $@ set on error
|
||||
## array
|
||||
## top - path to temp sandbox root
|
||||
## obj - path to temp sandbox moz_obj directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $_root_; # state $root
|
||||
sub createSandbox
|
||||
{
|
||||
# state $root;
|
||||
my @errors;
|
||||
|
||||
unless ($_root_)
|
||||
{
|
||||
my @tmp = split(m%/%, $FindBin::RealBin);
|
||||
splice(@tmp, -3);
|
||||
$_root_ = join('/', @tmp);
|
||||
}
|
||||
|
||||
my $work = tempdir(CLEANUP=>1);
|
||||
push(@workdirs, $work);
|
||||
my @dirs = map{ join('/', $work, dirname($_)) } @_;
|
||||
mkdirr(@dirs);
|
||||
push(@errors, "createSandbox: $@") if ($@);
|
||||
|
||||
foreach (@_)
|
||||
{
|
||||
## Copy sources into the temp source directory
|
||||
my $src = join('/', $_root_, $_);
|
||||
my $dst = join('/', $work, $_);
|
||||
unless (copy($src, $dst))
|
||||
{
|
||||
push(@errors, "copy($src, $dst) failed: $!");
|
||||
}
|
||||
}
|
||||
print STDERR "createSandbox: $work\n" if ($main::argv{debug});
|
||||
$@ = join('', map{ "$_\n" } @errors);
|
||||
$work;
|
||||
} # createSandbox
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify legacy dirname function
|
||||
###########################################################################
|
||||
sub check_dirname_legacy
|
||||
{
|
||||
print "Running: check_dirname_legacy\n" if ($main::argv{debug});
|
||||
|
||||
foreach (
|
||||
['/dev/null', '/dev'],
|
||||
['/foo/bar/Makefile', '/foo/bar'],
|
||||
)
|
||||
{
|
||||
my ($src, $exp) = @{ $_ };
|
||||
my $dir = dirname_legacy($src);
|
||||
ok($dir, $exp, "dirname_legacy($src) failed");
|
||||
}
|
||||
|
||||
my $path = dirname_legacy(undef);
|
||||
ok($path ? 1 : 0, 1, "dirname('') should expand to cwd");
|
||||
} # check_dirname_legacy
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify topdir lookup function
|
||||
###########################################################################
|
||||
sub check_getTopDir
|
||||
{
|
||||
print "Running: check_getTopDir\n" if ($main::argv{debug});
|
||||
|
||||
my $path = getTopDir();
|
||||
|
||||
## Unit test is special, cmd not invoked from the same directory
|
||||
## as the makemakefile.pm module.
|
||||
ok($path ? 1 : 0, 1, "getTopDir failed");
|
||||
ok(-d $path ? 1 : 0, 1, "getTopDir: directory $path does not exist");
|
||||
ok($FindBin::RealBin =~ m%$path/% ? 1 : 0, 1, 'Invalid topdir path');
|
||||
ok(-e "$path/client.mk" ? 1 : 0, 1, "client.mk not found in $path");
|
||||
} # check_getTopDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify objdir lookup function
|
||||
###########################################################################
|
||||
sub check_getObjDir
|
||||
{
|
||||
print "Running: check_getObjDir\n" if ($main::argv{debug});
|
||||
local $main::argv{obj} = '/bin';
|
||||
my $path = getObjDir('_reset_');
|
||||
ok($path ? 1 : 0, 1, "getObjDir failed");
|
||||
ok(-d $path ? 1 : 0, 1, "getObjDir: directory $path does not exist");
|
||||
|
||||
my $top = getTopDir();
|
||||
$main::argv{obj} = join('/', $top, 'browser'); # use existing path so file can be resolved
|
||||
my $obj = getObjDir('_reset_');
|
||||
ok($top ne $obj ? 1 : 0, 1, "top and object directory paths should not match");
|
||||
|
||||
## If we fail for /bin use here getObjDir() was not reset
|
||||
my $client = join('/', $obj, '..', 'client.mk');
|
||||
ok(-e $client ? 1 : 0, 1, "client.mk not found in parent of $path, $client");
|
||||
getObjDir('_set_'); # clear cached value and recompute
|
||||
|
||||
foreach my $file ("$top/memory/mozalloc/Makefile")
|
||||
{
|
||||
my $obj = getObjDir('_reset_', $file);
|
||||
ok($obj ne $file ? 1 : 0, 1, "getObjDir($file) failed")
|
||||
}
|
||||
} # check_getObjDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify rel-path-to-root/getdepth function
|
||||
###########################################################################
|
||||
sub check_getDepth
|
||||
{
|
||||
my @tmp = split(m%/%o, $FindBin::Bin);
|
||||
splice(@tmp, -3);
|
||||
my $root = abs_path( join('/', @tmp) );
|
||||
|
||||
my %data =
|
||||
(
|
||||
$root => '.',
|
||||
join('/', $root, 'netwerk/Makefile.in') => '..',
|
||||
|
||||
join('/', $root, 'browser/components/privatebrowsing/test/browser/Makefile.in') => '../../../../..',
|
||||
join('/', $root, 'browser/components/privatebrowsing/test/browser/') => '../../../../..',
|
||||
join('/', $root, 'browser/components/privatebrowsing/test/browser') => '../../../../..',
|
||||
join('/', $root, 'browser/components/privatebrowsing/test') => '../../../..',
|
||||
);
|
||||
|
||||
while (my($k, $v) = each %data)
|
||||
{
|
||||
my $depth = makemakefile::getDepth($k);
|
||||
ok($depth, $v, "getDepth($k) failed");
|
||||
}
|
||||
} # check_getDepth
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify reading the exclusion file
|
||||
###########################################################################
|
||||
sub check_getExclusions
|
||||
{
|
||||
my $cfg = join('/', $FindBin::RealBin, 'make-makefile.excl');
|
||||
my %excl = getExclusions($cfg);
|
||||
ok($@, '', '$@ should not be set');
|
||||
|
||||
my @excl = sort keys %excl;
|
||||
ok(scalar @excl, 4, "Exclusion file is invalid: \@excl=@excl");
|
||||
} # check_getExclusions
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify rel-path-to-root function
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## none
|
||||
## Returns:
|
||||
## none
|
||||
## -----------------------------------------------------------------------
|
||||
## Note:
|
||||
## String test only, top and obj paths are bogus for this test
|
||||
###########################################################################
|
||||
sub check_getRelPath
|
||||
{
|
||||
my @tmp = split(m%/%o, $FindBin::Bin);
|
||||
splice(@tmp, -3);
|
||||
my $root = abs_path( join('/', @tmp) );
|
||||
my $obj0 = 'obj-arch';
|
||||
my $obj = join('/', $root, $obj0);
|
||||
|
||||
local $main::argv{top} = $root;
|
||||
local $main::argv{obj} = $obj;
|
||||
getTopDir('_reset_');
|
||||
getObjDir('_set_', $obj);
|
||||
|
||||
## Cannot test relative paths with objdir beneath /tmp
|
||||
## Commented paths are needed for full test coverage
|
||||
## but are not currently supported by all module functions.
|
||||
my %data =
|
||||
(
|
||||
# Relative - path correct for build directory but
|
||||
'profile/dirserviceprovider/public/Makefile.in' => 'profile/dirserviceprovider/public',
|
||||
|
||||
join('/', $root, 'profile/dirserviceprovider/public/Makefile.in') => 'profile/dirserviceprovider/public',
|
||||
|
||||
# File search
|
||||
'profile/dirserviceprovider/public' => 'profile/dirserviceprovider/public',
|
||||
|
||||
# cwd + cleanup
|
||||
# '../../../profile/dirserviceprovider/public/Makefile.in' => 'profile/dirserviceprovider/public',
|
||||
# "../../../${obj0}/profile/dirserviceprovider/public/Makefile.in" => 'profile/dirserviceprovider/public',
|
||||
|
||||
## Special case: This could be handled but permutations of non-existent files, non-overlapping paths
|
||||
## and relative paths containing partial subdirectories will compilicate the logic. Wait until needed.
|
||||
## Relative path: $root + obj + subdir
|
||||
# "${obj0}/profile/dirserviceprovider/public/Makefile" => 'profile/dirserviceprovider/public',
|
||||
join('/', $obj, 'profile/dirserviceprovider/public/Makefile') => 'profile/dirserviceprovider/public',
|
||||
|
||||
# $RealBin, -d ../../..
|
||||
# top and obj not subdirectories of each other: /foo/x, /bar/y
|
||||
);
|
||||
|
||||
while (my($k, $v) = each %data)
|
||||
{
|
||||
my $dir = getRelPath($k);
|
||||
ok($@, '', '$@ should not be set');
|
||||
ok($dir, $v, "ERROR[$k]: exp[$v] != found=[$dir]");
|
||||
}
|
||||
|
||||
|
||||
my $top = '/tmp/foo';
|
||||
my $tmp = '/tmp/bar';
|
||||
local $main::argv{top} = $tmp;
|
||||
local $main::argv{obj} = $obj;
|
||||
|
||||
%data =
|
||||
(
|
||||
# "$top/profile/dirserviceprovider/public/Makefile.in" => 'profile/dirserviceprovider/public',
|
||||
"$obj/profile/dirserviceprovider/public/Makefile" => 'profile/dirserviceprovider/public',
|
||||
);
|
||||
|
||||
while (my($k, $v) = each %data)
|
||||
{
|
||||
my $dir = getRelPath($k);
|
||||
ok($dir, $v, "ERROR[$k]: exp[$v] != found=[$dir]");
|
||||
}
|
||||
} # check_getRelPath
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify rel-path-to-root directory creation
|
||||
###########################################################################
|
||||
sub check_mkdirr
|
||||
{
|
||||
if (-w '/bin') # cygwin may be writable
|
||||
{
|
||||
ok(1, 1, 'bogus test to maintain count');
|
||||
} else {
|
||||
mkdirr('/bin/invalid/Makefile');
|
||||
ok($@ ? 1 : 0, 1, '$@ should be set');
|
||||
}
|
||||
|
||||
my $work = createSandbox();
|
||||
my @paths = map{ join('/', $work, $_, 'Makefile.in') } qw (xyz/abc foo/bar a/b/c/d/e);
|
||||
mkdirr(@paths);
|
||||
ok($@ ? 1 : 0, 0, '$@ should not be set');
|
||||
|
||||
push(@paths, '/bin');
|
||||
|
||||
my @errors;
|
||||
foreach (@paths)
|
||||
{
|
||||
my $dir = dirname($_);
|
||||
next if (-d $dir);
|
||||
push(@errors, "mkdirr($dir) failed\n");
|
||||
}
|
||||
ok(scalar @errors, 0, "Errors detected: @errors");
|
||||
} # check_mkdirr
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify permutations for system("config.status")
|
||||
###########################################################################
|
||||
sub check_run_config_status
|
||||
{
|
||||
print STDERR "Running: check_run_config_status()\n"
|
||||
if ($main::argv{debug});
|
||||
|
||||
my $work = createSandbox();
|
||||
chdir $work;
|
||||
run_config_status();
|
||||
ok($@ ? 1 : 0, '$@ should be set, config.status does not exist');
|
||||
|
||||
my $cfg = join('/', $work, 'config.status');
|
||||
local *CFG;
|
||||
open(CFG, "> $cfg") && close(CFG);
|
||||
run_config_status();
|
||||
ok($@, qr/config.status failed/, '$@ should be set, config.status is not executabl');
|
||||
|
||||
open(CFG, "> $cfg");
|
||||
print CFG join("\n",
|
||||
'#!/bin/sh',
|
||||
'',
|
||||
'true',
|
||||
'');
|
||||
close(CFG);
|
||||
chmod 0555, $cfg;
|
||||
run_config_status();
|
||||
ok($@, qr/config.status failed/, '$@ should not be set');
|
||||
|
||||
} # check_run_config_status
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify makefile generation by legacy make-makefile functions
|
||||
## o make-makefile -t /x/y -d ..
|
||||
###########################################################################
|
||||
sub check_update_makefiles_legacy
|
||||
{
|
||||
print STDERR "Running: check_update_makefiles_legacy()\n"
|
||||
if ($main::argv{debug});
|
||||
|
||||
return unless ($argv{legacy});
|
||||
print STDERR "check_update_makefiles_legacy: not yet implemented\n";
|
||||
|
||||
} # check_update_makefiles_legacy
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify updateMakefiles()
|
||||
## o a makefile is generated when none exists.
|
||||
## o a makefile will only be updated when the templates changes.
|
||||
## o existing makefiles will be updated when the template changes.
|
||||
## o @foo@ tokens have been expanded
|
||||
###########################################################################
|
||||
sub check_updateMakefiles
|
||||
{
|
||||
my @errors;
|
||||
|
||||
print STDERR "Running: check_updateMakefiles()\n"
|
||||
if ($main::argv{debug});
|
||||
|
||||
my $mf = 'memory/mozalloc/Makefile.in';
|
||||
|
||||
my $work = createSandbox($mf);
|
||||
my $obj = join('/', $work, 'obj');
|
||||
my %args =
|
||||
(
|
||||
top => $work,
|
||||
obj => $obj,
|
||||
);
|
||||
|
||||
my $mf_src = join('/', $work, 'memory/mozalloc/Makefile.in');
|
||||
my $mf_dst = join('/', $obj, 'memory/mozalloc/Makefile');
|
||||
|
||||
updateMakefiles('memory/mozalloc', \%args);
|
||||
my $tlm0 = (stat $mf_dst)[9] || 0;
|
||||
ok(-e $mf_dst ? 1 : 0, 1, "failed to generate makefile: $mf_dst");
|
||||
|
||||
#############################
|
||||
## Regeneration will be a nop
|
||||
#############################
|
||||
updateMakefiles('memory/mozalloc', \%args);
|
||||
my $tlm1 = (stat $mf_dst)[9] || -1;
|
||||
ok($tlm1, $tlm0, "makefile should not have been modified");
|
||||
|
||||
#####################################################
|
||||
## Modify template to verify makefile will regenerate
|
||||
#####################################################
|
||||
local *MF;
|
||||
if (open(MF, ">> $mf_src"))
|
||||
{
|
||||
print MF map{ "# MODIFIED MAKEFILE\n" } 0..4;
|
||||
close(MF);
|
||||
}
|
||||
updateMakefiles('memory/mozalloc', \%args);
|
||||
my @data = makemakefile::cat($mf_dst);
|
||||
## Check content to avoid a silly 'sleep [n]' call here
|
||||
ok(grep(/^\# MODIFIED MAKEFILE/o, @data) ? 1 : 0,
|
||||
1,
|
||||
"template modified, makefile should have regenerated");
|
||||
|
||||
## VERIFY template expansion
|
||||
my @gen = makemakefile::cat($mf_dst);
|
||||
push(@errors, $@) if ($@);
|
||||
|
||||
foreach (@gen)
|
||||
{
|
||||
if (/\@[^\@]+\@/o)
|
||||
{
|
||||
push(@errors, join("\n",
|
||||
"Unexpanded template string detected [$_]",
|
||||
"Makefile: $mf_src",
|
||||
));
|
||||
last;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ok(scalar(@errors), 0, "Errors detected: @errors");
|
||||
} # check_updateMakefiles
|
||||
|
||||
###########################################################################
|
||||
## Intent: Verify makefile generation by updateMakefiles() when
|
||||
## command line arguments --top and --obj were passed.
|
||||
###########################################################################
|
||||
sub check_updateMakefilesByTopObj
|
||||
{
|
||||
my @errors;
|
||||
|
||||
print STDERR "Running: check_updateMakefilesByTopObj()\n"
|
||||
if ($main::argv{debug});
|
||||
|
||||
my $work = createSandbox();
|
||||
my %args =
|
||||
(
|
||||
top => $work,
|
||||
obj => $work,
|
||||
);
|
||||
|
||||
## Grab a list of makefile templates to generate
|
||||
my @all = glob('data/mf.*');
|
||||
my @src = map{ /\.exp$/o ? () : $_ } @all;
|
||||
|
||||
foreach my $src (@src)
|
||||
{
|
||||
my $dst = join('/', $work, 'Makefile');
|
||||
unlink $dst;
|
||||
copy($src, "$work/Makefile.in");
|
||||
updateMakefiles('.', \%args);
|
||||
ok($@, '', '$@ should not be set');
|
||||
|
||||
my @dst = makemakefile::cat($dst);
|
||||
|
||||
my $exp = join('.', $src, 'exp');
|
||||
my @exp = makemakefile::cat($exp);
|
||||
ok("@dst", "@exp", "updateMakefile($dst) failed");
|
||||
}
|
||||
return;
|
||||
} # check_updateMakefilesByTopObj
|
||||
|
||||
###########################################################################
|
||||
## Intent: Smoke tests for the unittests module
|
||||
###########################################################################
|
||||
sub smoke
|
||||
{
|
||||
print STDERR "Running test: smoke()\n" if ($argv{debug});
|
||||
} # smoke()
|
||||
|
||||
###########################################################################
|
||||
## Intent: Intitialize global test objects and consts
|
||||
###########################################################################
|
||||
sub init
|
||||
{
|
||||
print "Running: init()\n" if ($argv{debug});
|
||||
# testplan(24, 0);
|
||||
|
||||
my @path = split(m%/%, $FindBin::RealBin);
|
||||
splice(@path, -3);
|
||||
my $top = join('/', @path);
|
||||
## Top set based on make-makefile startup directory so adjust for test/ use
|
||||
getTopDir('_set_', $top);
|
||||
|
||||
} # init()
|
||||
|
||||
##----------------##
|
||||
##---] MAIN [---##
|
||||
##----------------##
|
||||
unless(GetOptions(\%argv,
|
||||
qw(
|
||||
debug|d
|
||||
manual
|
||||
test=s@
|
||||
verbose
|
||||
)))
|
||||
{
|
||||
print "USAGE: $0\n";
|
||||
print " --debug Enable script debug mode\n";
|
||||
print " --manual Also run disabled tests\n";
|
||||
print " --smoke Run smoke tests then exit\n";
|
||||
print " --test Run a list of tests by function name\n";
|
||||
print " --verbose Enable script verbose mode\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
init();
|
||||
smoke();
|
||||
|
||||
check_dirname_legacy();
|
||||
|
||||
check_getTopDir();
|
||||
check_getObjDir();
|
||||
check_getDepth();
|
||||
check_getExclusions();
|
||||
check_getRelPath();
|
||||
check_mkdirr();
|
||||
|
||||
check_updateMakefiles();
|
||||
check_update_makefiles_legacy();
|
||||
check_updateMakefilesByTopObj();
|
@ -1,95 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
###########################################################################
|
||||
## Intent:
|
||||
## Test::Harness is a testing wrapper that will process output
|
||||
## from Test.pm module tests. Sumarize results, report stats
|
||||
## and exit with overall status for the testing suites.
|
||||
##
|
||||
## Run testing suite:
|
||||
## % make clean test
|
||||
## % perl runtest
|
||||
##
|
||||
## Run Individual tests
|
||||
## % perl tUtils0
|
||||
###########################################################################
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
|
||||
use Test::Harness;
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(1.0);
|
||||
use FindBin;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
my %argv;
|
||||
|
||||
##----------------##
|
||||
##---] MAIN [---##
|
||||
##----------------##
|
||||
unless(GetOptions(\%argv,
|
||||
qw(debug|d)
|
||||
))
|
||||
{
|
||||
print "Usage: $0\n";
|
||||
print " --debug Enable debug mode\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if (2 > $Test::Harness::VERSION)
|
||||
{
|
||||
print "Unit tests will not be run, Test::Harness is too old\n"
|
||||
if ($argv{debug});
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
my @tests;
|
||||
|
||||
########################################
|
||||
## Gather a list of tests if none passed
|
||||
########################################
|
||||
unless (@tests = @ARGV)
|
||||
{
|
||||
local *D;
|
||||
opendir(D, '.');
|
||||
while($_ = readdir(D)) {
|
||||
next unless /.t\S+$/;
|
||||
next if (/\.ts$/);
|
||||
push(@tests, $_);
|
||||
}
|
||||
closedir(D);
|
||||
}
|
||||
|
||||
###############################################
|
||||
## Glob a list of tests when directories passed
|
||||
###############################################
|
||||
my @tmp;
|
||||
foreach (@tests)
|
||||
{
|
||||
local *D;
|
||||
if (-d $_ && (my $dir = $_))
|
||||
{
|
||||
opendir(D, $_) || die "opendir(D) failed: $!";
|
||||
my @tests = grep(/\.t[^\.\s]+/o, readdir(D));
|
||||
closedir(D);
|
||||
push(@tmp, map{ join('/', $dir, $_); } @tests);
|
||||
} else {
|
||||
push(@tmp, $_);
|
||||
}
|
||||
}
|
||||
@tests = @tmp;
|
||||
|
||||
print "$0: @ARGV\n" if ($argv{debug});
|
||||
runtests(@tests);
|
||||
|
||||
# EOF
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env perl
|
||||
#! /usr/bin/env perl
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
@ -16,12 +16,10 @@
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999-2011
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Steve Lamm (slamm@netscape.com).
|
||||
# Joey Armstrong <joey@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
@ -37,63 +35,29 @@
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
# make-makefiles - Quickly create Makefiles for subdirectories.
|
||||
# Also, creates any needed subdirectories.
|
||||
#
|
||||
# usage: make-makefiles [ -t <topsrcdir> -p <print_topsrcdir> -d <depth> ] [ <subdir> | <subdir>/Makefile ] ...
|
||||
|
||||
use Benchmark;
|
||||
use Cwd;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
use File::Path qw{mkpath};
|
||||
# Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(2.0);
|
||||
#$debug = 1;
|
||||
|
||||
##--------------------##
|
||||
##---] INCLUDES [---##
|
||||
##--------------------##
|
||||
use FindBin;
|
||||
use lib $FindBin::Bin;
|
||||
use makemakefile;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
my %argv;
|
||||
|
||||
my $t0 = Benchmark->new();
|
||||
sub END
|
||||
{
|
||||
if ($argv{bench})
|
||||
{
|
||||
my $t1 = Benchmark->new();
|
||||
my $delta = timediff($t1, $t0);
|
||||
print STDERR timestr($delta), "\n";
|
||||
}
|
||||
if ($^O eq 'msys') {
|
||||
$pwdcmd = 'pwd -W';
|
||||
}
|
||||
else {
|
||||
$pwdcmd = 'pwd';
|
||||
}
|
||||
|
||||
##----------------##
|
||||
##---] MAIN [---##
|
||||
##----------------##
|
||||
umask 0;
|
||||
|
||||
my $debug = $argv{debug} || 0;
|
||||
|
||||
my $pwdcmd = ($^O eq 'msys') ? 'pwd -W' : 'pwd';
|
||||
|
||||
# Determine various tree path variables
|
||||
#
|
||||
my ($topsrcdir, $ptopsrcdir, $depth, @makefiles) = parse_arguments(@ARGV);
|
||||
($topsrcdir, $ptopsrcdir, $depth, @makefiles) = parse_arguments(@ARGV);
|
||||
|
||||
my $object_fullpath = `$pwdcmd`; # Cwd::getcwd()
|
||||
$object_fullpath = `$pwdcmd`;
|
||||
chdir $depth;
|
||||
my $object_root = `$pwdcmd`; # Cwd::getcwd()
|
||||
$object_root = `$pwdcmd`;
|
||||
chomp $object_fullpath;
|
||||
chomp $object_root;
|
||||
|
||||
@ -101,23 +65,24 @@ chomp $object_root;
|
||||
# 'make-makefile' was called. For example, if make-makefile was
|
||||
# called from "mozilla/gfx/src", then $source_subdir would be
|
||||
# "gfx/src/".
|
||||
my $source_subdir = "$object_fullpath/";
|
||||
$source_subdir = "$object_fullpath/";
|
||||
my $quoted_object_root = quotemeta($object_root);
|
||||
$source_subdir =~ s|^$quoted_object_root/||;
|
||||
|
||||
# Prefix makefiles with $source_subdir so that paths
|
||||
# will be relative to the top of the object tree.
|
||||
#
|
||||
my $makefile;
|
||||
for $makefile (@makefiles) { # dead code ?
|
||||
for $makefile (@makefiles) {
|
||||
$makefile = "$source_subdir$makefile";
|
||||
}
|
||||
|
||||
create_directories(@makefiles);
|
||||
|
||||
# Find the path to the source directory based on how 'make-makefile'
|
||||
# was invoked. The path is either relative to the object directory
|
||||
# or an absolute path.
|
||||
my $given_srcdir = find_srcdir($topsrcdir, $depth);
|
||||
my $pgiven_srcdir = find_srcdir($ptopsrcdir, $depth);
|
||||
$given_srcdir = find_srcdir($topsrcdir, $depth);
|
||||
$pgiven_srcdir = find_srcdir($ptopsrcdir, $depth);
|
||||
|
||||
if ($debug) {
|
||||
warn "object_fullpath = $object_fullpath\n";
|
||||
@ -127,21 +92,18 @@ if ($debug) {
|
||||
warn "given_srcdir = $given_srcdir\n";
|
||||
}
|
||||
|
||||
my @errors;
|
||||
my @unhandled = update_makefiles_legacy($given_srcdir, $pgiven_srcdir, @makefiles);
|
||||
push(@errors, $@) if ($@);
|
||||
@unhandled = update_makefiles($given_srcdir, $pgiven_srcdir, @makefiles);
|
||||
|
||||
run_config_status(@unhandled);
|
||||
push(@errors, $@) if ($@ && $argv{'no-warnings'});
|
||||
|
||||
exit scalar(@errors);
|
||||
|
||||
# end of Main
|
||||
############################################################
|
||||
|
||||
###########################################################################
|
||||
sub dirname {
|
||||
return $_[0] =~ /(.*)\/.*/ ? "$1" : '.';
|
||||
}
|
||||
|
||||
# find_depth: Pull the value of DEPTH out of a Makefile (or Makefile.in)
|
||||
###########################################################################
|
||||
sub find_depth {
|
||||
my $depth = '';
|
||||
open(MAKEFILE, "<$_[0]") || die "Unable to open $_[0]: $!\n";
|
||||
@ -154,115 +116,39 @@ sub find_depth {
|
||||
return $depth;
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Intent: Parse command line arguments and assign values
|
||||
###########################################################################
|
||||
sub parse_arguments {
|
||||
my @args = @_;
|
||||
my $depth = '';
|
||||
my $topsrcdir = '';
|
||||
my $ptopsrcdir;
|
||||
my @makefiles = ();
|
||||
|
||||
my @arglist = qw(badtokens! bench
|
||||
chdir=s
|
||||
debug
|
||||
depth|d=s
|
||||
enhanced
|
||||
obj=s top|t=s ptop|p=s
|
||||
src=s dst=s
|
||||
);
|
||||
unless(GetOptions(\%argv, @arglist))
|
||||
{
|
||||
my $script = join('/', $FindBin::RealBin, $FindBin::Script);
|
||||
system("perldoc $script </dev/null");
|
||||
exit
|
||||
}
|
||||
@args = @ARGV;
|
||||
|
||||
my $topsrcdir = $argv{top} || '';
|
||||
if (! $topsrcdir)
|
||||
{
|
||||
$topsrcdir = $argv{top} = getTopDir();
|
||||
while (1) {
|
||||
if ($args[0] eq '-d') {
|
||||
$depth = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} elsif ($args[0] eq '-t') {
|
||||
$topsrcdir = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} elsif ($args[0] eq '-p') {
|
||||
$ptopsrcdir = $args[1];
|
||||
shift @args;
|
||||
shift @args;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
my $ptopsrcdir ||= $argv{ptop} || $topsrcdir || '';
|
||||
|
||||
## Init --no- switch values
|
||||
foreach my $var (qw(badtokens exclusions warnings))
|
||||
{
|
||||
$argv{"no-${var}"} = $argv{$var} || 0;
|
||||
if ($topsrcdir eq '') {
|
||||
$topsrcdir = $0; # Figure out topsrcdir based on program name.
|
||||
$topsrcdir =~ s|/?build/autoconf/.*$||;
|
||||
}
|
||||
# Propogate parsed arguments for module use [--debug, --verbose]
|
||||
while (my($k, $v) = each %argv)
|
||||
{
|
||||
$main::argv{$k} = $v;
|
||||
if ($ptopsrcdir eq '') {
|
||||
$ptopsrcdir = $topsrcdir;
|
||||
}
|
||||
|
||||
if ($argv{chdir})
|
||||
{
|
||||
chdir $argv{chdir} || die "chdir $argv{chdir} failed: $!";
|
||||
}
|
||||
|
||||
##############################################################
|
||||
## Arguments allowing make-makefile to be invoked from $topsrc
|
||||
##############################################################
|
||||
if (!$argv{top} || !$argv{obj})
|
||||
{
|
||||
}
|
||||
## Limit access to container makefiles for now
|
||||
elsif ($argv{enhanced})
|
||||
{
|
||||
my @errors;
|
||||
|
||||
## iterate over @ARGV to preserve original filename for 'unhandled'
|
||||
my @files = map{ getRelPath($_) } @ARGV;
|
||||
|
||||
my $top = getTopDir();
|
||||
my $obj = getObjDir();
|
||||
|
||||
mkdirr(map{ "$obj/$_" } @files);
|
||||
push(@errors, $@) if ($@); # legacy behavior: do not exit with status
|
||||
|
||||
my $exclude = join('/', $FindBin::RealBin, $FindBin::Script);
|
||||
$exclude .= '.excl'; # $argv{exclude}
|
||||
my %exclude = getExclusions($exclude);
|
||||
my @unhandled;
|
||||
foreach my $relpath (@files)
|
||||
{
|
||||
my $rel = join('/', $relpath, 'Makefile.in');
|
||||
my $mf = join('/', $top, $rel);
|
||||
next if ($exclude{$rel});
|
||||
print STDERR " ** relpath=[$relpath], mf=[$mf]\n" if ($main::argv{debug});
|
||||
|
||||
my $rc = updateMakefiles($relpath, {depth=>$depth, obj=>$obj, top=>$top});
|
||||
if ($@)
|
||||
{
|
||||
push(@errors, $@);
|
||||
}
|
||||
elsif ($rc eq 'badtokens')
|
||||
{
|
||||
push(@unhandled, $mf);
|
||||
}
|
||||
}
|
||||
|
||||
run_config_status(@unhandled);
|
||||
push(@errors, $@) if ($@ && $argv{'no-warnings'});
|
||||
exit scalar(@errors);
|
||||
}
|
||||
|
||||
|
||||
my $depth = $argv{depth} || '';
|
||||
if (! $depth)
|
||||
{
|
||||
foreach my $fyl (@args)
|
||||
{
|
||||
if (my $tmp = find_depth($fyl))
|
||||
{
|
||||
$depth = $tmp;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $depth) {
|
||||
if ($depth eq '') {
|
||||
# Use $(DEPTH) in the Makefile or Makefile.in to determine the depth
|
||||
if (-e "Makefile.in") {
|
||||
$depth = find_depth("Makefile.in");
|
||||
@ -280,21 +166,34 @@ sub parse_arguments {
|
||||
# Build the list of makefiles to generate
|
||||
#
|
||||
@makefiles = ();
|
||||
while (@args)
|
||||
{
|
||||
next unless my $makefile = shift @args;
|
||||
$makefile =~ s/\.in$//;
|
||||
$makefile =~ s/\/$//;
|
||||
$makefile =~ /Makefile$/
|
||||
or $makefile =~ /^\.\//
|
||||
or $makefile .= "/Makefile";
|
||||
my $makefile;
|
||||
foreach $makefile (@args) {
|
||||
$makefile =~ s/\.in$//;
|
||||
$makefile =~ s/\/$//;
|
||||
$makefile =~ /Makefile$/
|
||||
or $makefile =~ /^\.\//
|
||||
or $makefile .= "/Makefile";
|
||||
push @makefiles, "$makefile";
|
||||
}
|
||||
@makefiles = "Makefile" unless @makefiles;
|
||||
@makefiles = "Makefile" unless @args;
|
||||
|
||||
return ($topsrcdir, $ptopsrcdir, $depth, @makefiles);
|
||||
}
|
||||
|
||||
|
||||
# Create all the directories at once.
|
||||
# This can be much faster than calling mkdir() for each one.
|
||||
sub create_directories {
|
||||
my @makefiles = @_;
|
||||
my @dirs = ();
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
push @dirs, dirname($ac_file);
|
||||
}
|
||||
# Call mkdir with the directories sorted by subdir count (how many /'s)
|
||||
system "mkdir -p ". join(' ', map("\"$_\"", @dirs)) if @dirs;
|
||||
}
|
||||
|
||||
# Find the top of the source directory
|
||||
# (Assuming that the executable is in $top_srcdir/build/autoconf)
|
||||
sub find_srcdir {
|
||||
@ -315,146 +214,111 @@ sub find_srcdir {
|
||||
return $ac_given_srcdir;
|
||||
}
|
||||
|
||||
1;
|
||||
###########################################################################
|
||||
## perldoc
|
||||
###########################################################################
|
||||
__END__
|
||||
# Output the makefiles.
|
||||
#
|
||||
sub update_makefiles {
|
||||
my ($ac_given_srcdir, $pac_given_srcdir, @makefiles) = @_;
|
||||
my @unhandled=();
|
||||
|
||||
=head1 NAME
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
my $ac_dir = dirname($ac_file);
|
||||
my $ac_dots = '';
|
||||
my $ac_dir_suffix = '';
|
||||
my $srcdir = '.';
|
||||
my $top_srcdir = '.';
|
||||
|
||||
make-makefile - Generate a Makefile from a F<Makefile.in> template
|
||||
# Determine $srcdir and $top_srcdir
|
||||
#
|
||||
if ($ac_dir ne '.') {
|
||||
$ac_dir_suffix = "/$ac_dir";
|
||||
$ac_dir_suffix =~ s%^/\./%/%;
|
||||
$ac_dots = $ac_dir_suffix;
|
||||
# Remove .. components from the provided dir suffix, and
|
||||
# also the forward path components they were reversing.
|
||||
my $backtracks = $ac_dots =~ s%\.\.(/|$)%%g;
|
||||
while ($backtracks--) {
|
||||
$ac_dots =~ s%/[^/]*%%;
|
||||
}
|
||||
$ac_dots =~ s%/[^/]*%../%g;
|
||||
}
|
||||
if ($ac_given_srcdir eq '.') {
|
||||
if ($ac_dots ne '') {
|
||||
$top_srcdir = $ac_dots;
|
||||
$top_srcdir =~ s%/$%%;
|
||||
}
|
||||
} elsif ($pac_given_srcdir =~ m%^/% or $pac_given_srcdir =~ m%^.:/%) {
|
||||
$srcdir = "$pac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$pac_given_srcdir";
|
||||
} else {
|
||||
if ($debug) {
|
||||
print "ac_dots = $ac_dots\n";
|
||||
print "ac_dir_suffix = $ac_dir_suffix\n";
|
||||
}
|
||||
$srcdir = "$ac_dots$ac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$ac_dots$ac_given_srcdir";
|
||||
}
|
||||
|
||||
=head1 SYNOPSIS
|
||||
if ($debug) {
|
||||
print "ac_dir = $ac_dir\n";
|
||||
print "ac_file = $ac_file\n";
|
||||
print "ac_file_in = $ac_file_in\n";
|
||||
print "srcdir = $srcdir\n";
|
||||
print "top_srcdir = $top_srcdir\n";
|
||||
print "cwd = " . `$pwdcmd` . "\n";
|
||||
}
|
||||
|
||||
make-makefile [--top t] [--obj o] [--depth d] foo/bar/Makefile.in tans/fans/Makefile foo/bar
|
||||
# Copy the file and make substitutions.
|
||||
# @srcdir@ -> value of $srcdir
|
||||
# @top_srcdir@ -> value of $top_srcdir
|
||||
#
|
||||
if (-e $ac_file) {
|
||||
next if -M _ < -M $ac_file_in; # Next if Makefile is up-to-date.
|
||||
warn "updating $ac_file\n";
|
||||
} else {
|
||||
warn "creating $ac_file\n";
|
||||
}
|
||||
|
||||
=head1 DESCRIPTION
|
||||
open INFILE, "<$ac_file_in" or do {
|
||||
warn "$0: Cannot read $ac_file_in: No such file or directory\n";
|
||||
next;
|
||||
};
|
||||
open OUTFILE, ">$ac_file" or do {
|
||||
warn "$0: Unable to create $ac_file\n";
|
||||
next;
|
||||
};
|
||||
|
||||
Given options and makefile path arguments determine path to the template
|
||||
F<Makefile.in> beneath a source directory and path to generated F<Makefile>
|
||||
beneath $MOZ_OBJDIR. DEPTH from destination directory to the 'root' will
|
||||
also be determined. F<Makefile.in> will be read in, template strings of the
|
||||
gorm @token@ will be replaced with derived values and a generated makefile
|
||||
will be written out as F<Makefile>.
|
||||
while (<INFILE>) {
|
||||
#if (/\@[_a-zA-Z]*\@.*\@[_a-zA-Z]*\@/) {
|
||||
# #warn "Two defines on a line:$ac_file:$.:$_";
|
||||
# push @unhandled, $ac_file;
|
||||
# last;
|
||||
#}
|
||||
|
||||
Makefile DEPTH= can be determined in a few different ways:
|
||||
o The string C<DEPTH=../../..> may be embedded within F<Makefile.in>.
|
||||
o Search parent directories for F<Makefile.in> and use it to assign the child.
|
||||
s/\@srcdir\@/$srcdir/g;
|
||||
s/\@top_srcdir\@/$top_srcdir/g;
|
||||
|
||||
if (/\@[_a-zA-Z]*\@/) {
|
||||
#warn "Unknown variable:$ac_file:$.:$_";
|
||||
push @unhandled, $ac_file;
|
||||
last;
|
||||
}
|
||||
print OUTFILE;
|
||||
}
|
||||
close INFILE;
|
||||
close OUTFILE;
|
||||
}
|
||||
return @unhandled;
|
||||
}
|
||||
|
||||
=head2 Option List
|
||||
sub run_config_status {
|
||||
my @unhandled = @_;
|
||||
|
||||
=over 4
|
||||
|
||||
=item --chdir
|
||||
|
||||
Move to this directory before doing anything else
|
||||
|
||||
=item -d, --depth
|
||||
|
||||
Explicitly specify the relative path from directory containing Makefile.in
|
||||
to the top sandbox directory. memory/makefile, DEPTH=../.., js/src/config, DEPTH=..
|
||||
|
||||
=item --enhanced
|
||||
|
||||
Use alternate/simplified path construction when options --top and --obj are
|
||||
passed. This feature will be used by container makefiles to support makefile
|
||||
generation while cd'd into the sandbox top directory.
|
||||
|
||||
=item -t, --top
|
||||
|
||||
Path the root of a development sandbox.
|
||||
|
||||
=item --obj
|
||||
|
||||
Path to object directory where generated makefile will be written ($MOZ_OBJDIR).
|
||||
|
||||
=item --ptop
|
||||
|
||||
Print top source dir
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Options List DEBUG
|
||||
|
||||
=over 4
|
||||
|
||||
=item --bench
|
||||
|
||||
Enable script benchmarking, report elapsed runtime.
|
||||
|
||||
=item --debug
|
||||
|
||||
Enable script debug mode.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Options List --NO-
|
||||
|
||||
=over 4
|
||||
|
||||
=item --no-badtokens (wip)
|
||||
|
||||
Handle unexpanded @token@ makefile tokens as an error condition.
|
||||
Do not rely on system(config.status) to externally supply values.
|
||||
|
||||
=item --no-excludes
|
||||
|
||||
Ignore file entries on the exclusion list, generate everything.
|
||||
|
||||
=item --no-warnings
|
||||
|
||||
Warnings are handled as an error condition.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Examples
|
||||
|
||||
=over 4
|
||||
|
||||
=item * make-makefile -t /mozilla/nightly -d . memory/mozalloc
|
||||
|
||||
cd $MOZ_OBJDIR;
|
||||
--top and --depth are explicitly set for generting memory/mozalloc/Makefile.
|
||||
|
||||
=item * make-makefile -t /mozilla/nightly -d ../../../.. html5lib_tree_construction/Makefile
|
||||
|
||||
cd $MOZ_OBJDIR/parser/htmlparser/tests/mochitest
|
||||
|
||||
--top and --depth are explicitly set for generting a makefile from within
|
||||
a subdirectory of $MOZ_OBJDIR
|
||||
|
||||
=item * make-makefile --top /mozilla/nightly --obj /mozilla/nightly/obj memory/mozalloc
|
||||
|
||||
With --top and --obj explicitly set generate $MOZ_OBJDIR/memory/mozalloc/Makefile
|
||||
while sitting in the sandbox root.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Work In Progress
|
||||
|
||||
=over 4
|
||||
|
||||
=item --no-badtokens
|
||||
|
||||
Fail on unexpanded @foo@ makefile tokens. Any tokens that can be expanded
|
||||
directly by make-makefile will avoid config.status shell overhead.
|
||||
|
||||
=item Depth from delta(--obj, --top)
|
||||
|
||||
If DEPTH= has not been embedded within a makefile the value could
|
||||
be set directly if --top and --obj are specified and the paths overlap.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<config/rules.mk>
|
||||
|
||||
=cut
|
||||
# Run config.status with any unhandled files.
|
||||
#
|
||||
if (@unhandled) {
|
||||
$ENV{CONFIG_FILES}= join ' ', @unhandled;
|
||||
system "./config.status";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
###########################################################################
|
||||
## Intent: Exclusion list for container make builds
|
||||
###########################################################################
|
||||
|
||||
# EOF
|
@ -1,745 +0,0 @@
|
||||
package makemakefile;
|
||||
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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/MPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1999-2011
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Steve Lamm (slamm@netscape.com).
|
||||
# Joey Armstrong <joey@mozilla.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
##----------------------------##
|
||||
##---] CORE/CPAN INCLUDES [---##
|
||||
##----------------------------##
|
||||
use strict;
|
||||
use warnings;
|
||||
# use feature 'state'; 5.10+ not available everywhere
|
||||
|
||||
##-------------------##
|
||||
##---] EXPORTS [---##
|
||||
##-------------------##
|
||||
our $VERSION = qw(2.0);
|
||||
use Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(dirname_legacy
|
||||
getConfig getDepth getRelPath getObjDir getTopDir mkdirr
|
||||
getExclusions
|
||||
run_config_status
|
||||
updateMakefiles
|
||||
update_makefiles_legacy
|
||||
);
|
||||
|
||||
##--------------------##
|
||||
##---] INCLUDES [---##
|
||||
##--------------------##
|
||||
use Cwd;
|
||||
use Cwd qw{abs_path};
|
||||
use FindBin;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
|
||||
##-------------------##
|
||||
##---] GLOBALS [---##
|
||||
##-------------------##
|
||||
umask 0;
|
||||
my $cwd = Cwd::abs_path('.');
|
||||
my %argv;
|
||||
|
||||
|
||||
###########################################################################
|
||||
## Intent: Helper function, retrieve contents of a file with error checking
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar path to input file
|
||||
## Returns:
|
||||
## array contents of the given file
|
||||
## $@ set on error
|
||||
###########################################################################
|
||||
sub cat
|
||||
{
|
||||
my $fyl = shift || '';
|
||||
$@ = '';
|
||||
my @data;
|
||||
|
||||
local *FYL;
|
||||
if (!open(FYL, $fyl))
|
||||
{
|
||||
$@ = "open($fyl) failed: $!";
|
||||
}
|
||||
else
|
||||
{
|
||||
@data = <FYL>;
|
||||
close(FYL);
|
||||
}
|
||||
return @data;
|
||||
} # cat
|
||||
|
||||
###########################################################################
|
||||
## Intent: Return directory path for a given argument
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
## Todo:
|
||||
## o Check if function can be replaced by File::Basename::dirname()
|
||||
###########################################################################
|
||||
sub dirname_legacy
|
||||
{
|
||||
my $str = (@_ && defined($_[0])) ? shift : '';
|
||||
return $str =~ /(.*)\/.*/ ? "$1" : '.';
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Intent: Given a list of makefile paths recursively create all
|
||||
## directories between file and the root
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array A list of makefiles
|
||||
## fargs Function arguments
|
||||
## mode Filesystem mode used for directory creation
|
||||
## Returns:
|
||||
## $@ Set on error
|
||||
## 0 on success
|
||||
## -----------------------------------------------------------------------
|
||||
## Note:
|
||||
## Reporting directory creation can be enabled by the --verbose
|
||||
## command line argument.
|
||||
###########################################################################
|
||||
sub mkdirr
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_])) ? %{ (pop) } : ();
|
||||
my $mode = $fargs{mode} || 0755;
|
||||
my $verbose = $main::argv{verbose} || 0;
|
||||
$@ = '' unless ($fargs{recursive});
|
||||
$fargs{recursive} = 1;
|
||||
|
||||
my @errors;
|
||||
push(@errors, $@) if ($@);
|
||||
foreach my $path (@_)
|
||||
{
|
||||
(my $dir = $path) =~ s%/?Makefile[^/]*$%%o;
|
||||
next unless (length($dir));
|
||||
next if (-e $dir);
|
||||
mkdirr( dirname($dir), \%fargs);
|
||||
eval{ File::Path::mkpath($dir, $verbose, 0755); };
|
||||
push(@errors, $@) if ($@);
|
||||
}
|
||||
$@ = join("\n", @errors);
|
||||
return $@ ? 0 : 1;
|
||||
} # mkdirr
|
||||
|
||||
###########################################################################
|
||||
## Intent: Read in configure values and return a hash of key/value pairs
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## fargs Function arguments
|
||||
## reset clear value storage and repopulate
|
||||
## Returns:
|
||||
## hash configure data to use for makefile substitutions
|
||||
## -----------------------------------------------------------------------
|
||||
## Todo: wrapper for reading config* and run_config_status
|
||||
###########################################################################
|
||||
my %_CONFIG_; # todo: state %config; w/5.10
|
||||
sub getConfig
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_]) eq 'HASH') ? %{ (pop) } : ();
|
||||
if ($fargs{reset})
|
||||
{
|
||||
%_CONFIG_ = ();
|
||||
shift;
|
||||
}
|
||||
|
||||
#my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
#my $ac_dir = dirname_legacy($ac_file);
|
||||
#my $ac_dots = '';
|
||||
#my $ac_dir_suffix = '';
|
||||
#my $srcdir = '.';
|
||||
#my $top_srcdir = '.';
|
||||
unless (%_CONFIG_)
|
||||
{
|
||||
while (@_)
|
||||
{
|
||||
my ($k, $v) = splice(@_, 0, 2);
|
||||
$_CONFIG_{$k} = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return %_CONFIG_;
|
||||
} # getConfig
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine path depth between leaf and root directory.
|
||||
## o DEPTH= may be set by makefile content
|
||||
## o DEPTH= may be set by Makefile in a parent
|
||||
## o Manually determine by relpath form leaf to sandbox top
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar Path to makefile or directory to determine DEPTH for
|
||||
## Returns:
|
||||
## scalar Relative path from leaf to root directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub getDepth($)
|
||||
{
|
||||
my $fyl = shift || '';
|
||||
|
||||
my @path = split(m%/%o, $fyl);
|
||||
pop(@path) if ('Makefile' eq substr($path[$#path], 0, 8));
|
||||
my $depth;
|
||||
my @depth;
|
||||
|
||||
my $top = getTopDir();
|
||||
my @top = split(m%/%o, $top);
|
||||
my @pathNoTop = @path;
|
||||
splice(@pathNoTop, 0, scalar(@top));
|
||||
|
||||
SEARCH:
|
||||
while (@path)
|
||||
{
|
||||
## Search for a file containing DEPTH=../..
|
||||
foreach my $fyl ( qw{Makefile.in Makefile} )
|
||||
{
|
||||
my $path = join('/', @path, $fyl);
|
||||
local *FYL;
|
||||
if (!open(FYL, $path)) {} # NOP
|
||||
elsif (my @tmp = map{ /^\s*DEPTH\s*=\s*([\.\/]+)/o ? $1 : () } <FYL>)
|
||||
{
|
||||
$depth = join('/', @depth, shift @tmp);
|
||||
last SEARCH;
|
||||
}
|
||||
close(FYL);
|
||||
}
|
||||
pop @path;
|
||||
pop @pathNoTop;
|
||||
|
||||
if (0 == scalar(@pathNoTop))
|
||||
{
|
||||
$depth = join('/', @depth);
|
||||
last;
|
||||
}
|
||||
|
||||
## Construct path manually
|
||||
push(@depth, '..');
|
||||
}
|
||||
return $depth;
|
||||
} # getDepth
|
||||
|
||||
###########################################################################
|
||||
## Intent: Read in the exclusion file
|
||||
###########################################################################
|
||||
sub getExclusions
|
||||
{
|
||||
my $file = shift || '';
|
||||
|
||||
return () if ($main::argv{'no-exclusions'});
|
||||
|
||||
my %exclude;
|
||||
if ($file)
|
||||
{
|
||||
my @data = cat($file);
|
||||
foreach (@data)
|
||||
{
|
||||
next unless ($_);
|
||||
next if (/^\s*\#/o);
|
||||
next unless (m%/%);
|
||||
chomp;
|
||||
$exclude{$_}++;
|
||||
}
|
||||
}
|
||||
return %exclude;
|
||||
} # getExclusions
|
||||
|
||||
###########################################################################
|
||||
## Intent: Given the path to a makefile beneath either src or obj
|
||||
## derive the relative path prefix between makefile and root.
|
||||
###########################################################################
|
||||
sub getRelPath
|
||||
{
|
||||
my $path0 = shift;
|
||||
my $abspath;
|
||||
|
||||
# Determine type and orientation
|
||||
my $name = basename($path0);
|
||||
my $haveMF = ($name eq 'Makefile.in') ? 1
|
||||
: ($name eq 'Makefile') ? -1
|
||||
: 0
|
||||
;
|
||||
|
||||
####################################################
|
||||
## Prep work: form a relative path with ../ removed
|
||||
####################################################
|
||||
my $top = getTopDir();
|
||||
my $obj = getObjDir();
|
||||
## If the same Makefile will be created alongside Makefile.in
|
||||
my $topQM = quotemeta($top);
|
||||
my $objQM = quotemeta($obj);
|
||||
|
||||
if ('..' eq substr($path0, 0, 2))
|
||||
{
|
||||
my @cwd = split(m%/%, $cwd);
|
||||
my @pth = split(m%/%, $path0);
|
||||
while (@pth && $pth[0] eq '..')
|
||||
{
|
||||
pop(@cwd);
|
||||
shift @pth;
|
||||
}
|
||||
$path0 = join('/', @cwd, @pth);
|
||||
$abspath = $path0;
|
||||
}
|
||||
|
||||
if ('/' eq substr($path0, 0, 1))
|
||||
{
|
||||
$path0 =~ s%^$objQM\/?%%;
|
||||
$path0 =~ s%^$topQM\/?%%;
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## Build a list of directories to search. Input source will be one
|
||||
## of path to Makefile.in, path to Makefile, directory, file within
|
||||
## a directory or relative path from cwd.
|
||||
#######################################################################
|
||||
my @subdirs;
|
||||
my $path = (0 == $haveMF) ? $path0 : dirname($path0);
|
||||
push(@subdirs, $path); # containing directory
|
||||
push(@subdirs, dirname($path)) if (0 == $haveMF && -f $path); # Arg is file within a directory
|
||||
push(@subdirs, $cwd); # relative to pwd
|
||||
|
||||
# obj - path to generated makefile
|
||||
# top - path to Makefile.in source template
|
||||
my @prefixes = ('/' ne substr($path0, 0, 1))
|
||||
? (&getTopDir, &getObjDir)
|
||||
: ()
|
||||
;
|
||||
|
||||
ON_SAFARI:
|
||||
for my $prefix (@prefixes)
|
||||
{
|
||||
next unless ($prefix); # no command line not passed
|
||||
foreach my $subdir (@subdirs)
|
||||
{
|
||||
foreach my $mf ('Makefile.in', 'Makefile')
|
||||
{
|
||||
my $path = join('/', $prefix, $subdir, $mf);
|
||||
if (-e $path)
|
||||
{
|
||||
$name = $mf;
|
||||
$haveMF = ($mf eq 'Makefile.in') ? 1 : -1;
|
||||
$abspath = $path;
|
||||
last ON_SAFARI;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## Generated makefile does not yet exist or path is invalid.
|
||||
## Should this conditon be handled to detect non-existent Makefile.in:
|
||||
## Makefile.am => Makefile.in => Makefile but Makefile.in
|
||||
#######################################################################
|
||||
if (!$abspath && -1 == $haveMF && $obj)
|
||||
{
|
||||
$abspath = ('/' eq substr($path0, 0, 1))
|
||||
? $path0
|
||||
: join('/', $obj, $path0)
|
||||
;
|
||||
}
|
||||
|
||||
########################################################
|
||||
## If --top and/or --obj specified extract relative path
|
||||
########################################################
|
||||
my $relpath;
|
||||
if (! $abspath)
|
||||
{
|
||||
# Error, fall through
|
||||
}
|
||||
elsif (1 == $haveMF) # Makefile.in
|
||||
{
|
||||
## err w/o --top
|
||||
(my $tmp = $abspath) =~ s%^$topQM/?%%;
|
||||
$relpath = dirname($tmp) unless ($tmp eq $abspath);
|
||||
}
|
||||
elsif (-1 == $haveMF) # Makefile
|
||||
{
|
||||
## err w/o --obj
|
||||
(my $tmp = $abspath) =~ s%^$objQM/?%%;
|
||||
$relpath = dirname($tmp) unless ($tmp eq $abspath);
|
||||
}
|
||||
|
||||
$relpath ||= '';
|
||||
$relpath =~ s%/./%/%og; # filter ./
|
||||
|
||||
$@ = ($relpath) ? '' : "ERROR($path0): Unable to locate sources";
|
||||
return $relpath || '';
|
||||
} # getRelPath
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine sandbox root from script startup directory
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## _set_ optional, if passed use the given value as path
|
||||
## _reset_ clear cached directory path to reassign
|
||||
## Returns:
|
||||
## scalar - absolute path to the sandbox root directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $gtd_dir;
|
||||
sub getTopDir
|
||||
{
|
||||
if (@_) # testing override
|
||||
{
|
||||
$gtd_dir = abs_path($_[1] || '.') if ($_[0] eq '_set_');
|
||||
$gtd_dir = '' if ($_[0] eq '_reset_');
|
||||
}
|
||||
|
||||
unless ($gtd_dir)
|
||||
{
|
||||
## Set by command line
|
||||
if ($main::argv{top})
|
||||
{
|
||||
$gtd_dir = $main::argv{top};
|
||||
}
|
||||
else
|
||||
{
|
||||
my $path = abs_path($FindBin::RealBin);
|
||||
my @path = split(m%/%o, $path);
|
||||
## --2 memory/mozalloc/Makefile.in
|
||||
## --3 was this for FindBin::Script ?
|
||||
splice(@path, -2);
|
||||
$gtd_dir = join('/', @path);
|
||||
}
|
||||
}
|
||||
return $gtd_dir;
|
||||
} # getTopDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Determine path to MOZ_OBJDIR/object directory
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## _set_ optional testing arg, if passed re-compute cached value
|
||||
## Returns:
|
||||
## scalar - absolute path to the sandbox object directory
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
my $god_dir;
|
||||
sub getObjDir
|
||||
{
|
||||
if (@_) # testing override
|
||||
{
|
||||
if ($_[0] eq '_reset_')
|
||||
{
|
||||
$god_dir = '';
|
||||
shift;
|
||||
}
|
||||
elsif ($_[0] eq '_set_')
|
||||
{
|
||||
shift;
|
||||
my $path = $_[0] || '.';
|
||||
$god_dir = abs_path($path);
|
||||
shift;
|
||||
}
|
||||
}
|
||||
|
||||
## extract $obj from given path
|
||||
unless ($god_dir)
|
||||
{
|
||||
if ($main::argv{obj})
|
||||
{
|
||||
$god_dir = $main::argv{obj};
|
||||
}
|
||||
elsif (@_ && 'Makefile' eq substr($_, -8))
|
||||
{
|
||||
$god_dir = abs_path(shift);
|
||||
}
|
||||
else # assume we are sitting in moz_objdir
|
||||
{
|
||||
$god_dir = abs_path('.');
|
||||
}
|
||||
}
|
||||
|
||||
return $god_dir;
|
||||
} # getObjDir
|
||||
|
||||
###########################################################################
|
||||
## Intent: Generate Makefile from a given Makefile.in template
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## scalar Relative path to a directory containing a makefile
|
||||
## fargs Hash ref of function arguments.
|
||||
## obj Absolute path to MOZ_OBJ/a destination directory
|
||||
## top Absolute path to the sandbox root
|
||||
## Returns:
|
||||
## $@ Set on error
|
||||
## scalar
|
||||
## 1 True if the makefile was updated
|
||||
## 0 Otherwise
|
||||
## badtokens - If the makefile contains unexpandable @token@ strings
|
||||
## -----------------------------------------------------------------------
|
||||
###########################################################################
|
||||
sub updateMakefiles
|
||||
{
|
||||
my %fargs = (@_ && ref($_[$#_])) ? %{ (pop) } : ();
|
||||
local $_;
|
||||
$@ = '';
|
||||
|
||||
my $top = $fargs{top};
|
||||
my $obj = $fargs{obj};
|
||||
|
||||
my $relpath = shift || '';
|
||||
my $src = join('/', $top, $relpath, 'Makefile.in');
|
||||
my $depth = getDepth($src);
|
||||
|
||||
my @src = cat($src);
|
||||
return 0 if ($@);
|
||||
|
||||
my $dst = join('/', $obj, $relpath, 'Makefile');
|
||||
my @dst = cat($dst);
|
||||
$@ = '';
|
||||
|
||||
my $dstD = dirname($dst);
|
||||
mkdirr($dstD);
|
||||
return 0 if ($@);
|
||||
|
||||
my %data =
|
||||
( getConfig(),
|
||||
depth => $depth,
|
||||
srcdir => join('/', $top, $relpath),
|
||||
top_srcdir => $top,
|
||||
);
|
||||
|
||||
my $line = 0;
|
||||
my @data;
|
||||
while (scalar @src)
|
||||
{
|
||||
$line++;
|
||||
$_ = shift(@src);
|
||||
|
||||
## Expand embedded @foo@
|
||||
while (/\@[^\@\s\$]+\@/go)
|
||||
{
|
||||
my $end = pos($_);
|
||||
my $val = $&;
|
||||
my $len = length($val);
|
||||
$val =~ s/^\@\s*//o;
|
||||
$val =~ s/\s*\@$//o;
|
||||
|
||||
## Identify expansions to see if we can avoid shell overhead
|
||||
if (!defined $data{$val} && !$argv{'no-badtokens'})
|
||||
{
|
||||
if (1) # warnings
|
||||
{
|
||||
print STDERR "WARNING: token $val not defined\n";
|
||||
print STDERR " line $line, src: $src\n";
|
||||
}
|
||||
return 'badtokens';
|
||||
}
|
||||
|
||||
# Insert $(error txt) makefile macros for invalid tokens
|
||||
my $val1 = defined($data{$val})
|
||||
? $data{$val}
|
||||
: "\$(error $FindBin::Script: variable ${val} is undefined)"
|
||||
;
|
||||
substr($_, ($end-$len), $len, $val1);
|
||||
}
|
||||
push(@data, $_);
|
||||
}
|
||||
|
||||
if (("@data" eq "@dst") && scalar(@data))
|
||||
{
|
||||
print "Skipping up2date makefile: $dst\n" if ($argv{verbose});
|
||||
}
|
||||
else
|
||||
{
|
||||
my $action = (scalar @dst) ? 'Updating' : 'Creating';
|
||||
print "$action makefile: $dst\n";
|
||||
|
||||
my $tmp = join('.', $dst, "tmp_$$");
|
||||
if (!open(FYL, "> $tmp"))
|
||||
{
|
||||
$@ = "open($tmp) failed: $!";
|
||||
}
|
||||
else
|
||||
{
|
||||
print FYL @data;
|
||||
close(FYL);
|
||||
|
||||
## Install the new makefile
|
||||
File::Copy::move($tmp, $dst)
|
||||
|| ($@ = "move($tmp, $dst) failed: $!");
|
||||
}
|
||||
}
|
||||
|
||||
return $@ ? 0 : 1;
|
||||
} # updateMakefiles
|
||||
|
||||
# Output the makefiles.
|
||||
#
|
||||
sub update_makefiles_legacy {
|
||||
my ($ac_given_srcdir, $pac_given_srcdir, @makefiles) = @_;
|
||||
my $debug = $main::argv{debug} || 0;
|
||||
my $pwdcmd = ($^O eq 'msys') ? 'pwd -W' : 'pwd';
|
||||
my @unhandled=();
|
||||
|
||||
my @warn;
|
||||
|
||||
my $ac_file;
|
||||
foreach $ac_file (@makefiles) {
|
||||
my $ac_file_in = "$ac_given_srcdir/${ac_file}.in";
|
||||
my $ac_dir = dirname_legacy($ac_file);
|
||||
my $ac_dots = '';
|
||||
my $ac_dir_suffix = '';
|
||||
my $srcdir = '.';
|
||||
my $top_srcdir = '.';
|
||||
|
||||
# Determine $srcdir and $top_srcdir
|
||||
#
|
||||
if ($ac_dir ne '.') {
|
||||
$ac_dir_suffix = "/$ac_dir";
|
||||
$ac_dir_suffix =~ s%^/\./%/%;
|
||||
$ac_dots = $ac_dir_suffix;
|
||||
# Remove .. components from the provided dir suffix, and
|
||||
# also the forward path components they were reversing.
|
||||
my $backtracks = $ac_dots =~ s%\.\.(/|$)%%g;
|
||||
while ($backtracks--) {
|
||||
$ac_dots =~ s%/[^/]*%%;
|
||||
}
|
||||
$ac_dots =~ s%/[^/]*%../%g;
|
||||
}
|
||||
if ($ac_given_srcdir eq '.') {
|
||||
if ($ac_dots ne '') {
|
||||
$top_srcdir = $ac_dots;
|
||||
$top_srcdir =~ s%/$%%;
|
||||
}
|
||||
} elsif ($pac_given_srcdir =~ m%^/% or $pac_given_srcdir =~ m%^.:/%) {
|
||||
$srcdir = "$pac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$pac_given_srcdir";
|
||||
} else {
|
||||
if ($debug) {
|
||||
print "ac_dots = $ac_dots\n";
|
||||
print "ac_dir_suffix = $ac_dir_suffix\n";
|
||||
}
|
||||
$srcdir = "$ac_dots$ac_given_srcdir$ac_dir_suffix";
|
||||
$top_srcdir = "$ac_dots$ac_given_srcdir";
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
print "ac_dir = $ac_dir\n";
|
||||
print "ac_file = $ac_file\n";
|
||||
print "ac_file_in = $ac_file_in\n";
|
||||
print "srcdir = $srcdir\n";
|
||||
print "top_srcdir = $top_srcdir\n";
|
||||
print "cwd = " . `$pwdcmd` . "\n";
|
||||
}
|
||||
|
||||
# Copy the file and make substitutions.
|
||||
# @srcdir@ -> value of $srcdir
|
||||
# @top_srcdir@ -> value of $top_srcdir
|
||||
#
|
||||
if (-e $ac_file) {
|
||||
next if -M _ < -M $ac_file_in; # Next if Makefile is up-to-date.
|
||||
warn "updating $ac_file\n";
|
||||
} else {
|
||||
warn "creating $ac_file\n";
|
||||
}
|
||||
|
||||
mkdirr(dirname($ac_file));
|
||||
|
||||
open INFILE, "<$ac_file_in" or do {
|
||||
warn "$0: Cannot read $ac_file_in: No such file or directory\n";
|
||||
next;
|
||||
};
|
||||
open OUTFILE, ">$ac_file" or do {
|
||||
warn "$0: Unable to create $ac_file\n";
|
||||
next;
|
||||
};
|
||||
|
||||
while (<INFILE>) {
|
||||
s/\@srcdir\@/$srcdir/g;
|
||||
s/\@top_srcdir\@/$top_srcdir/g;
|
||||
|
||||
if (/\@[_a-zA-Z]*\@/) {
|
||||
#warn "Unknown variable:$ac_file:$.:$_";
|
||||
push @unhandled, $ac_file;
|
||||
last;
|
||||
}
|
||||
print OUTFILE;
|
||||
}
|
||||
close INFILE;
|
||||
close OUTFILE;
|
||||
}
|
||||
return @unhandled;
|
||||
} # update_makefiles_legacy
|
||||
|
||||
###########################################################################
|
||||
## Intent: Invoke config.status for unknown makefiles to create
|
||||
## directory hierarchy for the tree.
|
||||
## -----------------------------------------------------------------------
|
||||
## Args:
|
||||
## array an optional list of makefiles to process
|
||||
## Returns:
|
||||
## 0 on success
|
||||
## $# set on error
|
||||
## -----------------------------------------------------------------------
|
||||
## Note: Is this function needed anymore ? Undefined tokens should fail
|
||||
## at time of expansion rather than having to source config.status.
|
||||
## Also config.status could be parsed to define values and avoide the
|
||||
## shell overhead altogether.
|
||||
###########################################################################
|
||||
sub run_config_status {
|
||||
my @unhandled = @_;
|
||||
|
||||
# Run config.status with any unhandled files.
|
||||
#
|
||||
my @errors;
|
||||
if (@unhandled) {
|
||||
local $ENV{CONFIG_FILES}= join ' ', @unhandled;
|
||||
|
||||
my $conf = 'config.status';
|
||||
if (! -e $conf) # legacy behavior, warn rather than err
|
||||
{
|
||||
my $cwd = cwd();
|
||||
my $err = "$FindBin::Script ERROR: Config file $conf does not exist, cwd=$cwd";
|
||||
push(@errors, $err);
|
||||
}
|
||||
elsif (0 != system("./config.status"))
|
||||
{
|
||||
my $cwd = cwd();
|
||||
push(@errors, "config.status failed \$?=$?, \$!=$!, cwd: $cwd");
|
||||
}
|
||||
}
|
||||
$@ = join("\n", @errors);
|
||||
|
||||
## Legacy behavior: config.status problems are not fatal {yet}.
|
||||
## Display warning since caller will not be calling die.
|
||||
warn $@ if ($@ && $argv{'no-warnings'});
|
||||
return $@ ? 1 : 0;
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user