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
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
50 # Programs that we don't want to install at all
58 # Default patterns for top-level .gitignore
75 "dlls/*/tests/*crosstest.exe",
76 "dlls/*/tests/testlist.c",
79 "programs/winetest/*_test.exe",
80 "programs/winetest/*_test.rc",
81 "programs/winetest/build.rc",
84 # Source files and their resulting target to ignore
86 [ 'BISON_SRCS', '\.y', '.tab.c' ],
87 [ 'BISON_SRCS', '\.y', '.tab.h' ],
88 [ 'LEX_SRCS', '\.l', '.yy.c' ],
89 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
90 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
91 [ 'IDL_H_SRCS', '\.idl', '.h' ],
92 [ 'IDL_C_SRCS', '\.idl', '.h' ],
93 [ 'IDL_I_SRCS', '\.idl', '.h' ],
94 [ 'IDL_P_SRCS', '\.idl', '.h' ],
95 [ 'IDL_S_SRCS', '\.idl', '.h' ],
96 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
97 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
98 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
99 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
102 my %exported_wine_headers = (
104 "wine/exception.h" => 1,
105 "wine/library.h" => 1,
106 "wine/unicode.h" => 1,
107 "wine/itss.idl" => 1,
108 "wine/svcctl.idl" => 1,
111 my %private_idl_headers = (
136 "wine/wined3d.idl" => 1,
137 "wine/winedxgi.idl" => 1,
140 my %ignored_source_files = (
141 "dlls/wineps.drv/afm2c.c" => 1,
142 "dlls/wineps.drv/mkagl.c" => 1,
143 "programs/winetest/dist.rc" => 1,
146 my (@all_files, @makefiles, %makefiles);
151 return "" unless $ret =~ /\//;
156 # update a file if changed
160 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
167 rename "$file.new", "$file";
168 print "$file updated\n";
169 if ($file eq "configure.ac")
172 print "configure updated\n";
178 # replace some lines in a file between two markers
179 sub replace_in_file($$$@)
185 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
189 open OLD_FILE, "$file" or die "cannot open $file";
204 print NEW_FILE $_ unless $skip;
209 close OLD_FILE if defined($start);
211 return update_file($file);
214 # replace a variable in a makefile
215 sub replace_makefile_variable($$)
217 my ($file, $var) = @_;
218 my $make = $makefiles{$file};
220 return unless defined ${$make}{"=$var"};
222 my @values = @{${$make}{"=$var"}};
223 ${$make}{$var} = \@values;
225 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
227 open OLD_FILE, "$file.in" or die "cannot open $file.in";
230 if (/^\s*($var\s+)=/)
232 # try to preserve formatting
234 my $multiline = /\\$/ || (@values > 1);
242 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
246 print NEW_FILE "$prefix= @values\n";
254 return update_file("$file.in");
257 # parse the specified makefile to identify the rules file
258 sub parse_makefile($)
263 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
265 open MAKE, "$file.in" or die "cannot open $file.in\n";
271 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
274 if (/^\@(MAKE.*RULES)\@/)
277 $make{"=rules"} = $makerules{$var};
280 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
285 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|C_SRCS16|RC_SRCS16|SPEC_SRCS16|EXTRA_OBJS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
287 my @list = split(/\s+/, $2);
295 # assign source files to their respective makefile
296 sub assign_sources_to_makefiles()
298 foreach my $file (@all_files)
300 next if defined $ignored_source_files{$file};
301 my $dir = dirname( $file );
303 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
306 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
308 my $make = $makefiles{"$dir/Makefile"};
309 my $basename = substr( $file, length($dir) + 1 );
311 if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
312 elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
313 elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
314 elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
315 elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
316 elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
320 ################################################################
321 # update the makefile list in configure.ac
323 sub update_makefiles(@)
327 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
329 my $file = $makerules{$var};
330 my %make = %{$makefiles{$file}};
331 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
332 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
336 foreach my $file (sort @_)
338 my %make = %{$makefiles{$file}};
339 my $rules = $make{"=rules"};
341 if ($rules eq $makerules{"MAKE_DLL_RULES"})
343 $args = ",[dlls],[ALL_DLL_DIRS]";
344 $args .= ",[enable_win16]" if $make{"MODULE"} =~ /(16|\.vxd)$/;
346 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
347 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
348 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
350 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
351 $args = ",[programs],[ALL_PROGRAM_DIRS";
352 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
353 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
355 $args .= ",[enable_win16]" if $make{"MODULE"} =~ /16$/;
357 elsif ($file =~ /^[^\/]*\/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
358 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
361 # update the source variables in all the makefiles
363 foreach my $file (sort @_)
365 my %make = %{$makefiles{$file}};
367 replace_makefile_variable( $file, "LEX_SRCS" );
368 replace_makefile_variable( $file, "BISON_SRCS" );
369 replace_makefile_variable( $file, "MC_SRCS" );
370 replace_makefile_variable( $file, "SVG_SRCS" );
371 replace_makefile_variable( $file, "C_SRCS" ) unless defined $make{"C_SRCS16"};
372 replace_makefile_variable( $file, "RC_SRCS" ) unless defined $make{"RC_SRCS16"};
375 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
376 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
380 ################################################################
381 # process ignore targets for generic source files
383 sub update_ignores(@)
387 foreach my $file (sort @_)
389 my %makefile = %{$makefiles{$file}};
392 foreach my $src (@ignore_srcs)
394 my @pattern = @{$src};
395 next unless defined $makefile{$pattern[0]};
396 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
398 foreach my $f (@list)
400 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
406 ################################################################
407 # update dlls/Makefile.in
411 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
415 foreach my $make (@_)
417 my %makefile = %{$makefiles{$make}};
418 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
420 next unless defined $makefile{"MODULE"};
421 my $module = $makefile{"MODULE"};
422 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
424 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
426 $staticlib_dirs{$module} = $dir;
427 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
431 die "invalid module $module" unless $module =~ /\./;
432 (my $mod = $module) =~ s/\.dll$//;
433 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
434 $directories{$module} = $dir;
437 if (defined $makefile{"IMPORTLIB"})
439 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
441 $importlibs{$module} = $1;
445 die "invalid importlib name $makefile{IMPORTLIB} in $make";
449 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
451 if (defined $makefile{"SPEC_SRCS16"})
453 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
454 $altnames{$module} = \@list;
456 if (defined $makefile{"EXTRA_OBJS16"})
458 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
460 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
465 # output the list of 16-bit files
468 foreach my $mod (sort keys %directories)
470 next unless defined $altnames{$mod};
471 foreach my $i (sort @{$altnames{$mod}})
473 push @targets16, $i . "16";
476 $text .= "# 16-bit dlls\n\n";
477 $text .= "WIN16_FILES = \\\n";
478 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
479 $text .= "\@MAKE_RULES\@\n\n";
481 # output the all: target
483 $text .= "# Main target\n\n";
484 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
486 # output the lib name -> directory rules
488 $text .= "# Placeholders for 16-bit libraries\n\n";
489 foreach my $mod (sort keys %directories)
491 next unless defined $altnames{$mod};
492 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
493 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
496 # output the import libraries rules
498 $text .= "# Import libraries\n\n";
499 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
501 my @lib_symlinks = ();
502 foreach my $mod (sort keys %importlibs)
504 my $dir = $directories{$mod};
505 my $lib = $importlibs{$mod};
506 if ($lib ne $dir) { push @lib_symlinks, $mod; }
508 $text .= "IMPORT_SYMLINKS =";
509 foreach my $mod (sort @lib_symlinks)
511 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
514 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
515 foreach my $mod (sort keys %staticlib_dirs)
517 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
519 foreach my $mod (sort keys %importlibs)
521 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
522 next unless defined $static_implibs{$mod};
523 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
525 $text .= "\n\nCROSS_IMPLIBS =";
526 foreach my $mod (sort @lib_symlinks)
528 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
530 foreach my $mod (sort keys %importlibs)
532 next if defined $static_implibs{$mod};
533 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
536 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
537 $text .= "implib: \$(IMPORT_LIBS)\n\n";
538 $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
539 $text .= ".PHONY: implib testsubdirs\n\n";
541 foreach my $mod (sort keys %importlibs)
543 my $dir = $directories{$mod};
544 my $lib = $importlibs{$mod};
547 if (defined($static_implibs{$mod}))
549 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
550 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
551 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
552 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
556 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
557 $dir, $lib, $dir, $lib, $dir, $spec;
558 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
561 foreach my $mod (sort @lib_symlinks)
563 my $dir = $directories{$mod};
564 my $lib = "lib" . $importlibs{$mod};
565 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
566 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
567 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
568 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
571 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
572 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
574 # output the inter-dll dependencies and rules
576 $text .= "# Map library name to the corresponding directory\n\n";
578 foreach my $mod (sort keys %staticlib_dirs)
580 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
582 $text .= "\n# Misc rules\n";
584 replace_in_file( "dlls/Makefile.in",
591 foreach my $mod (sort @lib_symlinks)
593 push @ignores, "dlls/lib$importlibs{$mod}.def";
595 foreach my $mod (sort keys %directories)
597 next unless defined $altnames{$mod};
598 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
605 ################################################################
606 # update include/Makefile.in
608 sub update_includes()
610 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
611 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
612 foreach my $incl (@includes)
614 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
615 next if ($incl =~ /\.in$/);
616 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
618 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
621 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
622 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
623 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
624 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
625 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
626 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
627 else { die "unknown file $incl in include dir"; }
629 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
630 "PRIVATE_IDL_H_SRCS = \\\n\t",
631 join( " \\\n\t", sort @private_idl_srcs ),
632 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
633 join( " \\\n\t", sort @public_idl_srcs ),
634 "\n\nIDL_TLB_SRCS = \\\n\t",
635 join( " \\\n\t", sort @tlb_srcs ),
636 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
637 join( " \\\n\t", sort @h_srcs ),
638 "\n\nEXTRASUBDIRS = ",
639 join( " ", sort keys %subdirs ),
640 "\n\nINSTALLDIRS = \\\n" );
641 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
645 ################################################################
646 # update the main .gitignore
648 sub update_gitignore(@)
650 my @ignores = values %makerules;
652 foreach my $make (@makefiles)
654 my %makefile = %{$makefiles{$make}};
655 my $dir = $makefile{"=dir"};
656 if (defined $makefile{"MANPAGES"})
658 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
660 if (defined $makefile{"PROGRAMS"})
662 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
666 # prepend a slash to paths that don't have one
667 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
669 # get rid of duplicates
671 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
673 replace_in_file( ".gitignore", undef, undef,
674 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
675 join("\n", sort keys %ignores), "\n" );
679 die "needs to be run from a git checkout" unless -d ".git";
681 @all_files = split /\0/, `git ls-files -c -z`;
682 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
684 foreach my $file (sort values %makerules, @makefiles)
686 my %make = parse_makefile( $file );
687 $makefiles{$file} = \%make;
690 assign_sources_to_makefiles();
691 update_makefiles( @makefiles );
692 push @ignores, update_includes();
693 push @ignores, update_ignores( @makefiles );
694 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
695 update_gitignore( @ignores );