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
27 "MAKE_RULES" => "Make.rules",
28 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
31 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
34 # Programs that we want to install in the bin directory too
50 # Programs that we don't want to install at all
58 # Default patterns for top-level .gitignore
75 "dlls/*/tests/*crosstest.exe",
76 "dlls/*/tests/testlist.c",
79 "programs/winetest/*_test.exe",
80 "programs/winetest/*_test.rc",
81 "programs/winetest/build.rc",
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 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
91 [ 'IDL_H_SRCS', '\.idl', '.h' ],
92 [ 'IDL_C_SRCS', '\.idl', '.h' ],
93 [ 'IDL_I_SRCS', '\.idl', '.h' ],
94 [ 'IDL_P_SRCS', '\.idl', '.h' ],
95 [ 'IDL_S_SRCS', '\.idl', '.h' ],
96 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
97 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
98 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
99 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
102 my %exported_wine_headers = (
104 "wine/exception.h" => 1,
105 "wine/library.h" => 1,
106 "wine/unicode.h" => 1,
107 "wine/itss.idl" => 1,
108 "wine/svcctl.idl" => 1,
111 my %private_idl_headers = (
128 "wine/wined3d.idl" => 1,
129 "wine/winedxgi.idl" => 1,
132 my %ignored_source_files = (
133 "dlls/wineps.drv/afm2c.c" => 1,
134 "dlls/wineps.drv/mkagl.c" => 1,
135 "programs/winetest/dist.rc" => 1,
138 my (@all_files, @makefiles, %makefiles);
143 return "" unless $ret =~ /\//;
148 # update a file if changed
152 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
159 rename "$file.new", "$file";
160 print "$file updated\n";
161 if ($file eq "configure.ac")
164 print "configure updated\n";
170 # replace some lines in a file between two markers
171 sub replace_in_file
($$$@
)
177 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
181 open OLD_FILE
, "$file" or die "cannot open $file";
196 print NEW_FILE
$_ unless $skip;
201 close OLD_FILE
if defined($start);
203 return update_file
($file);
206 # replace a variable in a makefile
207 sub replace_makefile_variable
($$)
209 my ($file, $var) = @_;
210 my $make = $makefiles{$file};
212 return unless defined ${$make}{"=$var"};
214 my @values = @
{${$make}{"=$var"}};
215 ${$make}{$var} = \
@values;
217 open NEW_FILE
, ">$file.in.new" or die "cannot create $file.in.new";
219 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
222 if (/^\s*($var\s+)=/)
224 # try to preserve formatting
226 my $multiline = /\\$/ || (@values > 1);
234 print NEW_FILE
"$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
238 print NEW_FILE
"$prefix= @values\n";
246 return update_file
("$file.in");
249 # parse the specified makefile to identify the rules file
250 sub parse_makefile
($)
255 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
257 open MAKE
, "$file.in" or die "cannot open $file.in\n";
263 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
266 if (/^\@(MAKE.*RULES)\@/)
269 $make{"=rules"} = $makerules{$var};
272 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
277 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|C_SRCS16|RC_SRCS16|SPEC_SRCS16|EXTRA_OBJS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
279 my @list = split(/\s+/, $2);
287 # assign source files to their respective makefile
288 sub assign_sources_to_makefiles
()
290 foreach my $file (@all_files)
292 next if defined $ignored_source_files{$file};
293 my $dir = dirname
( $file );
295 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
298 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
300 my $make = $makefiles{"$dir/Makefile"};
301 my $basename = substr( $file, length($dir) + 1 );
303 if ($basename =~ /\.c$/) { push @
{${$make}{"=C_SRCS"}}, $basename; }
304 elsif ($basename =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $basename; }
305 elsif ($basename =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $basename; }
306 elsif ($basename =~ /\.rc$/) { push @
{${$make}{"=RC_SRCS"}}, $basename; }
307 elsif ($basename =~ /\.mc$/) { push @
{${$make}{"=MC_SRCS"}}, $basename; }
308 elsif ($basename =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $basename; }
312 ################################################################
313 # update the makefile list in configure.ac
315 sub update_makefiles
(@
)
319 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
321 my $file = $makerules{$var};
322 my %make = %{$makefiles{$file}};
323 my $rules = $make{"=rules"} ?
",[$make{\"=rules\"}]" : "";
324 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
328 foreach my $file (sort @_)
330 my %make = %{$makefiles{$file}};
331 my $rules = $make{"=rules"};
333 if ($rules eq $makerules{"MAKE_DLL_RULES"})
335 $args = ",[dlls],[ALL_DLL_DIRS]";
336 $args .= ",[enable_win16]" if $make{"MODULE"} =~ /(16|\.vxd)$/;
338 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
339 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
340 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
342 (my $name = $file) =~ s/^programs\/(.*)\/Makefile
/$1/;
343 $args = ",[programs],[ALL_PROGRAM_DIRS";
344 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
345 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
347 $args .= ",[enable_win16]" if $make{"MODULE"} =~ /16$/;
349 elsif ($file =~ /^[^\/]*\
/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
350 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
353 # update the source variables in all the makefiles
355 foreach my $file (sort @_)
357 my %make = %{$makefiles{$file}};
359 replace_makefile_variable
( $file, "LEX_SRCS" );
360 replace_makefile_variable
( $file, "BISON_SRCS" );
361 replace_makefile_variable
( $file, "MC_SRCS" );
362 replace_makefile_variable
( $file, "SVG_SRCS" );
363 replace_makefile_variable
( $file, "C_SRCS" ) unless defined $make{"C_SRCS16"};
364 replace_makefile_variable
( $file, "RC_SRCS" ) unless defined $make{"RC_SRCS16"};
367 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
368 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
372 ################################################################
373 # process ignore targets for generic source files
375 sub update_ignores
(@
)
379 foreach my $file (sort @_)
381 my %makefile = %{$makefiles{$file}};
384 foreach my $src (@ignore_srcs)
386 my @pattern = @
{$src};
387 next unless defined $makefile{$pattern[0]};
388 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
390 foreach my $f (@list)
392 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
398 ################################################################
399 # update dlls/Makefile.in
403 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
407 foreach my $make (@_)
409 my %makefile = %{$makefiles{$make}};
410 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
412 next unless defined $makefile{"MODULE"};
413 my $module = $makefile{"MODULE"};
414 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
416 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
418 $staticlib_dirs{$module} = $dir;
419 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
423 die "invalid module $module" unless $module =~ /\./;
424 (my $mod = $module) =~ s/\.dll$//;
425 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
426 $directories{$module} = $dir;
429 if (defined $makefile{"IMPORTLIB"})
431 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
433 $importlibs{$module} = $1;
437 die "invalid importlib name $makefile{IMPORTLIB} in $make";
441 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
443 if (defined $makefile{"SPEC_SRCS16"})
445 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @
{$makefile{"SPEC_SRCS16"}};
446 $altnames{$module} = \
@list;
448 if (defined $makefile{"EXTRA_OBJS16"})
450 foreach my $obj (@
{$makefile{"EXTRA_OBJS16"}})
452 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @
{$altnames{$module}}, $1; }
457 # output the list of 16-bit files
460 foreach my $mod (sort keys %directories)
462 next unless defined $altnames{$mod};
463 foreach my $i (sort @
{$altnames{$mod}})
465 push @targets16, $i . "16";
468 $text .= "# 16-bit dlls\n\n";
469 $text .= "WIN16_FILES = \\\n";
470 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
471 $text .= "\@MAKE_RULES\@\n\n";
473 # output the all: target
475 $text .= "# Main target\n\n";
476 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
478 # output the lib name -> directory rules
480 $text .= "# Placeholders for 16-bit libraries\n\n";
481 foreach my $mod (sort keys %directories)
483 next unless defined $altnames{$mod};
484 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @
{$altnames{$mod}});
485 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
488 # output the import libraries rules
490 $text .= "# Import libraries\n\n";
491 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
493 my @lib_symlinks = ();
494 foreach my $mod (sort keys %importlibs)
496 my $dir = $directories{$mod};
497 my $lib = $importlibs{$mod};
498 if ($lib ne $dir) { push @lib_symlinks, $mod; }
500 $text .= "IMPORT_SYMLINKS =";
501 foreach my $mod (sort @lib_symlinks)
503 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
506 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
507 foreach my $mod (sort keys %staticlib_dirs)
509 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
511 foreach my $mod (sort keys %importlibs)
513 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
514 next unless defined $static_implibs{$mod};
515 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
517 $text .= "\n\nCROSS_IMPLIBS =";
518 foreach my $mod (sort @lib_symlinks)
520 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
522 foreach my $mod (sort keys %importlibs)
524 next if defined $static_implibs{$mod};
525 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
528 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
529 $text .= "implib: \$(IMPORT_LIBS)\n\n";
530 $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
531 $text .= ".PHONY: implib testsubdirs\n\n";
533 foreach my $mod (sort keys %importlibs)
535 my $dir = $directories{$mod};
536 my $lib = $importlibs{$mod};
539 if (defined($static_implibs{$mod}))
541 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
542 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
543 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
544 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
548 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
549 $dir, $lib, $dir, $lib, $dir, $spec;
550 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
553 foreach my $mod (sort @lib_symlinks)
555 my $dir = $directories{$mod};
556 my $lib = "lib" . $importlibs{$mod};
557 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
558 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
559 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
560 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
563 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
564 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
566 # output the inter-dll dependencies and rules
568 $text .= "# Map library name to the corresponding directory\n\n";
570 foreach my $mod (sort keys %staticlib_dirs)
572 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
574 $text .= "\n# Misc rules\n";
576 replace_in_file
( "dlls/Makefile.in",
583 foreach my $mod (sort @lib_symlinks)
585 push @ignores, "dlls/lib$importlibs{$mod}.def";
587 foreach my $mod (sort keys %directories)
589 next unless defined $altnames{$mod};
590 push @ignores, map { "dlls/" . $_ . "16"; } @
{$altnames{$mod}};
597 ################################################################
598 # update include/Makefile.in
600 sub update_includes
()
602 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
603 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\
//, @all_files;
604 foreach my $incl (@includes)
606 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
607 next if ($incl =~ /\.in$/);
608 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
610 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
613 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
614 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
615 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
616 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
617 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
618 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
619 else { die "unknown file $incl in include dir"; }
621 replace_in_file
( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
622 "PRIVATE_IDL_H_SRCS = \\\n\t",
623 join( " \\\n\t", sort @private_idl_srcs ),
624 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
625 join( " \\\n\t", sort @public_idl_srcs ),
626 "\n\nIDL_TLB_SRCS = \\\n\t",
627 join( " \\\n\t", sort @tlb_srcs ),
628 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
629 join( " \\\n\t", sort @h_srcs ),
630 "\n\nEXTRASUBDIRS = ",
631 join( " ", sort keys %subdirs ),
632 "\n\nINSTALLDIRS = \\\n" );
633 return map { s/(.*)\.idl$/include\/$1.h
/; $_; } @public_idl_srcs, @private_idl_srcs;
637 ################################################################
638 # update the main .gitignore
640 sub update_gitignore
(@
)
642 my @ignores = values %makerules;
644 foreach my $make (@makefiles)
646 my %makefile = %{$makefiles{$make}};
647 my $dir = $makefile{"=dir"};
648 if (defined $makefile{"MANPAGES"})
650 push @ignores, map { $dir . $_; } @
{$makefile{"MANPAGES"}};
652 if (defined $makefile{"PROGRAMS"})
654 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
658 # prepend a slash to paths that don't have one
659 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
661 # get rid of duplicates
663 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
665 replace_in_file
( ".gitignore", undef, undef,
666 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
667 join("\n", sort keys %ignores), "\n" );
671 die "needs to be run from a git checkout" unless -d
".git";
673 @all_files = split /\0/, `git ls-files -c -z`;
674 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
676 foreach my $file (sort values %makerules, @makefiles)
678 my %make = parse_makefile
( $file );
679 $makefiles{$file} = \
%make;
682 assign_sources_to_makefiles
();
683 update_makefiles
( @makefiles );
684 push @ignores, update_includes
();
685 push @ignores, update_ignores
( @makefiles );
686 push @ignores, update_dlls
( sort grep /^dlls\//, @makefiles );
687 update_gitignore
( @ignores );