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 "LIBRARY_REALNAME" => "string",
24 "PRIVATE_DEPENDENCIES" => "list",
25 "PUBLIC_DEPENDENCIES" => "list",
31 "PRIVATE_DEPENDENCIES" => "list",
32 "PUBLIC_DEPENDENCIES" => "list",
38 "STANDARD_VISIBILITY" => "string",
39 "INIT_FUNCTION_SENTINEL" => "string"
42 "SUBSYSTEM" => "string",
44 "INIT_FUNCTION" => "string",
46 "PRIVATE_DEPENDENCIES" => "list",
52 "OUTPUT_TYPE" => "list",
58 "PRIVATE_DEPENDENCIES" => "list",
62 "INSTALLDIR" => "string",
65 "STANDARD_VISIBILITY" => "string",
67 "USE_HOSTCC" => "bool"
70 "LIBRARY_REALNAME" => "string",
72 "INIT_FUNCTION_TYPE" => "string",
73 "INIT_FUNCTION_SENTINEL" => "string",
74 "OUTPUT_TYPE" => "list",
76 "PRIVATE_DEPENDENCIES" => "list",
77 "PUBLIC_DEPENDENCIES" => "list",
83 "STANDARD_VISIBILITY" => "string"
87 use vars qw(@parsed_files);
91 sub _read_config_file($$$)
95 my ($srcdir, $builddir, $filename) = @_;
98 # We need to change our working directory because config.mk files can
99 # give shell commands as the argument to "include". These shell
100 # commands can take arguments that are relative paths and we don't have
101 # a way of sensibly rewriting these.
105 if ($srcdir ne $builddir) {
106 # Push the builddir path on the front, so we prefer builddir
107 # to srcdir when the file exists in both.
108 @dirlist = ($builddir, $srcdir);
110 @dirlist = ($srcdir);
113 foreach my $d (@dirlist) {
120 # We need to catch the exception from open in the case where
121 # the filename is actually a shell pipeline. Why is this
122 # different to opening a regular file? Because this is perl!
124 open(CONFIG_MK, "./$filename");
125 @lines = <CONFIG_MK>;
130 next unless (@lines);
132 # I blame abartlett for this crazy hack -- jpeach
133 if ($filename =~ /\|$/) {
134 $basedir = $builddir;
136 $basedir = dirname($filename);
137 push(@parsed_files, $filename);
139 $basedir =~ s!^($builddir|$srcdir)[/]!!;
140 return ($filename, $basedir, @lines);
147 ###########################################################
148 # The parsing function which parses the file
150 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
152 # $filename - the path of the config.mk file
153 # which should be parsed
154 sub run_config_mk($$$$)
156 sub run_config_mk($$$$);
157 my ($input, $srcdir, $builddir, $filename) = @_;
161 my $section = "GLOBAL";
169 $ENV{builddir} = $builddir;
170 $ENV{srcdir} = $srcdir;
172 ($parsing_file, $basedir, @lines) =
173 _read_config_file($srcdir, $builddir, $filename);
175 die ("$0: can't open '$filename'")
176 unless ($parsing_file and $basedir and @lines);
181 # Emit a line that lets us match up final makefile output with the
182 # corresponding input files. The curlies are so you can match the
183 # BEGIN/END pairs in a text editor.
184 $makefile .= "# BEGIN{ $parsing_file\n";
189 # lines beginning with '#' are ignored
200 if ($line =~ /^\[([-a-zA-Z0-9_.:]+)\][\t ]*$/)
205 $result->{$section}{EXISTS}{KEY} = "EXISTS";
206 $result->{$section}{EXISTS}{VAL} = 1;
211 if ($line =~ /^mkinclude (.*)$/) {
213 my $subdir = dirname($filename);
214 $subdir =~ s/^\.$//g;
215 $subdir =~ s/^\.\///g;
216 $subdir .= "/" if ($subdir ne "");
217 $makefile .= "basedir := $subdir\n";
218 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
223 if ($line =~ /^[ \t]*$/) {
225 if ($infragment) { $makefile.="\n"; }
229 # global stuff is considered part of the makefile
230 if ($section eq "GLOBAL") {
231 if (!$infragment) { $makefile.="\n"; }
238 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
239 $result->{$section}{$1}{VAL} = $2;
240 $result->{$section}{$1}{KEY} = $1;
245 die("$parsing_file:$linenum: Bad line");
248 $makefile .= "# }END $parsing_file\n";
250 foreach my $section (keys %{$result}) {
251 my ($type, $name) = split(/::/, $section, 2);
253 my $sectype = $section_types->{$type};
254 if (not defined($sectype)) {
255 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
258 $input->{$name}{NAME} = $name;
259 $input->{$name}{TYPE} = $type;
260 $input->{$name}{MK_FILE} = $parsing_file;
261 $input->{$name}{BASEDIR} = $basedir;
263 foreach my $key (values %{$result->{$section}}) {
264 next if ($key->{KEY} eq "EXISTS");
265 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
266 my $vartype = $sectype->{$key->{KEY}};
267 if (not defined($vartype)) {
268 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
270 if ($vartype eq "string") {
271 $input->{$name}{$key->{KEY}} = $key->{VAL};
272 } elsif ($vartype eq "list") {
273 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
274 } elsif ($vartype eq "bool") {
275 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
276 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
278 $input->{$name}{$key->{KEY}} = $key->{VAL};