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;
14 my %attribute_types = (
16 "REQUIRED_SUBSYSTEMS" => "list",
17 "OUTPUT_TYPE" => "string",
18 "INIT_OBJ_FILES" => "list",
19 "ADD_OBJ_FILES" => "list",
20 "OBJ_FILES" => "list",
21 "SUBSYSTEM" => "string",
25 "INSTALLDIR" => "string",
27 "INIT_FUNCTION" => "string",
28 "MAJOR_VERSION" => "string",
29 "MINOR_VERSION" => "string",
30 "RELEASE_VERSION" => "string",
36 use vars qw(@parsed_files);
40 ###########################################################
41 # The parsing function which parses the file
43 # $result = _parse_config_mk($filename)
45 # $filename - the path of the config.mk file
46 # which should be parsed
49 sub run_config_mk($$);
50 my ($input, $filename) = @_;
54 my $section = "GLOBAL";
57 push (@parsed_files, $filename);
59 open(CONFIG_MK, $filename) or die("Can't open `$filename'\n");
60 my @lines = <CONFIG_MK>;
69 # lines beginning with '#' are ignored
80 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)
88 if ($line =~ /^include (.*)$/) {
89 $makefile .= run_config_mk($input, $1);
94 if ($line =~ /^[ \t]*$/) {
96 if ($infragment) { $makefile.="\n"; }
100 # global stuff is considered part of the makefile
101 if ($section eq "GLOBAL") {
109 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
110 $result->{$section}{$1}{VAL} = $2;
111 $result->{$section}{$1}{KEY} = $1;
116 die("$filename:$linenum: Bad line while parsing $filename");
119 foreach my $section (keys %{$result}) {
120 my ($type, $name) = split(/::/, $section, 2);
122 $input->{$name}{NAME} = $name;
123 $input->{$name}{TYPE} = $type;
125 foreach my $key (values %{$result->{$section}}) {
126 $key->{VAL} = smb_build::input::strtrim($key->{VAL});
127 my $vartype = $attribute_types{$key->{KEY}};
128 if (not defined($vartype)) {
129 die("$filename:Unknown attribute $key->{KEY} with value $key->{VAL} in section $section");
131 if ($vartype eq "string") {
132 $input->{$name}{$key->{KEY}} = $key->{VAL};
133 } elsif ($vartype eq "list") {
134 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
135 } elsif ($vartype eq "bool") {
136 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
137 die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
139 $input->{$name}{$key->{KEY}} = $key->{VAL};