msvcp80: Fix ostreambuf_iterator<char> structure definition.
[wine/multimedia.git] / tools / make_makefiles
blob4a0949e27022f629bb614dc22fefa0142acb39bf
1 #!/usr/bin/perl -w
3 # Build the auto-generated parts of the Wine makefiles.
5 # Copyright 2006 Alexandre Julliard
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 use strict;
24 # Make rules files
25 my %makerules =
27 "MAKE_RULES" => "Make.rules",
30 # Programs that we want to install in the bin directory too
31 my %bin_install =
33 "msiexec" => 1,
34 "notepad" => 1,
35 "regedit" => 1,
36 "regsvr32" => 1,
37 "wineboot" => 1,
38 "winecfg" => 1,
39 "wineconsole" => 1,
40 "winedbg" => 1,
41 "winefile" => 1,
42 "winemine" => 1,
43 "winepath" => 1,
46 # Programs that we don't want to install at all
47 my %dont_install =
49 "winetest" => 1,
52 # Dlls and programs that are 16-bit specific
53 my %modules16 =
55 "ifsmgr.vxd" => 1,
56 "mmdevldr.vxd" => 1,
57 "monodebg.vxd" => 1,
58 "vdhcp.vxd" => 1,
59 "vmm.vxd" => 1,
60 "vnbt.vxd" => 1,
61 "vnetbios.vxd" => 1,
62 "vtdapi.vxd" => 1,
63 "vwin32.vxd" => 1,
64 "w32skrnl.dll" => 1,
65 "winevdm.exe" => 1,
66 "wow32.dll" => 1,
69 my %exported_wine_headers = (
70 "wine/debug.h" => 1,
71 "wine/exception.h" => 1,
72 "wine/library.h" => 1,
73 "wine/unicode.h" => 1,
74 "wine/itss.idl" => 1,
75 "wine/svcctl.idl" => 1,
78 my %private_idl_headers = (
79 "access.idl" => 1,
80 "asynot.idl" => 1,
81 "asysta.idl" => 1,
82 "axcore.idl" => 1,
83 "axextend.idl" => 1,
84 "binres.idl" => 1,
85 "chprst.idl" => 1,
86 "cmdbas.idl" => 1,
87 "cmdtxt.idl" => 1,
88 "crtrow.idl" => 1,
89 "dbccmd.idl" => 1,
90 "dbcses.idl" => 1,
91 "dbdsad.idl" => 1,
92 "dbinit.idl" => 1,
93 "dbprop.idl" => 1,
94 "dbs.idl" => 1,
95 "devenum.idl" => 1,
96 "dyngraph.idl" => 1,
97 "errrec.idl" => 1,
98 "opnrst.idl" => 1,
99 "row.idl" => 1,
100 "rowchg.idl" => 1,
101 "rowpos.idl" => 1,
102 "rowpsc.idl" => 1,
103 "rstbas.idl" => 1,
104 "rstinf.idl" => 1,
105 "rstloc.idl" => 1,
106 "rstnot.idl" => 1,
107 "srcrst.idl" => 1,
108 "sesprp.idl" => 1,
109 "vmrender.idl" => 1,
110 "xmldom.idl" => 1,
111 "xmldso.idl" => 1,
112 "wine/winedxgi.idl" => 1,
115 my %ignored_source_files = (
116 "dlls/wineps.drv/afm2c.c" => 1,
117 "dlls/wineps.drv/mkagl.c" => 1,
118 "programs/winetest/dist.rc" => 1,
121 my (@linguas, @makefiles, %makefiles);
123 sub dirname($)
125 my $ret = shift;
126 return "" unless $ret =~ /\//;
127 $ret =~ s!/[^/]*$!!;
128 return $ret;
131 # update a file if changed
132 sub update_file($)
134 my $file = shift;
135 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
136 if (!$ret)
138 unlink "$file.new";
140 else
142 rename "$file.new", "$file";
143 print "$file updated\n";
144 if ($file eq "configure.ac")
146 system "autoconf";
147 print "configure updated\n";
150 return $ret;
153 # replace some lines in a file between two markers
154 sub replace_in_file($$$@)
156 my $file = shift;
157 my $start = shift;
158 my $end = shift;
160 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
162 if (defined($start))
164 open OLD_FILE, "$file" or die "cannot open $file";
165 while (<OLD_FILE>)
167 last if /$start/;
168 print NEW_FILE $_;
172 print NEW_FILE @_;
174 if (defined($end))
176 my $skip=1;
177 while (<OLD_FILE>)
179 print NEW_FILE $_ unless $skip;
180 $skip = 0 if /$end/;
184 close OLD_FILE if defined($start);
185 close NEW_FILE;
186 return update_file($file);
189 # replace a variable in a makefile
190 sub replace_makefile_variable($$)
192 my ($file, $var) = @_;
193 my $make = $makefiles{$file};
194 my $replaced = 0;
195 my @values;
197 if (defined ${$make}{"=$var"})
199 @values = @{${$make}{"=$var"}};
200 ${$make}{$var} = \@values;
202 else
204 return unless defined ${$make}{$var};
205 undef ${$make}{$var};
208 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
210 open OLD_FILE, "$file.in" or die "cannot open $file.in";
211 while (<OLD_FILE>)
213 if (/^\s*($var\s*)=/)
215 # try to preserve formatting
216 my $prefix = $1;
217 my $multiline = /\\$/ || (@values > 1);
218 while (/\\$/)
220 $_ = <OLD_FILE>;
221 last unless $_;
223 if (!@values)
225 # nothing
227 elsif ($multiline)
229 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
231 else
233 print NEW_FILE "$prefix= @values\n";
235 $replaced = 1;
236 next;
238 if (/^\@MAKE/ && !$replaced && @values)
240 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
242 print NEW_FILE $_;
244 close OLD_FILE;
245 close NEW_FILE;
246 return update_file("$file.in");
249 # parse the specified makefile and load the variables
250 sub parse_makefile($)
252 my $file = shift;
253 my %make;
255 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
257 open MAKE, "$file.in" or die "cannot open $file.in\n";
259 while (<MAKE>)
261 chomp;
262 next if (/^\s*#/);
263 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
264 next if (/^\s*$/);
266 if (/^\@(MAKE.*RULES)\@/)
268 my $var = $1;
269 $make{"=rules"} = $makerules{$var} || $var;
270 next;
272 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
274 my $var = $1;
275 $make{$var} = $2;
276 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
277 next;
279 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_SRCS|IMPLIB_SRCS|C_SRCS|OBJC_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|FONT_SRCS|IN_SRCS|PROGRAMS|EXTRA_TARGETS|MANPAGES)\s*=\s*(.*)/)
281 my $var = $1;
282 my @list = split(/\s+/, $2);
283 $make{$var} = \@list;
284 ${$make{"=flags"}}{"clean"} = 1 if $var eq "PROGRAMS";
285 ${$make{"=flags"}}{"clean"} = 1 if $var eq "EXTRA_TARGETS";
286 next;
288 if (/(install-lib|install-dev|clean)\s*:/)
290 ${$make{"=flags"}}{$1} = 1;
291 next;
293 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
295 die "Variable $1 in $file.in is obsolete";
299 if ($file =~ /^programs\/([^\/]+)\/Makefile/)
301 ${$make{"=flags"}}{"install"} = 1 unless $dont_install{$1};
302 ${$make{"=flags"}}{"installbin"} = 1 if $bin_install{$1};
305 if (defined $make{"=flags"} && defined $make{"MODULE"})
307 die "Custom install-lib rule not allowed in $file" if defined ${$make{"=flags"}}{"install-lib"};
308 die "Custom install-dev rule not allowed in $file" if defined ${$make{"=flags"}}{"install-dev"};
311 return %make;
314 # read pragma makedep flags from a source file
315 sub get_makedep_flags($)
317 my $file = shift;
318 my %flags;
320 open FILE, $file or die "cannot open $file";
321 while (<FILE>)
323 next unless /^#\s*pragma\s+makedep\s+(.*)/;
324 foreach my $flag (split /\s+/, $1)
326 last if $flag eq "depend";
327 $flags{$flag} = 1;
330 close FILE;
331 return %flags;
334 sub get_parent_makefile($)
336 my $file = shift;
337 my %make = %{$makefiles{$file}};
338 my $reldir = $make{"PARENTSRC"} || "";
339 return "" unless $reldir;
340 (my $path = $file) =~ s/\/Makefile$/\//;
341 while ($reldir =~ /^\.\.\//)
343 $reldir =~ s/^\.\.\///;
344 $path =~ s/[^\/]+\/$//;
346 return "$path$reldir/Makefile";
349 # preserve shared source files that are listed in the existing makefile
350 sub preserve_shared_source_files($$$)
352 my ($make, $parent, $var) = @_;
353 my %srcs;
355 return unless defined ${$parent}{"=$var"};
356 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
357 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
359 foreach my $file (@{${$make}{$var}})
361 next unless defined $srcs{$file} && $srcs{$file} == 1;
362 push @{${$make}{"=$var"}}, $file;
366 # assign source files to their respective makefile
367 sub assign_sources_to_makefiles(@)
369 foreach my $file (@_)
371 next if defined $ignored_source_files{$file};
372 next if $file =~ /Makefile\.in$/;
373 my $dir = dirname( $file );
374 my $subdir = $dir;
376 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
377 $subdir =~ s/^$dir\/?//;
378 next unless $dir;
380 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
382 my $make = $makefiles{"$dir/Makefile"};
383 my $name = substr( $file, length($dir) + 1 );
385 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
387 if ($dir eq "include")
389 next if ($name =~ /\.in$/);
390 if ($name =~ /^wine\// && !$exported_wine_headers{$name})
392 if ($private_idl_headers{$name}) { push @{${$make}{"=PRIVATE_IDL_H_SRCS"}}, $name; }
393 next;
395 if ($name =~ /stdole2\.idl$/) { push @{${$make}{"=IDL_TLB_SRCS"}}, $name; }
396 elsif ($private_idl_headers{$name}) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
397 elsif ($name =~ /\.h$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
398 elsif ($name =~ /\.x$/) { push @{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
399 elsif ($name =~ /\.rh$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
400 elsif ($name =~ /\.inl$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
401 elsif ($name =~ /\.idl$/) { push @{${$make}{"=PUBLIC_IDL_H_SRCS"}}, $name; }
402 else { die "unknown file $name in include dir"; }
404 else
406 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
407 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
408 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
409 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
410 elsif ($name =~ /\.sfd$/) { push @{${$make}{"=FONT_SRCS"}}, $name; }
411 elsif ($name =~ /\.c$/)
413 my %flags = get_makedep_flags( $file );
414 if (defined $flags{"implib"})
416 push @{${$make}{"=IMPLIB_SRCS"}}, $name;
417 ${${$make}{"=flags"}}{"staticimplib"} = 1;
419 push @{${$make}{"=C_SRCS"}}, $name;
421 elsif ($name =~ /\.rc$/)
423 my %flags = get_makedep_flags( $file );
424 ${${$make}{"=flags"}}{"po"} = 1 if defined $flags{"po"};
425 push @{${$make}{"=RC_SRCS"}}, $name;
427 elsif ($name =~ /\.mc$/)
429 push @{${$make}{"=MC_SRCS"}}, $name;
430 ${${$make}{"=flags"}}{"mc"} = 1;
432 elsif ($name =~ /\.idl$/)
434 push @{${$make}{"=IDL_SRCS"}}, $name;
435 ${${$make}{"=flags"}}{"clean"} = 1;
437 elsif ($name =~ /\.man\.in$/)
439 push @{${$make}{"=MANPAGES"}}, $name;
440 ${${$make}{"=flags"}}{"manpage"} = 1;
442 elsif ($name =~ /\.in$/)
444 push @{${$make}{"=IN_SRCS"}}, $name;
449 # add extra variables to include source list
450 my $make = $makefiles{"include/Makefile"};
451 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(XTEMPLATE_SRCS)";
452 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(PUBLIC_IDL_H_SRCS)";
453 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(IDL_TLB_SRCS)";
454 unshift @{${$make}{"=IDL_SRCS"}}, "\$(IDL_H_SRCS) \$(IDL_TLB_SRCS)";
456 # preserve shared source files from the parent makefile
457 foreach my $file (@makefiles)
459 my %make = %{$makefiles{$file}};
460 my $parent = get_parent_makefile( $file );
461 next unless $parent;
462 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
463 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
464 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
468 ################################################################
469 # update the makefile list in configure.ac
471 sub update_makefiles(@)
473 my (@lines);
475 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
477 my $file = $makerules{$var};
478 my %make = %{$makefiles{$file}};
479 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
480 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
482 push @lines, "\n";
484 foreach my $file (sort @_)
486 my %make = %{$makefiles{$file}};
487 my $args = "";
488 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
489 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
490 if (defined($make{"TESTDLL"})) # test
492 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
493 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
494 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
495 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
496 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
498 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
500 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
501 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
502 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
503 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
504 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
506 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
508 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
509 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
510 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
511 if ($name =~ /\./)
513 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
515 else
517 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
519 $args .= "," if $is_win16 || defined $make{"=flags"};
520 $args .= "enable_win16" if $is_win16;
521 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
523 elsif (defined($make{"MODULE"})) # dll
525 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
526 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
527 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
528 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
529 if ($name =~ /\./)
531 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
533 else
535 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
537 my $implib = $make{"IMPORTLIB"} || "";
538 $args .= "," if $is_win16 || defined $make{"=flags"};
539 $args .= "enable_win16" if $is_win16;
540 $args .= $flag_args;
541 $args .= ",[$implib]" if $implib && $implib ne $name;
542 push @lines, "WINE_CONFIG_DLL($name$args)\n";
544 elsif ($file =~ /^tools.*\/Makefile$/)
546 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
547 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
548 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
549 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
551 elsif ($file =~ /\/Makefile$/)
553 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
554 $args = "[$name]";
555 $args .= "," if defined $make{"=flags"};
556 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
560 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
562 # update the source variables in all the makefiles
564 foreach my $file (sort @_)
566 replace_makefile_variable( $file, "LEX_SRCS" );
567 replace_makefile_variable( $file, "BISON_SRCS" );
568 replace_makefile_variable( $file, "MC_SRCS" );
569 replace_makefile_variable( $file, "SVG_SRCS" );
570 replace_makefile_variable( $file, "FONT_SRCS" );
571 replace_makefile_variable( $file, "C_SRCS" );
572 replace_makefile_variable( $file, "OBJC_SRCS" );
573 replace_makefile_variable( $file, "RC_SRCS" );
574 replace_makefile_variable( $file, "IDL_SRCS" );
575 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
576 replace_makefile_variable( $file, "IN_SRCS" );
577 replace_makefile_variable( $file, "IMPLIB_SRCS" );
578 replace_makefile_variable( $file, "MANPAGES" );
579 next unless $file eq "include/Makefile";
580 replace_makefile_variable( $file, "PRIVATE_IDL_H_SRCS" );
581 replace_makefile_variable( $file, "PUBLIC_IDL_H_SRCS" );
582 replace_makefile_variable( $file, "IDL_TLB_SRCS" );
583 replace_makefile_variable( $file, "SRCDIR_INCLUDES" );
586 push @lines, "dnl End of auto-generated output commands\n";
587 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
591 ################################################################
592 # update the LINGUAS file
594 sub update_linguas(@)
596 replace_in_file( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
600 die "needs to be run from a git checkout" unless -d ".git";
602 my @all_files = split /\0/, `git ls-files -c -z`;
603 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\/.*\.po$/, @all_files;
604 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
606 foreach my $file (sort values %makerules, @makefiles)
608 my %make = parse_makefile( $file );
609 $makefiles{$file} = \%make;
612 assign_sources_to_makefiles( @all_files );
613 update_linguas( @linguas );
614 update_makefiles( @makefiles );