r14511: Install more headers
[gd/samba/.git] / source4 / build / smb_build / config_mk.pm
1 # Samba Build System
2 # - config.mk parsing functions
3 #
4 #  Copyright (C) Stefan (metze) Metzmacher 2004
5 #  Copyright (C) Jelmer Vernooij 2005
6 #  Released under the GNU GPL
7 #
8
9 package smb_build::config_mk;
10 use smb_build::input;
11 use File::Basename;
12
13 use strict;
14
15 my $section_types = {
16         "EXT_LIB" => {
17                 "LIBS"                  => "list",
18                 "CFLAGS"                => "list",
19                 "CPPFLAGS"              => "list",
20                 "LDFLAGS"               => "list",
21                 },
22         "SUBSYSTEM" => {
23                 "OBJ_FILES"             => "list",
24
25                 "REQUIRED_SUBSYSTEMS"   => "list",
26
27                 "ENABLE"                => "bool",
28
29                 "MANPAGE"               => "string",
30
31                 "PUBLIC_PROTO_HEADER"   => "string",
32                 "PRIVATE_PROTO_HEADER"  => "string",
33
34                 "PUBLIC_HEADERS"        => "list",
35
36                 "EXTRA_CFLAGS"          => "string",
37                 "STANDARD_VISIBILITY"   => "string"
38                 },
39         "MODULE" => {
40                 "SUBSYSTEM"             => "string",
41
42                 "INIT_FUNCTION"         => "string",
43                 "OBJ_FILES"             => "list",
44
45                 "REQUIRED_SUBSYSTEMS"   => "list",
46
47                 "ENABLE"                => "bool",
48
49                 "OUTPUT_TYPE"           => "string",
50
51                 "MANPAGE"               => "string",
52                 "PRIVATE_PROTO_HEADER"  => "string",
53
54                 "EXTRA_CFLAGS"          => "string"
55                 },
56         "BINARY" => {
57                 "OBJ_FILES"             => "list",
58
59                 "REQUIRED_SUBSYSTEMS"   => "list",
60
61                 "ENABLE"                => "bool",
62
63                 "MANPAGE"               => "string",
64                 "INSTALLDIR"            => "string",
65                 "PRIVATE_PROTO_HEADER"  => "string",
66                 "PUBLIC_PROTO_HEADER"   => "string",
67                 "PUBLIC_HEADERS"        => "list", 
68
69                 "EXTRA_CFLAGS"          => "string"
70                 },
71         "LIBRARY" => {
72                 "VERSION"               => "string",
73                 "SO_VERSION"            => "string",
74                 
75                 "INIT_FUNCTION_TYPE"    => "string",
76
77                 "OBJ_FILES"             => "list",
78
79                 "DESCRIPTION"           => "string",
80
81                 "REQUIRED_SUBSYSTEMS"   => "list",
82
83                 "ENABLE"                => "bool",
84
85                 "MANPAGE"               => "string",
86
87                 "PUBLIC_HEADERS"        => "list",
88
89                 "PUBLIC_PROTO_HEADER"   => "string",
90                 "PRIVATE_PROTO_HEADER"  => "string",
91
92                 "EXTRA_CFLAGS"          => "string",
93                 "STANDARD_VISIBILITY"   => "string"
94                 }
95 };
96
97 use vars qw(@parsed_files);
98
99 @parsed_files = ();
100
101 ###########################################################
102 # The parsing function which parses the file
103 #
104 # $result = _parse_config_mk($filename)
105 #
106 # $filename -   the path of the config.mk file
107 #               which should be parsed
108 sub run_config_mk($$$)
109 {
110         sub run_config_mk($$$);
111         my ($input, $srcdir, $filename) = @_;
112         my $result;
113         my $linenum = -1;
114         my $infragment = 0;
115         my $section = "GLOBAL";
116         my $makefile = "";
117
118         push (@parsed_files, $srcdir."/".$filename);
119         
120         open(CONFIG_MK, $srcdir."/".$filename) or die("Can't open `$srcdir/$filename'\n");
121         my @lines = <CONFIG_MK>;
122         close(CONFIG_MK);
123
124         my $line = "";
125         my $prev = "";
126
127         foreach (@lines) {
128                 $linenum++;
129
130                 # lines beginning with '#' are ignored
131                 next if (/^\#.*$/);
132                 
133                 if (/^(.*)\\$/) {
134                         $prev .= $1;
135                         next;
136                 } else {
137                         $line = "$prev$_";
138                         $prev = "";
139                 }
140
141                 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/) 
142                 {
143                         $section = $1;
144                         $infragment = 0;
145                         next;
146                 }
147
148                 # include
149                 if ($line =~ /^include (.*)$/) {
150                         $makefile .= run_config_mk($input, $srcdir, dirname($filename)."/$1");
151                         next;
152                 }
153
154                 # empty line
155                 if ($line =~ /^[ \t]*$/) {
156                         $section = "GLOBAL";
157                         if ($infragment) { $makefile.="\n"; }
158                         next;
159                 }
160
161                 # global stuff is considered part of the makefile
162                 if ($section eq "GLOBAL") {
163                         if (!$infragment) { $makefile.="\n"; }
164                         $makefile .= $line;
165                         $infragment = 1;
166                         next;
167                 }
168
169                 
170                 # Assignment
171                 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
172                         $result->{$section}{$1}{VAL} = $2;
173                         $result->{$section}{$1}{KEY} = $1;
174                 
175                         next;
176                 }
177
178                 die("$srcdir."/".$filename:$linenum: Bad line while parsing $srcdir."/".$filename");
179         }
180
181         foreach my $section (keys %{$result}) {
182                 my ($type, $name) = split(/::/, $section, 2);
183
184                 my $sectype = $section_types->{$type};
185                 if (not defined($sectype)) {
186                         die($srcdir."/".$filename.":[".$section."] unknown section type \"".$type."\"!");
187                 }
188
189                 $input->{$name}{NAME} = $name;
190                 $input->{$name}{TYPE} = $type;
191                 $input->{$name}{BASEDIR} = dirname($filename);
192
193                 foreach my $key (values %{$result->{$section}}) {
194                         $key->{VAL} = smb_build::input::strtrim($key->{VAL});
195                         my $vartype = $sectype->{$key->{KEY}};
196                         if (not defined($vartype)) {
197                                 die($srcdir."/".$filename.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
198                         }
199                         if ($vartype eq "string") {
200                                 $input->{$name}{$key->{KEY}} = $key->{VAL};
201                         } elsif ($vartype eq "list") {
202                                 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
203                         } elsif ($vartype eq "bool") {
204                                 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
205                                         die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
206                                 }
207                                 $input->{$name}{$key->{KEY}} = $key->{VAL};
208                         }
209                 }
210         }
211
212         return $makefile;
213 }
214
215 1;