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",
35 "STANDARD_VISIBILITY" => "string",
36 "INIT_FUNCTION_SENTINEL" => "string"
39 "SUBSYSTEM" => "string",
41 "INIT_FUNCTION" => "string",
43 "PRIVATE_DEPENDENCIES" => "list",
49 "OUTPUT_TYPE" => "list",
53 "PRIVATE_DEPENDENCIES" => "list",
57 "INSTALLDIR" => "string",
59 "STANDARD_VISIBILITY" => "string",
61 "USE_HOSTCC" => "bool"
64 "LIBRARY_REALNAME" => "string",
66 "INIT_FUNCTION_TYPE" => "string",
67 "INIT_FUNCTION_SENTINEL" => "string",
68 "OUTPUT_TYPE" => "list",
70 "PRIVATE_DEPENDENCIES" => "list",
71 "PUBLIC_DEPENDENCIES" => "list",
77 "STANDARD_VISIBILITY" => "string"
81 use vars qw(@parsed_files);
85 sub _read_config_file($$$)
89 my ($srcdir, $builddir, $filename) = @_;
92 # We need to change our working directory because config.mk files can
93 # give shell commands as the argument to "include". These shell
94 # commands can take arguments that are relative paths and we don't have
95 # a way of sensibly rewriting these.
99 if ($srcdir ne $builddir) {
100 # Push the builddir path on the front, so we prefer builddir
101 # to srcdir when the file exists in both.
102 @dirlist = ($builddir, $srcdir);
104 @dirlist = ($srcdir);
107 foreach my $d (@dirlist) {
114 # We need to catch the exception from open in the case where
115 # the filename is actually a shell pipeline. Why is this
116 # different to opening a regular file? Because this is perl!
118 open(CONFIG_MK, "./$filename");
119 @lines = <CONFIG_MK>;
124 next unless (@lines);
126 # I blame abartlett for this crazy hack -- jpeach
127 if ($filename =~ /\|$/) {
128 $basedir = $builddir;
130 $basedir = dirname($filename);
131 push(@parsed_files, $filename);
133 $basedir =~ s!^($builddir|$srcdir)[/]!!;
134 return ($filename, $basedir, @lines);
141 ###########################################################
142 # The parsing function which parses the file
144 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
146 # $filename - the path of the config.mk file
147 # which should be parsed
148 sub run_config_mk($$$$)
150 sub run_config_mk($$$$);
151 my ($input, $srcdir, $builddir, $filename) = @_;
155 my $section = "GLOBAL";
163 $ENV{builddir} = $builddir;
164 $ENV{srcdir} = $srcdir;
166 ($parsing_file, $basedir, @lines) =
167 _read_config_file($srcdir, $builddir, $filename);
169 die ("$0: can't open '$filename'")
170 unless ($parsing_file and $basedir and @lines);
175 # Emit a line that lets us match up final makefile output with the
176 # corresponding input files. The curlies are so you can match the
177 # BEGIN/END pairs in a text editor.
178 $makefile .= "# BEGIN{ $parsing_file\n";
183 # lines beginning with '#' are ignored
194 if ($line =~ /^\[([-a-zA-Z0-9_.:]+)\][\t ]*$/)
199 $result->{$section}{EXISTS}{KEY} = "EXISTS";
200 $result->{$section}{EXISTS}{VAL} = 1;
205 if ($line =~ /^mkinclude (.*)$/) {
207 my $subdir = dirname($filename);
208 $subdir =~ s/^\.$//g;
209 $subdir =~ s/^\.\///g;
210 $subdir .= "/" if ($subdir ne "");
211 $makefile .= "basedir := $subdir\n";
212 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
217 if ($line =~ /^[ \t]*$/) {
219 if ($infragment) { $makefile.="\n"; }
223 # global stuff is considered part of the makefile
224 if ($section eq "GLOBAL") {
225 if (!$infragment) { $makefile.="\n"; }
232 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
233 $result->{$section}{$1}{VAL} = $2;
234 $result->{$section}{$1}{KEY} = $1;
239 die("$parsing_file:$linenum: Bad line");
242 $makefile .= "# }END $parsing_file\n";
244 foreach my $section (keys %{$result}) {
245 my ($type, $name) = split(/::/, $section, 2);
247 my $sectype = $section_types->{$type};
248 if (not defined($sectype)) {
249 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
252 $input->{$name}{NAME} = $name;
253 $input->{$name}{TYPE} = $type;
254 $input->{$name}{MK_FILE} = $parsing_file;
255 $input->{$name}{BASEDIR} = $basedir;
257 foreach my $key (values %{$result->{$section}}) {
258 next if ($key->{KEY} eq "EXISTS");
259 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
260 my $vartype = $sectype->{$key->{KEY}};
261 if (not defined($vartype)) {
262 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
264 if ($vartype eq "string") {
265 $input->{$name}{$key->{KEY}} = $key->{VAL};
266 } elsif ($vartype eq "list") {
267 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
268 } elsif ($vartype eq "bool") {
269 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
270 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
272 $input->{$name}{$key->{KEY}} = $key->{VAL};