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