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",
48 "INIT_FUNCTION_SENTINEL" => "string"
51 "SUBSYSTEM" => "string",
53 "INIT_FUNCTION" => "string",
54 "OBJ_FILES" => "list",
56 "PRIVATE_DEPENDENCIES" => "list",
62 "OUTPUT_TYPE" => "list",
64 "MANPAGE" => "string",
65 "PRIVATE_PROTO_HEADER" => "string",
70 "OBJ_FILES" => "list",
72 "PRIVATE_DEPENDENCIES" => "list",
76 "MANPAGE" => "string",
77 "INSTALLDIR" => "string",
78 "PRIVATE_PROTO_HEADER" => "string",
82 "STANDARD_VISIBILITY" => "string",
84 "USE_HOSTCC" => "bool"
87 "VERSION" => "string",
88 "SO_VERSION" => "string",
89 "LIBRARY_REALNAME" => "string",
91 "INIT_FUNCTION_TYPE" => "string",
92 "INIT_FUNCTION_SENTINEL" => "string",
93 "OUTPUT_TYPE" => "list",
95 "OBJ_FILES" => "list",
97 "DESCRIPTION" => "string",
99 "PRIVATE_DEPENDENCIES" => "list",
100 "PUBLIC_DEPENDENCIES" => "list",
104 "MANPAGE" => "string",
106 "PUBLIC_HEADERS" => "list",
108 "PUBLIC_PROTO_HEADER" => "string",
109 "PRIVATE_PROTO_HEADER" => "string",
113 "STANDARD_VISIBILITY" => "string"
117 use vars qw(@parsed_files);
121 sub _read_config_file
127 my $builddir = shift;
128 my $filename = shift;
131 # We need to change our working directory because config.mk files can
132 # give shell commands as the argument to "include". These shell
133 # commands can take arguments that are relative paths and we don't have
134 # a way of sensibly rewriting these.
138 if ($srcdir ne $builddir) {
139 # Push the builddir path on the front, so we prefer builddir
140 # to srcdir when the file exists in both.
141 @dirlist = ($builddir, $srcdir);
143 @dirlist = ($srcdir);
146 foreach my $d (@dirlist) {
153 # We need to catch the exception from open in the case where
154 # the filename is actually a shell pipeline. Why is this
155 # different to opening a regular file? Because this is perl!
157 open(CONFIG_MK, "./$filename");
158 @lines = <CONFIG_MK>;
163 next unless (@lines);
165 # I blame abartlett for this crazy hack -- jpeach
166 if ($filename =~ /\|$/) {
167 $basedir = $builddir;
169 $basedir = dirname($filename);
170 push(@parsed_files, $filename);
172 $basedir =~ s!^($builddir|$srcdir)[/]!!;
173 return ($filename, $basedir, @lines);
180 ###########################################################
181 # The parsing function which parses the file
183 # $result = _parse_config_mk($input, $srcdir, $builddir, $filename)
185 # $filename - the path of the config.mk file
186 # which should be parsed
187 sub run_config_mk($$$$)
189 sub run_config_mk($$$$);
190 my ($input, $srcdir, $builddir, $filename) = @_;
194 my $section = "GLOBAL";
202 $ENV{builddir} = $builddir;
203 $ENV{srcdir} = $srcdir;
205 ($parsing_file, $basedir, @lines) =
206 _read_config_file($srcdir, $builddir, $filename);
208 die ("$0: can't open '$filename'")
209 unless ($parsing_file and $basedir and @lines);
214 # Emit a line that lets us match up final makefile output with the
215 # corresponding input files. The curlies are so you can match the
216 # BEGIN/END pairs in a text editor.
217 $makefile .= "# BEGIN{ $parsing_file\n";
218 $makefile .= "dir = $basedir\n";
223 # lines beginning with '#' are ignored
234 if ($line =~ /^\[([-a-zA-Z0-9_:]+)\][\t ]*$/)
242 if ($line =~ /^include (.*)$/) {
244 my $subdir = dirname($filename);
245 $subdir =~ s/^\.$//g;
246 $subdir =~ s/^\.\///g;
247 $subdir .= "/" if ($subdir ne "");
248 $makefile .= run_config_mk($input, $srcdir, $builddir, $subdir.$subfile);
253 if ($line =~ /^[ \t]*$/) {
255 if ($infragment) { $makefile.="\n"; }
259 # global stuff is considered part of the makefile
260 if ($section eq "GLOBAL") {
261 if (!$infragment) { $makefile.="\n"; }
269 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
270 $result->{$section}{$1}{VAL} = $2;
271 $result->{$section}{$1}{KEY} = $1;
276 die("$parsing_file:$linenum: Bad line while parsing $parsing_file");
279 $makefile .= "# }END $parsing_file\n";
281 foreach my $section (keys %{$result}) {
282 my ($type, $name) = split(/::/, $section, 2);
284 my $sectype = $section_types->{$type};
285 if (not defined($sectype)) {
286 die($parsing_file.":[".$section."] unknown section type \"".$type."\"!");
289 $input->{$name}{NAME} = $name;
290 $input->{$name}{TYPE} = $type;
291 $input->{$name}{MK_FILE} = $parsing_file;
292 $input->{$name}{BASEDIR} = $basedir;
294 foreach my $key (values %{$result->{$section}}) {
295 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
296 my $vartype = $sectype->{$key->{KEY}};
297 if (not defined($vartype)) {
298 die($parsing_file.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
300 if ($vartype eq "string") {
301 $input->{$name}{$key->{KEY}} = $key->{VAL};
302 } elsif ($vartype eq "list") {
303 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
304 } elsif ($vartype eq "bool") {
305 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
306 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
308 $input->{$name}{$key->{KEY}} = $key->{VAL};