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
52 # Programs that we don't want to install at all
60 # Special dlls that can be switched on or off by configure
63 "glu32" => "GLU32FILES",
64 "opengl32" => "OPENGLFILES",
65 "wined3d" => "OPENGLFILES",
66 "winex11.drv" => "XFILES",
67 "winequartz.drv" => "QUARTZFILES"
70 # Default patterns for top-level .gitignore
85 # Source files and their resulting target to ignore
87 [ 'BISON_SRCS', '\.y', '.tab.c' ],
88 [ 'BISON_SRCS', '\.y', '.tab.h' ],
89 [ 'LEX_SRCS', '\.l', '.yy.c' ],
90 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
91 [ 'RC_SRCS', '\.rc', '.res' ],
92 [ 'RC_SRCS16', '\.rc', '.res' ],
93 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
94 [ 'IDL_H_SRCS', '\.idl', '.h' ],
95 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
96 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
97 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
98 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
101 my (@makefiles, %makefiles);
103 # update a file if changed
107 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
114 rename "$file.new", "$file";
115 print "$file updated\n";
116 if ($file eq "configure.ac")
119 print "configure updated\n";
125 # replace some lines in a file between two markers
126 sub replace_in_file($$$@)
132 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
136 open OLD_FILE, "$file" or die "cannot open $file";
151 print NEW_FILE $_ unless $skip;
156 close OLD_FILE if defined($start);
158 return update_file($file);
161 # parse the specified makefile to identify the rules file
162 sub parse_makefile($)
167 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
169 open MAKE, "$file.in" or die "cannot open $file.in\n";
174 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
176 if (/^\@(MAKE.*RULES)\@/)
179 $make{"=rules"} = $makerules{$var};
182 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
187 if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
189 my @list = split(/\s+/, $2);
193 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
204 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
208 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
211 foreach my $file (sort values %makerules, @makefiles)
213 my %make = parse_makefile( $file );
214 $makefiles{$file} = \%make;
217 ################################################################
218 # update the makefile list in configure.ac
222 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
224 push @lines, "$var=$makerules{$var}\n";
225 push @lines, "AC_SUBST_FILE($var)\n\n";
228 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
230 "AC_CONFIG_FILES([\n",
231 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
234 ################################################################
235 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
237 sub update_winetest(@)
241 foreach my $file (@_)
243 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
245 push @lines, "TESTBINS =";
246 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
249 foreach my $test (sort @tests)
251 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
252 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
254 push @lines, "\n# Special rules\n";
256 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
258 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
259 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
261 # return a list of test exe files for .gitignore
262 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
266 ################################################################
267 # update the makefile list in Makefile.in
269 sub update_makefiles(@)
271 my (@targets, @depends);
273 foreach my $file (sort values %makerules)
275 push @targets, $file;
276 my %make = %{$makefiles{$file}};
277 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
278 else { push @depends, "$file: $file.in Make.rules"; }
281 foreach my $file (sort @_)
283 push @targets, $file unless $file eq "Makefile";
284 my %makefile = %{$makefiles{$file}};
285 my $dep = $makefile{"=rules"};
286 push @depends, "$file: $file.in $dep";
291 push @lines, "ALL_MAKEFILES = \\\n\t";
292 push @lines, join (" \\\n\t", @targets ), "\n\n";
293 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
294 push @lines, "\t\@./config.status \$\@\n\n";
295 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
296 push @lines, "distclean::\n";
297 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
298 push @lines, join ("\n", @depends ), "\n";
300 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
304 ################################################################
305 # process ignore targets for generic source files
307 sub update_ignores(@)
311 foreach my $file (sort @_)
313 my %makefile = %{$makefiles{$file}};
316 foreach my $src (@ignore_srcs)
318 my @pattern = @{$src};
319 next unless defined $makefile{$pattern[0]};
320 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
322 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
323 foreach my $f (@list)
325 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
331 ################################################################
332 # update dlls/Makefile.in
336 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
340 foreach my $make (@_)
342 my %makefile = %{$makefiles{$make}};
343 next if defined $makefile{"=skip"};
345 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
347 $testdirs{$1} = "$1/tests";
348 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
349 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
350 push @ignores, $makefile{"=dir"} . "testlist.c";
351 push @ignores, $makefile{"=dir"} . "*.ok";
355 next unless defined $makefile{"MODULE"};
356 my $module = $makefile{"MODULE"};
357 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
359 if ($module =~ /^lib.*\.a$/)
361 $staticlib_dirs{$module} = $dir;
362 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
366 (my $mod = $module) =~ s/\.dll$//;
367 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
368 $directories{$module} = $dir;
371 if (defined $makefile{"IMPORTLIB"})
373 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
375 $importlibs{$module} = $1;
379 die "invalid importlib name $makefile{IMPORTLIB} in $make";
383 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
385 if (defined $makefile{"SPEC_SRCS16"})
387 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
388 $altnames{$module} = \@list;
392 # output special dlls configure definitions
394 $text .= "# special configure-dependent targets\n\n";
396 foreach my $mod (sort keys %special_dlls)
398 $specials{$special_dlls{$mod}} .= " " . $mod;
400 foreach my $i (sort keys %specials)
402 $text .= $i . " =" . $specials{$i} . "\n";
404 $text .= "EXTRADIRS =";
405 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
408 # output the subdirs list
410 $text .= "# Subdir list\n\n";
411 $text .= "BASEDIRS =";
412 foreach my $dir (sort values %directories)
414 next if defined($special_dlls{$dir}); # skip special dlls
415 $text .= " \\\n\t" . $dir;
418 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
419 $text .= join " \\\n\t", sort values %staticlib_dirs;
421 $text .= "\n\nTESTSUBDIRS = \\\n\t";
422 $text .= join " \\\n\t", sort values %testdirs;
424 $text .= "\n\nSUBDIRS = \\\n\t";
425 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
427 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
428 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
429 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
431 # output the list of 16-bit files
434 foreach my $mod (sort keys %directories)
436 next unless defined $altnames{$mod};
437 foreach my $i (sort @{$altnames{$mod}})
439 push @targets16, $i . "16";
442 $text .= "\n# 16-bit dlls\n\n";
443 $text .= "WIN16_FILES = \\\n";
444 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
445 $text .= "\@MAKE_RULES\@\n\n";
447 # output the all: target
449 $text .= "# Main target\n\n";
450 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
452 # output the lib name -> directory rules
454 $text .= "# Placeholders for 16-bit libraries\n\n";
455 foreach my $mod (sort keys %directories)
457 next unless defined $altnames{$mod};
458 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
459 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
462 # output the import libraries rules
464 $text .= "# Import libraries\n\n";
465 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
467 my @lib_symlinks = ();
468 foreach my $mod (sort keys %importlibs)
470 my $dir = $directories{$mod};
471 my $lib = $importlibs{$mod};
472 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
474 $text .= "IMPORT_SYMLINKS =";
475 foreach my $mod (sort @lib_symlinks)
477 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
480 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
481 foreach my $mod (sort keys %staticlib_dirs)
483 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
485 foreach my $mod (sort keys %importlibs)
487 my $dir = $directories{$mod};
489 $def =~ s/\.(dll|drv)$//;
490 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
491 next unless defined $static_implibs{$mod};
492 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
495 $text .= "implib: \$(IMPORT_LIBS)\n\n";
496 $text .= ".PHONY: implib\n\n";
498 foreach my $mod (sort keys %importlibs)
500 my $dir = $directories{$mod};
501 my $lib = $importlibs{$mod};
504 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
505 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
506 next unless $static_implibs{$mod};
507 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
508 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
510 foreach my $mod (sort @lib_symlinks)
512 my $dir = $directories{$mod};
513 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
514 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
515 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
518 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
519 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
521 # output the inter-dll dependencies and rules
523 $text .= "# Map library name to the corresponding directory\n\n";
525 foreach my $mod (sort keys %staticlib_dirs)
527 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
529 $text .= "\n# Misc rules\n";
531 replace_in_file( "dlls/Makefile.in",
532 '^# special configure-dependent targets',
538 foreach my $mod (sort @lib_symlinks)
540 push @ignores, "dlls/$importlibs{$mod}.def";
542 foreach my $mod (sort keys %directories)
544 next unless defined $altnames{$mod};
545 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
547 foreach my $mod (sort keys %importlibs)
549 my $dir = $directories{$mod};
551 $def =~ s/\.(dll|drv)$//;
552 push @ignores, "dlls/$dir/lib$def.def";
559 ################################################################
560 # update programs/Makefile.in
564 my (@subdirs, @install_subdirs, @install_progs);
568 foreach my $make (@_)
570 my %makefile = %{$makefiles{$make}};
571 my $module = $makefile{"MODULE"};
572 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
573 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
574 next if defined $makefile{"=skip"};
576 push @ignores, "programs/$dir/$dir";
577 push @install_subdirs, $dir unless $dont_install{$dir};
578 push @install_progs, $dir if $bin_install{$dir};
581 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
583 join( " \\\n\t", @subdirs ),
584 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
585 join( " \\\n\t", @install_subdirs ),
586 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
587 join( " \\\n\t", @install_progs ),
588 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
594 ################################################################
595 # update the main .gitignore
597 sub update_gitignore(@)
599 my @ignores = values %makerules;
601 foreach my $make (@makefiles)
603 my %makefile = %{$makefiles{$make}};
604 my $dir = $makefile{"=dir"};
605 if (defined $makefile{"MANPAGES"})
607 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
609 if (defined $makefile{"PROGRAMS"})
611 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
615 # prepend a slash to paths that don't have one
616 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
620 replace_in_file( ".gitignore", undef, undef,
621 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
622 join("\n", sort @ignores), "\n" );
626 update_makefiles( @makefiles );
627 push @ignores, update_ignores( @makefiles );
628 push @ignores, update_winetest( @makefiles );
629 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
630 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
631 update_gitignore( @ignores );