summaryrefslogtreecommitdiff
path: root/source4/build/smb_build/config_mk.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-03 03:09:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:31:01 -0500
commit916505f66197b8ed9d767ea45e13cb3fd8319ae7 (patch)
tree0d86ae8e644b395cc7d777e7f3b318ec8b6ae8f7 /source4/build/smb_build/config_mk.pm
parentf10b2af0f8234d99c76cf7dd2e8c95ad6c3c4678 (diff)
downloadsamba-916505f66197b8ed9d767ea45e13cb3fd8319ae7.tar.gz
samba-916505f66197b8ed9d767ea45e13cb3fd8319ae7.tar.bz2
samba-916505f66197b8ed9d767ea45e13cb3fd8319ae7.zip
r8974: Support makefile fragments in .mk files
(This used to be commit 8d9c18a1b4cf31ebae1d0c84b00b4d781f55de66)
Diffstat (limited to 'source4/build/smb_build/config_mk.pm')
-rw-r--r--source4/build/smb_build/config_mk.pm121
1 files changed, 39 insertions, 82 deletions
diff --git a/source4/build/smb_build/config_mk.pm b/source4/build/smb_build/config_mk.pm
index 517bca08ec..274a2aab8b 100644
--- a/source4/build/smb_build/config_mk.pm
+++ b/source4/build/smb_build/config_mk.pm
@@ -55,118 +55,71 @@ sub _parse_config_mk($)
my $linenum = -1;
my $waiting = 0;
my $section = "GLOBAL";
- my $key;
+ my $makefile = "";
- $result->{ERROR_CODE} = -1;
-
- open(CONFIG_MK, "< $filename") || die ("Can't open $filename\n");
+ open(CONFIG_MK, "<$filename") or die("Can't open `$filename'\n");
while (<CONFIG_MK>) {
my $line = $_;
- my $val;
$linenum++;
- #
- # lines beginnig with '#' are ignored
- #
- if ($line =~ /^\#.*$/) {
- next;
- }
+ # lines beginning with '#' are ignored
+ next if ($line =~ /^\#.*$/);
- #
- #
- #
- if (($waiting == 0) && ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)) {
+ if (not $waiting and ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/))
+ {
$section = $1;
next;
}
-
- #
- # 1.) lines with an alphanumeric character indicate
- # a new variable,
- # 2.) followed by zero or more whitespaces or tabs
- # 3.) then one '=' character
- # 4.) followed by the value of the variable
- # 5.) a newline ('\n') can be escaped by a '\' before the newline
- # and the next line needs to start with a tab ('\t')
- #
- if (($waiting == 0) && ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/)) {
- $key = $1;
- $val = $2;
-
- #
- # when we have a '\' before the newline
- # then skip it and wait for the next line.
- #
- if ($val =~ /(.*)(\\)$/) {
- $val = $1;
- $waiting = 1;
- } else {
- $waiting = 0;
- }
- $result->{$section}{$key}{KEY} = $key;
- $result->{$section}{$key}{VAL} = $val;
+ # empty line
+ if ($line =~ /^[ \t]*$/) {
+ $waiting = 0;
+ $section = "GLOBAL";
next;
}
- #
- # when we are waiting for a value to continue then
- # check if it has a leading tab.
- #
- if (($waiting == 1) && ($line =~ /^\t(.*)$/)) {
- $val = $1;
-
- #
- # when we have a '\' before the newline
- # then skip it and wait for the next line.
- #
- if ($val =~ /(.*)( \\)$/) {
- $val = $1;
- $waiting = 1;
- } else {
- $waiting = 0;
- }
-
- $result->{$section}{$key}{VAL} .= " ";
- $result->{$section}{$key}{VAL} .= $val;
+ # global stuff is considered part of the makefile
+ if ($section eq "GLOBAL") {
+ $makefile .= $line;
next;
}
+
+ # Assignment
+ if (not $waiting and
+ ($line =~ /^([a-zA-Z0-9_]+)([\t ]*)=(.*)$/)) {
+ my $key = $1;
+ my $val = $3;
+
+ # Continuing lines
+ if ($val =~ /^(.*)\\$/) {
+ $val = $1;
+ ($val.= " $1") while(($line = <CONFIG_MK>) =~ /^[\t ]*(.*)\\$/);
+ $val .= $line;
+ }
- #
- # catch empty lines they're ignored
- # and we're no longer waiting for the value to continue
- #
- if ($line =~ /^$/) {
- $waiting = 0;
+ $result->{$section}{$key}{KEY} = $key;
+ $result->{$section}{$key}{VAL} = $val;
+
next;
}
- close(CONFIG_MK);
-
- $result->{ERROR_STR} = "Bad line while parsing $filename\n$filename:$linenum: $line";
-
- return $result;
+ die("$filename:$linenum: Bad line while parsing $filename");
}
close(CONFIG_MK);
- $result->{ERROR_CODE} = 0;
-
- return $result;
+ return ($result,$makefile);
}
sub import_file($$)
{
my ($input, $filename) = @_;
- my $result = _parse_config_mk($filename);
-
- die ($result->{ERROR_STR}) unless $result->{ERROR_CODE} == 0;
+ my ($result, $makefile) = _parse_config_mk($filename);
foreach my $section (keys %{$result}) {
- next if ($section eq "ERROR_CODE");
my ($type, $name) = split(/::/, $section, 2);
$input->{$name}{NAME} = $name;
@@ -176,7 +129,7 @@ sub import_file($$)
$key->{VAL} = smb_build::input::strtrim($key->{VAL});
my $vartype = $attribute_types{$key->{KEY}};
if (not defined($vartype)) {
- die("Unknown attribute $key->{KEY}");
+ die("$filename:Unknown attribute $key->{KEY} with value $key->{VAL} in section $section");
}
if ($vartype eq "string") {
$input->{$name}{$key->{KEY}} = $key->{VAL};
@@ -184,12 +137,14 @@ sub import_file($$)
$input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
} elsif ($vartype eq "bool") {
if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
- die("Invalid value for bool attribute $key->{KEY}: $key->{VAL}");
+ die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
}
$input->{$name}{$key->{KEY}} = $key->{VAL};
}
}
}
+
+ return $makefile;
}
sub import_files($$)
@@ -201,10 +156,12 @@ sub import_files($$)
close(IN);
$| = 1;
+ my $makefragment = "";
foreach (@mkfiles) {
s/\n//g;
- import_file($input, $_);
+ $makefragment.= import_file($input, $_);
}
+ return $makefragment;
}
1;