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;
21 "PC_NAME" => "string",
24 SWIG_FILE => "string",
25 "PRIVATE_DEPENDENCIES" => "list",
26 "PUBLIC_DEPENDENCIES" => "list",
27 "OBJ_FILES" => "list",
33 "OBJ_FILES" => "list",
35 "PRIVATE_DEPENDENCIES" => "list",
36 "PUBLIC_DEPENDENCIES" => "list",
40 "MANPAGE" => "string",
42 "PUBLIC_PROTO_HEADER" => "string",
43 "PRIVATE_PROTO_HEADER" => "string",
45 "PUBLIC_HEADERS" => "list",
49 "STANDARD_VISIBILITY" => "string",
50 "INIT_FUNCTION_SENTINEL" => "string"
53 "SUBSYSTEM" => "string",
55 "INIT_FUNCTION" => "string",
56 "OBJ_FILES" => "list",
58 "PRIVATE_DEPENDENCIES" => "list",
64 "OUTPUT_TYPE" => "list",
66 "MANPAGE" => "string",
67 "PRIVATE_PROTO_HEADER" => "string",
72 "OBJ_FILES" => "list",
74 "PRIVATE_DEPENDENCIES" => "list",
78 "MANPAGE" => "string",
79 "INSTALLDIR" => "string",
80 "PRIVATE_PROTO_HEADER" => "string",
84 "STANDARD_VISIBILITY" => "string",
86 "USE_HOSTCC" => "bool"
89 "VERSION" => "string",
90 "SO_VERSION" => "string",
91 "LIBRARY_REALNAME" => "string",
93 "PC_NAME" => "string",
94 "PC_FILE" => "string",
96 "INIT_FUNCTION_TYPE" => "string",
97 "INIT_FUNCTION_SENTINEL" => "string",
98 "OUTPUT_TYPE" => "list",
100 "OBJ_FILES" => "list",
102 "PRIVATE_DEPENDENCIES" => "list",
103 "PUBLIC_DEPENDENCIES" => "list",
107 "MANPAGE" => "string",
109 "PUBLIC_HEADERS" => "list",
111 "PUBLIC_PROTO_HEADER" => "string",
112 "PRIVATE_PROTO_HEADER" => "string",
116 "STANDARD_VISIBILITY" => "string"
120 use vars qw(@parsed_files);
124 sub _read_config_file
130 my $builddir = shift;
131 my $filename = shift;
134 # We need to change our working directory because config.mk files can
135 # give shell commands as the argument to "include". These shell
136 # commands can take arguments that are relative paths and we don't have
137 # a way of sensibly rewriting these.
141 if ($srcdir ne $builddir) {
142 # Push the builddir path on the front, so we prefer builddir
143 # to srcdir when the file exists in both.
144 @dirlist = ($builddir, $srcdir);
146 @dirlist = ($srcdir);
149 foreach my $d (@dirlist) {
156 # We need to catch the exception from open in the case where
157 # the filename is actually a shell pipeline. Why is this
158 # different to opening a regular file? Because this is perl!
160 open(CONFIG_MK, "./$filename");
161 @lines = <CONFIG_MK>;
166 next unless (@lines);
168 # I blame abartlett for this crazy hack -- jpeach
169 if ($filename =~ /\|$/) {
170 $basedir = $builddir;
172 $basedir = dirname($filename);
173 push(@parsed_files, $filename);
175 $basedir =~ s!^($builddir|$srcdir)[/]!!;
176 return ($filename, $basedir, @lines);
183 ###########################################################
184 # The parsing function which parses the file
186 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
188 # $filename - the path of the config.mk file
189 # which should be parsed
190 sub run_config_mk($$$$)
192 sub run_config_mk($$$$);
193 my ($input, $srcdir, $builddir, $filename) = @_;
197 my $section = "GLOBAL";
205 $ENV{builddir} = $builddir;
206 $ENV{srcdir} = $srcdir;
208 ($parsing_file, $basedir, @lines) =
209 _read_config_file($srcdir, $builddir, $filename);
211 die ("$0: can't open '$filename'")
212 unless ($parsing_file and $basedir and @lines);
217 # Emit a line that lets us match up final makefile output with the
218 # corresponding input files. The curlies are so you can match the
219 # BEGIN/END pairs in a text editor.
220 $makefile .= "# BEGIN{ $parsing_file\n";
225 # lines beginning with '#' are ignored
236 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
244 if ($line =~ /^include (.*)$/) {
246 my $subdir = dirname($filename);
247 $subdir =~ s/^\.$//g;
248 $subdir =~ s/^\.\///g;
249 $subdir .= "/" if ($subdir ne "");
250 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
255 if ($line =~ /^[ \t]*$/) {
257 if ($infragment) { $makefile.="\n"; }
261 # global stuff is considered part of the makefile
262 if ($section eq "GLOBAL") {
263 if (!$infragment) { $makefile.="\n"; }
271 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
272 $result->{$section}{$1}{VAL} = $2;
273 $result->{$section}{$1}{KEY} = $1;
278 die("$parsing_file:$linenum: Bad line while parsing $parsing_file");
281 $makefile .= "# }END $parsing_file\n";
283 foreach my $section (keys %{$result}) {
284 my ($type, $name) = split(/::/, $section, 2);
286 my $sectype = $section_types->{$type};
287 if (not defined($sectype)) {
288 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
291 $input->{$name}{NAME} = $name;
292 $input->{$name}{TYPE} = $type;
293 $input->{$name}{MK_FILE} = $parsing_file;
294 $input->{$name}{BASEDIR} = $basedir;
296 foreach my $key (values %{$result->{$section}}) {
297 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
298 my $vartype = $sectype->{$key->{KEY}};
299 if (not defined($vartype)) {
300 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
302 if ($vartype eq "string") {
303 $input->{$name}{$key->{KEY}} = $key->{VAL};
304 } elsif ($vartype eq "list") {
305 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
306 } elsif ($vartype eq "bool") {
307 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
308 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
310 $input->{$name}{$key->{KEY}} = $key->{VAL};