1 #!/usr/bin/perl -w
2 #
3 # Build the auto-generated parts of the Wine makefiles.
4 #
5 # Copyright 2006 Alexandre Julliard
6 #
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.
11 #
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.
16 #
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
20 #
21
22 # Make rules files
23 my %makerules =
24 (
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",
30 );
31
32 # Programs that we want to install in the bin directory too
33 my %bin_install =
34 (
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 );
50
51 # Programs that we don't want to install at all
52 my %dont_install =
53 (
54 "cmdlgtst" => 1,
55 "view" => 1,
56 "winetest" => 1,
57 );
58
59 # Default patterns for top-level .gitignore
60 my @ignores = (
61 "*.[oa]",
62 "*.ok",
63 "*.res",
64 "*.so",
65 "/autom4te.cache",
66 "/config.cache",
67 "/config.log",
68 "/config.status",
69 "/TAGS",
70 "/tags",
71 "Makefile",
72 "dlldata.c",
73 "dlls/*/*.def",
74 "dlls/*/tests/*crosstest.exe",
75 "dlls/*/tests/testlist.c",
76 "include/config.h",
77 "include/stamp-h",
78 "programs/winetest/tests.rc",
79 "programs/winetest/*_test.exe",
80 );
81
82 # Source files and their resulting target to ignore
83 my @ignore_srcs = (
84 [ 'BISON_SRCS', '\.y', '.tab.c' ],
85 [ 'BISON_SRCS', '\.y', '.tab.h' ],
86 [ 'LEX_SRCS', '\.l', '.yy.c' ],
87 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
88 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
89 [ 'IDL_H_SRCS', '\.idl', '.h' ],
90 [ 'IDL_C_SRCS', '\.idl', '.h' ],
91 [ 'IDL_I_SRCS', '\.idl', '.h' ],
92 [ 'IDL_P_SRCS', '\.idl', '.h' ],
93 [ 'IDL_S_SRCS', '\.idl', '.h' ],
94 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
95 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
96 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
97 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
98 );
99
100 my %exported_wine_headers = (
101 "wine/debug.h" => 1,
102 "wine/exception.h" => 1,
103 "wine/library.h" => 1,
104 "wine/unicode.h" => 1,
105 "wine/itss.idl" => 1,
106 "wine/svcctl.idl" => 1,
107 );
108
109 my %private_idl_headers = (
110 "axcore.idl" => 1,
111 "axextend.idl" => 1,
112 "dbinit.idl" => 1,
113 "dbprop.idl" => 1,
114 "dbs.idl" => 1,
115 "devenum.idl" => 1,
116 "dyngraph.idl" => 1,
117 "vmrender.idl" => 1,
118 "wine/wined3d.idl" => 1,
119 "wine/winedxgi.idl" => 1,
120 );
121
122 my (@makefiles, %makefiles);
123
124 # update a file if changed
125 sub update_file($)
126 {
127 my $file = shift;
128 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
129 if (!$ret)
130 {
131 unlink "$file.new";
132 }
133 else
134 {
135 rename "$file.new", "$file";
136 print "$file updated\n";
137 if ($file eq "configure.ac")
138 {
139 system "autoconf";
140 print "configure updated\n";
141 }
142 }
143 return $ret;
144 }
145
146 # replace some lines in a file between two markers
147 sub replace_in_file($$$@)
148 {
149 my $file = shift;
150 my $start = shift;
151 my $end = shift;
152
153 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
154
155 if (defined($start))
156 {
157 open OLD_FILE, "$file" or die "cannot open $file";
158 while (<OLD_FILE>)
159 {
160 last if /$start/;
161 print NEW_FILE $_;
162 }
163 }
164
165 print NEW_FILE @_;
166
167 if (defined($end))
168 {
169 my $skip=1;
170 while (<OLD_FILE>)
171 {
172 print NEW_FILE $_ unless $skip;
173 $skip = 0 if /$end/;
174 }
175 }
176
177 close OLD_FILE if defined($start);
178 close NEW_FILE;
179 return update_file($file);
180 }
181
182 # parse the specified makefile to identify the rules file
183 sub parse_makefile($)
184 {
185 my $file = shift;
186 my %make;
187
188 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
189
190 open MAKE, "$file.in" or die "cannot open $file.in\n";
191
192 while (<MAKE>)
193 {
194 chomp;
195 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
196
197 if (/^\@(MAKE.*RULES)\@/)
198 {
199 my $var = $1;
200 $make{"=rules"} = $makerules{$var};
201 next;
202 }
203 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
204 {
205 $make{$1} = $2;
206 next;
207 }
208 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*(.*)/)
209 {
210 my @list = split(/\s+/, $2);
211 $make{$1} = \@list;
212 next;
213 }
214 }
215 return %make;
216 }
217
218
219 ################################################################
220 # update the makefile list in configure.ac
221
222 sub update_makefiles(@)
223 {
224 my (@lines);
225
226 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
227 {
228 my $file = $makerules{$var};
229 my %make = %{$makefiles{$file}};
230 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
231 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
232 }
233 push @lines, "\n";
234
235 foreach my $file (sort @_)
236 {
237 my %make = %{$makefiles{$file}};
238 my $rules = $make{"=rules"};
239 my $args = "";
240 if ($rules eq $makerules{"MAKE_DLL_RULES"}) { $args = ",[dlls],[ALL_DLL_DIRS]"; }
241 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
242 elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
243 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
244 {
245 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
246 $args = ",[programs],[ALL_PROGRAM_DIRS";
247 $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
248 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
249 $args .= "]";
250 }
251 elsif ($file =~ /^[^\/]*\/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
252 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
253 }
254
255 push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
256 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
257 }
258
259
260 ################################################################
261 # process ignore targets for generic source files
262
263 sub update_ignores(@)
264 {
265 my @ignores;
266
267 foreach my $file (sort @_)
268 {
269 my %makefile = %{$makefiles{$file}};
270 my @list;
271
272 foreach my $src (@ignore_srcs)
273 {
274 my @pattern = @{$src};
275 next unless defined $makefile{$pattern[0]};
276 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
277 }
278 foreach my $f (@list)
279 {
280 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
281 }
282 }
283 return @ignores;
284 }
285
286 ################################################################
287 # update dlls/Makefile.in
288
289 sub update_dlls(@)
290 {
291 my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
292 my $text = "";
293 my @ignores = ();
294
295 foreach my $make (@_)
296 {
297 my %makefile = %{$makefiles{$make}};
298 next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
299
300 next unless defined $makefile{"MODULE"};
301 my $module = $makefile{"MODULE"};
302 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
303
304 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
305 {
306 $staticlib_dirs{$module} = $dir;
307 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
308 }
309 else
310 {
311 die "invalid module $module" unless $module =~ /\./;
312 (my $mod = $module) =~ s/\.dll$//;
313 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
314 $directories{$module} = $dir;
315 }
316
317 if (defined $makefile{"IMPORTLIB"})
318 {
319 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
320 {
321 $importlibs{$module} = $1;
322 }
323 else
324 {
325 die "invalid importlib name $makefile{IMPORTLIB} in $make";
326 }
327 }
328
329 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
330
331 if (defined $makefile{"SPEC_SRCS16"})
332 {
333 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
334 $altnames{$module} = \@list;
335 }
336 if (defined $makefile{"EXTRA_OBJS16"})
337 {
338 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
339 {
340 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
341 }
342 }
343 }
344
345 # output the list of 16-bit files
346
347 my @targets16 = ();
348 foreach my $mod (sort keys %directories)
349 {
350 next unless defined $altnames{$mod};
351 foreach my $i (sort @{$altnames{$mod}})
352 {
353 push @targets16, $i . "16";
354 }
355 }
356 $text .= "# 16-bit dlls\n\n";
357 $text .= "WIN16_FILES = \\\n";
358 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
359 $text .= "\@MAKE_RULES\@\n\n";
360
361 # output the all: target
362
363 $text .= "# Main target\n\n";
364 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
365
366 # output the lib name -> directory rules
367
368 $text .= "# Placeholders for 16-bit libraries\n\n";
369 foreach my $mod (sort keys %directories)
370 {
371 next unless defined $altnames{$mod};
372 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
373 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
374 }
375
376 # output the import libraries rules
377
378 $text .= "# Import libraries\n\n";
379 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
380
381 my @lib_symlinks = ();
382 foreach my $mod (sort keys %importlibs)
383 {
384 my $dir = $directories{$mod};
385 my $lib = $importlibs{$mod};
386 if ($lib ne $dir) { push @lib_symlinks, $mod; }
387 }
388 $text .= "IMPORT_SYMLINKS =";
389 foreach my $mod (sort @lib_symlinks)
390 {
391 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
392 }
393
394 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
395 foreach my $mod (sort keys %staticlib_dirs)
396 {
397 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
398 }
399 foreach my $mod (sort keys %importlibs)
400 {
401 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
402 next unless defined $static_implibs{$mod};
403 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
404 }
405 $text .= "\n\nCROSS_IMPLIBS =";
406 foreach my $mod (sort @lib_symlinks)
407 {
408 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
409 }
410 foreach my $mod (sort keys %importlibs)
411 {
412 next if defined $static_implibs{$mod};
413 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
414 }
415 $text .= "\n\n";
416 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
417 $text .= "implib: \$(IMPORT_LIBS)\n\n";
418 $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
419 $text .= ".PHONY: implib testsubdirs\n\n";
420
421 foreach my $mod (sort keys %importlibs)
422 {
423 my $dir = $directories{$mod};
424 my $lib = $importlibs{$mod};
425 my $spec = $mod;
426 $spec =~ s/\.dll$//;
427 if (defined($static_implibs{$mod}))
428 {
429 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
430 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
431 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
432 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
433 }
434 else
435 {
436 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
437 $dir, $lib, $dir, $lib, $dir, $spec;
438 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
439 }
440 }
441 foreach my $mod (sort @lib_symlinks)
442 {
443 my $dir = $directories{$mod};
444 my $lib = "lib" . $importlibs{$mod};
445 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
446 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
447 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
448 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
449 }
450
451 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
452 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
453
454 # output the inter-dll dependencies and rules
455
456 $text .= "# Map library name to the corresponding directory\n\n";
457
458 foreach my $mod (sort keys %staticlib_dirs)
459 {
460 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
461 }
462 $text .= "\n# Misc rules\n";
463
464 replace_in_file( "dlls/Makefile.in",
465 '^# 16-bit dlls',
466 '^# Misc rules',
467 $text );
468
469 # .gitignore file
470
471 foreach my $mod (sort @lib_symlinks)
472 {
473 push @ignores, "dlls/lib$importlibs{$mod}.def";
474 }
475 foreach my $mod (sort keys %directories)
476 {
477 next unless defined $altnames{$mod};
478 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
479 }
480
481 return @ignores;
482 }
483
484
485 ################################################################
486 # update include/Makefile.in
487
488 sub update_includes()
489 {
490 return unless -d ".git";
491 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
492 my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
493 foreach my $incl (@includes)
494 {
495 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
496 next if ($incl =~ /\.in$/);
497 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
498 {
499 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
500 next;
501 }
502 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
503 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
505 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
506 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
507 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
508 else { die "unknown file $incl in include dir"; }
509 }
510 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
511 "PRIVATE_IDL_H_SRCS = \\\n\t",
512 join( " \\\n\t", sort @private_idl_srcs ),
513 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
514 join( " \\\n\t", sort @public_idl_srcs ),
515 "\n\nIDL_TLB_SRCS = \\\n\t",
516 join( " \\\n\t", sort @tlb_srcs ),
517 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
518 join( " \\\n\t", sort @h_srcs ),
519 "\n\nEXTRASUBDIRS = ",
520 join( " ", sort keys %subdirs ),
521 "\n\nINSTALLDIRS = \\\n" );
522 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
523 }
524
525
526 ################################################################
527 # update the main .gitignore
528
529 sub update_gitignore(@)
530 {
531 my @ignores = values %makerules;
532
533 foreach my $make (@makefiles)
534 {
535 my %makefile = %{$makefiles{$make}};
536 my $dir = $makefile{"=dir"};
537 if (defined $makefile{"MANPAGES"})
538 {
539 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
540 }
541 if (defined $makefile{"PROGRAMS"})
542 {
543 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
544 }
545 if ($dir =~ /^programs\/(.*)\/$/)
546 {
547 push @ignores, "$dir$1";
548 }
549 }
550
551 # prepend a slash to paths that don't have one
552 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
553
554 # get rid of duplicates
555 my %ignores = ();
556 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
557
558 replace_in_file( ".gitignore", undef, undef,
559 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
560 join("\n", sort keys %ignores), "\n" );
561 }
562
563
564 if (-d ".git")
565 {
566 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
567 }
568 else
569 {
570 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
571 }
572
573 foreach my $file (sort values %makerules, @makefiles)
574 {
575 my %make = parse_makefile( $file );
576 $makefiles{$file} = \%make;
577 }
578
579 update_makefiles( @makefiles );
580 push @ignores, update_includes();
581 push @ignores, update_ignores( @makefiles );
582 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
583 update_gitignore( @ignores );
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.