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 "OBJ_FILES" => "list",
25 "REQUIRED_SUBSYSTEMS" => "list",
30 "MANPAGE" => "string",
32 "PUBLIC_PROTO_HEADER" => "string",
33 "PRIVATE_PROTO_HEADER" => "string",
35 "PUBLIC_HEADERS" => "list",
38 "SUBSYSTEM" => "string",
40 "INIT_FUNCTION" => "string",
41 "OBJ_FILES" => "list",
43 "REQUIRED_SUBSYSTEMS" => "list",
48 "OUTPUT_TYPE" => "string",
50 "MANPAGE" => "string",
51 "PRIVATE_PROTO_HEADER" => "string"
54 "OBJ_FILES" => "list",
56 "REQUIRED_SUBSYSTEMS" => "list",
61 "MANPAGE" => "string",
62 "INSTALLDIR" => "string",
63 "PRIVATE_PROTO_HEADER" => "string",
64 "PUBLIC_HEADERS" => "string"
67 "MAJOR_VERSION" => "string",
68 "MINOR_VERSION" => "string",
69 "RELEASE_VERSION" => "string",
71 "OBJ_FILES" => "list",
73 "DESCRIPTION" => "string",
75 "REQUIRED_SUBSYSTEMS" => "list",
80 "MANPAGE" => "string",
82 "PUBLIC_HEADERS" => "list",
84 "PUBLIC_PROTO_HEADER" => "string",
85 "PRIVATE_PROTO_HEADER" => "string"
89 use vars qw(@parsed_files);
93 ###########################################################
94 # The parsing function which parses the file
96 # $result = _parse_config_mk($filename)
98 # $filename - the path of the config.mk file
99 # which should be parsed
100 sub run_config_mk($$$)
102 sub run_config_mk($$$);
103 my ($input, $srcdir, $filename) = @_;
107 my $section = "GLOBAL";
110 push (@parsed_files, $srcdir."/".$filename);
112 open(CONFIG_MK, $srcdir."/".$filename) or die("Can't open `$srcdir/$filename'\n");
113 my @lines = <CONFIG_MK>;
122 # lines beginning with '#' are ignored
133 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)
141 if ($line =~ /^include (.*)$/) {
142 $makefile .= run_config_mk($input, $srcdir, dirname($filename)."/$1");
147 if ($line =~ /^[ \t]*$/) {
149 if ($infragment) { $makefile.="\n"; }
153 # global stuff is considered part of the makefile
154 if ($section eq "GLOBAL") {
162 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
163 $result->{$section}{$1}{VAL} = $2;
164 $result->{$section}{$1}{KEY} = $1;
169 die("$srcdir."/".$filename:$linenum: Bad line while parsing $srcdir."/".$filename");
172 foreach my $section (keys %{$result}) {
173 my ($type, $name) = split(/::/, $section, 2);
175 my $sectype = $section_types->{$type};
176 if (not defined($sectype)) {
177 die($srcdir."/".$filename.":[".$section."] unknown section type \"".$type."\"!");
180 $input->{$name}{NAME} = $name;
181 $input->{$name}{TYPE} = $type;
182 $input->{$name}{BASEDIR} = dirname($filename);
184 foreach my $key (values %{$result->{$section}}) {
185 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
186 my $vartype = $sectype->{$key->{KEY}};
187 if (not defined($vartype)) {
188 die($srcdir."/".$filename.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
190 if ($vartype eq "string") {
191 $input->{$name}{$key->{KEY}} = $key->{VAL};
192 } elsif ($vartype eq "list") {
193 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
194 } elsif ($vartype eq "bool") {
195 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
196 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
198 $input->{$name}{$key->{KEY}} = $key->{VAL};