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/) {
154 # skip eval lines for now
158 printf(STDERR "$linenum: Bad line: $line\n");
165 my $result = read_config_mk($filename);
167 #print Dumper $result;
169 print "# AUTOGENERATED by mktowscript.pl\n# Please remove this notice if hand editing\n\n";
173 foreach my $s (sort {$result->{$a}->{SECNUMBER} <=> $result->{$b}->{SECNUMBER}} keys %{$result}) {
174 next if ($s eq "GLOBAL");
175 my $sec = $result->{$s};
176 if ($sec->{TYPE} eq "SUBCONFIG") {
179 printf "bld.add_subdirs('%s')\n", dirname($s);
181 printf "\nbld.SAMBA_%s('%s'", $sec->{TYPE}, $s;
185 foreach my $k (keys %{$sec}) {
188 next if ($k eq "SECNUMBER");
189 next if ($k eq "TYPE");
190 if ($k eq "INIT_FUNCTION") {
191 $trailer .= sprintf(",\n\tinit_function='%s'", trim($sec->{$k}));
194 if ($k eq "INIT_FUNCTION_SENTINEL") {
195 $trailer .= sprintf(",\n\tinit_function_sentinal='%s'", trim($sec->{$k}));
198 if ($k eq "_PY_FILES" ||
199 $k eq "EPYDOC_OPTIONS" ||
200 $k eq "COV_TARGET" ||
203 $k eq "PUBLIC_HEADERS" ||
205 $k eq "CONFIG4FILE" ||
206 $k eq "LMHOSTSFILE4") {
207 $trailer .= sprintf(",\n\t# %s='%s'", $k, trim($sec->{$k}));
210 if ($k eq "SUBSYSTEM") {
211 $trailer .= sprintf(",\n\tsubsystem='%s'", trim($sec->{$k}));
214 if ($k eq "PRIVATE_DEPENDENCIES") {
215 $trailer .= sprintf(",\n\tdeps='%s'", strlist($sec->{$k}));
218 if ($k eq "PUBLIC_DEPENDENCIES") {
219 $trailer .= sprintf(",\n\tpublic_deps='%s'", strlist($sec->{$k}));
222 if ($k eq "ALIASES") {
223 $trailer .= sprintf(",\n\taliases='%s'", strlist($sec->{$k}));
226 if ($k eq "CFLAGS") {
227 $trailer .= sprintf(",\n\tcflags='%s'", strlist($sec->{$k}));
230 if ($k eq "LDFLAGS") {
231 $trailer .= sprintf(",\n\tldflags='%s'", strlist($sec->{$k}));
234 if ($k eq "INSTALLDIR") {
235 $trailer .= sprintf(",\n\tinstalldir='%s'", strlist($sec->{$k}));
238 if ($k eq "ENABLE") {
239 my $v = strlist($sec->{$k});
241 $trailer .= sprintf(",\n\tenabled=False");
244 next if ($v eq "YES");
245 die("Unknown ENABLE value $v in $s\n");
247 if ($k eq "$s" . "_VERSION") {
248 $trailer .= sprintf(",\n\tvnum='%s'", strlist($sec->{$k}));
251 if ($k eq "$s" . "_SOVERSION") {
254 if ($k eq "LIBRARY_REALNAME") {
255 $trailer .= sprintf(",\n\trealname='%s'", strlist($sec->{$k}));
258 if ($k eq "OUTPUT_TYPE") {
259 $trailer .= sprintf(",\n\toutput_type='%s'", strlist($sec->{$k}));
262 if ($k eq "$s" . "_OBJ_FILES") {
263 my $list = trim(strlist($sec->{$k}));
265 if ($list =~ /\$\(addprefix .*,(.*)\)(.*)$/) {
266 $list = trim("$1 $2");
267 $list = find_files($list);
269 } elsif ($list =~ /\$\(addprefix \$\((\w+)\)(.*),(.*)\)(.*)$/) {
273 my $res = "bld.SUBDIR('$dir', '$src')";
275 $res = "$res + '$4'";
279 $list = find_files($list);
282 $list =~ s/\$\(\w+srcdir\)\///g;
283 printf(",\n\t%s", $list);
287 die("Unknown keyword $k in $s\n");
289 die("No source list in $s\n") unless $got_src;
290 printf("%s\n\t)\n\n", $trailer);
294 #print Dumper $result;