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",
30 "PRIVATE_DEPENDENCIES" => "list",
31 "PUBLIC_DEPENDENCIES" => "list",
37 "STANDARD_VISIBILITY" => "string",
38 "INIT_FUNCTION_SENTINEL" => "string"
41 "SUBSYSTEM" => "string",
43 "INIT_FUNCTION" => "string",
45 "PRIVATE_DEPENDENCIES" => "list",
51 "OUTPUT_TYPE" => "list",
57 "PRIVATE_DEPENDENCIES" => "list",
61 "INSTALLDIR" => "string",
63 "STANDARD_VISIBILITY" => "string",
65 "USE_HOSTCC" => "bool"
68 "LIBRARY_REALNAME" => "string",
70 "INIT_FUNCTION_TYPE" => "string",
71 "INIT_FUNCTION_SENTINEL" => "string",
72 "OUTPUT_TYPE" => "list",
74 "PRIVATE_DEPENDENCIES" => "list",
75 "PUBLIC_DEPENDENCIES" => "list",
81 "STANDARD_VISIBILITY" => "string"
85 use vars
qw(@parsed_files);
89 sub _read_config_file($$$)
93 my ($srcdir, $builddir, $filename) = @_;
96 # We need to change our working directory because config.mk files can
97 # give shell commands as the argument to "include". These shell
98 # commands can take arguments that are relative paths and we don't have
99 # a way of sensibly rewriting these.
103 if ($srcdir ne $builddir) {
104 # Push the builddir path on the front, so we prefer builddir
105 # to srcdir when the file exists in both.
106 @dirlist = ($builddir, $srcdir);
108 @dirlist = ($srcdir);
111 foreach my $d (@dirlist) {
118 # We need to catch the exception from open in the case where
119 # the filename is actually a shell pipeline. Why is this
120 # different to opening a regular file? Because this is perl!
122 open(CONFIG_MK, "./$filename");
123 @lines = <CONFIG_MK>;
128 next unless (@lines);
130 # I blame abartlett for this crazy hack -- jpeach
131 if ($filename =~ /\|$/) {
132 $basedir = $builddir;
134 $basedir = dirname($filename);
135 push(@parsed_files, $filename);
137 $basedir =~ s!^($builddir|$srcdir)[/]!!;
138 return ($filename, $basedir, @lines);
145 ###########################################################
146 # The parsing function which parses the file
148 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
150 # $filename - the path of the config.mk file
151 # which should be parsed
152 sub run_config_mk($$$$)
154 sub run_config_mk($$$$);
155 my ($input, $srcdir, $builddir, $filename) = @_;
159 my $section = "GLOBAL";
167 $ENV{builddir} = $builddir;
168 $ENV{srcdir} = $srcdir;
170 ($parsing_file, $basedir, @lines) =
171 _read_config_file($srcdir, $builddir, $filename);
173 die ("$0: can't open '$filename'")
174 unless ($parsing_file and $basedir and @lines);
179 # Emit a line that lets us match up final makefile output with the
180 # corresponding input files. The curlies are so you can match the
181 # BEGIN/END pairs in a text editor.
182 $makefile .= "# BEGIN{ $parsing_file\n";
187 # lines beginning with '#' are ignored
198 if ($line =~ /^\[([-a-zA-Z0-9_.:]+)\][\t ]*$/)
203 $result->{$section}{EXISTS}{KEY} = "EXISTS";
204 $result->{$section}{EXISTS}{VAL} = 1;
209 if ($line =~ /^mkinclude (.*)$/) {
211 my $subdir = dirname($filename);
212 $subdir =~ s/^\.$//g;
213 $subdir =~ s/^\.\///g;
214 $subdir .= "/" if ($subdir ne "");
215 $makefile .= "basedir := $subdir\n";
216 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
221 if ($line =~ /^[ \t]*$/) {
223 if ($infragment) { $makefile.="\n"; }
227 # global stuff is considered part of the makefile
228 if ($section eq "GLOBAL") {
229 if (!$infragment) { $makefile.="\n"; }
236 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
237 $result->{$section}{$1}{VAL} = $2;
238 $result->{$section}{$1}{KEY} = $1;
243 die("$parsing_file:$linenum: Bad line");
246 $makefile .= "# }END $parsing_file\n";
248 foreach my $section (keys %{$result}) {
249 my ($type, $name) = split(/::/, $section, 2);
251 my $sectype = $section_types->{$type};
252 if (not defined($sectype)) {
253 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
256 $input->{$name}{NAME} = $name;
257 $input->{$name}{TYPE} = $type;
258 $input->{$name}{MK_FILE} = $parsing_file;
259 $input->{$name}{BASEDIR} = $basedir;
261 foreach my $key (values %{$result->{$section}}) {
262 next if ($key->{KEY} eq "EXISTS");
263 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
264 my $vartype = $sectype->{$key->{KEY}};
265 if (not defined($vartype)) {
266 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
268 if ($vartype eq "string") {
269 $input->{$name}{$key->{KEY}} = $key->{VAL};
270 } elsif ($vartype eq "list") {
271 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
272 } elsif ($vartype eq "bool") {
273 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
274 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
276 $input->{$name}{$key->{KEY}} = $key->{VAL};