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;
266 my $got_private_deps = 0;
268 foreach my $k (keys %{$sec}) {
271 next if ($k eq "SECNUMBER");
272 next if ($k eq "TYPE");
273 if ($k eq "INIT_FUNCTION") {
274 $trailer .= sprintf(",\n\tinit_function='%s'", trim($sec->{$k}));
277 if ($k eq "INIT_FUNCTION_SENTINEL") {
278 $trailer .= sprintf(",\n\tinit_function_sentinal='%s'", trim($sec->{$k}));
281 if ($k eq "_PY_FILES" ||
282 $k eq "EPYDOC_OPTIONS" ||
283 $k eq "COV_TARGET" ||
286 $k eq "CONFIG4FILE" ||
287 $k eq "LMHOSTSFILE4") {
288 $trailer .= sprintf(",\n\t# %s='%s'", $k, trim($sec->{$k}));
291 if ($k eq "SUBSYSTEM") {
292 $trailer .= sprintf(",\n\tsubsystem='%s'", trim($sec->{$k}));
295 if ($k eq "PRIVATE_DEPENDENCIES") {
296 $trailer .= sprintf(",\n\tdeps='%s'", strlist($sec->{$k}));
297 $got_private_deps = 1;
300 if ($k eq "PUBLIC_DEPENDENCIES") {
301 $trailer .= sprintf(",\n\tpublic_deps='%s'", strlist($sec->{$k}));
304 if ($k eq "ALIASES") {
305 $trailer .= sprintf(",\n\taliases='%s'", strlist($sec->{$k}));
308 if ($k eq "CFLAGS") {
309 $trailer .= sprintf(",\n\tcflags='%s'", strlist($sec->{$k}));
312 if ($k eq "OPTIONS") {
313 $trailer .= sprintf(",\n\toptions='%s'", strlist($sec->{$k}));
316 if ($k eq "DIRECTORY") {
317 $trailer .= sprintf(",\n\tdirectory='%s'", strlist($sec->{$k}));
320 if ($k eq "LDFLAGS") {
321 $trailer .= sprintf(",\n\tldflags='%s'", strlist($sec->{$k}));
324 if ($k eq "INSTALLDIR") {
325 $trailer .= sprintf(",\n\tinstalldir='%s'", strlist($sec->{$k}));
329 $trailer .= sprintf(",\n\tcompiler='%s'", strlist($sec->{$k}));
332 if ($k eq "ET_COMPILER") {
333 $trailer .= sprintf(",\n\tcompiler='%s'", strlist($sec->{$k}));
336 if ($k eq "ENABLE") {
337 my $v = strlist($sec->{$k});
339 $trailer .= sprintf(",\n\tenabled=False");
342 next if ($v eq "YES");
343 die("Unknown ENABLE value $v in $s\n");
345 if ($k eq "USE_HOSTCC") {
346 my $v = strlist($sec->{$k});
348 $trailer .= sprintf(",\n\tuse_hostcc=True");
351 next if ($v eq "NO");
352 die("Unknown HOST_CC value $v in $s\n");
354 if ($k eq "$s" . "_VERSION") {
355 $trailer .= sprintf(",\n\tvnum='%s'", strlist($sec->{$k}));
358 if ($k eq "$s" . "_SOVERSION") {
361 if ($k eq "LIBRARY_REALNAME") {
362 $trailer .= sprintf(",\n\trealname='%s'", strlist($sec->{$k}));
365 if ($k eq "OUTPUT_TYPE") {
366 $trailer .= sprintf(",\n\toutput_type='%s'", strlist($sec->{$k}));
369 if ($k eq "AUTOPROTO") {
370 my $list = trim(find_files(strlist($sec->{$k})));
371 $trailer .= sprintf(",\n\tautoproto='%s'", $list);
374 if ($k eq "PUBLIC_HEADERS") {
375 my $list = trim(strlist($sec->{$k}));
376 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
377 $list = trim("$1 $2");
378 $list = find_files($list);
380 $list = trim(find_files(strlist($sec->{$k})));
382 $trailer .= sprintf(",\n\tpublic_headers='%s'", $list);
385 if ($k eq "MANPAGES") {
386 my $list = trim(find_files(strlist($sec->{$k})));
387 $trailer .= sprintf(",\n\tmanpages='%s'", $list);
390 if ($k eq "$s" . "_OBJ_FILES") {
391 my $list = trim(strlist($sec->{$k}));
393 $list =~ s/\.ho/.c/g;
394 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
395 $list = trim("$1 $2");
396 $list = find_files($list);
398 } elsif ($list =~ /\$\(addprefix \$\((\w+)\)(.*),(.*)\)(.*)$/) {
402 my $res = "bld.SUBDIR('$dir', '$src')";
404 $res = "$res + '$4'";
408 $list = find_files($list);
411 $list =~ s/\$\(\w+srcdir\)\///g;
412 printf(",\n\tsource=%s", $list);
416 if ($k eq "HEIMDAL_GSSAPI_KRB5_OBJ_FILES" ||
417 $k eq "HEIMDAL_GSSAPI_SPNEGO_OBJ_FILES" ||
418 $k eq "HEIMDAL_HEIM_ASN1_DER_OBJ_FILES" ||
419 $k eq "HEIMDAL_HX509_OBJH_FILES" ||
420 $k eq "HEIMDAL_HX509_OBJG_FILES" ||
421 $k eq "HEIMDAL_ROKEN_OBJ_FILES"
425 die("Unknown keyword $k in $s\n");
427 die("No source list in $s\n") unless $got_src or $got_private_deps;
429 printf(",source=''\n\t");
431 printf("%s\n\t)\n\n", $trailer);
436 for (my $i=0; $i <= $#ARGV; $i++) {
437 my $filename=$ARGV[$i];
438 $dname=dirname($filename);
439 my $result = read_config_mk($filename);
443 print "# AUTOGENERATED by mktowscript.pl from $filename\n# Please remove this notice if hand editing\n\n";
444 die("Unable to chdir to $dname\n") unless chdir($dname);
445 process_results($result);