cmd: In function WCMD_goto() changed strcmp() to lstrcmpi().
[wine.git] / tools / make_makefiles
blob1064beff8dd273528ff5e9ca75d8f1150a91642f
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,
49 "winhelp" => 1,
52 # Programs that we don't want to install at all
53 my %dont_install =
55 "cmdlgtst" => 1,
56 "view" => 1,
57 "winetest" => 1,
60 # Special dlls that can be switched on or off by configure
61 my %special_dlls =
63 "glu32" => "GLU32FILES",
64 "opengl32" => "OPENGLFILES",
65 "wined3d" => "OPENGLFILES",
66 "winex11.drv" => "XFILES",
67 "winequartz.drv" => "QUARTZFILES"
70 # Default patterns for top-level .gitignore
71 my @ignores = (
72 "*.[oa]",
73 "*.so",
74 "/autom4te.cache",
75 "/config.cache",
76 "/config.log",
77 "/config.status",
78 "/TAGS",
79 "/tags",
80 "Makefile"
83 # Source files and their resulting target to ignore
84 my @ignore_srcs = (
85 [ 'BISON_SRCS', '\.y', '.tab.c' ],
86 [ 'BISON_SRCS', '\.y', '.tab.h' ],
87 [ 'LEX_SRCS', '\.l', '.yy.c' ],
88 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
89 [ 'RC_SRCS', '\.rc', '.res' ],
90 [ 'RC_SRCS16', '\.rc', '.res' ],
91 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
92 [ 'IDL_H_SRCS', '\.idl', '.h' ],
93 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
94 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
95 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
96 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
99 my (@makefiles, %makefiles);
101 # update a file if changed
102 sub update_file($)
104 my $file = shift;
105 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
106 if (!$ret)
108 unlink "$file.new";
110 else
112 rename "$file.new", "$file";
113 print "$file updated\n";
114 if ($file eq "configure.ac")
116 system "autoconf";
117 print "configure updated\n";
120 return $ret;
123 # replace some lines in a file between two markers
124 sub replace_in_file($$$@)
126 my $file = shift;
127 my $start = shift;
128 my $end = shift;
130 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
132 if (defined($start))
134 open OLD_FILE, "$file" or die "cannot open $file";
135 while (<OLD_FILE>)
137 last if /$start/;
138 print NEW_FILE $_;
142 print NEW_FILE @_;
144 if (defined($end))
146 my $skip=1;
147 while (<OLD_FILE>)
149 print NEW_FILE $_ unless $skip;
150 $skip = 0 if /$end/;
154 close OLD_FILE if defined($start);
155 close NEW_FILE;
156 return update_file($file);
159 # parse the specified makefile to identify the rules file
160 sub parse_makefile($)
162 my $file = shift;
163 my %make;
165 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
167 open MAKE, "$file.in" or die "cannot open $file.in\n";
169 while (<MAKE>)
171 chomp;
172 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
174 if (/^\@(MAKE.*RULES)\@/)
176 my $var = $1;
177 $make{"=rules"} = $makerules{$var};
178 next;
180 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
182 $make{$1} = $2;
183 next;
185 if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
187 my @list = split(/\s+/, $2);
188 $make{$1} = \@list;
189 next;
191 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
193 $make{"=skip"} = 1;
194 next;
197 return %make;
200 if (-d ".git")
202 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
204 else
206 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
209 foreach my $file (sort values %makerules, @makefiles)
211 my %make = parse_makefile( $file );
212 $makefiles{$file} = \%make;
215 ################################################################
216 # update the makefile list in configure.ac
218 my @lines = ();
220 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
222 push @lines, "$var=$makerules{$var}\n";
223 push @lines, "AC_SUBST_FILE($var)\n\n";
226 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
227 @lines,
228 "AC_CONFIG_FILES([\n",
229 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
232 ################################################################
233 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
235 sub update_winetest(@)
237 my (@tests, @lines);
239 foreach my $file (@_)
241 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
243 push @lines, "TESTBINS =";
244 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
245 push @lines, "\n\n";
247 foreach my $test (sort @tests)
249 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
250 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
252 push @lines, "\n# Special rules\n";
254 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
256 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
257 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
259 # return a list of test exe files for .gitignore
260 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
264 ################################################################
265 # update the makefile list in Makefile.in
267 sub update_makefiles(@)
269 my (@targets, @depends);
271 foreach my $file (sort values %makerules)
273 push @targets, $file;
274 my %make = %{$makefiles{$file}};
275 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
276 else { push @depends, "$file: $file.in Make.rules"; }
279 foreach my $file (sort @_)
281 push @targets, $file unless $file eq "Makefile";
282 my %makefile = %{$makefiles{$file}};
283 my $dep = $makefile{"=rules"};
284 push @depends, "$file: $file.in $dep";
288 @lines = ();
289 push @lines, "ALL_MAKEFILES = \\\n\t";
290 push @lines, join (" \\\n\t", @targets ), "\n\n";
291 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
292 push @lines, "\t\@./config.status \$\@\n\n";
293 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
294 push @lines, "distclean::\n";
295 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
296 push @lines, join ("\n", @depends ), "\n";
298 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
302 ################################################################
303 # process ignore targets for generic source files
305 sub update_ignores(@)
307 my @ignores;
309 foreach my $file (sort @_)
311 my %makefile = %{$makefiles{$file}};
312 my @list;
314 foreach my $src (@ignore_srcs)
316 my @pattern = @{$src};
317 next unless defined $makefile{$pattern[0]};
318 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
320 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
321 foreach my $f (@list)
323 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
326 return @ignores;
329 ################################################################
330 # update dlls/Makefile.in
332 sub update_dlls(@)
334 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
335 my $text = "";
336 my @ignores = ();
338 foreach my $make (@_)
340 my %makefile = %{$makefiles{$make}};
341 next if defined $makefile{"=skip"};
343 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
345 $testdirs{$1} = "$1/tests";
346 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
347 push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
348 push @ignores, $makefile{"=dir"} . "testlist.c";
349 push @ignores, $makefile{"=dir"} . "*.ok";
350 next;
353 next unless defined $makefile{"MODULE"};
354 my $module = $makefile{"MODULE"};
355 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
357 if ($module =~ /^lib.*\.a$/)
359 $staticlib_dirs{$module} = $dir;
360 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
362 else
364 (my $mod = $module) =~ s/\.dll$//;
365 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
366 $directories{$module} = $dir;
369 if (defined $makefile{"IMPORTLIB"})
371 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
373 $importlibs{$module} = $1;
375 else
377 die "invalid importlib name $makefile{IMPORTLIB} in $make";
381 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
383 if (defined $makefile{"SPEC_SRCS16"})
385 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
386 $altnames{$module} = \@list;
390 # output special dlls configure definitions
392 $text .= "# special configure-dependent targets\n\n";
393 my %specials = ();
394 foreach my $mod (sort keys %special_dlls)
396 $specials{$special_dlls{$mod}} .= " " . $mod;
398 foreach my $i (sort keys %specials)
400 $text .= $i . " =" . $specials{$i} . "\n";
402 $text .= "EXTRADIRS =";
403 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
404 $text .= "\n\n";
406 # output the subdirs list
408 $text .= "# Subdir list\n\n";
409 $text .= "BASEDIRS =";
410 foreach my $dir (sort values %directories)
412 next if defined($special_dlls{$dir}); # skip special dlls
413 $text .= " \\\n\t" . $dir;
416 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
417 $text .= join " \\\n\t", sort values %staticlib_dirs;
419 $text .= "\n\nTESTSUBDIRS = \\\n\t";
420 $text .= join " \\\n\t", sort values %testdirs;
422 $text .= "\n\nSUBDIRS = \\\n\t";
423 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
425 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
426 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
427 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
429 # output the list of 16-bit files
431 my @targets16 = ();
432 foreach my $mod (sort keys %directories)
434 next unless defined $altnames{$mod};
435 foreach my $i (sort @{$altnames{$mod}})
437 push @targets16, $i . "16";
440 $text .= "\n# 16-bit dlls\n\n";
441 $text .= "WIN16_FILES = \\\n";
442 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
443 $text .= "\@MAKE_RULES\@\n\n";
445 # output the all: target
447 $text .= "# Main target\n\n";
448 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
450 # output the lib name -> directory rules
452 $text .= "# Placeholders for 16-bit libraries\n\n";
453 foreach my $mod (sort keys %directories)
455 next unless defined $altnames{$mod};
456 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
457 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
460 # output the import libraries rules
462 $text .= "# Import libraries\n\n";
463 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
465 my @lib_symlinks = ();
466 foreach my $mod (sort keys %importlibs)
468 my $dir = $directories{$mod};
469 my $lib = $importlibs{$mod};
470 if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
472 $text .= "IMPORT_SYMLINKS =";
473 foreach my $mod (sort @lib_symlinks)
475 $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
478 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
479 foreach my $mod (sort keys %staticlib_dirs)
481 $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
483 foreach my $mod (sort keys %importlibs)
485 my $dir = $directories{$mod};
486 my $def = $mod;
487 $def =~ s/\.(dll|drv)$//;
488 $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
489 next unless defined $static_implibs{$mod};
490 $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
492 $text .= "\n\n";
493 $text .= "implib: \$(IMPORT_LIBS)\n\n";
494 $text .= ".PHONY: implib\n\n";
496 foreach my $mod (sort keys %importlibs)
498 my $dir = $directories{$mod};
499 my $lib = $importlibs{$mod};
500 my $spec = $mod;
501 $spec =~ s/\.dll$//;
502 $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
503 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
504 next unless $static_implibs{$mod};
505 $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
506 $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
508 foreach my $mod (sort @lib_symlinks)
510 my $dir = $directories{$mod};
511 my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
512 $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
513 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
516 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
517 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
519 # output the inter-dll dependencies and rules
521 $text .= "# Map library name to the corresponding directory\n\n";
523 foreach my $mod (sort keys %staticlib_dirs)
525 $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
527 $text .= "\n# Misc rules\n";
529 replace_in_file( "dlls/Makefile.in",
530 '^# special configure-dependent targets',
531 '^# Misc rules',
532 $text );
534 # .gitignore file
536 foreach my $mod (sort @lib_symlinks)
538 push @ignores, "dlls/$importlibs{$mod}.def";
540 foreach my $mod (sort keys %directories)
542 next unless defined $altnames{$mod};
543 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
545 foreach my $mod (sort keys %importlibs)
547 my $dir = $directories{$mod};
548 my $def = $mod;
549 $def =~ s/\.(dll|drv)$//;
550 push @ignores, "dlls/$dir/lib$def.def";
553 return @ignores;
557 ################################################################
558 # update programs/Makefile.in
560 sub update_progs(@)
562 my (@subdirs, @install_subdirs, @install_progs);
564 my @ignores = ();
566 foreach my $make (@_)
568 my %makefile = %{$makefiles{$make}};
569 my $module = $makefile{"MODULE"};
570 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
571 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
572 next if defined $makefile{"=skip"};
573 push @subdirs, $dir;
574 push @ignores, "programs/$dir/$dir";
575 push @install_subdirs, $dir unless $dont_install{$dir};
576 push @install_progs, $dir if $bin_install{$dir};
579 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
580 "SUBDIRS = \\\n\t",
581 join( " \\\n\t", @subdirs ),
582 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
583 join( " \\\n\t", @install_subdirs ),
584 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
585 join( " \\\n\t", @install_progs ),
586 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
588 return @ignores;
592 ################################################################
593 # update the main .gitignore
595 sub update_gitignore(@)
597 my @ignores = values %makerules;
599 foreach my $make (@makefiles)
601 my %makefile = %{$makefiles{$make}};
602 my $dir = $makefile{"=dir"};
603 if (defined $makefile{"MANPAGES"})
605 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
607 if (defined $makefile{"PROGRAMS"})
609 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
613 # prepend a slash to paths that don't have one
614 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
616 push @ignores, @_;
618 replace_in_file( ".gitignore", undef, undef,
619 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
620 join("\n", sort @ignores), "\n" );
624 update_makefiles( @makefiles );
625 push @ignores, update_ignores( @makefiles );
626 push @ignores, update_winetest( @makefiles );
627 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
628 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
629 update_gitignore( @ignores );