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 "INIT_FUNCTION" => "string",
24 "OBJ_FILES" => "list",
26 "REQUIRED_SUBSYSTEMS" => "list",
31 "MANPAGE" => "string",
34 "SUBSYSTEM" => "string",
36 "INIT_FUNCTION" => "string",
37 "OBJ_FILES" => "list",
39 "REQUIRED_SUBSYSTEMS" => "list",
44 "MANPAGE" => "string",
47 "OBJ_FILES" => "list",
49 "REQUIRED_SUBSYSTEMS" => "list",
54 "MANPAGE" => "string",
55 "INSTALLDIR" => "string",
58 "MAJOR_VERSION" => "string",
59 "MINOR_VERSION" => "string",
60 "RELEASE_VERSION" => "string",
62 "INIT_FUNCTION" => "string",
63 "OBJ_FILES" => "list",
65 "DESCRIPTION" => "string",
67 "REQUIRED_SUBSYSTEMS" => "list",
72 "MANPAGE" => "string",
74 "PUBLIC_HEADERS" => "list"
78 use vars qw(@parsed_files);
82 ###########################################################
83 # The parsing function which parses the file
85 # $result = _parse_config_mk($filename)
87 # $filename - the path of the config.mk file
88 # which should be parsed
91 sub run_config_mk($$);
92 my ($input, $filename) = @_;
96 my $section = "GLOBAL";
99 push (@parsed_files, $filename);
101 open(CONFIG_MK, $filename) or die("Can't open `$filename'\n");
102 my @lines = <CONFIG_MK>;
111 # lines beginning with '#' are ignored
122 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)
130 if ($line =~ /^include (.*)$/) {
131 $makefile .= run_config_mk($input, dirname($filename)."/$1");
136 if ($line =~ /^[ \t]*$/) {
138 if ($infragment) { $makefile.="\n"; }
142 # global stuff is considered part of the makefile
143 if ($section eq "GLOBAL") {
151 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
152 $result->{$section}{$1}{VAL} = $2;
153 $result->{$section}{$1}{KEY} = $1;
158 die("$filename:$linenum: Bad line while parsing $filename");
161 foreach my $section (keys %{$result}) {
162 my ($type, $name) = split(/::/, $section, 2);
164 my $sectype = $section_types->{$type};
165 if (not defined($sectype)) {
166 die($filename.":[".$section."] unknown section type \"".$type."\"!");
169 $input->{$name}{NAME} = $name;
170 $input->{$name}{TYPE} = $type;
171 $input->{$name}{BASEDIR} = dirname($filename);
173 foreach my $key (values %{$result->{$section}}) {
174 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
175 my $vartype = $sectype->{$key->{KEY}};
176 if (not defined($vartype)) {
177 die($filename.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
179 if ($vartype eq "string") {
180 $input->{$name}{$key->{KEY}} = $key->{VAL};
181 } elsif ($vartype eq "list") {
182 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
183 } elsif ($vartype eq "bool") {
184 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
185 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
187 $input->{$name}{$key->{KEY}} = $key->{VAL};