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
25 "MAKE_RULES" => "Make.rules",
26 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
27 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
28 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
29 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
32 # Programs that we want to install in the bin directory too
48 # Programs that we don't want to install at all
56 # Default patterns for top-level .gitignore
71 "dlls/*/tests/*crosstest.exe",
72 "dlls/*/tests/testlist.c",
75 "programs/winetest/tests.rc",
76 "programs/winetest/*_test.exe",
79 # Source files and their resulting target to ignore
81 [ 'BISON_SRCS', '\.y', '.tab.c' ],
82 [ 'BISON_SRCS', '\.y', '.tab.h' ],
83 [ 'LEX_SRCS', '\.l', '.yy.c' ],
84 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
85 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
86 [ 'IDL_H_SRCS', '\.idl', '.h' ],
87 [ 'IDL_C_SRCS', '\.idl', '.h' ],
88 [ 'IDL_I_SRCS', '\.idl', '.h' ],
89 [ 'IDL_P_SRCS', '\.idl', '.h' ],
90 [ 'IDL_S_SRCS', '\.idl', '.h' ],
91 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
92 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
93 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
94 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
97 my %exported_wine_headers = (
99 "wine/exception.h" => 1,
100 "wine/library.h" => 1,
101 "wine/unicode.h" => 1,
102 "wine/itss.idl" => 1,
103 "wine/svcctl.idl" => 1,
106 my %private_idl_headers = (
115 "wine/wined3d.idl" => 1,
116 "wine/winedxgi.idl" => 1,
119 my (@makefiles, %makefiles);
121 # update a file if changed
125 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
132 rename "$file.new", "$file";
133 print "$file updated\n";
134 if ($file eq "configure.ac")
137 print "configure updated\n";
143 # replace some lines in a file between two markers
144 sub replace_in_file($$$@)
150 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
154 open OLD_FILE, "$file" or die "cannot open $file";
169 print NEW_FILE $_ unless $skip;
174 close OLD_FILE if defined($start);
176 return update_file($file);
179 # parse the specified makefile to identify the rules file
180 sub parse_makefile($)
185 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
187 open MAKE, "$file.in" or die "cannot open $file.in\n";
192 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
194 if (/^\@(MAKE.*RULES)\@/)
197 $make{"=rules"} = $makerules{$var};
200 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
205 if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|EXTRA_OBJS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
207 my @list = split(/\s+/, $2);
216 ################################################################
217 # update the makefile list in configure.ac
219 sub update_makefiles(@)
223 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
225 my $file = $makerules{$var};
226 my %make = %{$makefiles{$file}};
227 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
228 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
232 foreach my $file (sort @_)
234 my %make = %{$makefiles{$file}};
235 my $rules = $make{"=rules"};
237 if ($rules eq $makerules{"MAKE_DLL_RULES"}) { $args = ",[dlls],[ALL_DLL_DIRS]"; }
238 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
239 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
240 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
242 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
243 $args = ",[programs],[ALL_PROGRAM_DIRS";
244 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
245 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
248 elsif ($file =~ /^[^\/]*\/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
249 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
252 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
253 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
257 ################################################################
258 # process ignore targets for generic source files
260 sub update_ignores(@)
264 foreach my $file (sort @_)
266 my %makefile = %{$makefiles{$file}};
269 foreach my $src (@ignore_srcs)
271 my @pattern = @{$src};
272 next unless defined $makefile{$pattern[0]};
273 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
275 foreach my $f (@list)
277 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
283 ################################################################
284 # update dlls/Makefile.in
288 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
292 foreach my $make (@_)
294 my %makefile = %{$makefiles{$make}};
295 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
297 next unless defined $makefile{"MODULE"};
298 my $module = $makefile{"MODULE"};
299 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
301 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
303 $staticlib_dirs{$module} = $dir;
304 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
308 die "invalid module $module" unless $module =~ /\./;
309 (my $mod = $module) =~ s/\.dll$//;
310 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
311 $directories{$module} = $dir;
314 if (defined $makefile{"IMPORTLIB"})
316 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
318 $importlibs{$module} = $1;
322 die "invalid importlib name $makefile{IMPORTLIB} in $make";
326 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
328 if (defined $makefile{"SPEC_SRCS16"})
330 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
331 $altnames{$module} = \@list;
333 if (defined $makefile{"EXTRA_OBJS16"})
335 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
337 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
342 # output the list of 16-bit files
345 foreach my $mod (sort keys %directories)
347 next unless defined $altnames{$mod};
348 foreach my $i (sort @{$altnames{$mod}})
350 push @targets16, $i . "16";
353 $text .= "# 16-bit dlls\n\n";
354 $text .= "WIN16_FILES = \\\n";
355 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
356 $text .= "\@MAKE_RULES\@\n\n";
358 # output the all: target
360 $text .= "# Main target\n\n";
361 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
363 # output the lib name -> directory rules
365 $text .= "# Placeholders for 16-bit libraries\n\n";
366 foreach my $mod (sort keys %directories)
368 next unless defined $altnames{$mod};
369 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
370 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
373 # output the import libraries rules
375 $text .= "# Import libraries\n\n";
376 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
378 my @lib_symlinks = ();
379 foreach my $mod (sort keys %importlibs)
381 my $dir = $directories{$mod};
382 my $lib = $importlibs{$mod};
383 if ($lib ne $dir) { push @lib_symlinks, $mod; }
385 $text .= "IMPORT_SYMLINKS =";
386 foreach my $mod (sort @lib_symlinks)
388 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
391 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
392 foreach my $mod (sort keys %staticlib_dirs)
394 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
396 foreach my $mod (sort keys %importlibs)
398 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
399 next unless defined $static_implibs{$mod};
400 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
402 $text .= "\n\nCROSS_IMPLIBS =";
403 foreach my $mod (sort @lib_symlinks)
405 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
407 foreach my $mod (sort keys %importlibs)
409 next if defined $static_implibs{$mod};
410 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
413 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
414 $text .= "implib: \$(IMPORT_LIBS)\n\n";
415 $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
416 $text .= ".PHONY: implib testsubdirs\n\n";
418 foreach my $mod (sort keys %importlibs)
420 my $dir = $directories{$mod};
421 my $lib = $importlibs{$mod};
424 if (defined($static_implibs{$mod}))
426 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
427 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
428 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
429 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
433 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
434 $dir, $lib, $dir, $lib, $dir, $spec;
435 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
438 foreach my $mod (sort @lib_symlinks)
440 my $dir = $directories{$mod};
441 my $lib = "lib" . $importlibs{$mod};
442 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
443 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
444 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
445 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
448 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
449 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
451 # output the inter-dll dependencies and rules
453 $text .= "# Map library name to the corresponding directory\n\n";
455 foreach my $mod (sort keys %staticlib_dirs)
457 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
459 $text .= "\n# Misc rules\n";
461 replace_in_file( "dlls/Makefile.in",
468 foreach my $mod (sort @lib_symlinks)
470 push @ignores, "dlls/lib$importlibs{$mod}.def";
472 foreach my $mod (sort keys %directories)
474 next unless defined $altnames{$mod};
475 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
482 ################################################################
483 # update include/Makefile.in
485 sub update_includes()
487 return unless -d ".git";
488 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
489 my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
490 foreach my $incl (@includes)
492 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
493 next if ($incl =~ /\.in$/);
494 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
496 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
499 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
500 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
501 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
502 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
503 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
505 else { die "unknown file $incl in include dir"; }
507 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
508 "PRIVATE_IDL_H_SRCS = \\\n\t",
509 join( " \\\n\t", sort @private_idl_srcs ),
510 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
511 join( " \\\n\t", sort @public_idl_srcs ),
512 "\n\nIDL_TLB_SRCS = \\\n\t",
513 join( " \\\n\t", sort @tlb_srcs ),
514 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
515 join( " \\\n\t", sort @h_srcs ),
516 "\n\nEXTRASUBDIRS = ",
517 join( " ", sort keys %subdirs ),
518 "\n\nINSTALLDIRS = \\\n" );
519 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
523 ################################################################
524 # update the main .gitignore
526 sub update_gitignore(@)
528 my @ignores = values %makerules;
530 foreach my $make (@makefiles)
532 my %makefile = %{$makefiles{$make}};
533 my $dir = $makefile{"=dir"};
534 if (defined $makefile{"MANPAGES"})
536 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
538 if (defined $makefile{"PROGRAMS"})
540 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
542 if ($dir =~ /^programs\/(.*)\/$/)
544 push @ignores, "$dir$1";
548 # prepend a slash to paths that don't have one
549 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
551 # get rid of duplicates
553 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
555 replace_in_file( ".gitignore", undef, undef,
556 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
557 join("\n", sort keys %ignores), "\n" );
563 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
567 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
570 foreach my $file (sort values %makerules, @makefiles)
572 my %make = parse_makefile( $file );
573 $makefiles{$file} = \%make;
576 update_makefiles( @makefiles );
577 push @ignores, update_includes();
578 push @ignores, update_ignores( @makefiles );
579 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
580 update_gitignore( @ignores );