dxgi/tests: Fix a test failure when no adapters are present.
[wine/multimedia.git] / tools / make_makefiles
blobfec44f6de015bee567e695658f08872e01ec9cda
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",
28 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
31 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
34 # Programs that we want to install in the bin directory too
35 my %bin_install =
37 "msiexec" => 1,
38 "notepad" => 1,
39 "regedit" => 1,
40 "regsvr32" => 1,
41 "wineboot" => 1,
42 "winecfg" => 1,
43 "wineconsole" => 1,
44 "winedbg" => 1,
45 "winefile" => 1,
46 "winemine" => 1,
47 "winepath" => 1,
50 # Programs that we don't want to install at all
51 my %dont_install =
53 "cmdlgtst" => 1,
54 "view" => 1,
55 "winetest" => 1,
58 # Dlls and programs that are 16-bit specific
59 my %modules16 =
61 "ifsmgr.vxd" => 1,
62 "mmdevldr.vxd" => 1,
63 "monodebg.vxd" => 1,
64 "vdhcp.vxd" => 1,
65 "vmm.vxd" => 1,
66 "vnbt.vxd" => 1,
67 "vnetbios.vxd" => 1,
68 "vtdapi.vxd" => 1,
69 "vwin32.vxd" => 1,
70 "w32skrnl.dll" => 1,
71 "winevdm.exe" => 1,
72 "wow32.dll" => 1,
75 # Default patterns for top-level .gitignore
76 my @ignores = (
77 "*.[oa]",
78 "*.fake",
79 "*.ok",
80 "*.res",
81 "*.so",
82 "/autom4te.cache",
83 "/config.cache",
84 "/config.log",
85 "/config.status",
86 "/configure.lineno",
87 "/TAGS",
88 "/tags",
89 "Makefile",
90 "dlldata.c",
91 "dlls/*/*.def",
92 "dlls/*/tests/*crosstest.exe",
93 "dlls/*/tests/testlist.c",
94 "include/config.h",
95 "include/stamp-h",
96 "programs/winetest/*_test.exe",
97 "programs/winetest/*_test.rc",
98 "programs/winetest/build.rc",
101 # Source files and their resulting target to ignore
102 my @ignore_srcs = (
103 [ 'BISON_SRCS', '\.y', '.tab.c' ],
104 [ 'BISON_SRCS', '\.y', '.tab.h' ],
105 [ 'LEX_SRCS', '\.l', '.yy.c' ],
106 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
107 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
108 [ 'IDL_H_SRCS', '\.idl', '.h' ],
109 [ 'IDL_C_SRCS', '\.idl', '.h' ],
110 [ 'IDL_I_SRCS', '\.idl', '.h' ],
111 [ 'IDL_P_SRCS', '\.idl', '.h' ],
112 [ 'IDL_S_SRCS', '\.idl', '.h' ],
113 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
114 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
115 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
116 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
119 my %exported_wine_headers = (
120 "wine/debug.h" => 1,
121 "wine/exception.h" => 1,
122 "wine/library.h" => 1,
123 "wine/unicode.h" => 1,
124 "wine/itss.idl" => 1,
125 "wine/svcctl.idl" => 1,
128 my %private_idl_headers = (
129 "access.idl" => 1,
130 "asynot.idl" => 1,
131 "asysta.idl" => 1,
132 "axcore.idl" => 1,
133 "axextend.idl" => 1,
134 "binres.idl" => 1,
135 "cmdbas.idl" => 1,
136 "cmdtxt.idl" => 1,
137 "crtrow.idl" => 1,
138 "dbccmd.idl" => 1,
139 "dbcses.idl" => 1,
140 "dbdsad.idl" => 1,
141 "dbinit.idl" => 1,
142 "dbprop.idl" => 1,
143 "dbs.idl" => 1,
144 "devenum.idl" => 1,
145 "dyngraph.idl" => 1,
146 "opnrst.idl" => 1,
147 "row.idl" => 1,
148 "rowchg.idl" => 1,
149 "rstbas.idl" => 1,
150 "rstinf.idl" => 1,
151 "rstloc.idl" => 1,
152 "sesprp.idl" => 1,
153 "vmrender.idl" => 1,
154 "wine/wined3d.idl" => 1,
155 "wine/winedxgi.idl" => 1,
158 my %ignored_source_files = (
159 "dlls/wineps.drv/afm2c.c" => 1,
160 "dlls/wineps.drv/mkagl.c" => 1,
161 "programs/winetest/dist.rc" => 1,
164 my (@all_files, @makefiles, %makefiles);
166 sub dirname($)
168 my $ret = shift;
169 return "" unless $ret =~ /\//;
170 $ret =~ s!/[^/]*$!!;
171 return $ret;
174 # update a file if changed
175 sub update_file($)
177 my $file = shift;
178 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
179 if (!$ret)
181 unlink "$file.new";
183 else
185 rename "$file.new", "$file";
186 print "$file updated\n";
187 if ($file eq "configure.ac")
189 system "autoconf";
190 print "configure updated\n";
193 return $ret;
196 # replace some lines in a file between two markers
197 sub replace_in_file($$$@)
199 my $file = shift;
200 my $start = shift;
201 my $end = shift;
203 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
205 if (defined($start))
207 open OLD_FILE, "$file" or die "cannot open $file";
208 while (<OLD_FILE>)
210 last if /$start/;
211 print NEW_FILE $_;
215 print NEW_FILE @_;
217 if (defined($end))
219 my $skip=1;
220 while (<OLD_FILE>)
222 print NEW_FILE $_ unless $skip;
223 $skip = 0 if /$end/;
227 close OLD_FILE if defined($start);
228 close NEW_FILE;
229 return update_file($file);
232 # replace a variable in a makefile
233 sub replace_makefile_variable($$)
235 my ($file, $var) = @_;
236 my $make = $makefiles{$file};
238 return unless defined ${$make}{"=$var"};
240 my @values = @{${$make}{"=$var"}};
241 ${$make}{$var} = \@values;
243 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
245 open OLD_FILE, "$file.in" or die "cannot open $file.in";
246 while (<OLD_FILE>)
248 if (/^\s*($var\s+)=/)
250 # try to preserve formatting
251 my $prefix = $1;
252 my $multiline = /\\$/ || (@values > 1);
253 while (/\\$/)
255 $_ = <OLD_FILE>;
256 last unless $_;
258 if ($multiline)
260 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
262 else
264 print NEW_FILE "$prefix= @values\n";
266 next;
268 print NEW_FILE $_;
270 close OLD_FILE;
271 close NEW_FILE;
272 return update_file("$file.in");
275 # parse the specified makefile to identify the rules file
276 sub parse_makefile($)
278 my $file = shift;
279 my %make;
281 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
283 open MAKE, "$file.in" or die "cannot open $file.in\n";
285 while (<MAKE>)
287 chomp;
288 next if (/^\s*#/);
289 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
290 next if (/^\s*$/);
292 if (/^\@(MAKE.*RULES)\@/)
294 my $var = $1;
295 $make{"=rules"} = $makerules{$var};
296 next;
298 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
300 $make{$1} = $2;
301 next;
303 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
305 my @list = split(/\s+/, $2);
306 $make{$1} = \@list;
307 next;
310 return %make;
313 # assign source files to their respective makefile
314 sub assign_sources_to_makefiles()
316 foreach my $file (@all_files)
318 next if defined $ignored_source_files{$file};
319 my $dir = dirname( $file );
321 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
322 next unless $dir;
324 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
326 my $make = $makefiles{"$dir/Makefile"};
327 my $basename = substr( $file, length($dir) + 1 );
329 if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
330 elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
331 elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
332 elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
333 elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
334 elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
338 ################################################################
339 # update the makefile list in configure.ac
341 sub update_makefiles(@)
343 my (@lines);
345 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
347 my $file = $makerules{$var};
348 my %make = %{$makefiles{$file}};
349 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
350 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
352 push @lines, "\n";
354 foreach my $file (sort @_)
356 my %make = %{$makefiles{$file}};
357 my $rules = $make{"=rules"};
358 my $args = "";
359 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
360 if ($rules eq $makerules{"MAKE_DLL_RULES"})
362 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
363 my $implib = $make{"IMPORTLIB"} || "";
364 my $implib_srcs = defined($make{"IMPLIB_SRCS"}) && join( " ", @{$make{"IMPLIB_SRCS"}} );
365 $args .= "," if $implib || $is_win16;
366 $args .= "enable_win16" if $is_win16;
367 $args .= ",[$implib]" if $implib;
368 $args .= ",[$implib_srcs]" if $implib_srcs;
369 push @lines, "WINE_CONFIG_DLL($name$args)\n";
371 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
373 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
374 $args = ",[ALL_PROGRAM_DIRS";
375 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
376 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
377 $args .= "]";
378 $args .= ",enable_win16" if $is_win16;
379 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
381 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
383 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
384 push @lines, "WINE_CONFIG_TEST($dir)\n";
386 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
388 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
389 push @lines, "WINE_CONFIG_LIB($name)\n";
391 elsif ($file =~ /^[^\/]*\/Makefile$/)
393 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules],[],[ALL_TOP_DIRS])\n";
395 else
397 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules])\n";
401 # update the source variables in all the makefiles
403 foreach my $file (sort @_)
405 my %make = %{$makefiles{$file}};
407 replace_makefile_variable( $file, "LEX_SRCS" );
408 replace_makefile_variable( $file, "BISON_SRCS" );
409 replace_makefile_variable( $file, "MC_SRCS" );
410 replace_makefile_variable( $file, "SVG_SRCS" );
411 replace_makefile_variable( $file, "C_SRCS" );
412 replace_makefile_variable( $file, "RC_SRCS" );
415 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
416 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
420 ################################################################
421 # process ignore targets for generic source files
423 sub update_ignores(@)
425 my @ignores;
427 foreach my $file (sort @_)
429 my %makefile = %{$makefiles{$file}};
430 my @list;
432 foreach my $src (@ignore_srcs)
434 my @pattern = @{$src};
435 next unless defined $makefile{$pattern[0]};
436 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
438 foreach my $f (@list)
440 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
443 if (defined $makefile{"IMPORTLIB"})
445 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
447 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
449 else
451 die "invalid importlib name $makefile{IMPORTLIB} in $file";
455 return @ignores;
459 ################################################################
460 # update include/Makefile.in
462 sub update_includes()
464 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
465 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
466 foreach my $incl (@includes)
468 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
469 next if ($incl =~ /\.in$/);
470 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
472 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
473 next;
475 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
476 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
477 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
478 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
479 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
480 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
481 else { die "unknown file $incl in include dir"; }
483 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
484 "PRIVATE_IDL_H_SRCS = \\\n\t",
485 join( " \\\n\t", sort @private_idl_srcs ),
486 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
487 join( " \\\n\t", sort @public_idl_srcs ),
488 "\n\nIDL_TLB_SRCS = \\\n\t",
489 join( " \\\n\t", sort @tlb_srcs ),
490 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
491 join( " \\\n\t", sort @h_srcs ),
492 "\n\nEXTRASUBDIRS = ",
493 join( " ", sort keys %subdirs ),
494 "\n\nINSTALLDIRS = \\\n" );
495 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
499 ################################################################
500 # update the main .gitignore
502 sub update_gitignore(@)
504 my @ignores = values %makerules;
506 foreach my $make (@makefiles)
508 my %makefile = %{$makefiles{$make}};
509 my $dir = $makefile{"=dir"};
510 if (defined $makefile{"MANPAGES"})
512 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
514 if (defined $makefile{"PROGRAMS"})
516 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
520 # prepend a slash to paths that don't have one
521 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
523 # get rid of duplicates
524 my %ignores = ();
525 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
527 replace_in_file( ".gitignore", undef, undef,
528 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
529 join("\n", sort keys %ignores), "\n" );
533 die "needs to be run from a git checkout" unless -d ".git";
535 @all_files = split /\0/, `git ls-files -c -z`;
536 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
538 foreach my $file (sort values %makerules, @makefiles)
540 my %make = parse_makefile( $file );
541 $makefiles{$file} = \%make;
544 assign_sources_to_makefiles();
545 update_makefiles( @makefiles );
546 push @ignores, update_includes();
547 push @ignores, update_ignores( @makefiles );
548 update_gitignore( @ignores );