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 "winex11.drv" => "XFILES",
66 "winequartz.drv" => "QUARTZFILES"
69 # Default patterns for top-level .gitignore
84 # Source files and their resulting target to ignore
86 [ 'BISON_SRCS', '\.y', '.tab.c' ],
87 [ 'BISON_SRCS', '\.y', '.tab.h' ],
88 [ 'LEX_SRCS', '\.l', '.yy.c' ],
89 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
90 [ 'RC_SRCS', '\.rc', '.res' ],
91 [ 'RC_SRCS16', '\.rc', '.res' ],
92 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
93 [ 'IDL_H_SRCS', '\.idl', '.h' ],
94 [ 'IDL_C_SRCS', '\.idl', '.h' ],
95 [ 'IDL_I_SRCS', '\.idl', '.h' ],
96 [ 'IDL_P_SRCS', '\.idl', '.h' ],
97 [ 'IDL_S_SRCS', '\.idl', '.h' ],
98 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
99 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
100 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
101 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
104 my %private_headers = (
108 "wine/mmsystem16.h" => 1,
109 "wine/mscvpdb.h" => 1,
111 "wine/pthread.h" => 1,
113 "wine/rpcss_shared.h" => 1,
114 "wine/server.h" => 1,
115 "wine/server_protocol.h" => 1,
118 "wine/winaspi.h" => 1,
119 "wine/winbase16.h" => 1,
120 "wine/windef16.h" => 1,
121 "wine/wined3d_caps.h" => 1,
122 "wine/wined3d_gl.h" => 1,
123 "wine/wined3d_interface.h" => 1,
124 "wine/wined3d_types.h" => 1,
125 "wine/wingdi16.h" => 1,
126 "wine/winnet16.h" => 1,
127 "wine/winsock16.h" => 1,
128 "wine/winuser16.h" => 1,
132 my %private_idl_headers = (
142 my (@makefiles, %makefiles);
144 # update a file if changed
148 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
155 rename "$file.new", "$file";
156 print "$file updated\n";
157 if ($file eq "configure.ac")
160 print "configure updated\n";
166 # replace some lines in a file between two markers
167 sub replace_in_file
($$$@
)
173 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
177 open OLD_FILE
, "$file" or die "cannot open $file";
192 print NEW_FILE
$_ unless $skip;
197 close OLD_FILE
if defined($start);
199 return update_file
($file);
202 # parse the specified makefile to identify the rules file
203 sub parse_makefile
($)
208 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
210 open MAKE
, "$file.in" or die "cannot open $file.in\n";
215 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
217 if (/^\@(MAKE.*RULES)\@/)
220 $make{"=rules"} = $makerules{$var};
223 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
228 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*(.*)/)
230 my @list = split(/\s+/, $2);
234 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
244 ################################################################
245 # update the makefile list in configure.ac
247 sub update_makerules
(@
)
252 ################################################################
253 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
255 sub update_winetest
(@
)
259 foreach my $file (@_)
261 if ($file =~ /^dlls\/(.*)\
/tests\/Makefile
/) { push @tests, $1; }
263 push @lines, "TESTBINS =";
264 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
267 foreach my $test (sort @tests)
269 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
270 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
272 push @lines, "\n# Special rules\n";
274 replace_in_file
( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
276 replace_in_file
( "programs/winetest/winetest.rc", ' TESTRES ', undef,
277 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
279 # return a list of test exe files for .gitignore
280 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
284 ################################################################
285 # update the makefile list in configure.ac and Makefile.in
287 sub update_makefiles
(@
)
289 my (@targets, @depends, @lines);
291 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
293 push @lines, "$var=$makerules{$var}\n";
294 push @lines, "AC_SUBST_FILE($var)\n\n";
297 foreach my $var ((sort values %makerules), (sort @_))
299 push @lines, "AC_CONFIG_FILES([$var])\n";
302 push @lines, "\nAC_OUTPUT\n";
303 replace_in_file
( "configure.ac", '^MAKE_RULES', '^AC_OUTPUT$', @lines);
305 foreach my $file (sort values %makerules)
307 push @targets, $file;
308 my %make = %{$makefiles{$file}};
309 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
310 else { push @depends, "$file: $file.in Make.rules"; }
313 foreach my $file (sort @_)
315 push @targets, $file unless $file eq "Makefile";
316 my %makefile = %{$makefiles{$file}};
317 my $dep = $makefile{"=rules"};
318 push @depends, "$file: $file.in $dep";
323 push @lines, "ALL_MAKEFILES = \\\n\t";
324 push @lines, join (" \\\n\t", @targets ), "\n\n";
325 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
326 push @lines, "\t\@./config.status \$\@\n";
327 push @lines, ".INIT: Makefile\n";
328 push @lines, ".BEGIN: Makefile\n\n";
329 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
330 push @lines, "distclean::\n";
331 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
332 push @lines, join ("\n", @depends ), "\n";
334 replace_in_file
( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
338 ################################################################
339 # process ignore targets for generic source files
341 sub update_ignores
(@
)
345 foreach my $file (sort @_)
347 my %makefile = %{$makefiles{$file}};
350 foreach my $src (@ignore_srcs)
352 my @pattern = @
{$src};
353 next unless defined $makefile{$pattern[0]};
354 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
356 push @list, @
{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
357 foreach my $f (@list)
359 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
365 ################################################################
366 # update dlls/Makefile.in
370 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
374 foreach my $make (@_)
376 my %makefile = %{$makefiles{$make}};
377 next if defined $makefile{"=skip"};
379 if ($make =~ /dlls\/(.*)\
/tests\/Makefile
/)
381 $testdirs{$1} = "$1/tests";
382 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
383 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
384 push @ignores, $makefile{"=dir"} . "testlist.c";
385 push @ignores, $makefile{"=dir"} . "*.ok";
389 next unless defined $makefile{"MODULE"};
390 my $module = $makefile{"MODULE"};
391 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
393 if ($module =~ /^lib.*\.a$/)
395 $staticlib_dirs{$module} = $dir;
396 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
400 die "invalid module $module" unless $module =~ /\./;
401 (my $mod = $module) =~ s/\.dll$//;
402 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
403 $directories{$module} = $dir;
406 if (defined $makefile{"IMPORTLIB"})
408 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
410 $importlibs{$module} = $1;
414 die "invalid importlib name $makefile{IMPORTLIB} in $make";
418 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
420 if (defined $makefile{"SPEC_SRCS16"})
422 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @
{$makefile{"SPEC_SRCS16"}};
423 $altnames{$module} = \
@list;
427 # output special dlls configure definitions
429 $text .= "# special configure-dependent targets\n\n";
431 foreach my $mod (sort keys %special_dlls)
433 $specials{$special_dlls{$mod}} .= " " . $mod;
435 foreach my $i (sort keys %specials)
437 $text .= $i . " =" . $specials{$i} . "\n";
439 $text .= "EXTRADIRS =";
440 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
443 # output the subdirs list
445 $text .= "# Subdir list\n\n";
446 $text .= "BASEDIRS =";
447 foreach my $dir (sort values %directories)
449 next if defined($special_dlls{$dir}); # skip special dlls
450 $text .= " \\\n\t" . $dir;
453 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
454 $text .= join " \\\n\t", sort values %staticlib_dirs;
456 $text .= "\n\nTESTSUBDIRS = \\\n\t";
457 $text .= join " \\\n\t", sort values %testdirs;
459 $text .= "\n\nSUBDIRS = \\\n\t";
460 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
462 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
463 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
464 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
466 # output the list of 16-bit files
469 foreach my $mod (sort keys %directories)
471 next unless defined $altnames{$mod};
472 foreach my $i (sort @
{$altnames{$mod}})
474 push @targets16, $i . "16";
477 $text .= "\n# 16-bit dlls\n\n";
478 $text .= "WIN16_FILES = \\\n";
479 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
480 $text .= "\@MAKE_RULES\@\n\n";
482 # output the all: target
484 $text .= "# Main target\n\n";
485 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
487 # output the lib name -> directory rules
489 $text .= "# Placeholders for 16-bit libraries\n\n";
490 foreach my $mod (sort keys %directories)
492 next unless defined $altnames{$mod};
493 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @
{$altnames{$mod}});
494 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
497 # output the import libraries rules
499 $text .= "# Import libraries\n\n";
500 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
502 my @lib_symlinks = ();
503 foreach my $mod (sort keys %importlibs)
505 my $dir = $directories{$mod};
506 my $lib = $importlibs{$mod};
507 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
509 $text .= "IMPORT_SYMLINKS =";
510 foreach my $mod (sort @lib_symlinks)
512 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
515 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
516 foreach my $mod (sort keys %staticlib_dirs)
518 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
520 foreach my $mod (sort keys %importlibs)
522 my $dir = $directories{$mod};
524 $def =~ s/\.(dll|drv)$//;
525 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
526 next unless defined $static_implibs{$mod};
527 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
530 $text .= "implib: \$(IMPORT_LIBS)\n\n";
531 $text .= ".PHONY: implib\n\n";
533 foreach my $mod (sort keys %importlibs)
535 my $dir = $directories{$mod};
536 my $lib = $importlibs{$mod};
539 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
540 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
541 next unless $static_implibs{$mod};
542 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
543 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
545 foreach my $mod (sort @lib_symlinks)
547 my $dir = $directories{$mod};
548 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
549 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
550 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
553 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
554 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
556 # output the inter-dll dependencies and rules
558 $text .= "# Map library name to the corresponding directory\n\n";
560 foreach my $mod (sort keys %staticlib_dirs)
562 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
564 $text .= "\n# Misc rules\n";
566 replace_in_file
( "dlls/Makefile.in",
567 '^# special configure-dependent targets',
573 foreach my $mod (sort @lib_symlinks)
575 push @ignores, "dlls/$importlibs{$mod}.def";
577 foreach my $mod (sort keys %directories)
579 next unless defined $altnames{$mod};
580 push @ignores, map { "dlls/" . $_ . "16"; } @
{$altnames{$mod}};
582 foreach my $mod (sort keys %importlibs)
584 my $dir = $directories{$mod};
586 $def =~ s/\.(dll|drv)$//;
587 push @ignores, "dlls/$dir/lib$def.def";
594 ################################################################
595 # update programs/Makefile.in
599 my (@subdirs, @install_subdirs, @install_progs);
603 foreach my $make (@_)
605 my %makefile = %{$makefiles{$make}};
606 my $module = $makefile{"MODULE"};
607 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile
$/$1/;
608 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
609 next if defined $makefile{"=skip"};
611 push @ignores, "programs/$dir/$dir";
612 push @install_subdirs, $dir unless $dont_install{$dir};
613 push @install_progs, $dir if $bin_install{$dir};
616 replace_in_file
( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
618 join( " \\\n\t", @subdirs ),
619 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
620 join( " \\\n\t", @install_subdirs ),
621 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
622 join( " \\\n\t", @install_progs ),
623 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
629 ################################################################
630 # update include/Makefile.in
632 sub update_includes
()
634 return unless -d
".git";
635 my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
636 my @includes = map { s/^include\///; $_; } split /\
0/, `git ls-files -c -z include`;
637 foreach my $incl (@includes)
639 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
640 next if ($private_headers{$incl});
641 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
642 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
643 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
644 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
645 elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
647 replace_in_file
( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
648 "IDL_H_SRCS = \\\n\t",
649 join( " \\\n\t", sort @idl_srcs ),
650 "\n\nIDL_TLB_SRCS = \\\n\t",
651 join( " \\\n\t", sort @tlb_srcs ),
652 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
653 join( " \\\n\t", sort @h_srcs ),
654 "\n\nEXTRASUBDIRS = ",
655 join( " ", sort keys %subdirs ),
656 "\n\nINSTALLDIRS = \\\n" );
660 ################################################################
661 # update the main .gitignore
663 sub update_gitignore
(@
)
665 my @ignores = values %makerules;
667 foreach my $make (@makefiles)
669 my %makefile = %{$makefiles{$make}};
670 my $dir = $makefile{"=dir"};
671 if (defined $makefile{"MANPAGES"})
673 push @ignores, map { $dir . $_; } @
{$makefile{"MANPAGES"}};
675 if (defined $makefile{"PROGRAMS"})
677 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
681 # prepend a slash to paths that don't have one
682 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
684 # get rid of duplicates
686 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
688 replace_in_file
( ".gitignore", undef, undef,
689 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
690 join("\n", sort keys %ignores), "\n" );
696 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
700 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s
/,`find . -name Makefile.in -print`);
705 foreach my $file (sort values %makerules, @makefiles)
707 my %make = parse_makefile
( $file );
708 $makefiles{$file} = \
%make;
711 update_makefiles
( @makefiles );
712 push @ignores, update_ignores
( @makefiles );
713 push @ignores, update_winetest
( @makefiles );
714 push @ignores, update_dlls
( sort grep /^dlls\//, @makefiles );
715 push @ignores, update_progs
( sort grep /^programs\/.*\
/Makefile$/, @makefiles );
716 update_gitignore
( @ignores );