r12498: Eliminate INIT_OBJ_FILES and ADD_OBJ_FILES. We were not using
[jelmer/samba4-debian.git] / source / 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                 "INIT_FUNCTION"         => "string",
24                 "OBJ_FILES"             => "list",
25
26                 "REQUIRED_SUBSYSTEMS"   => "list",
27
28                 "ENABLE"                => "bool",
29                 "NOPROTO"               => "bool",
30
31                 "MANPAGE"               => "string",
32                 },
33         "MODULE" => {
34                 "SUBSYSTEM"             => "string",
35
36                 "INIT_FUNCTION"         => "string",
37                 "OBJ_FILES"             => "list",
38
39                 "REQUIRED_SUBSYSTEMS"   => "list",
40
41                 "ENABLE"                => "bool",
42                 "NOPROTO"               => "bool",
43
44                 "MANPAGE"               => "string",
45                 },
46         "BINARY" => {
47                 "OBJ_FILES"             => "list",
48
49                 "REQUIRED_SUBSYSTEMS"   => "list",
50
51                 "ENABLE"                => "bool",
52                 "NOPROTO"               => "bool",
53
54                 "MANPAGE"               => "string",
55                 "INSTALLDIR"            => "string",
56                 },
57         "LIBRARY" => {
58                 "MAJOR_VERSION"         => "string",
59                 "MINOR_VERSION"         => "string",
60                 "RELEASE_VERSION"       => "string",
61
62                 "INIT_FUNCTION"         => "string",
63                 "OBJ_FILES"             => "list",
64
65                 "DESCRIPTION" => "string",
66
67                 "REQUIRED_SUBSYSTEMS"   => "list",
68
69                 "ENABLE"                => "bool",
70                 "NOPROTO"               => "bool",
71
72                 "MANPAGE"               => "string",
73
74                 "PUBLIC_HEADERS" => "list"
75                 }
76 };
77
78 use vars qw(@parsed_files);
79
80 @parsed_files = ();
81
82 ###########################################################
83 # The parsing function which parses the file
84 #
85 # $result = _parse_config_mk($filename)
86 #
87 # $filename -   the path of the config.mk file
88 #               which should be parsed
89 sub run_config_mk($$)
90 {
91         sub run_config_mk($$);
92         my ($input, $filename) = @_;
93         my $result;
94         my $linenum = -1;
95         my $infragment = 0;
96         my $section = "GLOBAL";
97         my $makefile = "";
98
99         push (@parsed_files, $filename);
100         
101         open(CONFIG_MK, $filename) or die("Can't open `$filename'\n");
102         my @lines = <CONFIG_MK>;
103         close(CONFIG_MK);
104
105         my $line = "";
106         my $prev = "";
107
108         foreach (@lines) {
109                 $linenum++;
110
111                 # lines beginning with '#' are ignored
112                 next if (/^\#.*$/);
113                 
114                 if (/^(.*)\\$/) {
115                         $prev .= $1;
116                         next;
117                 } else {
118                         $line = "$prev$_";
119                         $prev = "";
120                 }
121
122                 if ($line =~ /^\[([a-zA-Z0-9_:]+)\][\t ]*$/) 
123                 {
124                         $section = $1;
125                         $infragment = 0;
126                         next;
127                 }
128
129                 # include
130                 if ($line =~ /^include (.*)$/) {
131                         $makefile .= run_config_mk($input, dirname($filename)."/$1");
132                         next;
133                 }
134
135                 # empty line
136                 if ($line =~ /^[ \t]*$/) {
137                         $section = "GLOBAL";
138                         if ($infragment) { $makefile.="\n"; }
139                         next;
140                 }
141
142                 # global stuff is considered part of the makefile
143                 if ($section eq "GLOBAL") {
144                         $makefile .= $line;
145                         $infragment = 1;
146                         next;
147                 }
148
149                 
150                 # Assignment
151                 if ($line =~ /^([a-zA-Z0-9_]+)[\t ]*=(.*)$/) {
152                         $result->{$section}{$1}{VAL} = $2;
153                         $result->{$section}{$1}{KEY} = $1;
154                 
155                         next;
156                 }
157
158                 die("$filename:$linenum: Bad line while parsing $filename");
159         }
160
161         foreach my $section (keys %{$result}) {
162                 my ($type, $name) = split(/::/, $section, 2);
163
164                 my $sectype = $section_types->{$type};
165                 if (not defined($sectype)) {
166                         die($filename.":[".$section."] unknown section type \"".$type."\"!");
167                 }
168
169                 $input->{$name}{NAME} = $name;
170                 $input->{$name}{TYPE} = $type;
171                 $input->{$name}{BASEDIR} = dirname($filename);
172
173                 foreach my $key (values %{$result->{$section}}) {
174                         $key->{VAL} = smb_build::input::strtrim($key->{VAL});
175                         my $vartype = $sectype->{$key->{KEY}};
176                         if (not defined($vartype)) {
177                                 die($filename.":[".$section."]: unknown attribute type \"$key->{KEY}\"!");
178                         }
179                         if ($vartype eq "string") {
180                                 $input->{$name}{$key->{KEY}} = $key->{VAL};
181                         } elsif ($vartype eq "list") {
182                                 $input->{$name}{$key->{KEY}} = [smb_build::input::str2array($key->{VAL})];
183                         } elsif ($vartype eq "bool") {
184                                 if (($key->{VAL} ne "YES") and ($key->{VAL} ne "NO")) {
185                                         die("Invalid value for bool attribute $key->{KEY}: $key->{VAL} in section $section");
186                                 }
187                                 $input->{$name}{$key->{KEY}} = $key->{VAL};
188                         }
189                 }
190         }
191
192         return $makefile;
193 }
194
195 1;