6 use List::MoreUtils qw(uniq);
14 open(CONFIG_MK, "$filename");
15 my @lines = <CONFIG_MK>;
31 $s =~ s/\$\(SHLIBEXT\)/so/g;
32 $s =~ s/\$\(heimdalsrcdir\)/..\/heimdal/g;
33 $s =~ s/\$\(heimdalbuildsrcdir\)/..\/heimdal_build/g;
34 $s =~ s/\$\(nsswitchsrcdir\)/..\/nsswitch/g;
35 $s =~ s/\$\(param_OBJ_FILES\)/..\/pyparam.c/g;
36 $s =~ s/\$\(libclisrcdir\)\///g;
37 $s =~ s/\$\(socketwrappersrcdir\)\///g;
38 $s =~ s/\$\(libcompressionsrcdir\)\///g;
39 $s =~ s/\$\(\w*srcdir\)\///g;
40 $s =~ s/\$\(libgpodir\)\///g;
41 $s =~ s/\:\.o=\.ho//g;
44 # this one doesn't exist?
45 $s =~ s/\bLDAP_ENCODE\b//g;
47 # these need to use the library names
48 $s =~ s/\bLIBLDB\b/ldb/g;
49 $s =~ s/\bLDB\b/ldb/g;
50 $s =~ s/\bLIBTALLOC\b/talloc/g;
51 $s =~ s/\bTALLOC\b/talloc/g;
52 $s =~ s/\bLIBTEVENT\b/tevent/g;
53 $s =~ s/\bRESOLV\b/resolv/g;
55 return trim(join(' ', split(/\s+/, $s)));
62 foreach my $v (keys %{$vars}) {
63 if ($s =~ /\$\($v\)/) {
64 $s =~ s/\$\($v\)/$vars->{$v}/g;
68 foreach my $v (keys %{$globals}) {
69 if ($s =~ /\$\($v\)/) {
70 $s =~ s/\$\($v\)/$globals->{$v}/g;
82 printf(STDERR "bad variable expansion for file $orig in $dname\n");
96 $f2 = `find . -name "$f" -type f`;
97 return $f2 unless ($f2 eq "");
98 $f2 = `find .. -name "$f" -type f`;
99 return $f2 unless ($f2 eq "");
100 $f2 = `find ../.. -name "$f" -type f`;
101 return $f2 unless ($f2 eq "");
102 $f2 = `find ../../.. -name "$f" -type f`;
103 return $f2 unless ($f2 eq "");
104 printf(STDERR "Failed to find $orig in $dname\n");
113 foreach my $f (split(/\s+/, $list)) {
114 if ($f =~ /\.[0-9]$/) {
116 my $m = find_file($f . ".xml");
117 die("Unable to find man page $f\n") if ($m eq "");
125 $ret = strlist($ret);
126 my @list = split(/\s+/, $ret);
128 $ret = trim(join(' ', @list));
132 sub read_config_mk($)
134 my $filename = shift;
135 my @lines = read_file($filename);
138 my $section = "GLOBAL";
144 $result->{"GLOBAL"}->{SECNUMBER} = $secnumber++;
149 # lines beginning with '#' are ignored
160 if ($line =~ /^mkinclude.*asn1_deps.pl\s+([^\s]+)\s+([^\s]+)\s+\\\$\\\(\w+\\\)\/([^\s|]+)\s*([^|]*)\|$/) {
165 $section = "HEIMDAL_" . uc($section);
166 $result->{$section}->{TYPE} = 'ASN1';
167 $result->{$section}->{SECNUMBER} = $secnumber++;
168 if ($options ne '') {
169 $result->{$section}->{OPTIONS} = $options;
171 $result->{$section}->{DIRECTORY} = $dir;
172 $result->{$section}->{$section . '_OBJ_FILES'} = $src;
176 if ($line =~ /^mkinclude.*et_deps.pl\s+([^\s]+)\s+\\\$\\\(\w+\\\)\/([^\s|]+)\|$/) {
179 $section = basename($src);
180 $section =~ s/\./_/g;
181 $section = "HEIMDAL_" . uc($section);
182 $result->{$section}->{TYPE} = 'ERRTABLE';
183 $result->{$section}->{SECNUMBER} = $secnumber++;
184 $result->{$section}->{DIRECTORY} = "$dir";
185 $result->{$section}->{$section . '_OBJ_FILES'} = $src;
189 if ($line =~ /^\[(\w+)::([\w-]+)\]/)
195 $result->{$section}->{TYPE} = $type;
196 $result->{$section}->{SECNUMBER} = $secnumber++;
201 if ($line =~ /^mkinclude (.*)$/) {
203 $result->{$subfile}->{TYPE} = 'SUBCONFIG';
204 $result->{$subfile}->{SECNUMBER} = $secnumber++;
209 if ($line =~ /^[ \t]*$/) {
213 # global stuff is considered part of the makefile
214 if ($section eq "GLOBAL") {
220 if ($line =~ /^([a-zA-Z0-9_-]+)[\t ]*=(.*)$/) {
221 $result->{$section}->{$1} = expand_vars($result->{$section}, strlist($2));
222 $globals->{$1} = $result->{$section}->{$1};
227 if ($line =~ /^([a-zA-Z0-9_-]+)[\t ]*\+=(.*)$/) {
228 if (!$result->{$section}->{$1}) {
229 $result->{$section}->{$1}="";
231 $result->{$section}->{$1} .= " " . expand_vars($result->{$section}, strlist($2));
232 $globals->{$1} = $result->{$section}->{$1};
236 if ($line =~ /\$\(eval.\$\(call.proto_header_template.*,(.*),.*/) {
237 $result->{$section}->{AUTOPROTO} = $1;
239 if ($line =~ /^\$\(eval/) {
240 # skip eval lines for now
244 printf(STDERR "$linenum: Bad line: $line");
251 sub process_results($)
255 foreach my $s (sort {$result->{$a}->{SECNUMBER} <=> $result->{$b}->{SECNUMBER}} keys %{$result}) {
256 next if ($s eq "GLOBAL");
257 my $sec = $result->{$s};
258 if ($sec->{TYPE} eq "SUBCONFIG") {
261 printf "bld.BUILD_SUBDIR('%s')\n", dirname($s);
263 printf "\nbld.SAMBA_%s('%s'", $sec->{TYPE}, $s;
267 foreach my $k (keys %{$sec}) {
270 next if ($k eq "SECNUMBER");
271 next if ($k eq "TYPE");
272 if ($k eq "INIT_FUNCTION") {
273 $trailer .= sprintf(",\n\tinit_function='%s'", trim($sec->{$k}));
276 if ($k eq "INIT_FUNCTION_SENTINEL") {
277 $trailer .= sprintf(",\n\tinit_function_sentinal='%s'", trim($sec->{$k}));
280 if ($k eq "_PY_FILES" ||
281 $k eq "EPYDOC_OPTIONS" ||
282 $k eq "COV_TARGET" ||
285 $k eq "CONFIG4FILE" ||
286 $k eq "LMHOSTSFILE4") {
287 $trailer .= sprintf(",\n\t# %s='%s'", $k, trim($sec->{$k}));
290 if ($k eq "SUBSYSTEM") {
291 $trailer .= sprintf(",\n\tsubsystem='%s'", trim($sec->{$k}));
294 if ($k eq "PRIVATE_DEPENDENCIES") {
295 $trailer .= sprintf(",\n\tdeps='%s'", strlist($sec->{$k}));
298 if ($k eq "PUBLIC_DEPENDENCIES") {
299 $trailer .= sprintf(",\n\tpublic_deps='%s'", strlist($sec->{$k}));
302 if ($k eq "ALIASES") {
303 $trailer .= sprintf(",\n\taliases='%s'", strlist($sec->{$k}));
306 if ($k eq "CFLAGS") {
307 $trailer .= sprintf(",\n\tcflags='%s'", strlist($sec->{$k}));
310 if ($k eq "OPTIONS") {
311 $trailer .= sprintf(",\n\toptions='%s'", strlist($sec->{$k}));
314 if ($k eq "DIRECTORY") {
315 $trailer .= sprintf(",\n\tdirectory='%s'", strlist($sec->{$k}));
318 if ($k eq "LDFLAGS") {
319 $trailer .= sprintf(",\n\tldflags='%s'", strlist($sec->{$k}));
322 if ($k eq "INSTALLDIR") {
323 $trailer .= sprintf(",\n\tinstalldir='%s'", strlist($sec->{$k}));
327 $trailer .= sprintf(",\n\tcompiler='%s'", strlist($sec->{$k}));
330 if ($k eq "ET_COMPILER") {
331 $trailer .= sprintf(",\n\tcompiler='%s'", strlist($sec->{$k}));
334 if ($k eq "ENABLE") {
335 my $v = strlist($sec->{$k});
337 $trailer .= sprintf(",\n\tenabled=False");
340 next if ($v eq "YES");
341 die("Unknown ENABLE value $v in $s\n");
343 if ($k eq "USE_HOSTCC") {
344 my $v = strlist($sec->{$k});
346 $trailer .= sprintf(",\n\tuse_hostcc=True");
349 next if ($v eq "NO");
350 die("Unknown HOST_CC value $v in $s\n");
352 if ($k eq "$s" . "_VERSION") {
353 $trailer .= sprintf(",\n\tvnum='%s'", strlist($sec->{$k}));
356 if ($k eq "$s" . "_SOVERSION") {
359 if ($k eq "LIBRARY_REALNAME") {
360 $trailer .= sprintf(",\n\trealname='%s'", strlist($sec->{$k}));
363 if ($k eq "OUTPUT_TYPE") {
364 $trailer .= sprintf(",\n\toutput_type='%s'", strlist($sec->{$k}));
367 if ($k eq "AUTOPROTO") {
368 my $list = trim(find_files(strlist($sec->{$k})));
369 $trailer .= sprintf(",\n\tautoproto='%s'", $list);
372 if ($k eq "PUBLIC_HEADERS") {
373 my $list = trim(strlist($sec->{$k}));
374 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
375 $list = trim("$1 $2");
376 $list = find_files($list);
378 $list = trim(find_files(strlist($sec->{$k})));
380 $trailer .= sprintf(",\n\tpublic_headers='%s'", $list);
383 if ($k eq "MANPAGES") {
384 my $list = trim(find_files(strlist($sec->{$k})));
385 $trailer .= sprintf(",\n\tmanpages='%s'", $list);
388 if ($k eq "$s" . "_OBJ_FILES") {
389 my $list = trim(strlist($sec->{$k}));
391 $list =~ s/\.ho/.c/g;
392 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
393 $list = trim("$1 $2");
394 $list = find_files($list);
396 } elsif ($list =~ /\$\(addprefix \$\((\w+)\)(.*),(.*)\)(.*)$/) {
400 my $res = "bld.SUBDIR('$dir', '$src')";
402 $res = "$res + '$4'";
406 $list = find_files($list);
409 $list =~ s/\$\(\w+srcdir\)\///g;
410 printf(",\n\t%s", $list);
414 if ($k eq "HEIMDAL_GSSAPI_KRB5_OBJ_FILES" ||
415 $k eq "HEIMDAL_GSSAPI_SPNEGO_OBJ_FILES" ||
416 $k eq "HEIMDAL_HEIM_ASN1_DER_OBJ_FILES" ||
417 $k eq "HEIMDAL_HX509_OBJH_FILES" ||
418 $k eq "HEIMDAL_HX509_OBJG_FILES" ||
419 $k eq "HEIMDAL_ROKEN_OBJ_FILES"
423 die("Unknown keyword $k in $s\n");
425 die("No source list in $s\n") unless $got_src;
426 printf("%s\n\t)\n\n", $trailer);
431 for (my $i=0; $i <= $#ARGV; $i++) {
432 my $filename=$ARGV[$i];
433 $dname=dirname($filename);
434 my $result = read_config_mk($filename);
438 print "# AUTOGENERATED by mktowscript.pl from $filename\n# Please remove this notice if hand editing\n\n";
439 die("Unable to chdir to $dname\n") unless chdir($dname);
440 process_results($result);