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
24 # Programs that we want to install in the bin directory too
40 # Programs that we don't want to install at all
46 # Dlls and programs that are 16-bit specific
63 my %exported_wine_headers = (
65 "wine/exception.h" => 1,
66 "wine/library.h" => 1,
67 "wine/unicode.h" => 1,
69 "wine/svcctl.idl" => 1,
72 my %private_idl_headers = (
106 "wine/winedxgi.idl" => 1,
109 my %ignored_source_files = (
110 "dlls/wineps.drv/afm2c.c" => 1,
111 "dlls/wineps.drv/mkagl.c" => 1,
112 "programs/winetest/dist.rc" => 1,
113 "tools/makedep.c" => 1,
116 my (@linguas, @makefiles, %makefiles);
121 return "" unless $ret =~ /\//;
126 # update a file if changed
130 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
137 rename "$file.new", "$file";
138 print "$file updated\n";
139 if ($file eq "configure.ac")
142 print "configure updated\n";
148 # replace some lines in a file between two markers
149 sub replace_in_file
($$$@
)
155 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
159 open OLD_FILE
, "$file" or die "cannot open $file";
174 print NEW_FILE
$_ unless $skip;
179 close OLD_FILE
if defined($start);
181 return update_file
($file);
184 # replace a variable in a makefile
185 sub replace_makefile_variable
($$)
187 my ($file, $var) = @_;
188 my $make = $makefiles{$file};
192 if (defined ${$make}{"=$var"})
194 @values = @
{${$make}{"=$var"}};
195 ${$make}{$var} = \
@values;
199 return unless defined ${$make}{$var};
200 undef ${$make}{$var};
203 open NEW_FILE
, ">$file.in.new" or die "cannot create $file.in.new";
205 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
208 if (/^\s*($var\s*)=/)
210 # try to preserve formatting
212 my $multiline = /\\$/ || (@values > 1);
224 print NEW_FILE
"$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
228 print NEW_FILE
"$prefix= @values\n";
233 if (/^\@MAKE/ && !$replaced && @values)
235 print NEW_FILE
"$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
241 return update_file
("$file.in");
244 # parse the specified makefile and load the variables
245 sub parse_makefile
($)
250 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
252 open MAKE
, "$file.in" or die "cannot open $file.in\n";
258 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
261 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
265 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
268 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_SRCS|IMPLIB_SRCS|C_SRCS|OBJC_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|FONT_SRCS|IN_SRCS|PROGRAMS|EXTRA_TARGETS|MANPAGES)\s*=\s*(.*)/)
271 my @list = split(/\s+/, $2);
272 $make{$var} = \
@list;
273 ${$make{"=flags"}}{"clean"} = 1 if $var eq "PROGRAMS";
274 ${$make{"=flags"}}{"clean"} = 1 if $var eq "EXTRA_TARGETS";
277 if (/^\s*INSTALL_(LIB|DEV)\s*=\s*/)
279 ${$make{"=flags"}}{$1 eq "LIB" ?
"install-lib" : "install-dev"} = 1;
282 if (/(install-lib|install-dev|clean)\s*:/)
284 ${$make{"=flags"}}{$1} = 1;
287 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
289 die "Variable $1 in $file.in is obsolete";
291 if (/\@[A-Z_]+\@/) # config.status substitution variable
293 ${$make{"=flags"}}{"config"} = 1;
297 if ($file =~ /^programs\/([^\
/]+)\/Makefile
/)
299 ${$make{"=flags"}}{"install"} = 1 unless $dont_install{$1};
300 ${$make{"=flags"}}{"installbin"} = 1 if $bin_install{$1};
303 if (defined $make{"=flags"} && defined $make{"MODULE"})
305 die "Custom install-lib rule not allowed in $file" if defined ${$make{"=flags"}}{"install-lib"};
306 die "Custom install-dev rule not allowed in $file" if defined ${$make{"=flags"}}{"install-dev"};
312 # read pragma makedep flags from a source file
313 sub get_makedep_flags
($)
318 open FILE
, $file or die "cannot open $file";
321 next unless /^#\s*pragma\s+makedep\s+(.*)/;
322 foreach my $flag (split /\s+/, $1)
324 last if $flag eq "depend";
332 sub get_parent_makefile
($)
335 my %make = %{$makefiles{$file}};
336 my $reldir = $make{"PARENTSRC"} || "";
337 return "" unless $reldir;
338 (my $path = $file) =~ s/\/Makefile$/\
//;
339 while ($reldir =~ /^\.\.\//)
341 $reldir =~ s/^\.\.\///;
342 $path =~ s/[^\/]+\/$//;
344 return "$path$reldir/Makefile";
347 # preserve shared source files that are listed in the existing makefile
348 sub preserve_shared_source_files
($$$)
350 my ($make, $parent, $var) = @_;
353 return unless defined ${$parent}{"=$var"};
354 foreach my $file (@
{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
355 foreach my $file (@
{${$make}{"=$var"}}) { $srcs{$file} = 0; }
357 foreach my $file (@
{${$make}{$var}})
359 next unless defined $srcs{$file} && $srcs{$file} == 1;
360 push @
{${$make}{"=$var"}}, $file;
364 # assign source files to their respective makefile
365 sub assign_sources_to_makefiles
(@
)
367 foreach my $file (@_)
369 next if defined $ignored_source_files{$file};
370 next if $file =~ /Makefile\.in$/;
371 my $dir = dirname
( $file );
374 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
375 $subdir =~ s/^$dir\/?//;
378 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
380 my $make = $makefiles{"$dir/Makefile"};
381 my $name = substr( $file, length($dir) + 1 );
383 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
385 if ($dir eq "include")
387 next if ($name =~ /\.in$/);
388 if ($name =~ /^wine\// && !$exported_wine_headers{$name})
390 if ($private_idl_headers{$name}) { push @
{${$make}{"=PRIVATE_IDL_H_SRCS"}}, $name; }
393 if ($name =~ /stdole2\.idl$/) { push @
{${$make}{"=IDL_TLB_SRCS"}}, $name; }
394 elsif ($private_idl_headers{$name}) { push @
{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
395 elsif ($name =~ /\.h$/) { push @
{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
396 elsif ($name =~ /\.x$/) { push @
{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
397 elsif ($name =~ /\.rh$/) { push @
{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
398 elsif ($name =~ /\.inl$/) { push @
{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
399 elsif ($name =~ /\.idl$/) { push @
{${$make}{"=PUBLIC_IDL_H_SRCS"}}, $name; }
400 else { die "unknown file $name in include dir"; }
404 if ($name =~ /\.m$/) { push @
{${$make}{"=OBJC_SRCS"}}, $name; }
405 elsif ($name =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $name; }
406 elsif ($name =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $name; }
407 elsif ($name =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $name; }
408 elsif ($name =~ /\.sfd$/) { push @
{${$make}{"=FONT_SRCS"}}, $name; }
409 elsif ($name =~ /\.c$/)
411 my %flags = get_makedep_flags
( $file );
412 if (defined $flags{"implib"})
414 push @
{${$make}{"=IMPLIB_SRCS"}}, $name;
415 ${${$make}{"=flags"}}{"staticimplib"} = 1;
417 push @
{${$make}{"=C_SRCS"}}, $name;
419 elsif ($name =~ /\.rc$/)
421 my %flags = get_makedep_flags
( $file );
422 ${${$make}{"=flags"}}{"po"} = 1 if defined $flags{"po"};
423 push @
{${$make}{"=RC_SRCS"}}, $name;
425 elsif ($name =~ /\.mc$/)
427 push @
{${$make}{"=MC_SRCS"}}, $name;
428 ${${$make}{"=flags"}}{"mc"} = 1;
430 elsif ($name =~ /\.idl$/)
432 push @
{${$make}{"=IDL_SRCS"}}, $name;
433 ${${$make}{"=flags"}}{"clean"} = 1;
435 elsif ($name =~ /\.man\.in$/)
437 push @
{${$make}{"=MANPAGES"}}, $name;
438 ${${$make}{"=flags"}}{"manpage"} = 1;
440 elsif ($name =~ /\.in$/)
442 push @
{${$make}{"=IN_SRCS"}}, $name;
447 # add extra variables to include source list
448 my $make = $makefiles{"include/Makefile"};
449 unshift @
{${$make}{"=SRCDIR_INCLUDES"}}, "\$(XTEMPLATE_SRCS)";
450 unshift @
{${$make}{"=SRCDIR_INCLUDES"}}, "\$(PUBLIC_IDL_H_SRCS)";
451 unshift @
{${$make}{"=SRCDIR_INCLUDES"}}, "\$(IDL_TLB_SRCS)";
452 unshift @
{${$make}{"=IDL_SRCS"}}, "\$(IDL_H_SRCS) \$(IDL_TLB_SRCS)";
454 # preserve shared source files from the parent makefile
455 foreach my $file (@makefiles)
457 my $make = $makefiles{$file};
458 my $parent = get_parent_makefile
( $file );
460 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
461 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
462 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
463 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
464 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @
{${$make}{"=IDL_SRCS"}};
468 ################################################################
469 # update the makefile list in configure.ac
471 sub update_makefiles
(@
)
475 foreach my $file (sort @_)
477 my %make = %{$makefiles{$file}};
479 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
480 my $flag_args = defined $make{"=flags"} ?
",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
481 if (defined($make{"TESTDLL"})) # test
483 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\
/Makefile$/;
484 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
485 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
486 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
487 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
489 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
491 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
492 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
493 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
494 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
495 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
497 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
499 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
500 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
501 (my $name = $file) =~ s/^programs\/(.*)\/Makefile
/$1/;
504 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
508 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
510 $args .= "," if $is_win16 || defined $make{"=flags"};
511 $args .= "enable_win16" if $is_win16;
512 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
514 elsif (defined($make{"MODULE"})) # dll
516 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
517 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
518 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
519 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
522 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
526 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
528 my $implib = $make{"IMPORTLIB"} || "";
529 $args .= "," if $is_win16 || defined $make{"=flags"};
530 $args .= "enable_win16" if $is_win16;
532 $args .= ",[$implib]" if $implib && $implib ne $name;
533 push @lines, "WINE_CONFIG_DLL($name$args)\n";
535 elsif ($file =~ /^tools.*\/Makefile
$/)
537 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
538 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
539 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
540 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
542 elsif ($file =~ /\/Makefile
$/)
544 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
546 $args .= "," if defined $make{"=flags"};
547 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
551 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
553 # update the source variables in all the makefiles
555 foreach my $file (sort @_)
557 replace_makefile_variable
( $file, "LEX_SRCS" );
558 replace_makefile_variable
( $file, "BISON_SRCS" );
559 replace_makefile_variable
( $file, "MC_SRCS" );
560 replace_makefile_variable
( $file, "SVG_SRCS" );
561 replace_makefile_variable
( $file, "FONT_SRCS" );
562 replace_makefile_variable
( $file, "C_SRCS" );
563 replace_makefile_variable
( $file, "OBJC_SRCS" );
564 replace_makefile_variable
( $file, "RC_SRCS" );
565 replace_makefile_variable
( $file, "IDL_SRCS" );
566 replace_makefile_variable
( $file, "XTEMPLATE_SRCS" );
567 replace_makefile_variable
( $file, "IN_SRCS" );
568 replace_makefile_variable
( $file, "IMPLIB_SRCS" );
569 replace_makefile_variable
( $file, "MANPAGES" );
570 next unless $file eq "include/Makefile";
571 replace_makefile_variable
( $file, "PRIVATE_IDL_H_SRCS" );
572 replace_makefile_variable
( $file, "PUBLIC_IDL_H_SRCS" );
573 replace_makefile_variable
( $file, "IDL_TLB_SRCS" );
574 replace_makefile_variable
( $file, "SRCDIR_INCLUDES" );
577 push @lines, "dnl End of auto-generated output commands\n";
578 replace_in_file
( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
582 ################################################################
583 # update the LINGUAS file
585 sub update_linguas
(@
)
587 replace_in_file
( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
591 my $git_dir = $ENV{GIT_DIR
} || ".git";
592 die "needs to be run from a git checkout" unless -d
$git_dir;
594 my @all_files = split /\0/, `git ls-files -c -z`;
595 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\
/.*\.po$/, @all_files;
596 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
598 foreach my $file (sort @makefiles)
600 my %make = parse_makefile
( $file );
601 $makefiles{$file} = \
%make;
604 assign_sources_to_makefiles
( @all_files );
605 update_linguas
( @linguas );
606 update_makefiles
( @makefiles );