programs/wcmd: Rename to programs/cmd.
[wine.git] / tools / make_makefiles
blob4a2d78e0010910c4050c9b7d46012f9f77cc1a74
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 # update a file if changed
23 sub update_file($)
25 my $file = shift;
26 my $ret = system "cmp $file $file.new >/dev/null";
27 if (!$ret)
29 unlink "$file.new";
30 print "$file is unchanged\n";
32 else
34 rename "$file.new", "$file";
35 print "$file updated\n";
37 return $ret;
40 # replace some lines in a file between two markers
41 sub replace_in_file($$$@)
43 my $file = shift;
44 my $start = shift;
45 my $end = shift;
47 open OLD_FILE, "$file" or die "cannot open $file";
48 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
50 while (<OLD_FILE>)
52 last if /$start/;
53 print NEW_FILE $_;
56 print NEW_FILE @_;
58 if (defined($end))
60 my $skip=1;
61 while (<OLD_FILE>)
63 print NEW_FILE $_ unless $skip;
64 $skip = 0 if /$end/;
68 close OLD_FILE;
69 close NEW_FILE;
70 return update_file($file);
73 my (@makefiles, @makerules);
75 if (-d ".git")
77 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
78 @makerules = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Make\\*rules.in \\*/Make\\*rules.in`;
80 else
82 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
83 @makerules = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Make\\*.rules.in -print`);
87 ################################################################
88 # update the makefile list in configure.ac
90 replace_in_file( "configure.ac", '^AC_CONFIG_FILES\(', '\]\)$',
91 "AC_CONFIG_FILES([\n",
92 join ("\n", (sort @makerules), (sort @makefiles) ), "])\n" );
95 ################################################################
96 # update the tests list in programs/winetest/Makefile.in
98 my %modules = ( "kernel" => "kernel32", "gdi" => "gdi32", "user" => "user32" );
99 my %tests;
100 my @lines = ( "TESTBINS =" );
102 foreach my $file (sort grep /^dlls\/.*\/tests\/Makefile/, @makefiles)
104 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/)
106 my $dir = $1;
107 my $mod = $modules{$dir} || $dir;
108 $tests{$mod} = $dir;
109 push @lines, " \\\n\t${mod}_test.exe\$(DLLEXT)";
112 push @lines, "\n\n";
114 foreach my $test (sort keys %tests)
116 my $dir = $tests{$test};
117 push @lines, "${test}_test.exe\$(DLLEXT): \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT)\n";
118 push @lines, "\tcp \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
120 push @lines, "\n# Special rules\n";
122 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
125 ################################################################
126 # update dlls/Makefile.in
128 my @dll_makefiles = grep /^dlls\//, @makefiles;
129 system "dlls/make_dlls", @dll_makefiles;
132 ################################################################
133 # update programs/Makefile.in
135 my @prog_makefiles = grep /^programs\//, @makefiles;
136 system "programs/make_progs", @prog_makefiles;