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",
95 "INIT_FUNCTION_TYPE" => "string",
96 "INIT_FUNCTION_SENTINEL" => "string",
97 "OUTPUT_TYPE" => "list",
99 "OBJ_FILES" => "list",
101 "DESCRIPTION" => "string",
103 "PRIVATE_DEPENDENCIES" => "list",
104 "PUBLIC_DEPENDENCIES" => "list",
108 "MANPAGE" => "string",
110 "PUBLIC_HEADERS" => "list",
112 "PUBLIC_PROTO_HEADER" => "string",
113 "PRIVATE_PROTO_HEADER" => "string",
117 "STANDARD_VISIBILITY" => "string"
121 use vars qw(@parsed_files);
125 sub _read_config_file
131 my $builddir = shift;
132 my $filename = shift;
135 # We need to change our working directory because config.mk files can
136 # give shell commands as the argument to "include". These shell
137 # commands can take arguments that are relative paths and we don't have
138 # a way of sensibly rewriting these.
142 if ($srcdir ne $builddir) {
143 # Push the builddir path on the front, so we prefer builddir
144 # to srcdir when the file exists in both.
145 @dirlist = ($builddir, $srcdir);
147 @dirlist = ($srcdir);
150 foreach my $d (@dirlist) {
157 # We need to catch the exception from open in the case where
158 # the filename is actually a shell pipeline. Why is this
159 # different to opening a regular file? Because this is perl!
161 open(CONFIG_MK, "./$filename");
162 @lines = <CONFIG_MK>;
167 next unless (@lines);
169 # I blame abartlett for this crazy hack -- jpeach
170 if ($filename =~ /\|$/) {
171 $basedir = $builddir;
173 $basedir = dirname($filename);
174 push(@parsed_files, $filename);
176 $basedir =~ s!^($builddir|$srcdir)[/]!!;
177 return ($filename, $basedir, @lines);
184 ###########################################################
185 # The parsing function which parses the file
187 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
189 # $filename - the path of the config.mk file
190 # which should be parsed
191 sub run_config_mk($$$$)
193 sub run_config_mk($$$$);
194 my ($input, $srcdir, $builddir, $filename) = @_;
198 my $section = "GLOBAL";
206 $ENV{builddir} = $builddir;
207 $ENV{srcdir} = $srcdir;
209 ($parsing_file, $basedir, @lines) =
210 _read_config_file($srcdir, $builddir, $filename);
212 die ("$0: can't open '$filename'")
213 unless ($parsing_file and $basedir and @lines);
218 # Emit a line that lets us match up final makefile output with the
219 # corresponding input files. The curlies are so you can match the
220 # BEGIN/END pairs in a text editor.
221 $makefile .= "# BEGIN{ $parsing_file\n";
226 # lines beginning with '#' are ignored
237 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
245 if ($line =~ /^include (.*)$/) {
247 my $subdir = dirname($filename);
248 $subdir =~ s/^\.$//g;
249 $subdir =~ s/^\.\///g;
250 $subdir .= "/" if ($subdir ne "");
251 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
256 if ($line =~ /^[ \t]*$/) {
258 if ($infragment) { $makefile.="\n"; }
262 # global stuff is considered part of the makefile
263 if ($section eq "GLOBAL") {
264 if (!$infragment) { $makefile.="\n"; }
272 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
273 $result->{$section}{$1}{VAL} = $2;
274 $result->{$section}{$1}{KEY} = $1;
279 die("$parsing_file:$linenum: Bad line while parsing $parsing_file");
282 $makefile .= "# }END $parsing_file\n";
284 foreach my $section (keys %{$result}) {
285 my ($type, $name) = split(/::/, $section, 2);
287 my $sectype = $section_types->{$type};
288 if (not defined($sectype)) {
289 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
292 $input->{$name}{NAME} = $name;
293 $input->{$name}{TYPE} = $type;
294 $input->{$name}{MK_FILE} = $parsing_file;
295 $input->{$name}{BASEDIR} = $basedir;
297 foreach my $key (values %{$result->{$section}}) {
298 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
299 my $vartype = $sectype->{$key->{KEY}};
300 if (not defined($vartype)) {
301 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
303 if ($vartype eq "string") {
304 $input->{$name}{$key->{KEY}} = $key->{VAL};
305 } elsif ($vartype eq "list") {
306 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
307 } elsif ($vartype eq "bool") {
308 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
309 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
311 $input->{$name}{$key->{KEY}} = $key->{VAL};