1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
###########################################################
### SMB Build System ###
### - config.mk parsing functions ###
### ###
### Copyright (C) Stefan (metze) Metzmacher 2004 ###
### Released under the GNU GPL ###
###########################################################
package smb_build::config_mk;
use smb_build::input;
use strict;
my %attribute_types = (
"NOPROTO" => "bool",
"REQUIRED_SUBSYSTEMS" => "list",
"OUTPUT_TYPE" => "string",
"INIT_OBJ_FILES" => "list",
"ADD_OBJ_FILES" => "list",
"OBJ_FILES" => "list",
"SUBSYSTEM" => "string",
"CFLAGS" => "list",
"CPPFLAGS" => "list",
"LDFLAGS" => "list",
"INSTALLDIR" => "string",
"LIBS" => "list",
"INIT_FUNCTION" => "string",
"MAJOR_VERSION" => "string",
"MINOR_VERSION" => "string",
"RELEASE_VERSION" => "string",
"ENABLE" => "bool",
"CMD" => "string",
"MANPAGE" => "string"
);
use vars qw(@parsed_files);
@parsed_files = ();
###########################################################
# The parsing function which parses the file
#
# $result = _parse_config_mk($filename)
#
# $filename - the path of the config.mk file
# which should be parsed
sub run_config_mk($$)
{
sub run_config_mk($$);
my ($input, $filename) = @_;
my $result;
my $linenum = -1;
my $infragment = 0;
my $section = "GLOBAL";
my $makefile = "";
push (@parsed_files, $filename);
open(CONFIG_MK, $filename) or die("Can't open `$filename'\n");
my @lines = <CONFIG_MK>;
close(CONFIG_MK);
my $line = "";
my $prev = "";
foreach (@lines) {
$linenum++;
# lines beginning with '#' are ignored
next if (/^\#.*$/);
if (/^(.*)\\$/) {
$prev .= $1;
next;
} else {
$line = "$prev$_";
$prev = "";
}
if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/)
{
$section = $1;
$infragment = 0;
next;
}
# include
if ($line =~ /^include (.*)$/) {
$makefile .= run_config_mk($input, $1);
next;
}
# empty line
if ($line =~ /^[ \t]*$/) {
$section = "GLOBAL";
if ($infragment) { $makefile.="\n"; }
next;
}
# global stuff is considered part of the makefile
if ($section eq "GLOBAL") {
$makefile .= $line;
$infragment = 1;
next;
}
# Assignment
if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
$result->{$section}{$1}{VAL} = $2;
$result->{$section}{$1}{KEY} = $1;
next;
}
die("$filename:$linenum: Bad line while parsing $filename");
}
foreach my $section (keys %{$result}) {
my ($type, $name) = split(/::/, $section, 2);
$input->{$name}{NAME} = $name;
$input->{$name}{TYPE} = $type;
foreach my $key (values %{$result->{$section}}) {
$key->{VAL} = smb_build::input::strtrim($key->{VAL});
my $vartype = $attribute_types{$key->{KEY}};
if (not defined($vartype)) {
die("$filename:Unknown attribute $key->{KEY} with value $key->{VAL} in section $section");
}
if ($vartype eq "string") {
$input->{$name}{$key->{KEY}} = $key->{VAL};
} elsif ($vartype eq "list") {
$input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
} elsif ($vartype eq "bool") {
if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
}
$input->{$name}{$key->{KEY}} = $key->{VAL};
}
}
}
return $makefile;
}
1;
|