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 my (@makefiles, %makefiles);
72 # update a file if changed
76 my $ret = system "cmp $file $file.new >/dev/null";
80 #print "$file is unchanged\n";
84 rename "$file.new", "$file";
85 print "$file updated\n";
90 # replace some lines in a file between two markers
91 sub replace_in_file($$$@)
97 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
101 open OLD_FILE, "$file" or die "cannot open $file";
116 print NEW_FILE $_ unless $skip;
121 close OLD_FILE if defined($start);
123 return update_file($file);
126 # parse the specified makefile to identify the rules file
127 sub parse_makefile($)
132 open MAKE, "$file.in" or die "cannot open $file.in\n";
137 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
139 if (/^\@(MAKE.*RULES)\@/)
142 $make{"=rules"} = $makerules{$var};
145 if (/^(MODULE|IMPORTLIB)\s*=\s*(.*)/)
150 if (/^(IDL_H_SRCS|IMPLIB_SRCS|SPEC_SRCS16)\s*=\s*(.*)/)
152 my @list = split(/\s+/, $2);
156 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
167 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
171 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
174 foreach my $file (sort values %makerules, @makefiles)
176 my %make = parse_makefile( $file );
177 $makefiles{$file} = \%make;
180 ################################################################
181 # update the makefile list in configure.ac
185 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
187 push @lines, "$var=$makerules{$var}\n";
188 push @lines, "AC_SUBST_FILE($var)\n\n";
191 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
193 "AC_CONFIG_FILES([\n",
194 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
197 ################################################################
198 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
200 my %modules = ( "user" => "user32" );
202 @lines = ( "TESTBINS =" );
204 foreach my $file (sort grep /^dlls\/.*\/tests\/Makefile/, @makefiles)
206 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/)
209 my $mod = $modules{$dir} || $dir;
211 push @lines, " \\\n\t${mod}_test.exe";
216 foreach my $test (sort keys %tests)
218 my $dir = $tests{$test};
219 push @lines, "${test}_test.exe: \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT)\n";
220 push @lines, "\tcp \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
222 push @lines, "\n# Special rules\n";
224 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
227 foreach my $test (sort keys %tests)
229 push @lines, "${test}_test.exe TESTRES \"${test}_test.exe\"\n";
232 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef, @lines );
234 ################################################################
235 # update the makefile list in Makefile.in
240 foreach my $file (sort values %makerules)
242 push @targets, $file;
243 my %make = %{$makefiles{$file}};
244 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
245 else { push @depends, "$file: $file.in Make.rules"; }
248 foreach my $file (sort @makefiles)
250 push @targets, $file unless $file eq "Makefile";
251 my $dep = ${$makefiles{$file}}{"=rules"};
252 push @depends, "$file: $file.in $dep";
256 push @lines, "ALL_MAKEFILES = \\\n\t";
257 push @lines, join (" \\\n\t", @targets ), "\n\n";
258 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
259 push @lines, "\t\@./config.status \$\@\n\n";
260 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
261 push @lines, "distclean::\n";
262 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
263 push @lines, join ("\n", @depends ), "\n";
265 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
268 ################################################################
269 # update dlls/Makefile.in
273 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
281 "*/tests/testlist.c",
285 sub needs_symlink($$)
287 my ($mod, $dir) = @_;
292 foreach my $make (@_)
294 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
296 $testdirs{$1} = "$1/tests";
299 my %makefile = %{$makefiles{$make}};
301 next unless defined $makefile{"MODULE"};
302 my $module = $makefile{"MODULE"};
303 (my $dir = $make) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
305 if ($module =~ /^lib.*\.a$/)
307 $staticlib_dirs{$module} = $dir;
308 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
312 $directories{$module} = $dir;
315 if (defined $makefile{"IMPORTLIB"})
317 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
319 $importlibs{$module} = $1;
323 die "invalid importlib name $makefile{IMPORTLIB} in $make";
327 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
329 if (defined $makefile{"SPEC_SRCS16"})
331 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
332 $altnames{$module} = \@list;
335 if (defined $makefile{"IDL_H_SRCS"})
337 push @ignores, map { $_ =~ s/(.*)\.idl$/$dir\/$1.h/; $_; } @{$makefile{"IDL_H_SRCS"}};
341 # output special dlls configure definitions
343 $text .= "# special configure-dependent targets\n\n";
345 foreach my $mod (sort keys %special_dlls)
347 $specials{$special_dlls{$mod}} .= " " . $mod;
349 foreach my $i (sort keys %specials)
351 $text .= $i . " =" . $specials{$i} . "\n";
353 $text .= "EXTRADIRS =";
354 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
357 # output the subdirs list
359 $text .= "# Subdir list\n\n";
360 $text .= "BASEDIRS =";
361 foreach my $dir (sort values %directories)
363 next if defined($special_dlls{$dir}); # skip special dlls
364 $text .= " \\\n\t" . $dir;
367 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
368 $text .= join " \\\n\t", sort values %staticlib_dirs;
370 $text .= "\n\nTESTSUBDIRS = \\\n\t";
371 $text .= join " \\\n\t", sort values %testdirs;
373 $text .= "\n\nSUBDIRS = \\\n\t";
374 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
376 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
377 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
378 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
380 # output the all: target
382 my %targets = (); # use a hash to get rid of duplicate target names
384 foreach my $mod (sort keys %directories)
386 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
387 $targets{$mod . ".so"} = 1 if needs_symlink($mod, $directories{$mod});
388 next unless defined $altnames{$mod};
389 foreach my $i (sort @{$altnames{$mod}})
391 $targets16{$i . "16"} = $mod;
395 $text .= "\n\@MAKE_RULES\@\n\n";
396 $text .= "# Symbolic links\n\n";
397 $text .= "WIN16_FILES = \\\n";
398 $text .= "\t" . join( " \\\n\t", sort keys %targets16 ) . "\n\n";
399 $text .= "SYMLINKS_SO = \\\n";
400 $text .= "\t\@WIN16_FILES\@ \\\n";
401 $text .= "\t" . join( " \\\n\t", sort keys %targets ) . "\n\n";
402 $text .= "# Main target\n\n";
403 $text .= "all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)\n\n";
404 $text .= ".PHONY: symlinks symlinks.so implib\n\n";
405 $text .= "symlinks.so: \$(SYMLINKS_SO)\n\n";
406 $text .= "symlinks: \$(BUILDSUBDIRS)\n\n";
408 # output the lib name -> directory rules
410 $text .= "# Map symlink name to the corresponding library\n\n";
411 foreach my $mod (sort keys %directories)
413 next unless needs_symlink($mod, $directories{$mod});
414 $text .= sprintf "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
415 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
418 $text .= "# Placeholders for 16-bit libraries\n\n";
419 foreach my $mod (sort keys %directories)
421 next unless defined $altnames{$mod};
422 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
423 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
426 # output the import libraries rules
428 $text .= "# Import libraries\n\n";
429 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
431 my @lib_symlinks = ();
432 foreach my $mod (sort keys %importlibs)
434 my $dir = $directories{$mod};
435 my $lib = $importlibs{$mod};
436 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
438 $text .= "IMPORT_SYMLINKS =";
439 foreach my $mod (sort @lib_symlinks)
441 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
444 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
445 foreach my $mod (sort keys %staticlib_dirs)
447 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
449 foreach my $mod (sort keys %importlibs)
451 my $dir = $directories{$mod};
453 $def =~ s/\.(dll|drv)$//;
454 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
455 next unless defined $static_implibs{$mod};
456 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
459 $text .= "implib: \$(IMPORT_LIBS)\n\n";
461 foreach my $mod (sort keys %importlibs)
463 my $dir = $directories{$mod};
464 my $lib = $importlibs{$mod};
467 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
468 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
469 next unless $static_implibs{$mod};
470 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
471 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
473 foreach my $mod (sort @lib_symlinks)
475 my $dir = $directories{$mod};
476 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
477 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
478 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
481 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
482 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
484 # output the inter-dll dependencies and rules
486 $text .= "# Map library name to the corresponding directory\n\n";
488 foreach my $mod (sort keys %directories)
490 next unless needs_symlink($mod, $directories{$mod});
491 $text .= sprintf "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
493 foreach my $mod (sort keys %staticlib_dirs)
495 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
497 $text .= "\n# Misc rules\n";
499 replace_in_file( "dlls/Makefile.in",
500 '^# special configure-dependent targets',
506 foreach my $mod (sort @lib_symlinks)
508 push @ignores, "/$importlibs{$mod}.def";
510 foreach my $mod (sort keys %directories)
512 next unless defined $altnames{$mod};
513 push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}};
515 foreach my $mod (sort keys %importlibs)
517 my $dir = $directories{$mod};
519 $def =~ s/\.(dll|drv)$//;
520 push @ignores, "$dir/lib$def.def";
523 replace_in_file( "dlls/.gitignore", undef, undef,
524 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
525 join("\n", sort @ignores), "\n" );
530 ################################################################
531 # update programs/Makefile.in and programs/.gitignore
535 my (@subdirs, @install_subdirs, @install_progs);
544 foreach my $make (@_)
546 my %makefile = %{$makefiles{$make}};
547 my $module = $makefile{"MODULE"};
548 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
549 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
550 next if defined $makefile{"=skip"};
552 push @ignores, "$dir/$dir";
553 push @install_subdirs, $dir unless $dont_install{$dir};
554 push @install_progs, $dir if $bin_install{$dir};
557 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
559 join( " \\\n\t", @subdirs ),
560 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
561 join( " \\\n\t", @install_subdirs ),
562 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
563 join( " \\\n\t", @install_progs ),
564 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
566 replace_in_file( "programs/.gitignore", undef, undef,
567 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
568 join("\n", sort @ignores), "\n" );
571 update_dlls( sort grep /^dlls\//, @makefiles );
572 update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );