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
51 # Programs that we don't want to install at all
59 # Special dlls that can be switched on or off by configure
62 "glu32" => "GLU32FILES",
63 "opengl32" => "OPENGLFILES",
64 "winex11.drv" => "XFILES",
65 "winequartz.drv" => "QUARTZFILES"
68 # Default patterns for top-level .gitignore
83 "dlls/*/tests/*crosstest.exe",
84 "dlls/*/tests/testlist.c",
89 # Source files and their resulting target to ignore
91 [ 'BISON_SRCS', '\.y', '.tab.c' ],
92 [ 'BISON_SRCS', '\.y', '.tab.h' ],
93 [ 'LEX_SRCS', '\.l', '.yy.c' ],
94 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
95 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
96 [ 'IDL_H_SRCS', '\.idl', '.h' ],
97 [ 'IDL_C_SRCS', '\.idl', '.h' ],
98 [ 'IDL_I_SRCS', '\.idl', '.h' ],
99 [ 'IDL_P_SRCS', '\.idl', '.h' ],
100 [ 'IDL_S_SRCS', '\.idl', '.h' ],
101 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
102 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
103 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
104 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
107 my %private_headers = (
108 "wine/irot.idl" => 1,
110 "wine/mmsystem16.h" => 1,
111 "wine/mscvpdb.h" => 1,
113 "wine/pthread.h" => 1,
115 "wine/server.h" => 1,
116 "wine/server_protocol.h" => 1,
119 "wine/winaspi.h" => 1,
120 "wine/winbase16.h" => 1,
121 "wine/windef16.h" => 1,
122 "wine/wined3d_caps.h" => 1,
123 "wine/wined3d_gl.h" => 1,
124 "wine/wined3d_interface.h" => 1,
125 "wine/wined3d_types.h" => 1,
126 "wine/wingdi16.h" => 1,
127 "wine/winnet16.h" => 1,
128 "wine/winsock16.h" => 1,
129 "wine/winuser16.h" => 1,
133 my %private_idl_headers = (
144 my (@makefiles, %makefiles);
146 # update a file if changed
150 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
157 rename "$file.new", "$file";
158 print "$file updated\n";
159 if ($file eq "configure.ac")
162 print "configure updated\n";
168 # replace some lines in a file between two markers
169 sub replace_in_file
($$$@
)
175 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
179 open OLD_FILE
, "$file" or die "cannot open $file";
194 print NEW_FILE
$_ unless $skip;
199 close OLD_FILE
if defined($start);
201 return update_file
($file);
204 # parse the specified makefile to identify the rules file
205 sub parse_makefile
($)
210 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
212 open MAKE
, "$file.in" or die "cannot open $file.in\n";
217 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
219 if (/^\@(MAKE.*RULES)\@/)
222 $make{"=rules"} = $makerules{$var};
225 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
230 if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|EXTRA_OBJS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
232 my @list = split(/\s+/, $2);
236 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
246 ################################################################
247 # update the makefile list in configure.ac
249 sub update_makerules
(@
)
254 ################################################################
255 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
257 sub update_winetest
(@
)
261 foreach my $file (@_)
263 if ($file =~ /^dlls\/(.*)\
/tests\/Makefile
/) { push @tests, $1; }
265 push @lines, "TESTBINS =";
266 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
269 foreach my $test (sort @tests)
271 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
272 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
274 push @lines, "\n# Special rules\n";
276 replace_in_file
( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
278 replace_in_file
( "programs/winetest/winetest.rc", ' TESTRES ', undef,
279 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
281 # return a list of test exe files for .gitignore
282 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
286 ################################################################
287 # update the makefile list in configure.ac and Makefile.in
289 sub update_makefiles
(@
)
291 my (@targets, @depends, @lines);
293 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
295 push @lines, "$var=$makerules{$var}\n";
296 push @lines, "AC_SUBST_FILE($var)\n\n";
299 foreach my $var ((sort values %makerules), (sort @_))
301 push @lines, "AC_CONFIG_FILES([$var])\n";
304 push @lines, "\nAC_OUTPUT\n";
305 replace_in_file
( "configure.ac", '^MAKE_RULES', '^AC_OUTPUT$', @lines);
307 foreach my $file (sort values %makerules)
309 push @targets, $file;
310 my %make = %{$makefiles{$file}};
311 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
312 else { push @depends, "$file: $file.in Make.rules"; }
315 foreach my $file (sort @_)
317 push @targets, $file unless $file eq "Makefile";
318 my %makefile = %{$makefiles{$file}};
319 my $dep = $makefile{"=rules"};
320 push @depends, "$file: $file.in $dep";
325 push @lines, "ALL_MAKEFILES = \\\n\t";
326 push @lines, join (" \\\n\t", @targets ), "\n\n";
327 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
328 push @lines, "\t\@./config.status \$\@\n";
329 push @lines, ".INIT: Makefile\n";
330 push @lines, ".BEGIN: Makefile\n\n";
331 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
332 push @lines, "distclean::\n";
333 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
334 push @lines, join ("\n", @depends ), "\n";
336 replace_in_file
( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
340 ################################################################
341 # process ignore targets for generic source files
343 sub update_ignores
(@
)
347 foreach my $file (sort @_)
349 my %makefile = %{$makefiles{$file}};
352 foreach my $src (@ignore_srcs)
354 my @pattern = @
{$src};
355 next unless defined $makefile{$pattern[0]};
356 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
358 push @list, @
{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
359 foreach my $f (@list)
361 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
367 ################################################################
368 # update dlls/Makefile.in
372 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
376 foreach my $make (@_)
378 my %makefile = %{$makefiles{$make}};
379 next if defined $makefile{"=skip"};
381 if ($make =~ /dlls\/(.*)\
/tests\/Makefile
/)
383 $testdirs{$1} = "$1/tests";
384 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
388 next unless defined $makefile{"MODULE"};
389 my $module = $makefile{"MODULE"};
390 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
392 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
394 $staticlib_dirs{$module} = $dir;
395 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
399 die "invalid module $module" unless $module =~ /\./;
400 (my $mod = $module) =~ s/\.dll$//;
401 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
402 $directories{$module} = $dir;
405 if (defined $makefile{"IMPORTLIB"})
407 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
409 $importlibs{$module} = $1;
413 die "invalid importlib name $makefile{IMPORTLIB} in $make";
417 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
419 if (defined $makefile{"SPEC_SRCS16"})
421 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @
{$makefile{"SPEC_SRCS16"}};
422 $altnames{$module} = \
@list;
424 if (defined $makefile{"EXTRA_OBJS16"})
426 foreach my $obj (@
{$makefile{"EXTRA_OBJS16"}})
428 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @
{$altnames{$module}}, $1; }
433 # output special dlls configure definitions
435 $text .= "# special configure-dependent targets\n\n";
437 foreach my $mod (sort keys %special_dlls)
439 $specials{$special_dlls{$mod}} .= " " . $mod;
441 foreach my $i (sort keys %specials)
443 $text .= $i . " =" . $specials{$i} . "\n";
445 $text .= "EXTRADIRS =";
446 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
449 # output the subdirs list
451 $text .= "# Subdir list\n\n";
452 $text .= "BASEDIRS =";
453 foreach my $dir (sort values %directories)
455 next if defined($special_dlls{$dir}); # skip special dlls
456 $text .= " \\\n\t" . $dir;
459 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
460 $text .= join " \\\n\t", sort values %staticlib_dirs;
462 $text .= "\n\nTESTSUBDIRS = \\\n\t";
463 $text .= join " \\\n\t", sort values %testdirs;
465 $text .= "\n\nSUBDIRS = \\\n\t";
466 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
468 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
469 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
470 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
472 # output the list of 16-bit files
475 foreach my $mod (sort keys %directories)
477 next unless defined $altnames{$mod};
478 foreach my $i (sort @
{$altnames{$mod}})
480 push @targets16, $i . "16";
483 $text .= "\n# 16-bit dlls\n\n";
484 $text .= "WIN16_FILES = \\\n";
485 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
486 $text .= "\@MAKE_RULES\@\n\n";
488 # output the all: target
490 $text .= "# Main target\n\n";
491 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
493 # output the lib name -> directory rules
495 $text .= "# Placeholders for 16-bit libraries\n\n";
496 foreach my $mod (sort keys %directories)
498 next unless defined $altnames{$mod};
499 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @
{$altnames{$mod}});
500 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
503 # output the import libraries rules
505 $text .= "# Import libraries\n\n";
506 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
508 my @lib_symlinks = ();
509 foreach my $mod (sort keys %importlibs)
511 my $dir = $directories{$mod};
512 my $lib = $importlibs{$mod};
513 if ($lib ne $dir) { push @lib_symlinks, $mod; }
515 $text .= "IMPORT_SYMLINKS =";
516 foreach my $mod (sort @lib_symlinks)
518 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
521 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
522 foreach my $mod (sort keys %staticlib_dirs)
524 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
526 foreach my $mod (sort keys %importlibs)
528 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
529 next unless defined $static_implibs{$mod};
530 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
532 $text .= "\n\nCROSS_IMPLIBS =";
533 foreach my $mod (sort @lib_symlinks)
535 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
537 foreach my $mod (sort keys %importlibs)
539 next if defined $static_implibs{$mod};
540 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
543 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
544 $text .= "implib: \$(IMPORT_LIBS)\n\n";
545 $text .= ".PHONY: implib\n\n";
547 foreach my $mod (sort keys %importlibs)
549 my $dir = $directories{$mod};
550 my $lib = $importlibs{$mod};
553 if (defined($static_implibs{$mod}))
555 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
556 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
557 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
558 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
562 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
563 $dir, $lib, $dir, $lib, $dir, $spec;
564 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
567 foreach my $mod (sort @lib_symlinks)
569 my $dir = $directories{$mod};
570 my $lib = "lib" . $importlibs{$mod};
571 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
572 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
573 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
574 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
577 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
578 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
580 # output the inter-dll dependencies and rules
582 $text .= "# Map library name to the corresponding directory\n\n";
584 foreach my $mod (sort keys %staticlib_dirs)
586 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
588 $text .= "\n# Misc rules\n";
590 replace_in_file
( "dlls/Makefile.in",
591 '^# special configure-dependent targets',
597 foreach my $mod (sort @lib_symlinks)
599 push @ignores, "dlls/lib$importlibs{$mod}.def";
601 foreach my $mod (sort keys %directories)
603 next unless defined $altnames{$mod};
604 push @ignores, map { "dlls/" . $_ . "16"; } @
{$altnames{$mod}};
611 ################################################################
612 # update programs/Makefile.in
616 my (@subdirs, @install_subdirs, @install_progs);
620 foreach my $make (@_)
622 my %makefile = %{$makefiles{$make}};
623 my $module = $makefile{"MODULE"};
624 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile
$/$1/;
625 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
626 next if defined $makefile{"=skip"};
628 push @ignores, "programs/$dir/$dir";
629 push @install_subdirs, $dir unless $dont_install{$dir};
630 push @install_progs, $dir if $bin_install{$dir};
633 replace_in_file
( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
635 join( " \\\n\t", @subdirs ),
636 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
637 join( " \\\n\t", @install_subdirs ),
638 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
639 join( " \\\n\t", @install_progs ),
640 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
646 ################################################################
647 # update include/Makefile.in
649 sub update_includes
()
651 return unless -d
".git";
652 my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
653 my @includes = map { s/^include\///; $_; } split /\
0/, `git ls-files -c -z include`;
654 foreach my $incl (@includes)
656 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
657 next if ($private_headers{$incl});
658 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
659 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
660 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
661 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
662 elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
664 replace_in_file
( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
665 "IDL_H_SRCS = \\\n\t",
666 join( " \\\n\t", sort @idl_srcs ),
667 "\n\nIDL_TLB_SRCS = \\\n\t",
668 join( " \\\n\t", sort @tlb_srcs ),
669 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
670 join( " \\\n\t", sort @h_srcs ),
671 "\n\nEXTRASUBDIRS = ",
672 join( " ", sort keys %subdirs ),
673 "\n\nINSTALLDIRS = \\\n" );
677 ################################################################
678 # update the main .gitignore
680 sub update_gitignore
(@
)
682 my @ignores = values %makerules;
684 foreach my $make (@makefiles)
686 my %makefile = %{$makefiles{$make}};
687 my $dir = $makefile{"=dir"};
688 if (defined $makefile{"MANPAGES"})
690 push @ignores, map { $dir . $_; } @
{$makefile{"MANPAGES"}};
692 if (defined $makefile{"PROGRAMS"})
694 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
698 # prepend a slash to paths that don't have one
699 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
701 # get rid of duplicates
703 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
705 replace_in_file
( ".gitignore", undef, undef,
706 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
707 join("\n", sort keys %ignores), "\n" );
713 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
717 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s
/,`find . -name Makefile.in -print`);
722 foreach my $file (sort values %makerules, @makefiles)
724 my %make = parse_makefile
( $file );
725 $makefiles{$file} = \
%make;
728 update_makefiles
( @makefiles );
729 push @ignores, update_ignores
( @makefiles );
730 push @ignores, update_winetest
( @makefiles );
731 push @ignores, update_dlls
( sort grep /^dlls\//, @makefiles );
732 push @ignores, update_progs
( sort grep /^programs\/.*\
/Makefile$/, @makefiles );
733 update_gitignore
( @ignores );