make_makefiles: Explicitly list the Wine headers that should be exported.
[wine] / tools / make_makefiles
index ede3d9d..8f15011 100755 (executable)
@@ -46,7 +46,6 @@ my %bin_install =
   "winefile" => 1,
   "winemine" => 1,
   "winepath" => 1,
-  "winhelp" => 1,
 );
 
 # Programs that we don't want to install at all
@@ -62,7 +61,6 @@ my %special_dlls =
 (
   "glu32"    => "GLU32FILES",
   "opengl32" => "OPENGLFILES",
-  "wined3d"  => "OPENGLFILES",
   "winex11.drv" => "XFILES",
   "winequartz.drv" => "QUARTZFILES"
 );
@@ -70,6 +68,8 @@ my %special_dlls =
 # Default patterns for top-level .gitignore
 my @ignores = (
     "*.[oa]",
+    "*.ok",
+    "*.res",
     "*.so",
     "/autom4te.cache",
     "/config.cache",
@@ -78,6 +78,10 @@ my @ignores = (
     "/TAGS",
     "/tags",
     "Makefile",
+    "dlldata.c",
+    "dlls/*/*.def",
+    "dlls/*/tests/*crosstest.exe",
+    "dlls/*/tests/testlist.c",
     "include/config.h",
     "include/stamp-h"
 );
@@ -88,16 +92,38 @@ my @ignore_srcs = (
     [ 'BISON_SRCS',   '\.y',   '.tab.h' ],
     [ 'LEX_SRCS',     '\.l',   '.yy.c' ],
     [ 'MC_SRCS',      '\.mc',  '.mc.rc' ],
-    [ 'RC_SRCS',      '\.rc',  '.res' ],
-    [ 'RC_SRCS16',    '\.rc',  '.res' ],
     [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
     [ 'IDL_H_SRCS',   '\.idl', '.h' ],
+    [ 'IDL_C_SRCS',   '\.idl', '.h' ],
+    [ 'IDL_I_SRCS',   '\.idl', '.h' ],
+    [ 'IDL_P_SRCS',   '\.idl', '.h' ],
+    [ 'IDL_S_SRCS',   '\.idl', '.h' ],
     [ 'IDL_C_SRCS',   '\.idl', '_c.c' ],
     [ 'IDL_I_SRCS',   '\.idl', '_i.c' ],
     [ 'IDL_P_SRCS',   '\.idl', '_p.c' ],
     [ 'IDL_S_SRCS',   '\.idl', '_s.c' ],
 );
 
+my %exported_wine_headers = (
+    "wine/debug.h" => 1,
+    "wine/exception.h" => 1,
+    "wine/library.h" => 1,
+    "wine/unicode.h" => 1,
+    "wine/itss.idl" => 1,
+    "wine/svcctl.idl" => 1,
+);
+
+my %private_idl_headers = (
+    "axcore.idl" => 1,
+    "axextend.idl" => 1,
+    "dbinit.idl" => 1,
+    "dbprop.idl" => 1,
+    "dbs.idl" => 1,
+    "devenum.idl" => 1,
+    "dyngraph.idl" => 1,
+    "vmrender.idl" => 1,
+);
+
 my (@makefiles, %makefiles);
 
 # update a file if changed
@@ -184,7 +210,7 @@ sub parse_makefile($)
             $make{$1} = $2;
             next;
         }
-        if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
+        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*(.*)/)
         {
             my @list = split(/\s+/, $2);
             $make{$1} = \@list;
@@ -199,37 +225,14 @@ sub parse_makefile($)
     return %make;
 }
 
-if (-d ".git")
-{
-    @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
-}
-else
-{
-    @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
-}
-
-foreach my $file (sort values %makerules, @makefiles)
-{
-    my %make = parse_makefile( $file );
-    $makefiles{$file} = \%make;
-}
 
 ################################################################
 # update the makefile list in configure.ac
 
-my @lines = ();
-
-foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
+sub update_makerules(@)
 {
-    push @lines, "$var=$makerules{$var}\n";
-    push @lines, "AC_SUBST_FILE($var)\n\n";
 }
 
-replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
-                 @lines,
-                 "AC_CONFIG_FILES([\n",
-                 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
-
 
 ################################################################
 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
@@ -264,11 +267,25 @@ sub update_winetest(@)
 
 
 ################################################################
-# update the makefile list in Makefile.in
+# update the makefile list in configure.ac and Makefile.in
 
 sub update_makefiles(@)
 {
-    my (@targets, @depends);
+    my (@targets, @depends, @lines);
+
+    foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
+    {
+        push @lines, "$var=$makerules{$var}\n";
+        push @lines, "AC_SUBST_FILE($var)\n\n";
+    }
+
+    foreach my $var ((sort values %makerules), (sort @_))
+    {
+        push @lines, "AC_CONFIG_FILES([$var])\n";
+    }
+
+    push @lines, "\nAC_OUTPUT\n";
+    replace_in_file( "configure.ac", '^MAKE_RULES', '^AC_OUTPUT$', @lines);
 
     foreach my $file (sort values %makerules)
     {
@@ -291,7 +308,9 @@ sub update_makefiles(@)
     push @lines, "ALL_MAKEFILES = \\\n\t";
     push @lines, join (" \\\n\t", @targets ), "\n\n";
     push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
-    push @lines, "\t\@./config.status \$\@\n\n";
+    push @lines, "\t\@./config.status \$\@\n";
+    push @lines, ".INIT: Makefile\n";
+    push @lines, ".BEGIN: Makefile\n\n";
     push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
     push @lines, "distclean::\n";
     push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
@@ -346,9 +365,6 @@ sub update_dlls(@)
         {
             $testdirs{$1} = "$1/tests";
             (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
-            push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
-            push @ignores, $makefile{"=dir"} . "testlist.c";
-            push @ignores, $makefile{"=dir"} . "*.ok";
             next;
         }
 
@@ -356,13 +372,14 @@ sub update_dlls(@)
         my $module = $makefile{"MODULE"};
         (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
 
-        if ($module =~ /^lib.*\.a$/)
+        if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
         {
             $staticlib_dirs{$module} = $dir;
-            die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
+            die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
         }
         else
         {
+            die "invalid module $module" unless $module =~ /\./;
             (my $mod = $module) =~ s/\.dll$//;
             die "invalid directory $dir for module $module\n" unless $mod eq $dir;
             $directories{$module} = $dir;
@@ -370,7 +387,7 @@ sub update_dlls(@)
 
         if (defined $makefile{"IMPORTLIB"})
         {
-            if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
+            if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
             {
                 $importlibs{$module} = $1;
             }
@@ -387,6 +404,13 @@ sub update_dlls(@)
             my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
             $altnames{$module} = \@list;
         }
+        if (defined $makefile{"EXTRA_OBJS16"})
+        {
+            foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
+            {
+                if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
+            }
+        }
     }
 
     # output special dlls configure definitions
@@ -469,29 +493,37 @@ sub update_dlls(@)
     {
         my $dir = $directories{$mod};
         my $lib = $importlibs{$mod};
-        if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
+        if ($lib ne $dir) { push @lib_symlinks, $mod; }
     }
     $text .= "IMPORT_SYMLINKS =";
     foreach my $mod (sort @lib_symlinks)
     {
-        $text .= sprintf " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
+        $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
     }
 
     $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
     foreach my $mod (sort keys %staticlib_dirs)
     {
-        $text .= sprintf " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
+        $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
     }
     foreach my $mod (sort keys %importlibs)
     {
-        my $dir = $directories{$mod};
-        my $def = $mod;
-        $def =~ s/\.(dll|drv)$//;
-        $text .= sprintf " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
+        $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
         next unless defined $static_implibs{$mod};
-        $text .= sprintf " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def
+        $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
+    }
+    $text .= "\n\nCROSS_IMPLIBS =";
+    foreach my $mod (sort @lib_symlinks)
+    {
+        $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
+    }
+    foreach my $mod (sort keys %importlibs)
+    {
+        next if defined $static_implibs{$mod};
+        $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
     }
     $text .= "\n\n";
+    $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
     $text .= "implib: \$(IMPORT_LIBS)\n\n";
     $text .= ".PHONY: implib\n\n";
 
@@ -501,18 +533,28 @@ sub update_dlls(@)
         my $lib = $importlibs{$mod};
         my $spec = $mod;
         $spec =~ s/\.dll$//;
-        $text .= sprintf "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
-        $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
-        next unless $static_implibs{$mod};
-        $text .= sprintf "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
-        $text .= sprintf "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
+        if (defined($static_implibs{$mod}))
+        {
+            $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
+            $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
+            $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
+            $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
+        }
+        else
+        {
+            $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
+                             $dir, $lib, $dir, $lib, $dir, $spec;
+            $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
+        }
     }
     foreach my $mod (sort @lib_symlinks)
     {
         my $dir = $directories{$mod};
-        my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
-        $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
-        $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
+        my $lib = "lib" . $importlibs{$mod};
+        $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
+        $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
+        $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
+        $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
     }
 
     $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
@@ -524,7 +566,7 @@ sub update_dlls(@)
 
     foreach my $mod (sort keys %staticlib_dirs)
     {
-        $text .= sprintf "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
+        $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
     }
     $text .= "\n# Misc rules\n";
 
@@ -537,20 +579,13 @@ sub update_dlls(@)
 
     foreach my $mod (sort @lib_symlinks)
     {
-        push @ignores, "dlls/$importlibs{$mod}.def";
+        push @ignores, "dlls/lib$importlibs{$mod}.def";
     }
     foreach my $mod (sort keys %directories)
     {
         next unless defined $altnames{$mod};
         push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
     }
-    foreach my $mod (sort keys %importlibs)
-    {
-        my $dir = $directories{$mod};
-        my $def = $mod;
-        $def =~ s/\.(dll|drv)$//;
-        push @ignores, "dlls/$dir/lib$def.def";
-    }
 
     return @ignores;
 }
@@ -591,6 +626,37 @@ sub update_progs(@)
 }
 
 
+################################################################
+# update include/Makefile.in
+
+sub update_includes()
+{
+    return unless -d ".git";
+    my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
+    my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
+    foreach my $incl (@includes)
+    {
+        if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
+        next if ($incl =~ /^wine\// && !$exported_wine_headers{$incl});
+        if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
+        elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
+        elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
+        elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
+        elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
+    }
+    replace_in_file( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
+                     "IDL_H_SRCS = \\\n\t",
+                     join( " \\\n\t", sort @idl_srcs ),
+                     "\n\nIDL_TLB_SRCS = \\\n\t",
+                     join( " \\\n\t", sort @tlb_srcs ),
+                     "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
+                     join( " \\\n\t", sort @h_srcs ),
+                     "\n\nEXTRASUBDIRS = ",
+                     join( " ", sort keys %subdirs ),
+                     "\n\nINSTALLDIRS = \\\n" );
+}
+
+
 ################################################################
 # update the main .gitignore
 
@@ -615,14 +681,33 @@ sub update_gitignore(@)
     # prepend a slash to paths that don't have one
     @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
 
-    push @ignores, @_;
+    # get rid of duplicates
+    my %ignores = ();
+    foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
 
     replace_in_file( ".gitignore", undef, undef,
                      "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
-                     join("\n", sort @ignores), "\n" );
+                     join("\n", sort keys %ignores), "\n" );
 }
 
 
+if (-d ".git")
+{
+    @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
+}
+else
+{
+    @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
+}
+
+update_includes();
+
+foreach my $file (sort values %makerules, @makefiles)
+{
+    my %make = parse_makefile( $file );
+    $makefiles{$file} = \%make;
+}
+
 update_makefiles( @makefiles );
 push @ignores, update_ignores( @makefiles );
 push @ignores, update_winetest( @makefiles );