8 my $dname=dirname($filename);
13 open(CONFIG_MK, "$filename");
14 my @lines = <CONFIG_MK>;
30 $s =~ s/\$\(SHLIBEXT\)/so/g;
31 $s =~ s/\$\(heimdalsrcdir\)/..\/heimdal/g;
32 $s =~ s/\$\(heimdalbuildsrcdir\)/..\/heimdal_build/g;
33 $s =~ s/\$\(nsswitchsrcdir\)/..\/nsswitch/g;
34 $s =~ s/\$\(param_OBJ_FILES\)/..\/pyparam.c/g;
35 $s =~ s/\$\(libclisrcdir\)\///g;
37 return trim(join(' ', split(/\s+/, $s)));
51 #printf(STDERR "Trying $f in $dname\n");
55 $f2 = `find . -name $f -type f`;
56 return $f2 unless ($f2 eq "");
57 $f2 = `find .. -name $f -type f`;
58 return $f2 unless ($f2 eq "");
59 $f2 = `find ../.. -name $f -type f`;
60 return $f2 unless ($f2 eq "");
61 $f2 = `find ../../.. -name $f -type f`;
62 return $f2 unless ($f2 eq "");
63 printf(STDERR "Failed to find $orig in $dname\n");
72 foreach my $f (split(/\s+/, $list)) {
83 my @lines = read_file($filename);
86 my $section = "GLOBAL";
92 $result->{"GLOBAL"}->{SECNUMBER} = $secnumber++;
97 # lines beginning with '#' are ignored
108 if ($line =~ /^\[(\w+)::([\w-]+)\]/)
114 $result->{$section}->{TYPE} = $type;
115 $result->{$section}->{SECNUMBER} = $secnumber++;
120 if ($line =~ /^mkinclude (.*)$/) {
122 $result->{$subfile}->{TYPE} = 'SUBCONFIG';
123 $result->{$subfile}->{SECNUMBER} = $secnumber++;
128 if ($line =~ /^[ \t]*$/) {
132 # global stuff is considered part of the makefile
133 if ($section eq "GLOBAL") {
139 if ($line =~ /^([a-zA-Z0-9_-]+)[\t ]*=(.*)$/) {
140 $result->{$section}->{$1} = $2;
145 if ($line =~ /^([a-zA-Z0-9_-]+)[\t ]*\+=(.*)$/) {
146 if (!$result->{$section}->{$1}) {
147 $result->{$section}->{$1}="";
149 $result->{$section}->{$1} .= " " . $2;
153 if ($line =~ /\$\(eval.\$\(call.proto_header_template.*,(.*),.*/) {
154 $result->{$section}->{AUTOPROTO} = $1;
156 if ($line =~ /^\$\(eval/) {
157 # skip eval lines for now
161 printf(STDERR "$linenum: Bad line: $line\n");
168 my $result = read_config_mk($filename);
170 #print Dumper $result;
172 print "# AUTOGENERATED by mktowscript.pl\n# Please remove this notice if hand editing\n\n";
176 foreach my $s (sort {$result->{$a}->{SECNUMBER} <=> $result->{$b}->{SECNUMBER}} keys %{$result}) {
177 next if ($s eq "GLOBAL");
178 my $sec = $result->{$s};
179 if ($sec->{TYPE} eq "SUBCONFIG") {
182 printf "bld.add_subdirs('%s')\n", dirname($s);
184 printf "\nbld.SAMBA_%s('%s'", $sec->{TYPE}, $s;
188 foreach my $k (keys %{$sec}) {
191 next if ($k eq "SECNUMBER");
192 next if ($k eq "TYPE");
193 if ($k eq "INIT_FUNCTION") {
194 $trailer .= sprintf(",\n\tinit_function='%s'", trim($sec->{$k}));
197 if ($k eq "INIT_FUNCTION_SENTINEL") {
198 $trailer .= sprintf(",\n\tinit_function_sentinal='%s'", trim($sec->{$k}));
201 if ($k eq "_PY_FILES" ||
202 $k eq "EPYDOC_OPTIONS" ||
203 $k eq "COV_TARGET" ||
206 $k eq "PUBLIC_HEADERS" ||
208 $k eq "CONFIG4FILE" ||
209 $k eq "LMHOSTSFILE4") {
210 $trailer .= sprintf(",\n\t# %s='%s'", $k, trim($sec->{$k}));
213 if ($k eq "SUBSYSTEM") {
214 $trailer .= sprintf(",\n\tsubsystem='%s'", trim($sec->{$k}));
217 if ($k eq "PRIVATE_DEPENDENCIES") {
218 $trailer .= sprintf(",\n\tdeps='%s'", strlist($sec->{$k}));
221 if ($k eq "PUBLIC_DEPENDENCIES") {
222 $trailer .= sprintf(",\n\tpublic_deps='%s'", strlist($sec->{$k}));
225 if ($k eq "ALIASES") {
226 $trailer .= sprintf(",\n\taliases='%s'", strlist($sec->{$k}));
229 if ($k eq "CFLAGS") {
230 $trailer .= sprintf(",\n\tcflags='%s'", strlist($sec->{$k}));
233 if ($k eq "LDFLAGS") {
234 $trailer .= sprintf(",\n\tldflags='%s'", strlist($sec->{$k}));
237 if ($k eq "INSTALLDIR") {
238 $trailer .= sprintf(",\n\tinstalldir='%s'", strlist($sec->{$k}));
241 if ($k eq "ENABLE") {
242 my $v = strlist($sec->{$k});
244 $trailer .= sprintf(",\n\tenabled=False");
247 next if ($v eq "YES");
248 die("Unknown ENABLE value $v in $s\n");
250 if ($k eq "$s" . "_VERSION") {
251 $trailer .= sprintf(",\n\tvnum='%s'", strlist($sec->{$k}));
254 if ($k eq "$s" . "_SOVERSION") {
257 if ($k eq "LIBRARY_REALNAME") {
258 $trailer .= sprintf(",\n\trealname='%s'", strlist($sec->{$k}));
261 if ($k eq "OUTPUT_TYPE") {
262 $trailer .= sprintf(",\n\toutput_type='%s'", strlist($sec->{$k}));
265 if ($k eq "AUTOPROTO") {
266 my $list = trim(find_files(strlist($sec->{$k})));
267 $trailer .= sprintf(",\n\tautoproto='%s'", $list);
270 if ($k eq "$s" . "_OBJ_FILES") {
271 my $list = trim(strlist($sec->{$k}));
273 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
274 $list = trim("$1 $2");
275 $list = find_files($list);
277 } elsif ($list =~ /\$\(addprefix \$\((\w+)\)(.*),(.*)\)(.*)$/) {
281 my $res = "bld.SUBDIR('$dir', '$src')";
283 $res = "$res + '$4'";
287 $list = find_files($list);
290 $list =~ s/\$\(\w+srcdir\)\///g;
291 printf(",\n\t%s", $list);
295 die("Unknown keyword $k in $s\n");
297 die("No source list in $s\n") unless $got_src;
298 printf("%s\n\t)\n\n", $trailer);
302 #print Dumper $result;