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', '.h' ],
96 [ 'IDL_I_SRCS', '\.idl', '.h' ],
97 [ 'IDL_P_SRCS', '\.idl', '.h' ],
98 [ 'IDL_S_SRCS', '\.idl', '.h' ],
99 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
100 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
101 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
102 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
105 my (@makefiles, %makefiles);
107 # update a file if changed
111 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
118 rename "$file.new", "$file";
119 print "$file updated\n";
120 if ($file eq "configure.ac")
123 print "configure updated\n";
129 # replace some lines in a file between two markers
130 sub replace_in_file($$$@)
136 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
140 open OLD_FILE, "$file" or die "cannot open $file";
155 print NEW_FILE $_ unless $skip;
160 close OLD_FILE if defined($start);
162 return update_file($file);
165 # parse the specified makefile to identify the rules file
166 sub parse_makefile($)
171 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
173 open MAKE, "$file.in" or die "cannot open $file.in\n";
178 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
180 if (/^\@(MAKE.*RULES)\@/)
183 $make{"=rules"} = $makerules{$var};
186 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
191 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*(.*)/)
193 my @list = split(/\s+/, $2);
197 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
208 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
212 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
215 foreach my $file (sort values %makerules, @makefiles)
217 my %make = parse_makefile( $file );
218 $makefiles{$file} = \%make;
221 ################################################################
222 # update the makefile list in configure.ac
226 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
228 push @lines, "$var=$makerules{$var}\n";
229 push @lines, "AC_SUBST_FILE($var)\n\n";
232 foreach my $var ((sort values %makerules), (sort @makefiles))
234 push @lines, "AC_CONFIG_FILES([$var])\n";
237 push @lines, "\nAC_OUTPUT\n";
239 replace_in_file( "configure.ac", '^MAKE_RULES', '^AC_OUTPUT$', @lines);
242 ################################################################
243 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
245 sub update_winetest(@)
249 foreach my $file (@_)
251 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
253 push @lines, "TESTBINS =";
254 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
257 foreach my $test (sort @tests)
259 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
260 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
262 push @lines, "\n# Special rules\n";
264 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
266 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
267 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
269 # return a list of test exe files for .gitignore
270 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
274 ################################################################
275 # update the makefile list in Makefile.in
277 sub update_makefiles(@)
279 my (@targets, @depends);
281 foreach my $file (sort values %makerules)
283 push @targets, $file;
284 my %make = %{$makefiles{$file}};
285 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
286 else { push @depends, "$file: $file.in Make.rules"; }
289 foreach my $file (sort @_)
291 push @targets, $file unless $file eq "Makefile";
292 my %makefile = %{$makefiles{$file}};
293 my $dep = $makefile{"=rules"};
294 push @depends, "$file: $file.in $dep";
299 push @lines, "ALL_MAKEFILES = \\\n\t";
300 push @lines, join (" \\\n\t", @targets ), "\n\n";
301 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
302 push @lines, "\t\@./config.status \$\@\n";
303 push @lines, ".INIT: Makefile\n";
304 push @lines, ".BEGIN: Makefile\n\n";
305 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
306 push @lines, "distclean::\n";
307 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
308 push @lines, join ("\n", @depends ), "\n";
310 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
314 ################################################################
315 # process ignore targets for generic source files
317 sub update_ignores(@)
321 foreach my $file (sort @_)
323 my %makefile = %{$makefiles{$file}};
326 foreach my $src (@ignore_srcs)
328 my @pattern = @{$src};
329 next unless defined $makefile{$pattern[0]};
330 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
332 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
333 foreach my $f (@list)
335 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
341 ################################################################
342 # update dlls/Makefile.in
346 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
350 foreach my $make (@_)
352 my %makefile = %{$makefiles{$make}};
353 next if defined $makefile{"=skip"};
355 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
357 $testdirs{$1} = "$1/tests";
358 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
359 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
360 push @ignores, $makefile{"=dir"} . "testlist.c";
361 push @ignores, $makefile{"=dir"} . "*.ok";
365 next unless defined $makefile{"MODULE"};
366 my $module = $makefile{"MODULE"};
367 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
369 if ($module =~ /^lib.*\.a$/)
371 $staticlib_dirs{$module} = $dir;
372 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
376 die "invalid module $module" unless $module =~ /\./;
377 (my $mod = $module) =~ s/\.dll$//;
378 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
379 $directories{$module} = $dir;
382 if (defined $makefile{"IMPORTLIB"})
384 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
386 $importlibs{$module} = $1;
390 die "invalid importlib name $makefile{IMPORTLIB} in $make";
394 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
396 if (defined $makefile{"SPEC_SRCS16"})
398 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
399 $altnames{$module} = \@list;
403 # output special dlls configure definitions
405 $text .= "# special configure-dependent targets\n\n";
407 foreach my $mod (sort keys %special_dlls)
409 $specials{$special_dlls{$mod}} .= " " . $mod;
411 foreach my $i (sort keys %specials)
413 $text .= $i . " =" . $specials{$i} . "\n";
415 $text .= "EXTRADIRS =";
416 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
419 # output the subdirs list
421 $text .= "# Subdir list\n\n";
422 $text .= "BASEDIRS =";
423 foreach my $dir (sort values %directories)
425 next if defined($special_dlls{$dir}); # skip special dlls
426 $text .= " \\\n\t" . $dir;
429 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
430 $text .= join " \\\n\t", sort values %staticlib_dirs;
432 $text .= "\n\nTESTSUBDIRS = \\\n\t";
433 $text .= join " \\\n\t", sort values %testdirs;
435 $text .= "\n\nSUBDIRS = \\\n\t";
436 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
438 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
439 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
440 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
442 # output the list of 16-bit files
445 foreach my $mod (sort keys %directories)
447 next unless defined $altnames{$mod};
448 foreach my $i (sort @{$altnames{$mod}})
450 push @targets16, $i . "16";
453 $text .= "\n# 16-bit dlls\n\n";
454 $text .= "WIN16_FILES = \\\n";
455 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
456 $text .= "\@MAKE_RULES\@\n\n";
458 # output the all: target
460 $text .= "# Main target\n\n";
461 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
463 # output the lib name -> directory rules
465 $text .= "# Placeholders for 16-bit libraries\n\n";
466 foreach my $mod (sort keys %directories)
468 next unless defined $altnames{$mod};
469 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
470 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
473 # output the import libraries rules
475 $text .= "# Import libraries\n\n";
476 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
478 my @lib_symlinks = ();
479 foreach my $mod (sort keys %importlibs)
481 my $dir = $directories{$mod};
482 my $lib = $importlibs{$mod};
483 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
485 $text .= "IMPORT_SYMLINKS =";
486 foreach my $mod (sort @lib_symlinks)
488 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
491 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
492 foreach my $mod (sort keys %staticlib_dirs)
494 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
496 foreach my $mod (sort keys %importlibs)
498 my $dir = $directories{$mod};
500 $def =~ s/\.(dll|drv)$//;
501 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
502 next unless defined $static_implibs{$mod};
503 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
506 $text .= "implib: \$(IMPORT_LIBS)\n\n";
507 $text .= ".PHONY: implib\n\n";
509 foreach my $mod (sort keys %importlibs)
511 my $dir = $directories{$mod};
512 my $lib = $importlibs{$mod};
515 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
516 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
517 next unless $static_implibs{$mod};
518 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
519 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
521 foreach my $mod (sort @lib_symlinks)
523 my $dir = $directories{$mod};
524 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
525 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
526 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
529 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
530 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
532 # output the inter-dll dependencies and rules
534 $text .= "# Map library name to the corresponding directory\n\n";
536 foreach my $mod (sort keys %staticlib_dirs)
538 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
540 $text .= "\n# Misc rules\n";
542 replace_in_file( "dlls/Makefile.in",
543 '^# special configure-dependent targets',
549 foreach my $mod (sort @lib_symlinks)
551 push @ignores, "dlls/$importlibs{$mod}.def";
553 foreach my $mod (sort keys %directories)
555 next unless defined $altnames{$mod};
556 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
558 foreach my $mod (sort keys %importlibs)
560 my $dir = $directories{$mod};
562 $def =~ s/\.(dll|drv)$//;
563 push @ignores, "dlls/$dir/lib$def.def";
570 ################################################################
571 # update programs/Makefile.in
575 my (@subdirs, @install_subdirs, @install_progs);
579 foreach my $make (@_)
581 my %makefile = %{$makefiles{$make}};
582 my $module = $makefile{"MODULE"};
583 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
584 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
585 next if defined $makefile{"=skip"};
587 push @ignores, "programs/$dir/$dir";
588 push @install_subdirs, $dir unless $dont_install{$dir};
589 push @install_progs, $dir if $bin_install{$dir};
592 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
594 join( " \\\n\t", @subdirs ),
595 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
596 join( " \\\n\t", @install_subdirs ),
597 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
598 join( " \\\n\t", @install_progs ),
599 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
605 ################################################################
606 # update the main .gitignore
608 sub update_gitignore(@)
610 my @ignores = values %makerules;
612 foreach my $make (@makefiles)
614 my %makefile = %{$makefiles{$make}};
615 my $dir = $makefile{"=dir"};
616 if (defined $makefile{"MANPAGES"})
618 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
620 if (defined $makefile{"PROGRAMS"})
622 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
626 # prepend a slash to paths that don't have one
627 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
629 # get rid of duplicates
631 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
633 replace_in_file( ".gitignore", undef, undef,
634 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
635 join("\n", sort keys %ignores), "\n" );
639 update_makefiles( @makefiles );
640 push @ignores, update_ignores( @makefiles );
641 push @ignores, update_winetest( @makefiles );
642 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
643 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
644 update_gitignore( @ignores );