mstask/tests: Make task trigger tests independent.
[wine.git] / tools / make_makefiles
blobb26406b52aa18f558448417fd73bd4b3b97cc62d
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 %exported_wine_headers = (
42 "wine/debug.h" => 1,
43 "wine/exception.h" => 1,
44 "wine/library.h" => 1,
45 "wine/unicode.h" => 1,
46 "wine/itss.idl" => 1,
47 "wine/svcctl.idl" => 1,
50 my %ignored_source_files = (
51 "dlls/wineps.drv/afm2c.c" => 1,
52 "dlls/wineps.drv/mkagl.c" => 1,
53 "include/config.h.in" => 1,
54 "include/stamp-h.in" => 1,
55 "programs/winetest/dist.rc" => 1,
56 "tools/makedep.c" => 1,
59 my @source_vars = (
60 "BISON_SRCS",
61 "C_SRCS",
62 "FONT_SRCS",
63 "HEADER_SRCS",
64 "IDL_SRCS",
65 "IN_SRCS",
66 "LEX_SRCS",
67 "MANPAGES",
68 "MC_SRCS",
69 "OBJC_SRCS",
70 "PO_SRCS",
71 "RC_SRCS",
72 "SOURCES",
73 "SVG_SRCS",
74 "XTEMPLATE_SRCS"
77 my (@makefiles, %makefiles);
79 sub dirname($)
81 my $ret = shift;
82 return "" unless $ret =~ /\//;
83 $ret =~ s!/[^/]*$!!;
84 return $ret;
87 # update a file if changed
88 sub update_file($$)
90 my $file = shift;
91 my $new = shift;
93 open FILE, ">$file.new" or die "cannot create $file.new";
94 print FILE $new;
95 close FILE;
96 rename "$file.new", "$file";
97 print "$file updated\n";
98 if ($file eq "configure.ac")
100 system "autoconf";
101 print "configure updated\n";
105 # replace some lines in a file between two markers
106 sub replace_in_file($$$@)
108 my $file = shift;
109 my $start = shift;
110 my $end = shift;
111 my ($old, $new);
113 open OLD_FILE, "$file" or die "cannot open $file";
114 while (<OLD_FILE>)
116 $old .= $_;
117 last if /$start/;
118 $new .= $_;
121 $new .= join "", @_;
123 my $skip = 1;
124 while (<OLD_FILE>)
126 $old .= $_;
127 $new .= $_ unless $skip;
128 $skip = 0 if /$end/;
131 close OLD_FILE;
132 update_file($file, $new) if $old ne $new;
135 # replace all source variables in a makefile
136 sub replace_makefile_variables($)
138 my $file = shift;
139 my $make = $makefiles{$file};
140 my $source_vars_regexp = join "|", @source_vars;
141 my %replaced;
142 my $old;
143 my $new;
145 open OLD_FILE, "$file.in" or die "cannot open $file.in";
146 while (<OLD_FILE>)
148 $old .= $_;
149 if (/^\s*($source_vars_regexp)(\s*)=/)
151 # try to preserve formatting
152 my $var = $1;
153 my $spaces = $2;
154 my $replaced = 0;
155 my @values;
157 if (defined ${$make}{"=$var"})
159 @values = @{${$make}{"=$var"}};
160 ${$make}{$var} = \@values;
162 else
164 undef ${$make}{$var};
166 my $multiline = /\\$/ || (@values > 1);
167 my $old_str = $_;
168 while (/\\$/)
170 $_ = <OLD_FILE>;
171 last unless $_;
172 $old .= $_;
173 $old_str .= $_;
175 my $new_str = "";
176 if (!@values)
178 # nothing
180 elsif ($multiline)
182 $new_str = "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
183 $new .= $new_str;
185 else
187 $new_str = "$var$spaces= @values\n";
188 $new .= $new_str;
190 $replaced{$var} = 1;
191 next;
193 $new .= $_;
195 # if we are using SOURCES, ignore the other variables
196 unless ($replaced{"SOURCES"})
198 foreach my $var (@source_vars)
200 next if defined $replaced{$var};
201 next if $var eq "SOURCES";
202 next unless defined ${$make}{"=$var"};
203 my @values = @{${$make}{"=$var"}};
204 next unless @values;
205 $new .= "\n$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
208 close OLD_FILE;
209 update_file("$file.in", $new) if $old ne $new;
212 # parse the specified makefile and load the variables
213 sub parse_makefile($)
215 my $file = shift;
216 my %make;
218 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
220 open MAKE, "$file.in" or die "cannot open $file.in\n";
222 while (<MAKE>)
224 chomp;
225 next if (/^\s*#/);
226 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
227 next if (/^\s*$/);
229 if (/\@[A-Z_]+\@/) # config.status substitution variable
231 die "Configure substitution is not allowed in $file" unless $file eq "Makefile";
233 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
235 my $var = $1;
236 $make{$var} = $2;
237 next;
239 my $source_vars_regexp = join "|", @source_vars;
240 if (/^\s*($source_vars_regexp|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
242 my $var = $1;
243 my @list = split(/\s+/, $2);
244 $make{$var} = \@list;
245 next;
247 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
249 die "Variable $1 in $file.in is obsolete";
253 return %make;
256 # read pragma makedep flags from a source file
257 sub get_makedep_flags($)
259 my $file = shift;
260 my %flags;
262 open FILE, $file or die "cannot open $file";
263 if ($file =~ /\.sfd$/)
265 while (<FILE>)
267 next unless /^UComments:\s*\"(.*)\"$/;
268 foreach my $pragma (split /\+AAoA/, $1)
270 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
271 foreach my $flag (split /\s+/, $1)
273 $flags{$flag} = 1;
274 last if $flag eq "font";
279 else
281 while (<FILE>)
283 next unless /^#\s*pragma\s+makedep\s+(.*)/;
284 foreach my $flag (split /\s+/, $1)
286 last if $flag eq "depend";
287 $flags{$flag} = 1;
291 close FILE;
292 return %flags;
295 sub get_parent_makefile($)
297 my $file = shift;
298 my %make = %{$makefiles{$file}};
299 my $reldir = $make{"PARENTSRC"} || "";
300 return "" unless $reldir;
301 (my $path = $file) =~ s/\/Makefile$/\//;
302 while ($reldir =~ /^\.\.\//)
304 $reldir =~ s/^\.\.\///;
305 $path =~ s/[^\/]+\/$//;
307 return "$path$reldir/Makefile";
310 # preserve shared source files that are listed in the existing makefile
311 sub preserve_shared_source_files($$$)
313 my ($make, $parent, $var) = @_;
314 my %srcs;
316 return unless defined ${$parent}{"=$var"};
317 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
318 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
320 foreach my $file (@{${$make}{$var}})
322 next unless defined $srcs{$file} && $srcs{$file} == 1;
323 push @{${$make}{"=$var"}}, $file;
327 # assign source files to their respective makefile
328 sub assign_sources_to_makefiles(@)
330 foreach my $file (@_)
332 next if defined $ignored_source_files{$file};
333 next if $file =~ /Makefile\.in$/;
334 my $dir = dirname( $file );
335 my $subdir = $dir;
337 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
338 $subdir =~ s/^$dir\/?//;
339 next unless $dir;
341 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
343 my $make = $makefiles{"$dir/Makefile"};
344 my $name = substr( $file, length($dir) + 1 );
346 next if $file =~ /^include\/wine\// && !get_makedep_flags($file) && !$exported_wine_headers{$name};
348 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
349 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
350 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
351 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
352 elsif ($name =~ /\.sfd$/)
354 push @{${$make}{"=FONT_SRCS"}}, $name;
356 elsif ($name =~ /\.c$/)
358 push @{${$make}{"=C_SRCS"}}, $name;
360 elsif ($name =~ /\.h$/ || $name =~ /\.rh$/ || $name =~ /\.inl$/ || $name =~ /\.x$/)
362 next if $dir ne "include";
364 elsif ($name =~ /\.rc$/)
366 push @{${$make}{"=RC_SRCS"}}, $name;
368 elsif ($name =~ /\.mc$/)
370 push @{${$make}{"=MC_SRCS"}}, $name;
372 elsif ($name =~ /\.po$/)
374 push @{${$make}{"=PO_SRCS"}}, $name;
376 elsif ($name =~ /\.idl$/)
378 die "no makedep flags specified in $file" unless $dir eq "include" || get_makedep_flags($file);
379 push @{${$make}{"=IDL_SRCS"}}, $name;
381 elsif ($name =~ /\.man\.in$/)
383 push @{${$make}{"=MANPAGES"}}, $name;
385 elsif ($name =~ /\.in$/)
387 push @{${$make}{"=IN_SRCS"}}, $name;
389 elsif ($name =~ /\.spec$/)
391 next unless defined ${$make}{"TESTDLL"};
393 elsif ($dir ne "loader") # loader dir contains misc files
395 next;
397 push @{${$make}{"=SOURCES"}}, $name;
400 # preserve shared source files from the parent makefile
401 foreach my $file (@makefiles)
403 my $make = $makefiles{$file};
404 my $parent = get_parent_makefile( $file );
405 next unless $parent;
406 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
407 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
408 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
409 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
413 ################################################################
414 # update the makefile list in configure.ac
416 sub update_makefiles(@)
418 my (@lines);
420 foreach my $file (sort @_)
422 next if $file eq "Makefile";
423 my %make = %{$makefiles{$file}};
424 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
425 my $args = "";
426 if (defined($make{"TESTDLL"})) # test
428 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
429 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
430 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
432 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
434 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
435 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
436 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
438 elsif (defined($make{"MODULE"})) # dll or program
440 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile/$2/;
441 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
442 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
443 die "Invalid MODULE in $file" if $name =~ /\./ && $make{"MODULE"} ne $name;
444 if ($file =~ /^programs\//)
446 die "APPMODE should be defined in $file" unless defined $make{"APPMODE"} ;
447 die "Invalid MODULE in $file" unless $name =~ /\./ || $make{"MODULE"} eq "$name.exe";
449 else
451 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"} ;
452 die "Invalid MODULE in $file" unless $name =~ /\./ || $make{"MODULE"} eq "$name.dll";
454 if (defined $make{"IMPORTLIB"})
456 die "IMPORTLIB not allowed in programs\n" if $file =~ /^programs\//;
457 die "Invalid IMPORTLIB name in $file" if $make{"IMPORTLIB"} =~ /\./;
459 $args = ",enable_win16" if $make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}};
461 elsif ($file =~ /^tools.*\/Makefile$/)
463 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
464 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
465 $args = ",,[test \"x\$enable_tools\" = xno]";
467 elsif (($dir eq "fonts") || ($dir eq "server"))
469 # these are created as symlinks for wow64 builds
470 $args = ",,[test -n \"\$with_wine64\"]";
472 push @lines, "WINE_CONFIG_MAKEFILE($dir$args)\n";
475 # update the source variables in all the makefiles
477 foreach my $file (sort @_) { replace_makefile_variables( $file ); }
479 push @lines, "dnl End of auto-generated output commands\n";
480 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKEFILE', '^dnl End of auto-generated output commands\n$', @lines);
484 my $git_dir = $ENV{GIT_DIR} || ".git";
485 die "needs to be run from a git checkout" unless -d $git_dir;
487 my @all_files = split /\0/, `git ls-files -c -z`;
488 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
489 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
491 foreach my $file (sort @makefiles)
493 my %make = parse_makefile( $file );
494 $makefiles{$file} = \%make;
497 assign_sources_to_makefiles( @all_files );
498 update_makefiles( @makefiles );