1 ###########################################################
2 ### SMB Build System ###
3 ### - config.mk parsing functions ###
5 ### Copyright (C) Stefan (metze) Metzmacher 2004 ###
6 ### Released under the GNU GPL ###
7 ###########################################################
9 package smb_build::config_mk;
22 "INIT_FUNCTION" => "string",
23 "INIT_OBJ_FILES" => "list",
24 "ADD_OBJ_FILES" => "list",
25 "OBJ_FILES" => "list",
27 "REQUIRED_SUBSYSTEMS" => "list",
28 "TARGET_DEPS" => "list",
33 "MANPAGE" => "string",
36 "SUBSYSTEM" => "string",
38 "INIT_FUNCTION" => "string",
39 "INIT_OBJ_FILES" => "list",
40 "ADD_OBJ_FILES" => "list",
41 "OBJ_FILES" => "list",
43 "REQUIRED_SUBSYSTEMS" => "list",
44 "TARGET_DEPS" => "list",
49 "MANPAGE" => "string",
52 "OBJ_FILES" => "list",
54 "REQUIRED_SUBSYSTEMS" => "list",
55 "TARGET_DEPS" => "list",
60 "MANPAGE" => "string",
61 "INSTALLDIR" => "string",
64 "MAJOR_VERSION" => "string",
65 "MINOR_VERSION" => "string",
66 "RELEASE_VERSION" => "string",
68 "OBJ_FILES" => "list",
70 "REQUIRED_SUBSYSTEMS" => "list",
71 "TARGET_DEPS" => "list",
76 "MANPAGE" => "string",
77 "INSTALLDIR" => "string",
81 use vars qw(@parsed_files);
85 ###########################################################
86 # The parsing function which parses the file
88 # $result = _parse_config_mk($filename)
90 # $filename - the path of the config.mk file
91 # which should be parsed
94 sub run_config_mk($$);
95 my ($input, $filename) = @_;
99 my $section = "GLOBAL";
102 push (@parsed_files, $filename);
104 open(CONFIG_MK, $filename) or die("Can't open `$filename'\n");
105 my @lines = <CONFIG_MK>;
114 # lines beginning with '#' are ignored
125 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)
133 if ($line =~ /^include (.*)$/) {
134 $makefile .= run_config_mk($input, $1);
139 if ($line =~ /^[ \t]*$/) {
141 if ($infragment) { $makefile.="\n"; }
145 # global stuff is considered part of the makefile
146 if ($section eq "GLOBAL") {
154 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
155 $result->{$section}{$1}{VAL} = $2;
156 $result->{$section}{$1}{KEY} = $1;
161 die("$filename:$linenum: Bad line while parsing $filename");
164 foreach my $section (keys %{$result}) {
165 my ($type, $name) = split(/::/, $section, 2);
167 my $sectype = $section_types->{$type};
168 if (not defined($sectype)) {
169 die($filename.":[".$section."] unknown section type \"".$type."\"!");
172 $input->{$name}{NAME} = $name;
173 $input->{$name}{TYPE} = $type;
175 foreach my $key (values %{$result->{$section}}) {
176 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
177 my $vartype = $sectype->{$key->{KEY}};
178 if (not defined($vartype)) {
179 die($filename.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
181 if ($vartype eq "string") {
182 $input->{$name}{$key->{KEY}} = $key->{VAL};
183 } elsif ($vartype eq "list") {
184 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
185 } elsif ($vartype eq "bool") {
186 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
187 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
189 $input->{$name}{$key->{KEY}} = $key->{VAL};