ntoskrnl.exe: Add stub for PoSetPowerState.
[wine.git] / tools / make_makefiles
blob7084258d0a7581c23e7d40b87d068c2e34c80bf9
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 use strict;
24 # Make rules files
25 my %makerules =
27 "MAKE_RULES" => "Make.rules",
28 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30 "MAKE_TEST_RULES" => "Maketest.rules",
31 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
34 # Programs that we want to install in the bin directory too
35 my %bin_install =
37 "msiexec" => 1,
38 "notepad" => 1,
39 "regedit" => 1,
40 "regsvr32" => 1,
41 "wineboot" => 1,
42 "winecfg" => 1,
43 "wineconsole" => 1,
44 "winedbg" => 1,
45 "winefile" => 1,
46 "winemine" => 1,
47 "winepath" => 1,
50 # Programs that we don't want to install at all
51 my %dont_install =
53 "cmdlgtst" => 1,
54 "view" => 1,
55 "winetest" => 1,
58 # Dlls and programs that are 16-bit specific
59 my %modules16 =
61 "ifsmgr.vxd" => 1,
62 "mmdevldr.vxd" => 1,
63 "monodebg.vxd" => 1,
64 "vdhcp.vxd" => 1,
65 "vmm.vxd" => 1,
66 "vnbt.vxd" => 1,
67 "vnetbios.vxd" => 1,
68 "vtdapi.vxd" => 1,
69 "vwin32.vxd" => 1,
70 "w32skrnl.dll" => 1,
71 "winevdm.exe" => 1,
72 "wow32.dll" => 1,
75 # Default patterns for top-level .gitignore
76 my @ignores = (
77 "*.[oa]",
78 "*.fake",
79 "*.ok",
80 "*.res",
81 "*.so",
82 "/autom4te.cache",
83 "/config.cache",
84 "/config.log",
85 "/config.status",
86 "/configure.lineno",
87 "/TAGS",
88 "/tags",
89 "/wine",
90 "Makefile",
91 "dlldata.c",
92 "dlls/*/*.def",
93 "dlls/shell32/AUTHORS",
94 "*/*/tests/*crosstest.exe",
95 "*/*/tests/testlist.c",
96 "include/config.h",
97 "include/stamp-h",
98 "programs/winetest/*_test.exe",
99 "programs/winetest/*_test.rc",
100 "programs/winetest/build.nfo",
101 "programs/winetest/build.rc",
102 "tools/makedep",
105 # Source files and their resulting target to ignore
106 my @ignore_srcs = (
107 [ 'BISON_SRCS', '\.y', '.tab.c' ],
108 [ 'BISON_SRCS', '\.y', '.tab.h' ],
109 [ 'LEX_SRCS', '\.l', '.yy.c' ],
110 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
111 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
112 [ 'IDL_H_SRCS', '\.idl', '.h' ],
113 [ 'IDL_C_SRCS', '\.idl', '.h' ],
114 [ 'IDL_I_SRCS', '\.idl', '.h' ],
115 [ 'IDL_P_SRCS', '\.idl', '.h' ],
116 [ 'IDL_S_SRCS', '\.idl', '.h' ],
117 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
118 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
119 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
120 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
123 my %exported_wine_headers = (
124 "wine/debug.h" => 1,
125 "wine/exception.h" => 1,
126 "wine/library.h" => 1,
127 "wine/unicode.h" => 1,
128 "wine/itss.idl" => 1,
129 "wine/svcctl.idl" => 1,
132 my %private_idl_headers = (
133 "access.idl" => 1,
134 "asynot.idl" => 1,
135 "asysta.idl" => 1,
136 "axcore.idl" => 1,
137 "axextend.idl" => 1,
138 "binres.idl" => 1,
139 "cmdbas.idl" => 1,
140 "cmdtxt.idl" => 1,
141 "crtrow.idl" => 1,
142 "dbccmd.idl" => 1,
143 "dbcses.idl" => 1,
144 "dbdsad.idl" => 1,
145 "dbinit.idl" => 1,
146 "dbprop.idl" => 1,
147 "dbs.idl" => 1,
148 "devenum.idl" => 1,
149 "dyngraph.idl" => 1,
150 "opnrst.idl" => 1,
151 "row.idl" => 1,
152 "rowchg.idl" => 1,
153 "rstbas.idl" => 1,
154 "rstinf.idl" => 1,
155 "rstloc.idl" => 1,
156 "sesprp.idl" => 1,
157 "vmrender.idl" => 1,
158 "wine/wined3d.idl" => 1,
159 "wine/winedxgi.idl" => 1,
162 my %ignored_source_files = (
163 "dlls/wineps.drv/afm2c.c" => 1,
164 "dlls/wineps.drv/mkagl.c" => 1,
165 "programs/winetest/dist.rc" => 1,
168 my (@all_files, @makefiles, %makefiles);
170 sub dirname($)
172 my $ret = shift;
173 return "" unless $ret =~ /\//;
174 $ret =~ s!/[^/]*$!!;
175 return $ret;
178 # update a file if changed
179 sub update_file($)
181 my $file = shift;
182 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
183 if (!$ret)
185 unlink "$file.new";
187 else
189 rename "$file.new", "$file";
190 print "$file updated\n";
191 if ($file eq "configure.ac")
193 system "autoconf";
194 print "configure updated\n";
197 return $ret;
200 # replace some lines in a file between two markers
201 sub replace_in_file($$$@)
203 my $file = shift;
204 my $start = shift;
205 my $end = shift;
207 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
209 if (defined($start))
211 open OLD_FILE, "$file" or die "cannot open $file";
212 while (<OLD_FILE>)
214 last if /$start/;
215 print NEW_FILE $_;
219 print NEW_FILE @_;
221 if (defined($end))
223 my $skip=1;
224 while (<OLD_FILE>)
226 print NEW_FILE $_ unless $skip;
227 $skip = 0 if /$end/;
231 close OLD_FILE if defined($start);
232 close NEW_FILE;
233 return update_file($file);
236 # replace a variable in a makefile
237 sub replace_makefile_variable($$)
239 my ($file, $var) = @_;
240 my $make = $makefiles{$file};
242 return unless defined ${$make}{"=$var"};
244 my @values = @{${$make}{"=$var"}};
245 ${$make}{$var} = \@values;
247 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
249 open OLD_FILE, "$file.in" or die "cannot open $file.in";
250 while (<OLD_FILE>)
252 if (/^\s*($var\s+)=/)
254 # try to preserve formatting
255 my $prefix = $1;
256 my $multiline = /\\$/ || (@values > 1);
257 while (/\\$/)
259 $_ = <OLD_FILE>;
260 last unless $_;
262 if ($multiline)
264 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
266 else
268 print NEW_FILE "$prefix= @values\n";
270 next;
272 print NEW_FILE $_;
274 close OLD_FILE;
275 close NEW_FILE;
276 return update_file("$file.in");
279 # parse the specified makefile to identify the rules file
280 sub parse_makefile($)
282 my $file = shift;
283 my %make;
285 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
287 open MAKE, "$file.in" or die "cannot open $file.in\n";
289 while (<MAKE>)
291 chomp;
292 next if (/^\s*#/);
293 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
294 next if (/^\s*$/);
296 if (/^\@(MAKE.*RULES)\@/)
298 my $var = $1;
299 $make{"=rules"} = $makerules{$var};
300 next;
302 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
304 $make{$1} = $2;
305 next;
307 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
309 my @list = split(/\s+/, $2);
310 $make{$1} = \@list;
311 next;
313 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
315 die "Variable $1 in $file.in is obsolete";
318 return %make;
321 # assign source files to their respective makefile
322 sub assign_sources_to_makefiles()
324 foreach my $file (@all_files)
326 next if defined $ignored_source_files{$file};
327 my $dir = dirname( $file );
329 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
330 next unless $dir;
332 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
334 my $make = $makefiles{"$dir/Makefile"};
335 my $basename = substr( $file, length($dir) + 1 );
337 if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
338 elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
339 elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
340 elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
341 elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
342 elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
346 ################################################################
347 # update the makefile list in configure.ac
349 sub update_makefiles(@)
351 my (@lines);
353 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
355 my $file = $makerules{$var};
356 my %make = %{$makefiles{$file}};
357 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
358 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
360 push @lines, "\n";
362 foreach my $file (sort @_)
364 my %make = %{$makefiles{$file}};
365 my $rules = $make{"=rules"};
366 my $args = "";
367 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
368 if ($rules eq $makerules{"MAKE_DLL_RULES"})
370 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
371 if ($name =~ /\./)
373 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
375 else
377 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
379 my $implib = $make{"IMPORTLIB"} || "";
380 my $implib_srcs = defined($make{"IMPLIB_SRCS"}) && join( " ", @{$make{"IMPLIB_SRCS"}} );
381 $args .= "," if $implib || $is_win16;
382 $args .= "enable_win16" if $is_win16;
383 $args .= ",[$implib]" if $implib;
384 $args .= ",[$implib_srcs]" if $implib_srcs;
385 push @lines, "WINE_CONFIG_DLL($name$args)\n";
387 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
389 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
390 if ($name =~ /\./)
392 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
394 else
396 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
398 my $install = $dont_install{$name} ? "" : "install";
399 $install .= "bin" if $bin_install{$name};
400 $args .= "," if $is_win16 || $install;
401 $args .= "$install" if $install;
402 $args .= ",enable_win16" if $is_win16;
403 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
405 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
407 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
408 push @lines, "WINE_CONFIG_TEST($dir)\n";
410 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
412 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
413 push @lines, "WINE_CONFIG_LIB($name)\n";
415 elsif ($file =~ /^tools.*\/Makefile$/)
417 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
418 push @lines, "WINE_CONFIG_TOOL($name)\n";
420 elsif ($file =~ /\/Makefile$/)
422 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
423 push @lines, "WINE_CONFIG_MAKEFILE([$name])\n";
427 # update the source variables in all the makefiles
429 foreach my $file (sort @_)
431 my %make = %{$makefiles{$file}};
433 replace_makefile_variable( $file, "LEX_SRCS" );
434 replace_makefile_variable( $file, "BISON_SRCS" );
435 replace_makefile_variable( $file, "MC_SRCS" );
436 replace_makefile_variable( $file, "SVG_SRCS" );
437 replace_makefile_variable( $file, "C_SRCS" );
438 replace_makefile_variable( $file, "RC_SRCS" );
441 push @lines, "dnl End of auto-generated output commands\n";
442 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
446 ################################################################
447 # process ignore targets for generic source files
449 sub update_ignores(@)
451 my @ignores;
453 foreach my $file (sort @_)
455 my %makefile = %{$makefiles{$file}};
456 my @list;
458 foreach my $src (@ignore_srcs)
460 my @pattern = @{$src};
461 next unless defined $makefile{$pattern[0]};
462 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
464 foreach my $f (@list)
466 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
469 if (defined $makefile{"IMPORTLIB"})
471 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
473 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
475 else
477 die "invalid importlib name $makefile{IMPORTLIB} in $file";
481 return @ignores;
485 ################################################################
486 # update include/Makefile.in
488 sub update_includes()
490 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
491 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
492 foreach my $incl (@includes)
494 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
495 next if ($incl =~ /\.in$/);
496 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
498 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
499 next;
501 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
502 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
503 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
505 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
506 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
507 else { die "unknown file $incl in include dir"; }
509 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
510 "PRIVATE_IDL_H_SRCS = \\\n\t",
511 join( " \\\n\t", sort @private_idl_srcs ),
512 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
513 join( " \\\n\t", sort @public_idl_srcs ),
514 "\n\nIDL_TLB_SRCS = \\\n\t",
515 join( " \\\n\t", sort @tlb_srcs ),
516 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
517 join( " \\\n\t", sort @h_srcs ),
518 "\n\nEXTRASUBDIRS = ",
519 join( " ", sort keys %subdirs ),
520 "\n\nINSTALLDIRS = \\\n" );
521 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
525 ################################################################
526 # update the main .gitignore
528 sub update_gitignore(@)
530 my @ignores = values %makerules;
532 foreach my $make (@makefiles)
534 my %makefile = %{$makefiles{$make}};
535 my $dir = $makefile{"=dir"};
536 if (defined $makefile{"MANPAGES"})
538 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
540 if (defined $makefile{"PROGRAMS"})
542 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
546 # prepend a slash to paths that don't have one
547 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
549 # get rid of duplicates
550 my %ignores = ();
551 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
553 replace_in_file( ".gitignore", undef, undef,
554 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
555 join("\n", sort keys %ignores), "\n" );
559 die "needs to be run from a git checkout" unless -d ".git";
561 @all_files = split /\0/, `git ls-files -c -z`;
562 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
564 foreach my $file (sort values %makerules, @makefiles)
566 my %make = parse_makefile( $file );
567 $makefiles{$file} = \%make;
570 assign_sources_to_makefiles();
571 update_makefiles( @makefiles );
572 push @ignores, update_includes();
573 push @ignores, update_ignores( @makefiles );
574 update_gitignore( @ignores );