d3d9/tests: Test the presentation parameters after creating a device.
[wine.git] / tools / make_makefiles
blobf3f9329fe6362284e0e2d5c8b46dd7f7fb021177
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 # Dlls and programs that are 16-bit specific
25 my %modules16 =
27 "ifsmgr.vxd" => 1,
28 "mmdevldr.vxd" => 1,
29 "monodebg.vxd" => 1,
30 "vdhcp.vxd" => 1,
31 "vmm.vxd" => 1,
32 "vnbt.vxd" => 1,
33 "vnetbios.vxd" => 1,
34 "vtdapi.vxd" => 1,
35 "vwin32.vxd" => 1,
36 "w32skrnl.dll" => 1,
37 "winevdm.exe" => 1,
38 "wow32.dll" => 1,
41 my %ignored_source_files = (
42 "dlls/wineps.drv/afm2c.c" => 1,
43 "dlls/wineps.drv/mkagl.c" => 1,
44 "tools/makedep.c" => 1,
47 my (@makefiles, %makefiles);
48 my @nls_files;
50 sub dirname($)
52 my $ret = shift;
53 return "" unless $ret =~ /\//;
54 $ret =~ s!/[^/]*$!!;
55 return $ret;
58 # update a file if changed
59 sub update_file($$)
61 my $file = shift;
62 my $new = shift;
64 open FILE, ">$file.new" or die "cannot create $file.new";
65 print FILE $new;
66 close FILE;
67 rename "$file.new", "$file";
68 print "$file updated\n";
69 if ($file eq "configure.ac")
71 system "autoconf";
72 print "configure updated\n";
76 # replace some lines in a file between two markers
77 sub replace_in_file($$$@)
79 my $file = shift;
80 my $start = shift;
81 my $end = shift;
82 my ($old, $new);
84 open OLD_FILE, "$file" or die "cannot open $file";
85 while (<OLD_FILE>)
87 $old .= $_;
88 last if /$start/;
89 $new .= $_;
92 $new .= join "", @_;
94 my $skip = 1;
95 while (<OLD_FILE>)
97 $old .= $_;
98 $new .= $_ unless $skip;
99 $skip = 0 if /$end/;
102 close OLD_FILE;
103 update_file($file, $new) if $old ne $new;
106 # replace all source variables in a makefile
107 sub replace_makefile_variables($)
109 my $file = shift;
110 my $make = $makefiles{$file};
111 my $old;
112 my $new;
113 my $replaced = 0;
114 my $value = "";
116 $value = "\\\n\t" . join(" \\\n\t", sort @{${$make}{"=SOURCES"}}) if defined ${$make}{"=SOURCES"};
118 open OLD_FILE, $file or die "cannot open $file";
119 while (<OLD_FILE>)
121 $old .= $_;
122 if (/^\s*SOURCES\s*=/)
124 my $old_str = $_;
125 while (/\\$/)
127 $_ = <OLD_FILE>;
128 last unless $_;
129 $old .= $_;
130 $old_str .= $_;
132 $new .= "SOURCES = $value\n" if $value;
133 $replaced = 1;
134 next;
136 $new .= $_;
138 unless ($replaced)
140 $new .= "\nSOURCES = $value\n" if $value;
142 close OLD_FILE;
143 update_file($file, $new) if $old ne $new;
146 # parse the specified makefile and load the variables
147 sub parse_makefile($)
149 my $file = shift;
150 my %make;
152 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
154 open MAKE, $file or die "cannot open $file\n";
156 while (<MAKE>)
158 chomp;
159 next if (/^\s*#/);
160 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
161 next if (/^\s*$/);
163 if (/\@[A-Z_]+\@/) # config.status substitution variable
165 die "Configure substitution is not allowed in $file" unless $file eq "Makefile.in";
167 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|STATICLIB|PARENTSRC|EXTRADLLFLAGS)\s*=\s*(.*)/)
169 my $var = $1;
170 $make{$var} = $2;
171 next;
173 if (/^\s*(SOURCES|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
175 my $var = $1;
176 my @list = split(/\s+/, $2);
177 $make{$var} = \@list;
178 next;
180 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
182 die "Variable $1 in $file is obsolete";
186 return %make;
189 # read pragma makedep flags from a source file
190 sub get_makedep_flags($)
192 my $file = shift;
193 my %flags;
195 open FILE, $file or die "cannot open $file";
196 if ($file =~ /\.sfd$/)
198 while (<FILE>)
200 next unless /^UComments:\s*\"(.*)\"$/;
201 foreach my $pragma (split /\+AAoA/, $1)
203 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
204 foreach my $flag (split /\s+/, $1)
206 $flags{$flag} = 1;
207 last if $flag eq "font";
212 else
214 while (<FILE>)
216 next unless /^#\s*pragma\s+makedep\s+(.*)/;
217 foreach my $flag (split /\s+/, $1)
219 last if $flag eq "depend";
220 $flags{$flag} = 1;
224 close FILE;
225 return %flags;
228 sub get_parent_makefile($)
230 my $file = shift;
231 my %make = %{$makefiles{$file}};
232 my $reldir = $make{"PARENTSRC"} || "";
233 return "" unless $reldir;
234 (my $path = $file) =~ s/\/Makefile\.in$/\//;
235 while ($reldir =~ /^\.\.\//)
237 $reldir =~ s/^\.\.\///;
238 $path =~ s/[^\/]+\/$//;
240 return "$path$reldir/Makefile.in";
243 # preserve shared source files that are listed in the existing makefile
244 sub preserve_shared_source_files($$)
246 my ($make, $parent) = @_;
247 my %srcs;
249 return unless defined ${$parent}{"=SOURCES"};
250 foreach my $file (@{${$parent}{"=SOURCES"}}) { $srcs{$file} = 1; }
251 foreach my $file (@{${$make}{"=SOURCES"}}) { $srcs{$file} = 0; }
253 foreach my $file (@{${$make}{SOURCES}})
255 next unless defined $srcs{$file} && $srcs{$file} == 1;
256 push @{${$make}{"=SOURCES"}}, $file;
260 # assign source files to their respective makefile
261 sub assign_sources_to_makefiles(@)
263 foreach my $file (@_)
265 next if defined $ignored_source_files{$file};
266 next if $file =~ /Makefile\.in$/;
267 my $dir = dirname( $file );
268 my $subdir = $dir;
270 while ($dir && !defined $makefiles{"$dir/Makefile.in"}) { $dir = dirname( $dir ); }
271 $subdir =~ s/^$dir\/?//;
272 next unless $dir;
274 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile.in"};
276 my $make = $makefiles{"$dir/Makefile.in"};
277 my $name = substr( $file, length($dir) + 1 );
279 if ($name =~ /\.h$/)
281 next if $dir ne "include";
283 elsif ($name =~ /\.idl$/)
285 die "no makedep flags specified in $file" unless $dir eq "include" || get_makedep_flags($file);
287 elsif ($name =~ /\.spec$/)
289 my $dllflags = ${$make}{"EXTRADLLFLAGS"} || "";
290 next unless defined ${$make}{"TESTDLL"} ||
291 ($dllflags =~ /-Wb,--data-only/) ||
292 ($dllflags =~ /-Wl,--subsystem,native/);
294 elsif ($name =~ /\.nls$/)
296 push @nls_files, $name if $dir eq "nls";
298 elsif ($name =~ /\.xml$/)
300 next unless $dir eq "dlls/winewayland.drv";
302 elsif ($name !~ /\.(c|in|inl|l|m|mc|po|rc|rh|sfd|svg|x|y)$/)
304 next unless $dir eq "loader"; # loader dir contains misc files
306 push @{${$make}{"=SOURCES"}}, $name;
309 # preserve shared source files from the parent makefile
310 foreach my $file (@makefiles)
312 my $make = $makefiles{$file};
313 my $parent = get_parent_makefile( $file );
314 next unless $parent;
315 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent} );
319 ################################################################
320 # update the makefile list in configure.ac
322 sub update_makefiles(@)
324 my (@lines);
326 foreach my $file (sort @_)
328 next if $file eq "Makefile.in";
329 my %make = %{$makefiles{$file}};
330 (my $dir = $file) =~ s/^(.*)\/Makefile\.in/$1/;
331 my $args = "";
332 if (defined($make{"TESTDLL"})) # test
334 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile\.in$/;
335 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
336 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
338 elsif (defined($make{"STATICLIB"}))
340 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
341 die "invalid STATICLIB name" unless $make{"STATICLIB"} =~ /\.a$/;
343 elsif (defined($make{"MODULE"})) # dll or program
345 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile\.in/$2/;
346 my $dllflags = $make{"EXTRADLLFLAGS"} || "";
347 die "invalid MODULE name" if $make{"MODULE"} =~ /\.a$/;
348 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
349 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
350 if ($file =~ /^programs\//)
352 die "EXTRADLLFLAGS should be defined in $file" unless $dllflags;
353 die "EXTRADLLFLAGS should contain -mconsole or -mwindows in $file" unless $dllflags =~ /-m(console|windows)/;
354 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.exe";
356 else
358 die "EXTRADLLFLAGS should not contain -mconsole or -mwindows in $file" if $dllflags =~ /-m(console|windows)/;
359 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.dll";
361 if (defined $make{"IMPORTLIB"})
363 die "IMPORTLIB not allowed in programs\n" if $file =~ /^programs\//;
364 die "Invalid IMPORTLIB name in $file" if $make{"IMPORTLIB"} =~ /\./;
366 $args = ",enable_win16" if $make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}};
368 elsif ($file =~ /^tools.*\/Makefile\.in$/)
370 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
371 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
372 die "EXTRADLLFLAGS should not be defined in $file" if defined $make{"EXTRADLLFLAGS"};
373 $args = ",,[test \"x\$enable_tools\" = xno]";
375 push @lines, "WINE_CONFIG_MAKEFILE($dir$args)\n";
378 # update the source variables in all the makefiles
380 foreach my $file (sort @_) { replace_makefile_variables( $file ); }
382 push @lines, "dnl End of auto-generated output commands\n";
383 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKEFILE', '^dnl End of auto-generated output commands\n$', @lines);
386 sub update_wine_inf()
388 my @lines;
389 push @lines, "[NlsFiles]", sort grep(!/^sort/, @nls_files);
390 push @lines, "\n[SortFiles]", sort grep(/^sort/, @nls_files);
391 push @lines, "\n[WineSourceDirs]\n";
392 replace_in_file "loader/wine.inf.in", '^\[NlsFiles\]', '^\[WineSourceDirs\]', join( "\n", @lines );
395 my $git_dir = $ENV{GIT_DIR} || ".git";
396 die "needs to be run from a git checkout" unless -e $git_dir;
398 my @all_files = split /\0/, `git ls-files -c -z` or die "cannot get files list";
399 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
400 @makefiles = grep /Makefile.in$/, @all_files;
402 foreach my $file (sort @makefiles)
404 my %make = parse_makefile( $file );
405 $makefiles{$file} = \%make;
408 assign_sources_to_makefiles( @all_files );
409 update_makefiles( @makefiles );
410 update_wine_inf();