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
83 # Source files and their resulting target to ignore
85 [ 'BISON_SRCS', '\.y', '.tab.c' ],
86 [ 'BISON_SRCS', '\.y', '.tab.h' ],
87 [ 'LEX_SRCS', '\.l', '.yy.c' ],
88 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
89 [ 'RC_SRCS', '\.rc', '.res' ],
90 [ 'RC_SRCS16', '\.rc', '.res' ],
91 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
92 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
93 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
94 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
95 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
98 my (@makefiles, %makefiles);
100 # update a file if changed
104 my $ret = system "cmp $file $file.new >/dev/null";
111 rename "$file.new", "$file";
112 print "$file updated\n";
113 if ($file eq "configure.ac")
116 print "configure updated\n";
122 # replace some lines in a file between two markers
123 sub replace_in_file($$$@)
129 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
133 open OLD_FILE, "$file" or die "cannot open $file";
148 print NEW_FILE $_ unless $skip;
153 close OLD_FILE if defined($start);
155 return update_file($file);
158 # parse the specified makefile to identify the rules file
159 sub parse_makefile($)
164 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
166 open MAKE, "$file.in" or die "cannot open $file.in\n";
171 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
173 if (/^\@(MAKE.*RULES)\@/)
176 $make{"=rules"} = $makerules{$var};
179 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
184 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*(.*)/)
186 my @list = split(/\s+/, $2);
190 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
201 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
205 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
208 foreach my $file (sort values %makerules, @makefiles)
210 my %make = parse_makefile( $file );
211 $makefiles{$file} = \%make;
214 ################################################################
215 # update the makefile list in configure.ac
219 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
221 push @lines, "$var=$makerules{$var}\n";
222 push @lines, "AC_SUBST_FILE($var)\n\n";
225 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
227 "AC_CONFIG_FILES([\n",
228 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
231 ################################################################
232 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
234 sub update_winetest(@)
238 foreach my $file (@_)
240 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
242 push @lines, "TESTBINS =";
243 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
246 foreach my $test (sort @tests)
248 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
249 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
251 push @lines, "\n# Special rules\n";
253 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
255 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
256 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
258 # return a list of test exe files for .gitignore
259 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
263 ################################################################
264 # update the makefile list in Makefile.in
266 sub update_makefiles(@)
268 my (@targets, @depends);
270 foreach my $file (sort values %makerules)
272 push @targets, $file;
273 my %make = %{$makefiles{$file}};
274 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
275 else { push @depends, "$file: $file.in Make.rules"; }
278 foreach my $file (sort @_)
280 push @targets, $file unless $file eq "Makefile";
281 my %makefile = %{$makefiles{$file}};
282 my $dep = $makefile{"=rules"};
283 push @depends, "$file: $file.in $dep";
288 push @lines, "ALL_MAKEFILES = \\\n\t";
289 push @lines, join (" \\\n\t", @targets ), "\n\n";
290 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
291 push @lines, "\t\@./config.status \$\@\n\n";
292 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
293 push @lines, "distclean::\n";
294 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
295 push @lines, join ("\n", @depends ), "\n";
297 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
301 ################################################################
302 # process ignore targets for generic source files
304 sub update_ignores(@)
308 foreach my $file (sort @_)
310 my %makefile = %{$makefiles{$file}};
313 foreach my $src (@ignore_srcs)
315 my @pattern = @{$src};
316 next unless defined $makefile{$pattern[0]};
317 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
319 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
321 push @ignores, map { $makefile{"=dir"} . $_; } @list;
326 ################################################################
327 # update dlls/Makefile.in
331 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
335 sub needs_symlink($$)
337 my ($mod, $dir) = @_;
342 foreach my $make (@_)
344 my %makefile = %{$makefiles{$make}};
345 next if defined $makefile{"=skip"};
347 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
349 $testdirs{$1} = "$1/tests";
350 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
351 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
352 push @ignores, $makefile{"=dir"} . "testlist.c";
353 push @ignores, $makefile{"=dir"} . "*.ok";
357 next unless defined $makefile{"MODULE"};
358 my $module = $makefile{"MODULE"};
359 (my $dir = $make) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
361 if ($module =~ /^lib.*\.a$/)
363 $staticlib_dirs{$module} = $dir;
364 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
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;
391 if (defined $makefile{"IDL_H_SRCS"})
393 push @ignores, map { $_ =~ s/(.*)\.idl$/dlls\/$dir\/$1.h/; $_; } @{$makefile{"IDL_H_SRCS"}};
397 # output special dlls configure definitions
399 $text .= "# special configure-dependent targets\n\n";
401 foreach my $mod (sort keys %special_dlls)
403 $specials{$special_dlls{$mod}} .= " " . $mod;
405 foreach my $i (sort keys %specials)
407 $text .= $i . " =" . $specials{$i} . "\n";
409 $text .= "EXTRADIRS =";
410 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
413 # output the subdirs list
415 $text .= "# Subdir list\n\n";
416 $text .= "BASEDIRS =";
417 foreach my $dir (sort values %directories)
419 next if defined($special_dlls{$dir}); # skip special dlls
420 $text .= " \\\n\t" . $dir;
423 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
424 $text .= join " \\\n\t", sort values %staticlib_dirs;
426 $text .= "\n\nTESTSUBDIRS = \\\n\t";
427 $text .= join " \\\n\t", sort values %testdirs;
429 $text .= "\n\nSUBDIRS = \\\n\t";
430 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
432 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
433 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
434 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
436 # output the all: target
438 my %targets = (); # use a hash to get rid of duplicate target names
440 foreach my $mod (sort keys %directories)
442 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
443 $targets{$mod . ".so"} = 1 if needs_symlink($mod, $directories{$mod});
444 next unless defined $altnames{$mod};
445 foreach my $i (sort @{$altnames{$mod}})
447 $targets16{$i . "16"} = $mod;
451 $text .= "\n\@MAKE_RULES\@\n\n";
452 $text .= "# Symbolic links\n\n";
453 $text .= "WIN16_FILES = \\\n";
454 $text .= "\t" . join( " \\\n\t", sort keys %targets16 ) . "\n\n";
455 $text .= "SYMLINKS_SO = \\\n";
456 $text .= "\t\@WIN16_FILES\@ \\\n";
457 $text .= "\t" . join( " \\\n\t", sort keys %targets ) . "\n\n";
458 $text .= "# Main target\n\n";
459 $text .= "all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)\n\n";
460 $text .= ".PHONY: symlinks symlinks.so implib\n\n";
461 $text .= "symlinks.so: \$(SYMLINKS_SO)\n\n";
462 $text .= "symlinks: \$(BUILDSUBDIRS)\n\n";
464 # output the lib name -> directory rules
466 $text .= "# Map symlink name to the corresponding library\n\n";
467 foreach my $mod (sort keys %directories)
469 next unless needs_symlink($mod, $directories{$mod});
470 $text .= sprintf "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
471 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
474 $text .= "# Placeholders for 16-bit libraries\n\n";
475 foreach my $mod (sort keys %directories)
477 next unless defined $altnames{$mod};
478 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
479 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
482 # output the import libraries rules
484 $text .= "# Import libraries\n\n";
485 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
487 my @lib_symlinks = ();
488 foreach my $mod (sort keys %importlibs)
490 my $dir = $directories{$mod};
491 my $lib = $importlibs{$mod};
492 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
494 $text .= "IMPORT_SYMLINKS =";
495 foreach my $mod (sort @lib_symlinks)
497 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
500 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
501 foreach my $mod (sort keys %staticlib_dirs)
503 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
505 foreach my $mod (sort keys %importlibs)
507 my $dir = $directories{$mod};
509 $def =~ s/\.(dll|drv)$//;
510 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
511 next unless defined $static_implibs{$mod};
512 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
515 $text .= "implib: \$(IMPORT_LIBS)\n\n";
517 foreach my $mod (sort keys %importlibs)
519 my $dir = $directories{$mod};
520 my $lib = $importlibs{$mod};
523 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
524 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
525 next unless $static_implibs{$mod};
526 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
527 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
529 foreach my $mod (sort @lib_symlinks)
531 my $dir = $directories{$mod};
532 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
533 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
534 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
537 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
538 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
540 # output the inter-dll dependencies and rules
542 $text .= "# Map library name to the corresponding directory\n\n";
544 foreach my $mod (sort keys %directories)
546 next unless needs_symlink($mod, $directories{$mod});
547 $text .= sprintf "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
549 foreach my $mod (sort keys %staticlib_dirs)
551 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
553 $text .= "\n# Misc rules\n";
555 replace_in_file( "dlls/Makefile.in",
556 '^# special configure-dependent targets',
562 foreach my $mod (sort @lib_symlinks)
564 push @ignores, "dlls/$importlibs{$mod}.def";
566 foreach my $mod (sort keys %directories)
568 next unless defined $altnames{$mod};
569 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
571 foreach my $mod (sort keys %importlibs)
573 my $dir = $directories{$mod};
575 $def =~ s/\.(dll|drv)$//;
576 push @ignores, "dlls/$dir/lib$def.def";
583 ################################################################
584 # update programs/Makefile.in
588 my (@subdirs, @install_subdirs, @install_progs);
592 foreach my $make (@_)
594 my %makefile = %{$makefiles{$make}};
595 my $module = $makefile{"MODULE"};
596 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
597 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
598 next if defined $makefile{"=skip"};
600 push @ignores, "programs/$dir/$dir";
601 push @install_subdirs, $dir unless $dont_install{$dir};
602 push @install_progs, $dir if $bin_install{$dir};
605 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
607 join( " \\\n\t", @subdirs ),
608 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
609 join( " \\\n\t", @install_subdirs ),
610 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
611 join( " \\\n\t", @install_progs ),
612 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
618 ################################################################
619 # update the main .gitignore
621 sub update_gitignore(@)
623 my @ignores = values %makerules;
625 foreach my $make (@makefiles)
627 my %makefile = %{$makefiles{$make}};
628 my $dir = $makefile{"=dir"};
629 if (defined $makefile{"MANPAGES"})
631 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
633 if (defined $makefile{"PROGRAMS"})
635 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
639 # prepend a slash to paths that don't have one
640 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
644 replace_in_file( ".gitignore", undef, undef,
645 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
646 join("\n", sort @ignores), "\n" );
650 update_makefiles( @makefiles );
651 push @ignores, update_ignores( @makefiles );
652 push @ignores, update_winetest( @makefiles );
653 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
654 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
655 update_gitignore( @ignores );