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
94 my (@makefiles, %makefiles);
96 # update a file if changed
100 my $ret = system "cmp $file $file.new >/dev/null";
107 rename "$file.new", "$file";
108 print "$file updated\n";
109 if ($file eq "configure.ac")
112 print "configure updated\n";
118 # replace some lines in a file between two markers
119 sub replace_in_file($$$@)
125 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
129 open OLD_FILE, "$file" or die "cannot open $file";
144 print NEW_FILE $_ unless $skip;
149 close OLD_FILE if defined($start);
151 return update_file($file);
154 # parse the specified makefile to identify the rules file
155 sub parse_makefile($)
160 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
162 open MAKE, "$file.in" or die "cannot open $file.in\n";
167 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
169 if (/^\@(MAKE.*RULES)\@/)
172 $make{"=rules"} = $makerules{$var};
175 if (/^(MODULE|IMPORTLIB)\s*=\s*(.*)/)
180 if (/^(IDL_H_SRCS|IMPLIB_SRCS|SPEC_SRCS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
182 my @list = split(/\s+/, $2);
186 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
197 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
201 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
204 foreach my $file (sort values %makerules, @makefiles)
206 my %make = parse_makefile( $file );
207 $makefiles{$file} = \%make;
210 ################################################################
211 # update the makefile list in configure.ac
215 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
217 push @lines, "$var=$makerules{$var}\n";
218 push @lines, "AC_SUBST_FILE($var)\n\n";
221 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
223 "AC_CONFIG_FILES([\n",
224 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
227 ################################################################
228 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
230 sub update_winetest(@)
234 foreach my $file (@_)
236 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
238 push @lines, "TESTBINS =";
239 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
242 foreach my $test (sort @tests)
244 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
245 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
247 push @lines, "\n# Special rules\n";
249 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
251 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
252 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
254 # return a list of test exe files for .gitignore
255 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
259 ################################################################
260 # update the makefile list in Makefile.in
265 foreach my $file (sort values %makerules)
267 push @targets, $file;
268 my %make = %{$makefiles{$file}};
269 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
270 else { push @depends, "$file: $file.in Make.rules"; }
273 foreach my $file (sort @makefiles)
275 push @targets, $file unless $file eq "Makefile";
276 my $dep = ${$makefiles{$file}}{"=rules"};
277 push @depends, "$file: $file.in $dep";
281 push @lines, "ALL_MAKEFILES = \\\n\t";
282 push @lines, join (" \\\n\t", @targets ), "\n\n";
283 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
284 push @lines, "\t\@./config.status \$\@\n\n";
285 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
286 push @lines, "distclean::\n";
287 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
288 push @lines, join ("\n", @depends ), "\n";
290 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
293 ################################################################
294 # update dlls/Makefile.in
298 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
303 "dlls/*/tests/testlist.c",
307 sub needs_symlink($$)
309 my ($mod, $dir) = @_;
314 foreach my $make (@_)
316 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
318 $testdirs{$1} = "$1/tests";
321 my %makefile = %{$makefiles{$make}};
323 next unless defined $makefile{"MODULE"};
324 my $module = $makefile{"MODULE"};
325 (my $dir = $make) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
327 if ($module =~ /^lib.*\.a$/)
329 $staticlib_dirs{$module} = $dir;
330 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
334 $directories{$module} = $dir;
337 if (defined $makefile{"IMPORTLIB"})
339 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
341 $importlibs{$module} = $1;
345 die "invalid importlib name $makefile{IMPORTLIB} in $make";
349 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
351 if (defined $makefile{"SPEC_SRCS16"})
353 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
354 $altnames{$module} = \@list;
357 if (defined $makefile{"IDL_H_SRCS"})
359 push @ignores, map { $_ =~ s/(.*)\.idl$/dlls\/$dir\/$1.h/; $_; } @{$makefile{"IDL_H_SRCS"}};
363 # output special dlls configure definitions
365 $text .= "# special configure-dependent targets\n\n";
367 foreach my $mod (sort keys %special_dlls)
369 $specials{$special_dlls{$mod}} .= " " . $mod;
371 foreach my $i (sort keys %specials)
373 $text .= $i . " =" . $specials{$i} . "\n";
375 $text .= "EXTRADIRS =";
376 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
379 # output the subdirs list
381 $text .= "# Subdir list\n\n";
382 $text .= "BASEDIRS =";
383 foreach my $dir (sort values %directories)
385 next if defined($special_dlls{$dir}); # skip special dlls
386 $text .= " \\\n\t" . $dir;
389 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
390 $text .= join " \\\n\t", sort values %staticlib_dirs;
392 $text .= "\n\nTESTSUBDIRS = \\\n\t";
393 $text .= join " \\\n\t", sort values %testdirs;
395 $text .= "\n\nSUBDIRS = \\\n\t";
396 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
398 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
399 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
400 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
402 # output the all: target
404 my %targets = (); # use a hash to get rid of duplicate target names
406 foreach my $mod (sort keys %directories)
408 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
409 $targets{$mod . ".so"} = 1 if needs_symlink($mod, $directories{$mod});
410 next unless defined $altnames{$mod};
411 foreach my $i (sort @{$altnames{$mod}})
413 $targets16{$i . "16"} = $mod;
417 $text .= "\n\@MAKE_RULES\@\n\n";
418 $text .= "# Symbolic links\n\n";
419 $text .= "WIN16_FILES = \\\n";
420 $text .= "\t" . join( " \\\n\t", sort keys %targets16 ) . "\n\n";
421 $text .= "SYMLINKS_SO = \\\n";
422 $text .= "\t\@WIN16_FILES\@ \\\n";
423 $text .= "\t" . join( " \\\n\t", sort keys %targets ) . "\n\n";
424 $text .= "# Main target\n\n";
425 $text .= "all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)\n\n";
426 $text .= ".PHONY: symlinks symlinks.so implib\n\n";
427 $text .= "symlinks.so: \$(SYMLINKS_SO)\n\n";
428 $text .= "symlinks: \$(BUILDSUBDIRS)\n\n";
430 # output the lib name -> directory rules
432 $text .= "# Map symlink name to the corresponding library\n\n";
433 foreach my $mod (sort keys %directories)
435 next unless needs_symlink($mod, $directories{$mod});
436 $text .= sprintf "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
437 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
440 $text .= "# Placeholders for 16-bit libraries\n\n";
441 foreach my $mod (sort keys %directories)
443 next unless defined $altnames{$mod};
444 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
445 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
448 # output the import libraries rules
450 $text .= "# Import libraries\n\n";
451 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
453 my @lib_symlinks = ();
454 foreach my $mod (sort keys %importlibs)
456 my $dir = $directories{$mod};
457 my $lib = $importlibs{$mod};
458 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
460 $text .= "IMPORT_SYMLINKS =";
461 foreach my $mod (sort @lib_symlinks)
463 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
466 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
467 foreach my $mod (sort keys %staticlib_dirs)
469 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
471 foreach my $mod (sort keys %importlibs)
473 my $dir = $directories{$mod};
475 $def =~ s/\.(dll|drv)$//;
476 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
477 next unless defined $static_implibs{$mod};
478 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
481 $text .= "implib: \$(IMPORT_LIBS)\n\n";
483 foreach my $mod (sort keys %importlibs)
485 my $dir = $directories{$mod};
486 my $lib = $importlibs{$mod};
489 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
490 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
491 next unless $static_implibs{$mod};
492 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
493 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
495 foreach my $mod (sort @lib_symlinks)
497 my $dir = $directories{$mod};
498 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
499 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
500 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
503 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
504 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
506 # output the inter-dll dependencies and rules
508 $text .= "# Map library name to the corresponding directory\n\n";
510 foreach my $mod (sort keys %directories)
512 next unless needs_symlink($mod, $directories{$mod});
513 $text .= sprintf "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
515 foreach my $mod (sort keys %staticlib_dirs)
517 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
519 $text .= "\n# Misc rules\n";
521 replace_in_file( "dlls/Makefile.in",
522 '^# special configure-dependent targets',
528 foreach my $mod (sort @lib_symlinks)
530 push @ignores, "dlls/$importlibs{$mod}.def";
532 foreach my $mod (sort keys %directories)
534 next unless defined $altnames{$mod};
535 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
537 foreach my $mod (sort keys %importlibs)
539 my $dir = $directories{$mod};
541 $def =~ s/\.(dll|drv)$//;
542 push @ignores, "dlls/$dir/lib$def.def";
549 ################################################################
550 # update programs/Makefile.in
554 my (@subdirs, @install_subdirs, @install_progs);
558 foreach my $make (@_)
560 my %makefile = %{$makefiles{$make}};
561 my $module = $makefile{"MODULE"};
562 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
563 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
564 next if defined $makefile{"=skip"};
566 push @ignores, "programs/$dir/$dir";
567 push @install_subdirs, $dir unless $dont_install{$dir};
568 push @install_progs, $dir if $bin_install{$dir};
571 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
573 join( " \\\n\t", @subdirs ),
574 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
575 join( " \\\n\t", @install_subdirs ),
576 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
577 join( " \\\n\t", @install_progs ),
578 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
584 ################################################################
585 # update the main .gitignore
587 sub update_gitignore(@)
589 my @ignores = values %makerules;
591 foreach my $make (@makefiles)
593 my %makefile = %{$makefiles{$make}};
594 my $dir = $makefile{"=dir"};
595 if (defined $makefile{"MANPAGES"})
597 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
599 if (defined $makefile{"PROGRAMS"})
601 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
605 # prepend a slash to paths that don't have one
606 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
610 replace_in_file( ".gitignore", undef, undef,
611 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
612 join("\n", sort @ignores), "\n" );
616 push @ignores, update_winetest( @makefiles );
617 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
618 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
619 update_gitignore( @ignores );