diff options
author | James Peach <jpeach@samba.org> | 2007-04-02 17:08:21 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:49:42 -0500 |
commit | 7dc8e67f81d97efb297ce37896bb996f6d133f08 (patch) | |
tree | f08722d34705a2f987adc13184e7ded0a456d2a8 /source4 | |
parent | 2882b2ba63ea65c806643f86d996513414c827d0 (diff) | |
download | samba-7dc8e67f81d97efb297ce37896bb996f6d133f08.tar.gz samba-7dc8e67f81d97efb297ce37896bb996f6d133f08.tar.bz2 samba-7dc8e67f81d97efb297ce37896bb996f6d133f08.zip |
r22030: Simplify include parsing for config.mk files, making sure we get
it right for the srcdir != builddir case. Emit some comment lines
that can be used to figure out which parts of the Makefile output
is generated from which config files.
(This used to be commit bdb1532d3a0fc73e615f66966c3d633c7e93fbb6)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/build/smb_build/config_mk.pm | 104 |
1 files changed, 73 insertions, 31 deletions
diff --git a/source4/build/smb_build/config_mk.pm b/source4/build/smb_build/config_mk.pm index 42c96f1792..6c095c5a5b 100644 --- a/source4/build/smb_build/config_mk.pm +++ b/source4/build/smb_build/config_mk.pm @@ -114,6 +114,64 @@ use vars qw(@parsed_files); @parsed_files = (); +sub _read_config_file +{ + use File::Basename; + use Cwd; + + my $srcdir = shift; + my $builddir = shift; + my $filename = shift; + my @dirlist; + + # We need to change our working directory because config.mk files can + # give shell commands as the argument to "include". These shell + # commands can take arguments that are relative paths and we don't have + # a way of sensibly rewriting these. + my $cwd = getcwd; + chomp $cwd; + + if ($srcdir ne $builddir) { + # Push the builddir path on the front, so we prefer builddir + # to srcdir when the file exists in both. + @dirlist = ($builddir, $srcdir); + } else { + @dirlist = ($srcdir); + } + + foreach my $d (@dirlist) { + my @lines; + my $basedir; + + chdir $cwd; + chdir $d; + + # We need to catch the exception from open in the case where + # the filename is actually a shell pipeline. Why is this + # different to opening a regular file? Because this is perl! + eval { + open(CONFIG_MK, "./$filename"); + @lines = <CONFIG_MK>; + close(CONFIG_MK); + }; + + chdir $cwd; + next unless (@lines); + + # I blame abartlett for this crazy hack -- jpeach + if ($filename =~ /\|$/) { + $basedir = $builddir; + } else { + $basedir = dirname($filename); + } + $basedir =~ s!^($builddir|$srcdir)[/]!!; + return ($filename, $basedir, @lines); + } + + chdir $cwd; + return; +} + ########################################################### # The parsing function which parses the file # @@ -131,46 +189,28 @@ sub run_config_mk($$$$) my $section = "GLOBAL"; my $makefile = ""; - my $parsing_file = $filename; - my $retry_parsing_file = undef; my $basedir; - $ENV{samba_builddir} = $builddir; - $ENV{samba_srcdir} = $srcdir; - - if (($srcdir ne ".") or ($builddir ne ".")) { - $parsing_file = $builddir."/".$filename; - $retry_parsing_file = $srcdir."/".$filename; - } + my $parsing_file; + my @lines; - if (open(CONFIG_MK, $parsing_file)) { - $retry_parsing_file = undef; - } else { - die("Can't open $parsing_file") unless defined($retry_parsing_file); - } + $ENV{builddir} = $builddir; + $ENV{srcdir} = $srcdir; - if (defined($retry_parsing_file)) { - if (open(CONFIG_MK, $parsing_file)) { - $parsing_file = $retry_parsing_file; - $retry_parsing_file = undef; - } else { - die("Can't open neither '$parsing_file' nor '$retry_parsing_file'\n"); - } - } + ($parsing_file, $basedir, @lines) = + _read_config_file($srcdir, $builddir, $filename); - if ($parsing_file =~ /\|$/) { - $basedir = $builddir; - } else { - $basedir = dirname($filename); - push (@parsed_files, $parsing_file); - } - - my @lines = <CONFIG_MK>; - close(CONFIG_MK); + die ("$0: can't open '$filename'") + unless ($parsing_file and $basedir and @lines); my $line = ""; my $prev = ""; + # Emit a line that lets us match up final makefile output with the + # corresponding input files. The curlies are so you can match the + # BEGIN/END pairs in a text editor. + $makefile .= "# BEGIN{ $parsing_file\n"; + foreach (@lines) { $linenum++; @@ -230,6 +270,8 @@ sub run_config_mk($$$$) die("$parsing_file:$linenum: Bad line while parsing $parsing_file"); } + $makefile .= "# }END $parsing_file\n"; + foreach my $section (keys %{$result}) { my ($type, $name) = split(/::/, $section, 2); |