2 # - config.mk parsing functions
4 # Copyright (C) Stefan (metze) Metzmacher 2004
5 # Copyright (C) Jelmer Vernooij 2005
6 # Released under the GNU GPL
9 package smb_build::config_mk;
23 SWIG_FILE => "string",
24 "PRIVATE_DEPENDENCIES" => "list",
25 "PUBLIC_DEPENDENCIES" => "list",
26 "OBJ_FILES" => "list",
32 "OBJ_FILES" => "list",
34 "PRIVATE_DEPENDENCIES" => "list",
35 "PUBLIC_DEPENDENCIES" => "list",
39 "PUBLIC_PROTO_HEADER" => "string",
40 "PRIVATE_PROTO_HEADER" => "string",
42 "PUBLIC_HEADERS" => "list",
46 "STANDARD_VISIBILITY" => "string",
47 "INIT_FUNCTION_SENTINEL" => "string"
50 "SUBSYSTEM" => "string",
52 "INIT_FUNCTION" => "string",
53 "OBJ_FILES" => "list",
55 "PRIVATE_DEPENDENCIES" => "list",
61 "OUTPUT_TYPE" => "list",
63 "PRIVATE_PROTO_HEADER" => "string",
68 "OBJ_FILES" => "list",
70 "PRIVATE_DEPENDENCIES" => "list",
74 "INSTALLDIR" => "string",
75 "PRIVATE_PROTO_HEADER" => "string",
79 "STANDARD_VISIBILITY" => "string",
81 "USE_HOSTCC" => "bool"
84 "VERSION" => "string",
85 "SO_VERSION" => "string",
86 "LIBRARY_REALNAME" => "string",
88 "PC_FILE" => "string",
90 "INIT_FUNCTION_TYPE" => "string",
91 "INIT_FUNCTION_SENTINEL" => "string",
92 "OUTPUT_TYPE" => "list",
94 "OBJ_FILES" => "list",
96 "PRIVATE_DEPENDENCIES" => "list",
97 "PUBLIC_DEPENDENCIES" => "list",
101 "PUBLIC_HEADERS" => "list",
103 "PUBLIC_PROTO_HEADER" => "string",
104 "PRIVATE_PROTO_HEADER" => "string",
108 "STANDARD_VISIBILITY" => "string"
112 use vars qw(@parsed_files);
116 sub _read_config_file
122 my $builddir = shift;
123 my $filename = shift;
126 # We need to change our working directory because config.mk files can
127 # give shell commands as the argument to "include". These shell
128 # commands can take arguments that are relative paths and we don't have
129 # a way of sensibly rewriting these.
133 if ($srcdir ne $builddir) {
134 # Push the builddir path on the front, so we prefer builddir
135 # to srcdir when the file exists in both.
136 @dirlist = ($builddir, $srcdir);
138 @dirlist = ($srcdir);
141 foreach my $d (@dirlist) {
148 # We need to catch the exception from open in the case where
149 # the filename is actually a shell pipeline. Why is this
150 # different to opening a regular file? Because this is perl!
152 open(CONFIG_MK, "./$filename");
153 @lines = <CONFIG_MK>;
158 next unless (@lines);
160 # I blame abartlett for this crazy hack -- jpeach
161 if ($filename =~ /\|$/) {
162 $basedir = $builddir;
164 $basedir = dirname($filename);
165 push(@parsed_files, $filename);
167 $basedir =~ s!^($builddir|$srcdir)[/]!!;
168 return ($filename, $basedir, @lines);
175 ###########################################################
176 # The parsing function which parses the file
178 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
180 # $filename - the path of the config.mk file
181 # which should be parsed
182 sub run_config_mk($$$$)
184 sub run_config_mk($$$$);
185 my ($input, $srcdir, $builddir, $filename) = @_;
189 my $section = "GLOBAL";
197 $ENV{builddir} = $builddir;
198 $ENV{srcdir} = $srcdir;
200 ($parsing_file, $basedir, @lines) =
201 _read_config_file($srcdir, $builddir, $filename);
203 die ("$0: can't open '$filename'")
204 unless ($parsing_file and $basedir and @lines);
209 # Emit a line that lets us match up final makefile output with the
210 # corresponding input files. The curlies are so you can match the
211 # BEGIN/END pairs in a text editor.
212 $makefile .= "# BEGIN{ $parsing_file\n";
217 # lines beginning with '#' are ignored
228 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
236 if ($line =~ /^mkinclude (.*)$/) {
238 my $subdir = dirname($filename);
239 $subdir =~ s/^\.$//g;
240 $subdir =~ s/^\.\///g;
241 $subdir .= "/" if ($subdir ne "");
242 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
247 if ($line =~ /^[ \t]*$/) {
249 if ($infragment) { $makefile.="\n"; }
253 # global stuff is considered part of the makefile
254 if ($section eq "GLOBAL") {
255 if (!$infragment) { $makefile.="\n"; }
263 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
264 $result->{$section}{$1}{VAL} = $2;
265 $result->{$section}{$1}{KEY} = $1;
270 die("$parsing_file:$linenum: Bad line while parsing $parsing_file");
273 $makefile .= "# }END $parsing_file\n";
275 foreach my $section (keys %{$result}) {
276 my ($type, $name) = split(/::/, $section, 2);
278 my $sectype = $section_types->{$type};
279 if (not defined($sectype)) {
280 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
283 $input->{$name}{NAME} = $name;
284 $input->{$name}{TYPE} = $type;
285 $input->{$name}{MK_FILE} = $parsing_file;
286 $input->{$name}{BASEDIR} = $basedir;
288 foreach my $key (values %{$result->{$section}}) {
289 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
290 my $vartype = $sectype->{$key->{KEY}};
291 if (not defined($vartype)) {
292 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
294 if ($vartype eq "string") {
295 $input->{$name}{$key->{KEY}} = $key->{VAL};
296 } elsif ($vartype eq "list") {
297 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
298 } elsif ($vartype eq "bool") {
299 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
300 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
302 $input->{$name}{$key->{KEY}} = $key->{VAL};