configure: Generate the dlls directory lists in configure instead of make_makefiles.
[wine/wine64.git] / tools / make_makefiles
blobb6c66bfaa0459130c08a428030e6cf559cd4d18f
1 #!/usr/bin/perl -w
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
22 # Make rules files
23 my %makerules =
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
33 my %bin_install =
35 "msiexec" => 1,
36 "notepad" => 1,
37 "progman" => 1,
38 "regedit" => 1,
39 "regsvr32" => 1,
40 "uninstaller" => 1,
41 "wineboot" => 1,
42 "winebrowser" => 1,
43 "winecfg" => 1,
44 "wineconsole" => 1,
45 "winedbg" => 1,
46 "winefile" => 1,
47 "winemine" => 1,
48 "winepath" => 1,
51 # Programs that we don't want to install at all
52 my %dont_install =
54 "cmdlgtst" => 1,
55 "view" => 1,
56 "winetest" => 1,
59 # Special dlls that can be switched on or off by configure
60 my %special_dlls =
62 "glu32" => "GLU32FILES",
63 "opengl32" => "OPENGLFILES",
64 "winex11.drv" => "XFILES",
65 "winequartz.drv" => "QUARTZFILES"
68 # Default patterns for top-level .gitignore
69 my @ignores = (
70 "*.[oa]",
71 "*.ok",
72 "*.res",
73 "*.so",
74 "/autom4te.cache",
75 "/config.cache",
76 "/config.log",
77 "/config.status",
78 "/TAGS",
79 "/tags",
80 "Makefile",
81 "dlldata.c",
82 "dlls/*/*.def",
83 "dlls/*/tests/*crosstest.exe",
84 "dlls/*/tests/testlist.c",
85 "include/config.h",
86 "include/stamp-h"
89 # Source files and their resulting target to ignore
90 my @ignore_srcs = (
91 [ 'BISON_SRCS', '\.y', '.tab.c' ],
92 [ 'BISON_SRCS', '\.y', '.tab.h' ],
93 [ 'LEX_SRCS', '\.l', '.yy.c' ],
94 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
95 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
96 [ 'IDL_H_SRCS', '\.idl', '.h' ],
97 [ 'IDL_C_SRCS', '\.idl', '.h' ],
98 [ 'IDL_I_SRCS', '\.idl', '.h' ],
99 [ 'IDL_P_SRCS', '\.idl', '.h' ],
100 [ 'IDL_S_SRCS', '\.idl', '.h' ],
101 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
102 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
103 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
104 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
107 my %exported_wine_headers = (
108 "wine/debug.h" => 1,
109 "wine/exception.h" => 1,
110 "wine/library.h" => 1,
111 "wine/unicode.h" => 1,
112 "wine/itss.idl" => 1,
113 "wine/svcctl.idl" => 1,
116 my %private_idl_headers = (
117 "axcore.idl" => 1,
118 "axextend.idl" => 1,
119 "dbinit.idl" => 1,
120 "dbprop.idl" => 1,
121 "dbs.idl" => 1,
122 "devenum.idl" => 1,
123 "dyngraph.idl" => 1,
124 "vmrender.idl" => 1,
127 my (@makefiles, %makefiles);
129 # update a file if changed
130 sub update_file($)
132 my $file = shift;
133 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
134 if (!$ret)
136 unlink "$file.new";
138 else
140 rename "$file.new", "$file";
141 print "$file updated\n";
142 if ($file eq "configure.ac")
144 system "autoconf";
145 print "configure updated\n";
148 return $ret;
151 # replace some lines in a file between two markers
152 sub replace_in_file($$$@)
154 my $file = shift;
155 my $start = shift;
156 my $end = shift;
158 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
160 if (defined($start))
162 open OLD_FILE, "$file" or die "cannot open $file";
163 while (<OLD_FILE>)
165 last if /$start/;
166 print NEW_FILE $_;
170 print NEW_FILE @_;
172 if (defined($end))
174 my $skip=1;
175 while (<OLD_FILE>)
177 print NEW_FILE $_ unless $skip;
178 $skip = 0 if /$end/;
182 close OLD_FILE if defined($start);
183 close NEW_FILE;
184 return update_file($file);
187 # parse the specified makefile to identify the rules file
188 sub parse_makefile($)
190 my $file = shift;
191 my %make;
193 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
195 open MAKE, "$file.in" or die "cannot open $file.in\n";
197 while (<MAKE>)
199 chomp;
200 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
202 if (/^\@(MAKE.*RULES)\@/)
204 my $var = $1;
205 $make{"=rules"} = $makerules{$var};
206 next;
208 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
210 $make{$1} = $2;
211 next;
213 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*(.*)/)
215 my @list = split(/\s+/, $2);
216 $make{$1} = \@list;
217 next;
219 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
221 $make{"=skip"} = 1;
222 next;
225 return %make;
229 ################################################################
230 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
232 sub update_winetest(@)
234 my (@tests, @lines);
236 foreach my $file (@_)
238 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
240 push @lines, "TESTBINS =";
241 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
242 push @lines, "\n\n";
244 foreach my $test (sort @tests)
246 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
247 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
249 push @lines, "\n# Special rules\n";
251 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
253 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
254 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
256 # return a list of test exe files for .gitignore
257 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
261 ################################################################
262 # update the makefile list in configure.ac
264 sub update_makefiles(@)
266 my (@lines);
268 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
270 my $file = $makerules{$var};
271 my %make = %{$makefiles{$file}};
272 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
273 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
275 push @lines, "\n";
277 foreach my $file (sort @_)
279 my %make = %{$makefiles{$file}};
280 my $rules = $make{"=rules"};
281 my $args = "";
282 if ($rules eq $makerules{"MAKE_DLL_RULES"}) { $args = ",[dlls],[ALL_DLL_DIRS]"; }
283 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
284 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS]"; }
285 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
288 push @lines, "\nAC_OUTPUT\n";
289 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^AC_OUTPUT$', @lines);
293 ################################################################
294 # process ignore targets for generic source files
296 sub update_ignores(@)
298 my @ignores;
300 foreach my $file (sort @_)
302 my %makefile = %{$makefiles{$file}};
303 my @list;
305 foreach my $src (@ignore_srcs)
307 my @pattern = @{$src};
308 next unless defined $makefile{$pattern[0]};
309 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
311 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
312 foreach my $f (@list)
314 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
317 return @ignores;
320 ################################################################
321 # update dlls/Makefile.in
323 sub update_dlls(@)
325 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
326 my $text = "";
327 my @ignores = ();
329 foreach my $make (@_)
331 my %makefile = %{$makefiles{$make}};
332 next if defined $makefile{"=skip"};
333 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
335 next unless defined $makefile{"MODULE"};
336 my $module = $makefile{"MODULE"};
337 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
339 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
341 $staticlib_dirs{$module} = $dir;
342 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
344 else
346 die "invalid module $module" unless $module =~ /\./;
347 (my $mod = $module) =~ s/\.dll$//;
348 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
349 $directories{$module} = $dir;
352 if (defined $makefile{"IMPORTLIB"})
354 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
356 $importlibs{$module} = $1;
358 else
360 die "invalid importlib name $makefile{IMPORTLIB} in $make";
364 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
366 if (defined $makefile{"SPEC_SRCS16"})
368 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
369 $altnames{$module} = \@list;
371 if (defined $makefile{"EXTRA_OBJS16"})
373 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
375 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
380 # output special dlls configure definitions
382 $text .= "# special configure-dependent targets\n\n";
383 my %specials = ();
384 foreach my $mod (sort keys %special_dlls)
386 $specials{$special_dlls{$mod}} .= " " . $mod;
388 foreach my $i (sort keys %specials)
390 $text .= $i . " =" . $specials{$i} . "\n";
392 $text .= "EXTRADIRS =";
393 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
394 $text .= "\n\n";
396 # output the subdirs list
398 $text .= "# Subdir list\n\n";
399 $text .= "BASEDIRS =";
400 foreach my $dir (sort values %directories)
402 next if defined($special_dlls{$dir}); # skip special dlls
403 $text .= " \\\n\t" . $dir;
406 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
407 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
408 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
410 # output the list of 16-bit files
412 my @targets16 = ();
413 foreach my $mod (sort keys %directories)
415 next unless defined $altnames{$mod};
416 foreach my $i (sort @{$altnames{$mod}})
418 push @targets16, $i . "16";
421 $text .= "\n# 16-bit dlls\n\n";
422 $text .= "WIN16_FILES = \\\n";
423 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
424 $text .= "\@MAKE_RULES\@\n\n";
426 # output the all: target
428 $text .= "# Main target\n\n";
429 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
431 # output the lib name -> directory rules
433 $text .= "# Placeholders for 16-bit libraries\n\n";
434 foreach my $mod (sort keys %directories)
436 next unless defined $altnames{$mod};
437 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
438 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
441 # output the import libraries rules
443 $text .= "# Import libraries\n\n";
444 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
446 my @lib_symlinks = ();
447 foreach my $mod (sort keys %importlibs)
449 my $dir = $directories{$mod};
450 my $lib = $importlibs{$mod};
451 if ($lib ne $dir) { push @lib_symlinks, $mod; }
453 $text .= "IMPORT_SYMLINKS =";
454 foreach my $mod (sort @lib_symlinks)
456 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
459 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
460 foreach my $mod (sort keys %staticlib_dirs)
462 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
464 foreach my $mod (sort keys %importlibs)
466 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
467 next unless defined $static_implibs{$mod};
468 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
470 $text .= "\n\nCROSS_IMPLIBS =";
471 foreach my $mod (sort @lib_symlinks)
473 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
475 foreach my $mod (sort keys %importlibs)
477 next if defined $static_implibs{$mod};
478 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
480 $text .= "\n\n";
481 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
482 $text .= "implib: \$(IMPORT_LIBS)\n\n";
483 $text .= ".PHONY: implib\n\n";
485 foreach my $mod (sort keys %importlibs)
487 my $dir = $directories{$mod};
488 my $lib = $importlibs{$mod};
489 my $spec = $mod;
490 $spec =~ s/\.dll$//;
491 if (defined($static_implibs{$mod}))
493 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
494 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
495 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
496 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
498 else
500 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
501 $dir, $lib, $dir, $lib, $dir, $spec;
502 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
505 foreach my $mod (sort @lib_symlinks)
507 my $dir = $directories{$mod};
508 my $lib = "lib" . $importlibs{$mod};
509 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
510 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
511 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
512 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
515 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
516 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
518 # output the inter-dll dependencies and rules
520 $text .= "# Map library name to the corresponding directory\n\n";
522 foreach my $mod (sort keys %staticlib_dirs)
524 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
526 $text .= "\n# Misc rules\n";
528 replace_in_file( "dlls/Makefile.in",
529 '^# special configure-dependent targets',
530 '^# Misc rules',
531 $text );
533 # .gitignore file
535 foreach my $mod (sort @lib_symlinks)
537 push @ignores, "dlls/lib$importlibs{$mod}.def";
539 foreach my $mod (sort keys %directories)
541 next unless defined $altnames{$mod};
542 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
545 return @ignores;
549 ################################################################
550 # update programs/Makefile.in
552 sub update_progs(@)
554 my (@subdirs, @install_subdirs, @install_progs);
556 my @ignores = ();
558 foreach my $make (@_)
560 my %makefile = %{$makefiles{$make}};
561 my $module = $makefile{"MODULE"};
562 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
563 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
564 next if defined $makefile{"=skip"};
565 push @subdirs, $dir;
566 push @ignores, "programs/$dir/$dir";
567 push @install_subdirs, $dir unless $dont_install{$dir};
568 push @install_progs, $dir if $bin_install{$dir};
571 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
572 "SUBDIRS = \\\n\t",
573 join( " \\\n\t", @subdirs ),
574 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
575 join( " \\\n\t", @install_subdirs ),
576 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
577 join( " \\\n\t", @install_progs ),
578 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
580 return @ignores;
584 ################################################################
585 # update include/Makefile.in
587 sub update_includes()
589 return unless -d ".git";
590 my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
591 my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
592 foreach my $incl (@includes)
594 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
595 next if ($incl =~ /^wine\// && !$exported_wine_headers{$incl});
596 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
597 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
598 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
599 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
600 elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
602 replace_in_file( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
603 "IDL_H_SRCS = \\\n\t",
604 join( " \\\n\t", sort @idl_srcs ),
605 "\n\nIDL_TLB_SRCS = \\\n\t",
606 join( " \\\n\t", sort @tlb_srcs ),
607 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
608 join( " \\\n\t", sort @h_srcs ),
609 "\n\nEXTRASUBDIRS = ",
610 join( " ", sort keys %subdirs ),
611 "\n\nINSTALLDIRS = \\\n" );
615 ################################################################
616 # update the main .gitignore
618 sub update_gitignore(@)
620 my @ignores = values %makerules;
622 foreach my $make (@makefiles)
624 my %makefile = %{$makefiles{$make}};
625 my $dir = $makefile{"=dir"};
626 if (defined $makefile{"MANPAGES"})
628 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
630 if (defined $makefile{"PROGRAMS"})
632 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
636 # prepend a slash to paths that don't have one
637 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
639 # get rid of duplicates
640 my %ignores = ();
641 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
643 replace_in_file( ".gitignore", undef, undef,
644 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
645 join("\n", sort keys %ignores), "\n" );
649 if (-d ".git")
651 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
653 else
655 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
658 update_includes();
660 foreach my $file (sort values %makerules, @makefiles)
662 my %make = parse_makefile( $file );
663 $makefiles{$file} = \%make;
666 update_makefiles( @makefiles );
667 push @ignores, update_ignores( @makefiles );
668 push @ignores, update_winetest( @makefiles );
669 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
670 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
671 update_gitignore( @ignores );