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|IMPLIB_SRCS|SPEC_SRCS16)\s*=\s*(.*)/)
150 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
161 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
165 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
168 foreach my $file (sort values %makerules, @makefiles)
170 my %make = parse_makefile( $file );
171 $makefiles{$file} = \%make;
174 ################################################################
175 # update the makefile list in configure.ac
179 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
181 push @lines, "$var=$makerules{$var}\n";
182 push @lines, "AC_SUBST_FILE($var)\n\n";
185 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
187 "AC_CONFIG_FILES([\n",
188 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
191 ################################################################
192 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
194 my %modules = ( "user" => "user32" );
196 @lines = ( "TESTBINS =" );
198 foreach my $file (sort grep /^dlls\/.*\/tests\/Makefile/, @makefiles)
200 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/)
203 my $mod = $modules{$dir} || $dir;
205 push @lines, " \\\n\t${mod}_test.exe";
210 foreach my $test (sort keys %tests)
212 my $dir = $tests{$test};
213 push @lines, "${test}_test.exe: \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT)\n";
214 push @lines, "\tcp \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
216 push @lines, "\n# Special rules\n";
218 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
221 foreach my $test (sort keys %tests)
223 push @lines, "${test}_test.exe TESTRES \"${test}_test.exe\"\n";
226 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef, @lines );
228 ################################################################
229 # update the makefile list in Makefile.in
234 foreach my $file (sort values %makerules)
236 push @targets, $file;
237 my %make = %{$makefiles{$file}};
238 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
239 else { push @depends, "$file: $file.in Make.rules"; }
242 foreach my $file (sort @makefiles)
244 push @targets, $file unless $file eq "Makefile";
245 my $dep = ${$makefiles{$file}}{"=rules"};
246 push @depends, "$file: $file.in $dep";
250 push @lines, "ALL_MAKEFILES = \\\n\t";
251 push @lines, join (" \\\n\t", @targets ), "\n\n";
252 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
253 push @lines, "\t\@./config.status \$\@\n\n";
254 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
255 push @lines, "distclean::\n";
256 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
257 push @lines, join ("\n", @depends ), "\n";
259 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
262 ################################################################
263 # update dlls/Makefile.in
267 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
275 "*/tests/testlist.c",
279 sub needs_symlink($$)
281 my ($mod, $dir) = @_;
286 foreach my $make (@_)
288 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
290 $testdirs{$1} = "$1/tests";
293 my %makefile = %{$makefiles{$make}};
295 next unless defined $makefile{"MODULE"};
296 my $module = $makefile{"MODULE"};
298 if ($module =~ /^lib.*\.a$/)
300 ($staticlib_dirs{$module} = $make) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
301 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
305 ($directories{$module} = $make) =~ s/^dlls\/(.*)\/[^\/]+$/$1/;
308 if (defined $makefile{"IMPORTLIB"})
310 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
312 $importlibs{$module} = $1;
316 die "invalid importlib name $makefile{IMPORTLIB} in $make";
320 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
322 if (defined $makefile{"SPEC_SRCS16"})
324 my @list = split(/\s+/, $makefile{"SPEC_SRCS16"});
325 @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
326 $altnames{$module} = \@list;
330 # output special dlls configure definitions
332 $text .= "# special configure-dependent targets\n\n";
334 foreach my $mod (sort keys %special_dlls)
336 $specials{$special_dlls{$mod}} .= " " . $mod;
338 foreach my $i (sort keys %specials)
340 $text .= $i . " =" . $specials{$i} . "\n";
342 $text .= "EXTRADIRS =";
343 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
346 # output the subdirs list
348 $text .= "# Subdir list\n\n";
349 $text .= "BASEDIRS =";
350 foreach my $dir (sort values %directories)
352 next if defined($special_dlls{$dir}); # skip special dlls
353 $text .= " \\\n\t" . $dir;
356 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
357 $text .= join " \\\n\t", sort values %staticlib_dirs;
359 $text .= "\n\nTESTSUBDIRS = \\\n\t";
360 $text .= join " \\\n\t", sort values %testdirs;
362 $text .= "\n\nSUBDIRS = \\\n\t";
363 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
365 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
366 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
367 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
369 # output the all: target
371 my %targets = (); # use a hash to get rid of duplicate target names
373 foreach my $mod (sort keys %directories)
375 next if defined($special_dlls{$directories{$mod}}); # skip special dlls
376 $targets{$mod . ".so"} = 1 if needs_symlink($mod, $directories{$mod});
377 next unless defined $altnames{$mod};
378 foreach my $i (sort @{$altnames{$mod}})
380 $targets16{$i . "16"} = $mod;
384 $text .= "\n\@MAKE_RULES\@\n\n";
385 $text .= "# Symbolic links\n\n";
386 $text .= "WIN16_FILES = \\\n";
387 $text .= "\t" . join( " \\\n\t", sort keys %targets16 ) . "\n\n";
388 $text .= "SYMLINKS_SO = \\\n";
389 $text .= "\t\@WIN16_FILES\@ \\\n";
390 $text .= "\t" . join( " \\\n\t", sort keys %targets ) . "\n\n";
391 $text .= "# Main target\n\n";
392 $text .= "all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)\n\n";
393 $text .= ".PHONY: symlinks symlinks.so implib\n\n";
394 $text .= "symlinks.so: \$(SYMLINKS_SO)\n\n";
395 $text .= "symlinks: \$(BUILDSUBDIRS)\n\n";
397 # output the lib name -> directory rules
399 $text .= "# Map symlink name to the corresponding library\n\n";
400 foreach my $mod (sort keys %directories)
402 next unless needs_symlink($mod, $directories{$mod});
403 $text .= sprintf "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
404 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
407 $text .= "# Placeholders for 16-bit libraries\n\n";
408 foreach my $mod (sort keys %directories)
410 next unless defined $altnames{$mod};
411 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
412 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
415 # output the import libraries rules
417 $text .= "# Import libraries\n\n";
418 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
420 my @lib_symlinks = ();
421 foreach my $mod (sort keys %importlibs)
423 my $dir = $directories{$mod};
424 my $lib = $importlibs{$mod};
425 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
427 $text .= "IMPORT_SYMLINKS =";
428 foreach my $mod (sort @lib_symlinks)
430 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
433 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
434 foreach my $mod (sort keys %staticlib_dirs)
436 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
438 foreach my $mod (sort keys %importlibs)
440 my $dir = $directories{$mod};
442 $def =~ s/\.(dll|drv)$//;
443 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
444 next unless defined $static_implibs{$mod};
445 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
448 $text .= "implib: \$(IMPORT_LIBS)\n\n";
450 foreach my $mod (sort keys %importlibs)
452 my $dir = $directories{$mod};
453 my $lib = $importlibs{$mod};
456 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
457 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
458 next unless $static_implibs{$mod};
459 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
460 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
462 foreach my $mod (sort @lib_symlinks)
464 my $dir = $directories{$mod};
465 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
466 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
467 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
470 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
471 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
473 # output the inter-dll dependencies and rules
475 $text .= "# Map library name to the corresponding directory\n\n";
477 foreach my $mod (sort keys %directories)
479 next unless needs_symlink($mod, $directories{$mod});
480 $text .= sprintf "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
482 foreach my $mod (sort keys %staticlib_dirs)
484 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
486 $text .= "\n# Misc rules\n";
488 replace_in_file( "dlls/Makefile.in",
489 '^# special configure-dependent targets',
495 foreach my $mod (sort @lib_symlinks)
497 push @ignores, "/$importlibs{$mod}.def";
499 foreach my $mod (sort keys %directories)
501 next unless defined $altnames{$mod};
502 push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}};
504 foreach my $mod (sort keys %importlibs)
506 my $dir = $directories{$mod};
508 $def =~ s/\.(dll|drv)$//;
509 push @ignores, "$dir/lib$def.def";
512 replace_in_file( "dlls/.gitignore", undef, undef,
513 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
514 join("\n", sort @ignores), "\n" );
519 ################################################################
520 # update programs/Makefile.in and programs/.gitignore
524 my (@subdirs, @install_subdirs, @install_progs);
533 foreach my $make (@_)
535 my %makefile = %{$makefiles{$make}};
536 my $module = $makefile{"MODULE"};
537 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
538 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
539 next if defined $makefile{"=skip"};
541 push @ignores, "$dir/$dir";
542 push @install_subdirs, $dir unless $dont_install{$dir};
543 push @install_progs, $dir if $bin_install{$dir};
546 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
548 join( " \\\n\t", @subdirs ),
549 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
550 join( " \\\n\t", @install_subdirs ),
551 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
552 join( " \\\n\t", @install_progs ),
553 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
555 replace_in_file( "programs/.gitignore", undef, undef,
556 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
557 join("\n", sort @ignores), "\n" );
560 update_dlls( sort grep /^dlls\//, @makefiles );
561 update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );