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_H_SRCS', '\.idl', '.h' ],
93 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
94 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
95 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
96 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
99 my (@makefiles, %makefiles);
101 # update a file if changed
105 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
112 rename "$file.new", "$file";
113 print "$file updated\n";
114 if ($file eq "configure.ac")
117 print "configure updated\n";
123 # replace some lines in a file between two markers
124 sub replace_in_file
($$$@
)
130 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
134 open OLD_FILE
, "$file" or die "cannot open $file";
149 print NEW_FILE
$_ unless $skip;
154 close OLD_FILE
if defined($start);
156 return update_file
($file);
159 # parse the specified makefile to identify the rules file
160 sub parse_makefile
($)
165 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
167 open MAKE
, "$file.in" or die "cannot open $file.in\n";
172 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
174 if (/^\@(MAKE.*RULES)\@/)
177 $make{"=rules"} = $makerules{$var};
180 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
185 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*(.*)/)
187 my @list = split(/\s+/, $2);
191 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
202 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
206 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s
/,`find . -name Makefile.in -print`);
209 foreach my $file (sort values %makerules, @makefiles)
211 my %make = parse_makefile
( $file );
212 $makefiles{$file} = \
%make;
215 ################################################################
216 # update the makefile list in configure.ac
220 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
222 push @lines, "$var=$makerules{$var}\n";
223 push @lines, "AC_SUBST_FILE($var)\n\n";
226 replace_in_file
( "configure.ac", '^MAKE_RULES', '\]\)$',
228 "AC_CONFIG_FILES([\n",
229 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
232 ################################################################
233 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
235 sub update_winetest
(@
)
239 foreach my $file (@_)
241 if ($file =~ /^dlls\/(.*)\
/tests\/Makefile
/) { push @tests, $1; }
243 push @lines, "TESTBINS =";
244 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
247 foreach my $test (sort @tests)
249 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
250 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
252 push @lines, "\n# Special rules\n";
254 replace_in_file
( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
256 replace_in_file
( "programs/winetest/winetest.rc", ' TESTRES ', undef,
257 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
259 # return a list of test exe files for .gitignore
260 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
264 ################################################################
265 # update the makefile list in Makefile.in
267 sub update_makefiles
(@
)
269 my (@targets, @depends);
271 foreach my $file (sort values %makerules)
273 push @targets, $file;
274 my %make = %{$makefiles{$file}};
275 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
276 else { push @depends, "$file: $file.in Make.rules"; }
279 foreach my $file (sort @_)
281 push @targets, $file unless $file eq "Makefile";
282 my %makefile = %{$makefiles{$file}};
283 my $dep = $makefile{"=rules"};
284 push @depends, "$file: $file.in $dep";
289 push @lines, "ALL_MAKEFILES = \\\n\t";
290 push @lines, join (" \\\n\t", @targets ), "\n\n";
291 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
292 push @lines, "\t\@./config.status \$\@\n\n";
293 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
294 push @lines, "distclean::\n";
295 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
296 push @lines, join ("\n", @depends ), "\n";
298 replace_in_file
( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
302 ################################################################
303 # process ignore targets for generic source files
305 sub update_ignores
(@
)
309 foreach my $file (sort @_)
311 my %makefile = %{$makefiles{$file}};
314 foreach my $src (@ignore_srcs)
316 my @pattern = @
{$src};
317 next unless defined $makefile{$pattern[0]};
318 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
320 push @list, @
{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
321 foreach my $f (@list)
323 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
329 ################################################################
330 # update dlls/Makefile.in
334 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
338 foreach my $make (@_)
340 my %makefile = %{$makefiles{$make}};
341 next if defined $makefile{"=skip"};
343 if ($make =~ /dlls\/(.*)\
/tests\/Makefile
/)
345 $testdirs{$1} = "$1/tests";
346 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
347 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
348 push @ignores, $makefile{"=dir"} . "testlist.c";
349 push @ignores, $makefile{"=dir"} . "*.ok";
353 next unless defined $makefile{"MODULE"};
354 my $module = $makefile{"MODULE"};
355 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
357 if ($module =~ /^lib.*\.a$/)
359 $staticlib_dirs{$module} = $dir;
360 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
364 (my $mod = $module) =~ s/\.dll$//;
365 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
366 $directories{$module} = $dir;
369 if (defined $makefile{"IMPORTLIB"})
371 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
373 $importlibs{$module} = $1;
377 die "invalid importlib name $makefile{IMPORTLIB} in $make";
381 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
383 if (defined $makefile{"SPEC_SRCS16"})
385 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @
{$makefile{"SPEC_SRCS16"}};
386 $altnames{$module} = \
@list;
390 # output special dlls configure definitions
392 $text .= "# special configure-dependent targets\n\n";
394 foreach my $mod (sort keys %special_dlls)
396 $specials{$special_dlls{$mod}} .= " " . $mod;
398 foreach my $i (sort keys %specials)
400 $text .= $i . " =" . $specials{$i} . "\n";
402 $text .= "EXTRADIRS =";
403 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
406 # output the subdirs list
408 $text .= "# Subdir list\n\n";
409 $text .= "BASEDIRS =";
410 foreach my $dir (sort values %directories)
412 next if defined($special_dlls{$dir}); # skip special dlls
413 $text .= " \\\n\t" . $dir;
416 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
417 $text .= join " \\\n\t", sort values %staticlib_dirs;
419 $text .= "\n\nTESTSUBDIRS = \\\n\t";
420 $text .= join " \\\n\t", sort values %testdirs;
422 $text .= "\n\nSUBDIRS = \\\n\t";
423 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
425 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
426 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
427 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
429 # output the list of 16-bit files
432 foreach my $mod (sort keys %directories)
434 next unless defined $altnames{$mod};
435 foreach my $i (sort @
{$altnames{$mod}})
437 push @targets16, $i . "16";
440 $text .= "\n# 16-bit dlls\n\n";
441 $text .= "WIN16_FILES = \\\n";
442 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
443 $text .= "\@MAKE_RULES\@\n\n";
445 # output the all: target
447 $text .= "# Main target\n\n";
448 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
450 # output the lib name -> directory rules
452 $text .= "# Placeholders for 16-bit libraries\n\n";
453 foreach my $mod (sort keys %directories)
455 next unless defined $altnames{$mod};
456 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @
{$altnames{$mod}});
457 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
460 # output the import libraries rules
462 $text .= "# Import libraries\n\n";
463 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
465 my @lib_symlinks = ();
466 foreach my $mod (sort keys %importlibs)
468 my $dir = $directories{$mod};
469 my $lib = $importlibs{$mod};
470 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
472 $text .= "IMPORT_SYMLINKS =";
473 foreach my $mod (sort @lib_symlinks)
475 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
478 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
479 foreach my $mod (sort keys %staticlib_dirs)
481 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
483 foreach my $mod (sort keys %importlibs)
485 my $dir = $directories{$mod};
487 $def =~ s/\.(dll|drv)$//;
488 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
489 next unless defined $static_implibs{$mod};
490 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
493 $text .= "implib: \$(IMPORT_LIBS)\n\n";
494 $text .= ".PHONY: implib\n\n";
496 foreach my $mod (sort keys %importlibs)
498 my $dir = $directories{$mod};
499 my $lib = $importlibs{$mod};
502 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
503 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
504 next unless $static_implibs{$mod};
505 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
506 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
508 foreach my $mod (sort @lib_symlinks)
510 my $dir = $directories{$mod};
511 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
512 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
513 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
516 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
517 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
519 # output the inter-dll dependencies and rules
521 $text .= "# Map library name to the corresponding directory\n\n";
523 foreach my $mod (sort keys %staticlib_dirs)
525 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
527 $text .= "\n# Misc rules\n";
529 replace_in_file
( "dlls/Makefile.in",
530 '^# special configure-dependent targets',
536 foreach my $mod (sort @lib_symlinks)
538 push @ignores, "dlls/$importlibs{$mod}.def";
540 foreach my $mod (sort keys %directories)
542 next unless defined $altnames{$mod};
543 push @ignores, map { "dlls/" . $_ . "16"; } @
{$altnames{$mod}};
545 foreach my $mod (sort keys %importlibs)
547 my $dir = $directories{$mod};
549 $def =~ s/\.(dll|drv)$//;
550 push @ignores, "dlls/$dir/lib$def.def";
557 ################################################################
558 # update programs/Makefile.in
562 my (@subdirs, @install_subdirs, @install_progs);
566 foreach my $make (@_)
568 my %makefile = %{$makefiles{$make}};
569 my $module = $makefile{"MODULE"};
570 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile
$/$1/;
571 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
572 next if defined $makefile{"=skip"};
574 push @ignores, "programs/$dir/$dir";
575 push @install_subdirs, $dir unless $dont_install{$dir};
576 push @install_progs, $dir if $bin_install{$dir};
579 replace_in_file
( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
581 join( " \\\n\t", @subdirs ),
582 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
583 join( " \\\n\t", @install_subdirs ),
584 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
585 join( " \\\n\t", @install_progs ),
586 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
592 ################################################################
593 # update the main .gitignore
595 sub update_gitignore
(@
)
597 my @ignores = values %makerules;
599 foreach my $make (@makefiles)
601 my %makefile = %{$makefiles{$make}};
602 my $dir = $makefile{"=dir"};
603 if (defined $makefile{"MANPAGES"})
605 push @ignores, map { $dir . $_; } @
{$makefile{"MANPAGES"}};
607 if (defined $makefile{"PROGRAMS"})
609 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
613 # prepend a slash to paths that don't have one
614 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
618 replace_in_file
( ".gitignore", undef, undef,
619 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
620 join("\n", sort @ignores), "\n" );
624 update_makefiles
( @makefiles );
625 push @ignores, update_ignores
( @makefiles );
626 push @ignores, update_winetest
( @makefiles );
627 push @ignores, update_dlls
( sort grep /^dlls\//, @makefiles );
628 push @ignores, update_progs
( sort grep /^programs\/.*\
/Makefile$/, @makefiles );
629 update_gitignore
( @ignores );