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 # Default patterns for top-level .gitignore
74 "dlls/*/tests/*crosstest.exe",
75 "dlls/*/tests/testlist.c",
78 "programs/winetest/tests.rc",
79 "programs/winetest/*_test.exe",
82 # Source files and their resulting target to ignore
84 [ 'BISON_SRCS', '\.y', '.tab.c' ],
85 [ 'BISON_SRCS', '\.y', '.tab.h' ],
86 [ 'LEX_SRCS', '\.l', '.yy.c' ],
87 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
88 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
89 [ 'IDL_H_SRCS', '\.idl', '.h' ],
90 [ 'IDL_C_SRCS', '\.idl', '.h' ],
91 [ 'IDL_I_SRCS', '\.idl', '.h' ],
92 [ 'IDL_P_SRCS', '\.idl', '.h' ],
93 [ 'IDL_S_SRCS', '\.idl', '.h' ],
94 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
95 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
96 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
97 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
100 my %exported_wine_headers = (
102 "wine/exception.h" => 1,
103 "wine/library.h" => 1,
104 "wine/unicode.h" => 1,
105 "wine/itss.idl" => 1,
106 "wine/svcctl.idl" => 1,
109 my %private_idl_headers = (
118 "wine/wined3d.idl" => 1,
121 my (@makefiles, %makefiles);
123 # update a file if changed
127 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
134 rename "$file.new", "$file";
135 print "$file updated\n";
136 if ($file eq "configure.ac")
139 print "configure updated\n";
145 # replace some lines in a file between two markers
146 sub replace_in_file($$$@)
152 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
156 open OLD_FILE, "$file" or die "cannot open $file";
171 print NEW_FILE $_ unless $skip;
176 close OLD_FILE if defined($start);
178 return update_file($file);
181 # parse the specified makefile to identify the rules file
182 sub parse_makefile($)
187 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
189 open MAKE, "$file.in" or die "cannot open $file.in\n";
194 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
196 if (/^\@(MAKE.*RULES)\@/)
199 $make{"=rules"} = $makerules{$var};
202 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
207 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*(.*)/)
209 my @list = split(/\s+/, $2);
218 ################################################################
219 # update the makefile list in configure.ac
221 sub update_makefiles(@)
225 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
227 my $file = $makerules{$var};
228 my %make = %{$makefiles{$file}};
229 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
230 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
234 foreach my $file (sort @_)
236 my %make = %{$makefiles{$file}};
237 my $rules = $make{"=rules"};
239 if ($rules eq $makerules{"MAKE_DLL_RULES"}) { $args = ",[dlls],[ALL_DLL_DIRS]"; }
240 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
241 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
242 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
244 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
245 $args = ",[programs],[ALL_PROGRAM_DIRS";
246 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
247 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
250 elsif ($file =~ /^[^\/]*\/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
251 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
254 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
255 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
259 ################################################################
260 # process ignore targets for generic source files
262 sub update_ignores(@)
266 foreach my $file (sort @_)
268 my %makefile = %{$makefiles{$file}};
271 foreach my $src (@ignore_srcs)
273 my @pattern = @{$src};
274 next unless defined $makefile{$pattern[0]};
275 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
277 foreach my $f (@list)
279 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
285 ################################################################
286 # update dlls/Makefile.in
290 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
294 foreach my $make (@_)
296 my %makefile = %{$makefiles{$make}};
297 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
299 next unless defined $makefile{"MODULE"};
300 my $module = $makefile{"MODULE"};
301 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
303 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
305 $staticlib_dirs{$module} = $dir;
306 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
310 die "invalid module $module" unless $module =~ /\./;
311 (my $mod = $module) =~ s/\.dll$//;
312 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
313 $directories{$module} = $dir;
316 if (defined $makefile{"IMPORTLIB"})
318 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
320 $importlibs{$module} = $1;
324 die "invalid importlib name $makefile{IMPORTLIB} in $make";
328 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
330 if (defined $makefile{"SPEC_SRCS16"})
332 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
333 $altnames{$module} = \@list;
335 if (defined $makefile{"EXTRA_OBJS16"})
337 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
339 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
344 # output the list of 16-bit files
347 foreach my $mod (sort keys %directories)
349 next unless defined $altnames{$mod};
350 foreach my $i (sort @{$altnames{$mod}})
352 push @targets16, $i . "16";
355 $text .= "# 16-bit dlls\n\n";
356 $text .= "WIN16_FILES = \\\n";
357 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
358 $text .= "\@MAKE_RULES\@\n\n";
360 # output the all: target
362 $text .= "# Main target\n\n";
363 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
365 # output the lib name -> directory rules
367 $text .= "# Placeholders for 16-bit libraries\n\n";
368 foreach my $mod (sort keys %directories)
370 next unless defined $altnames{$mod};
371 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
372 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
375 # output the import libraries rules
377 $text .= "# Import libraries\n\n";
378 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
380 my @lib_symlinks = ();
381 foreach my $mod (sort keys %importlibs)
383 my $dir = $directories{$mod};
384 my $lib = $importlibs{$mod};
385 if ($lib ne $dir) { push @lib_symlinks, $mod; }
387 $text .= "IMPORT_SYMLINKS =";
388 foreach my $mod (sort @lib_symlinks)
390 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
393 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
394 foreach my $mod (sort keys %staticlib_dirs)
396 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
398 foreach my $mod (sort keys %importlibs)
400 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
401 next unless defined $static_implibs{$mod};
402 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
404 $text .= "\n\nCROSS_IMPLIBS =";
405 foreach my $mod (sort @lib_symlinks)
407 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
409 foreach my $mod (sort keys %importlibs)
411 next if defined $static_implibs{$mod};
412 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
415 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
416 $text .= "implib: \$(IMPORT_LIBS)\n\n";
417 $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
418 $text .= ".PHONY: implib testsubdirs\n\n";
420 foreach my $mod (sort keys %importlibs)
422 my $dir = $directories{$mod};
423 my $lib = $importlibs{$mod};
426 if (defined($static_implibs{$mod}))
428 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
429 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
430 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
431 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
435 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
436 $dir, $lib, $dir, $lib, $dir, $spec;
437 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
440 foreach my $mod (sort @lib_symlinks)
442 my $dir = $directories{$mod};
443 my $lib = "lib" . $importlibs{$mod};
444 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
445 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
446 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
447 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
450 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
451 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
453 # output the inter-dll dependencies and rules
455 $text .= "# Map library name to the corresponding directory\n\n";
457 foreach my $mod (sort keys %staticlib_dirs)
459 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
461 $text .= "\n# Misc rules\n";
463 replace_in_file( "dlls/Makefile.in",
470 foreach my $mod (sort @lib_symlinks)
472 push @ignores, "dlls/lib$importlibs{$mod}.def";
474 foreach my $mod (sort keys %directories)
476 next unless defined $altnames{$mod};
477 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
484 ################################################################
485 # update include/Makefile.in
487 sub update_includes()
489 return unless -d ".git";
490 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
491 my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
492 foreach my $incl (@includes)
494 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
495 next if ($incl =~ /\.in$/);
496 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
498 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
501 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
502 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
503 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
505 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
506 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
507 else { die "unknown file $incl in include dir"; }
509 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
510 "PRIVATE_IDL_H_SRCS = \\\n\t",
511 join( " \\\n\t", sort @private_idl_srcs ),
512 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
513 join( " \\\n\t", sort @public_idl_srcs ),
514 "\n\nIDL_TLB_SRCS = \\\n\t",
515 join( " \\\n\t", sort @tlb_srcs ),
516 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
517 join( " \\\n\t", sort @h_srcs ),
518 "\n\nEXTRASUBDIRS = ",
519 join( " ", sort keys %subdirs ),
520 "\n\nINSTALLDIRS = \\\n" );
521 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
525 ################################################################
526 # update the main .gitignore
528 sub update_gitignore(@)
530 my @ignores = values %makerules;
532 foreach my $make (@makefiles)
534 my %makefile = %{$makefiles{$make}};
535 my $dir = $makefile{"=dir"};
536 if (defined $makefile{"MANPAGES"})
538 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
540 if (defined $makefile{"PROGRAMS"})
542 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
544 if ($dir =~ /^programs\/(.*)\/$/)
546 push @ignores, "$dir$1";
550 # prepend a slash to paths that don't have one
551 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
553 # get rid of duplicates
555 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
557 replace_in_file( ".gitignore", undef, undef,
558 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
559 join("\n", sort keys %ignores), "\n" );
565 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
569 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
572 foreach my $file (sort values %makerules, @makefiles)
574 my %make = parse_makefile( $file );
575 $makefiles{$file} = \%make;
578 update_makefiles( @makefiles );
579 push @ignores, update_includes();
580 push @ignores, update_ignores( @makefiles );
581 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
582 update_gitignore( @ignores );