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",
31 "OBJ_FILES" => "list",
33 "PRIVATE_DEPENDENCIES" => "list",
34 "PUBLIC_DEPENDENCIES" => "list",
38 "MANPAGE" => "string",
40 "PUBLIC_PROTO_HEADER" => "string",
41 "PRIVATE_PROTO_HEADER" => "string",
43 "PUBLIC_HEADERS" => "list",
47 "STANDARD_VISIBILITY" => "string"
50 "SUBSYSTEM" => "string",
52 "INIT_FUNCTION" => "string",
53 "OBJ_FILES" => "list",
55 "PRIVATE_DEPENDENCIES" => "list",
61 "OUTPUT_TYPE" => "list",
63 "MANPAGE" => "string",
64 "PRIVATE_PROTO_HEADER" => "string",
69 "OBJ_FILES" => "list",
71 "PRIVATE_DEPENDENCIES" => "list",
75 "MANPAGE" => "string",
76 "INSTALLDIR" => "string",
77 "PRIVATE_PROTO_HEADER" => "string",
81 "STANDARD_VISIBILITY" => "string",
83 "USE_HOSTCC" => "bool"
86 "VERSION" => "string",
87 "SO_VERSION" => "string",
88 "LIBRARY_REALNAME" => "string",
90 "INIT_FUNCTION_TYPE" => "string",
91 "OUTPUT_TYPE" => "list",
93 "OBJ_FILES" => "list",
95 "DESCRIPTION" => "string",
97 "PRIVATE_DEPENDENCIES" => "list",
98 "PUBLIC_DEPENDENCIES" => "list",
102 "MANPAGE" => "string",
104 "PUBLIC_HEADERS" => "list",
106 "PUBLIC_PROTO_HEADER" => "string",
107 "PRIVATE_PROTO_HEADER" => "string",
111 "STANDARD_VISIBILITY" => "string"
115 use vars qw(@parsed_files);
119 sub _read_config_file
125 my $builddir = shift;
126 my $filename = shift;
129 # We need to change our working directory because config.mk files can
130 # give shell commands as the argument to "include". These shell
131 # commands can take arguments that are relative paths and we don't have
132 # a way of sensibly rewriting these.
136 if ($srcdir ne $builddir) {
137 # Push the builddir path on the front, so we prefer builddir
138 # to srcdir when the file exists in both.
139 @dirlist = ($builddir, $srcdir);
141 @dirlist = ($srcdir);
144 foreach my $d (@dirlist) {
151 # We need to catch the exception from open in the case where
152 # the filename is actually a shell pipeline. Why is this
153 # different to opening a regular file? Because this is perl!
155 open(CONFIG_MK, "./$filename");
156 @lines = <CONFIG_MK>;
161 next unless (@lines);
163 # I blame abartlett for this crazy hack -- jpeach
164 if ($filename =~ /\|$/) {
165 $basedir = $builddir;
167 $basedir = dirname($filename);
168 push(@parsed_files, $filename);
170 $basedir =~ s!^($builddir|$srcdir)[/]!!;
171 return ($filename, $basedir, @lines);
178 ###########################################################
179 # The parsing function which parses the file
181 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
183 # $filename - the path of the config.mk file
184 # which should be parsed
185 sub run_config_mk($$$$)
187 sub run_config_mk($$$$);
188 my ($input, $srcdir, $builddir, $filename) = @_;
192 my $section = "GLOBAL";
200 $ENV{builddir} = $builddir;
201 $ENV{srcdir} = $srcdir;
203 ($parsing_file, $basedir, @lines) =
204 _read_config_file($srcdir, $builddir, $filename);
206 die ("$0: can't open '$filename'")
207 unless ($parsing_file and $basedir and @lines);
212 # Emit a line that lets us match up final makefile output with the
213 # corresponding input files. The curlies are so you can match the
214 # BEGIN/END pairs in a text editor.
215 $makefile .= "# BEGIN{ $parsing_file\n";
220 # lines beginning with '#' are ignored
231 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
239 if ($line =~ /^include (.*)$/) {
241 my $subdir = dirname($filename);
242 $subdir =~ s/^\.$//g;
243 $subdir =~ s/^\.\///g;
244 $subdir .= "/" if ($subdir ne "");
245 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
250 if ($line =~ /^[ \t]*$/) {
252 if ($infragment) { $makefile.="\n"; }
256 # global stuff is considered part of the makefile
257 if ($section eq "GLOBAL") {
258 if (!$infragment) { $makefile.="\n"; }
266 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
267 $result->{$section}{$1}{VAL} = $2;
268 $result->{$section}{$1}{KEY} = $1;
273 die("$parsing_file:$linenum: Bad line while parsing $parsing_file");
276 $makefile .= "# }END $parsing_file\n";
278 foreach my $section (keys %{$result}) {
279 my ($type, $name) = split(/::/, $section, 2);
281 my $sectype = $section_types->{$type};
282 if (not defined($sectype)) {
283 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
286 $input->{$name}{NAME} = $name;
287 $input->{$name}{TYPE} = $type;
288 $input->{$name}{MK_FILE} = $parsing_file;
289 $input->{$name}{BASEDIR} = $basedir;
291 foreach my $key (values %{$result->{$section}}) {
292 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
293 my $vartype = $sectype->{$key->{KEY}};
294 if (not defined($vartype)) {
295 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
297 if ($vartype eq "string") {
298 $input->{$name}{$key->{KEY}} = $key->{VAL};
299 } elsif ($vartype eq "list") {
300 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
301 } elsif ($vartype eq "bool") {
302 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
303 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
305 $input->{$name}{$key->{KEY}} = $key->{VAL};