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",
31 "PRIVATE_DEPENDENCIES" => "list",
32 "PUBLIC_DEPENDENCIES" => "list",
36 "PRIVATE_PROTO_HEADER" => "string",
40 "STANDARD_VISIBILITY" => "string",
41 "INIT_FUNCTION_SENTINEL" => "string"
44 "SUBSYSTEM" => "string",
46 "INIT_FUNCTION" => "string",
48 "PRIVATE_DEPENDENCIES" => "list",
54 "OUTPUT_TYPE" => "list",
56 "PRIVATE_PROTO_HEADER" => "string",
62 "PRIVATE_DEPENDENCIES" => "list",
66 "INSTALLDIR" => "string",
67 "PRIVATE_PROTO_HEADER" => "string",
71 "STANDARD_VISIBILITY" => "string",
73 "USE_HOSTCC" => "bool"
76 "LIBRARY_REALNAME" => "string",
78 "INIT_FUNCTION_TYPE" => "string",
79 "INIT_FUNCTION_SENTINEL" => "string",
80 "OUTPUT_TYPE" => "list",
82 "PRIVATE_DEPENDENCIES" => "list",
83 "PUBLIC_DEPENDENCIES" => "list",
87 "PRIVATE_PROTO_HEADER" => "string",
91 "STANDARD_VISIBILITY" => "string"
95 use vars qw(@parsed_files);
105 my $builddir = shift;
106 my $filename = shift;
109 # We need to change our working directory because config.mk files can
110 # give shell commands as the argument to "include". These shell
111 # commands can take arguments that are relative paths and we don't have
112 # a way of sensibly rewriting these.
116 if ($srcdir ne $builddir) {
117 # Push the builddir path on the front, so we prefer builddir
118 # to srcdir when the file exists in both.
119 @dirlist = ($builddir, $srcdir);
121 @dirlist = ($srcdir);
124 foreach my $d (@dirlist) {
131 # We need to catch the exception from open in the case where
132 # the filename is actually a shell pipeline. Why is this
133 # different to opening a regular file? Because this is perl!
135 open(CONFIG_MK, "./$filename");
136 @lines = <CONFIG_MK>;
141 next unless (@lines);
143 # I blame abartlett for this crazy hack -- jpeach
144 if ($filename =~ /\|$/) {
145 $basedir = $builddir;
147 $basedir = dirname($filename);
148 push(@parsed_files, $filename);
150 $basedir =~ s!^($builddir|$srcdir)[/]!!;
151 return ($filename, $basedir, @lines);
158 ###########################################################
159 # The parsing function which parses the file
161 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
163 # $filename - the path of the config.mk file
164 # which should be parsed
165 sub run_config_mk($$$$)
167 sub run_config_mk($$$$);
168 my ($input, $srcdir, $builddir, $filename) = @_;
172 my $section = "GLOBAL";
180 $ENV{builddir} = $builddir;
181 $ENV{srcdir} = $srcdir;
183 ($parsing_file, $basedir, @lines) =
184 _read_config_file($srcdir, $builddir, $filename);
186 die ("$0: can't open '$filename'")
187 unless ($parsing_file and $basedir and @lines);
192 # Emit a line that lets us match up final makefile output with the
193 # corresponding input files. The curlies are so you can match the
194 # BEGIN/END pairs in a text editor.
195 $makefile .= "# BEGIN{ $parsing_file\n";
200 # lines beginning with '#' are ignored
211 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
216 $result->{$section}{EXISTS}{KEY} = "EXISTS";
217 $result->{$section}{EXISTS}{VAL} = 1;
222 if ($line =~ /^mkinclude (.*)$/) {
224 my $subdir = dirname($filename);
225 $subdir =~ s/^\.$//g;
226 $subdir =~ s/^\.\///g;
227 $subdir .= "/" if ($subdir ne "");
228 $makefile .= "basedir := $subdir\n";
229 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
234 if ($line =~ /^[ \t]*$/) {
236 if ($infragment) { $makefile.="\n"; }
240 # global stuff is considered part of the makefile
241 if ($section eq "GLOBAL") {
242 if (!$infragment) { $makefile.="\n"; }
249 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
250 $result->{$section}{$1}{VAL} = $2;
251 $result->{$section}{$1}{KEY} = $1;
256 die("$parsing_file:$linenum: Bad line");
259 $makefile .= "# }END $parsing_file\n";
261 foreach my $section (keys %{$result}) {
262 my ($type, $name) = split(/::/, $section, 2);
264 my $sectype = $section_types->{$type};
265 if (not defined($sectype)) {
266 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
269 $input->{$name}{NAME} = $name;
270 $input->{$name}{TYPE} = $type;
271 $input->{$name}{MK_FILE} = $parsing_file;
272 $input->{$name}{BASEDIR} = $basedir;
274 foreach my $key (values %{$result->{$section}}) {
275 next if ($key->{KEY} eq "EXISTS");
276 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
277 my $vartype = $sectype->{$key->{KEY}};
278 if (not defined($vartype)) {
279 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
281 if ($vartype eq "string") {
282 $input->{$name}{$key->{KEY}} = $key->{VAL};
283 } elsif ($vartype eq "list") {
284 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
285 } elsif ($vartype eq "bool") {
286 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
287 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
289 $input->{$name}{$key->{KEY}} = $key->{VAL};