1 ###########################################################
2 ### SMB Build System ###
3 ### - config.mk parsing functions ###
5 ### Copyright (C) Stefan (metze) Metzmacher 2004 ###
6 ### Released under the GNU GPL ###
7 ###########################################################
14 my %attribute_types = (
16 "REQUIRED_SUBSYSTEMS" => "list",
17 "OUTPUT_TYPE" => "string",
18 "INIT_OBJ_FILES" => "list",
19 "ADD_OBJ_FILES" => "list",
20 "OBJ_FILES" => "list",
21 "SUBSYSTEM" => "string",
26 "INIT_FUNCTION" => "string",
27 "MAJOR_VERSION" => "string",
28 "MINOR_VERSION" => "string",
29 "RELEASE_VERSION" => "string",
35 ###########################################################
36 # The parsing function which parses the file
38 # $result = _parse_config_mk($filename)
40 # $filename - the path of the config.mk file
41 # which should be parsed
43 # $result - the resulting structure
45 # $result->{ERROR_CODE} - the error_code, '0' means success
46 # $result->{ERROR_STR} - the error string
48 # $result->{$key}{KEY} - the key == the variable which was parsed
49 # $result->{$key}{VAL} - the value of the variable
50 sub _parse_config_mk
($)
56 my $section = "GLOBAL";
59 $result->{ERROR_CODE
} = -1;
61 open(CONFIG_MK
, "< $filename") || die ("Can't open $filename\n");
70 # lines beginnig with '#' are ignored
72 if ($line =~ /^\#.*$/) {
79 if (($waiting == 0) && ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)) {
85 # 1.) lines with an alphanumeric character indicate
87 # 2.) followed by zero or more whitespaces or tabs
88 # 3.) then one '=' character
89 # 4.) followed by the value of the variable
90 # 5.) a newline ('\n') can be escaped by a '\' before the newline
91 # and the next line needs to start with a tab ('\t')
93 if (($waiting == 0) && ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/)) {
98 # when we have a '\' before the newline
99 # then skip it and wait for the next line.
101 if ($val =~ /(.*)(\\)$/) {
108 $result->{$section}{$key}{KEY
} = $key;
109 $result->{$section}{$key}{VAL
} = $val;
114 # when we are waiting for a value to continue then
115 # check if it has a leading tab.
117 if (($waiting == 1) && ($line =~ /^\t(.*)$/)) {
121 # when we have a '\' before the newline
122 # then skip it and wait for the next line.
124 if ($val =~ /(.*)( \\)$/) {
131 $result->{$section}{$key}{VAL
} .= " ";
132 $result->{$section}{$key}{VAL
} .= $val;
137 # catch empty lines they're ignored
138 # and we're no longer waiting for the value to continue
147 $result->{ERROR_STR
} = "Bad line while parsing $filename\n$filename:$linenum: $line";
154 $result->{ERROR_CODE
} = 0;
161 my ($input, $filename) = @_;
163 my $result = _parse_config_mk
($filename);
165 die ($result->{ERROR_STR
}) unless $result->{ERROR_CODE
} == 0;
167 foreach my $section (keys %{$result}) {
168 next if ($section eq "ERROR_CODE");
169 my ($type, $name) = split(/::/, $section, 2);
171 $input->{$name}{NAME
} = $name;
172 $input->{$name}{TYPE
} = $type;
174 foreach my $key (values %{$result->{$section}}) {
175 $key->{VAL
} = smb_build
::input
::strtrim
($key->{VAL
});
176 my $vartype = $attribute_types{$key->{KEY
}};
177 if (not defined($vartype)) {
178 die("Unknown attribute $key->{KEY}");
180 if ($vartype eq "string") {
181 $input->{$name}{$key->{KEY
}} = $key->{VAL
};
182 } elsif ($vartype eq "list") {
183 $input->{$name}{$key->{KEY
}} = [smb_build
::input
::str2array
($key->{VAL
})];
184 } elsif ($vartype eq "bool") {
185 if (($key->{VAL
} ne "YES") and ($key->{VAL
} ne "NO")) {
186 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL}");
188 $input->{$name}{$key->{KEY
}} = $key->{VAL
};
196 my ($input, $config_list) = @_;
198 open(IN
, $config_list) or die("Can't open $config_list: $!");
199 my @mkfiles = grep{!/^#/} <IN
>;
206 import_file
($input, $_);