make_dlls: Ignore generated import libraries from the top-level .gitignore.
[wine] / dlls / make_dlls
index ba663c5..da0b90c 100755 (executable)
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 #
 
 use strict;
 
 my $makefiles = `find . -name Makefile.in -print`;
 
-my %imports = ();
 my %directories = ();
+my %importlibs = ();
+my %static_implibs = ();
+my %staticlib_dirs = ();
 my %altnames = ();
-my %linked_dlls = ();
 
 # list of special dlls that can be switched on or off by configure
 my %special_dlls =
 (
-  "ddraw"    => "XFILES",
   "glu32"    => "GLU32FILES",
+  "glut32"   => "GLUT32FILES",
   "opengl32" => "OPENGLFILES",
-  "x11drv"   => "XFILES"
+  "wined3d"  => "OPENGLFILES",
+  "winex11.drv" => "XFILES"
 );
 
+sub needs_symlink($)
+{
+    (my $mod = $_[0]) =~ s/\.dll$//;
+    return $mod ne $directories{$_[0]};
+}
+
 foreach my $i (split(/\s/,$makefiles))
 {
     my $module;
 
+    next if $i =~ /\/tests\/Makefile.in/;
+
     open MAKE,$i;
 
     $module = undef;
@@ -55,31 +65,38 @@ foreach my $i (split(/\s/,$makefiles))
         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
         {
             $module = $1;
-            $imports{$module} = [ ];
-            ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
+            if ($module =~ /^lib.*\.a$/)
+            {
+                ($staticlib_dirs{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
+                die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module;
+            }
+            else
+            {
+                ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
+            }
             next;
         }
-        if (/^ALTNAMES\s*=\s*(.*)/)
+        if (/^IMPORTLIB\s*=\s*([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/)
         {
-            my @list = split(/\s/,$1);
-            $altnames{$module} = \@list;
+            $importlibs{$module} = $1;
             next;
         }
-        if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
+        if (/^IMPLIB_SRCS\s*=/)
         {
-            my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
-            push @{$imports{$module}}, @list;
+            $static_implibs{$module} = 1;
             next;
         }
-        if (/^LDIMPORTS\s*=\s*(.*)/)
+        if (/^SPEC_SRCS16\s*=\s*(.*)/)
         {
-            my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
-            $linked_dlls{$module} = \@list;
+            my $specs = $1;
+            while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . <MAKE>; }
+            my @list = split(/\s+/,$specs);
+            @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list;
+            $altnames{$module} = \@list;
             next;
         }
     }
     close MAKE;
-    push @{$imports{$module}}, "kernel32.dll" unless !defined($module) || @{$imports{$module}} || $module eq "ntdll.dll";
 }
 
 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
@@ -125,7 +142,13 @@ foreach my $dir (sort values %directories)
     printf NEWMAKE " \\\n\t%s", $dir;
 }
 
-printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
+printf NEWMAKE "\n\nIMPLIBSUBDIRS =";
+foreach my $dir (sort values %staticlib_dirs)
+{
+    printf NEWMAKE " \\\n\t%s", $dir;
+}
+
+printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS) \\\n\t\$(IMPLIBSUBDIRS)";
 foreach my $dir (sort keys %special_dlls)
 {
     printf NEWMAKE " \\\n\t%s", $dir;
@@ -134,158 +157,233 @@ printf NEWMAKE <<EOF;
 
 
 BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
+
+INSTALLSUBDIRS = \$(BUILDSUBDIRS) \$(IMPLIBSUBDIRS)
 EOF
 
 ################################################################
 # output the all: target
 
 my %targets = ();  # use a hash to get rid of duplicate target names
+my %targets16 = ();
 foreach my $mod (sort keys %directories)
 {
     next if defined($special_dlls{$directories{$mod}});  # skip special dlls
-    $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
+    $targets{$mod . ".so"} = 1 if needs_symlink($mod);
     next unless defined $altnames{$mod};
     foreach my $i (sort @{$altnames{$mod}})
     {
-        $targets{sprintf("%s\$(DLLEXT)",$i)} = 1;
+        $targets16{$i . "16"} = $mod;
     }
 }
-print NEWMAKE <<EOF;
 
-# Main target
+print NEWMAKE <<EOF;
 
 \@MAKE_RULES\@
 
-all: \\
-       \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
+# Symbolic links
+
+WIN16_FILES = \\
 EOF
-printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
+printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets16 );
 
+print NEWMAKE <<EOF;
 
-################################################################
-# output the lib name -> directory rules
+SYMLINKS_SO = \\
+       \@WIN16_FILES\@ \\
+EOF
+printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
 
 print NEWMAKE <<EOF;
 
-# Map symlink name to the corresponding library
+# Main target
 
-EOF
+all: \$(BUILDSUBDIRS) symlinks\$(DLLEXT)
 
-foreach my $mod (sort keys %directories)
-{
-    printf NEWMAKE "%s\$(DLLEXT)", $mod;
-    if (defined $altnames{$mod})
-    {
-        my $count = 1;
-        foreach my $i (sort @{$altnames{$mod}})
-        {
-            if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
-            printf NEWMAKE " %s\$(DLLEXT)", $i;
-        }
-    }
-    printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
-    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
-}
+.PHONY: symlinks symlinks.so implib
 
+symlinks.so: \$(SYMLINKS_SO)
 
-################################################################
-# output the inter-dll dependencies and rules
+symlinks: \$(BUILDSUBDIRS)
 
-print NEWMAKE "# Map library name to the corresponding directory\n\n";
+EOF
 
+################################################################
+# output the lib name -> directory rules
+
+print NEWMAKE "# Map symlink name to the corresponding library\n\n";
 foreach my $mod (sort keys %directories)
 {
-    printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
+    next unless needs_symlink($mod);
+    printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod;
+    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod;
 }
 
-print NEWMAKE "\n# Inter-dll dependencies\n\n";
-
-my @depends = ();
-foreach my $mod (sort keys %imports)
+print NEWMAKE "# Placeholders for 16-bit libraries\n\n";
+foreach my $mod (sort keys %directories)
 {
-    next unless @{$imports{$mod}};
-    my $count = 0;
-    my $dep = sprintf("%s:", $directories{$mod});
-    $dep .= " " x (8-length($directories{$mod}));
-    foreach my $i (@{$imports{$mod}})
-    {
-        if ($count++ >= 4)
-        {
-            $count = 1;
-            $dep .= " \\\n" . " " x 9;
-        }
-        $dep .= sprintf(" %s\$(DLLEXT)", $i);
-    }
-    foreach my $i (@{$linked_dlls{$mod}})
-    {
-        if ($count++ >= 4)
-        {
-            $count = 1;
-            $dep .= " \\\n" . " " x 9;
-        }
-        $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
-    }
-    push @depends, $dep . "\n";
+    next unless defined $altnames{$mod};
+    printf NEWMAKE "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
+    printf NEWMAKE "\techo \"%s\" >\$\@\n\n", $mod;
 }
-print NEWMAKE sort @depends;
-
 
 ################################################################
-# output the linkable dlls special links
+# output the import libraries rules
+
+print NEWMAKE "# Import libraries\n\n";
+print NEWMAKE "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
 
-my %linkable_dlls = ();
-foreach my $mod (keys %imports)
+my @lib_symlinks = ();
+foreach my $mod (sort keys %importlibs)
 {
-    foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
+    my $dir = $directories{$mod};
+    my $lib = $importlibs{$mod};
+    if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; }
+}
+print NEWMAKE "IMPORT_SYMLINKS =";
+foreach my $mod (sort @lib_symlinks)
+{
+    printf NEWMAKE " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod};
 }
 
-print NEWMAKE "\n# Special targets for dlls that we need to link to\n\n";
-printf NEWMAKE "LINKABLE_DLLS = %s\n\n", join( " ", keys %linkable_dlls );
+print NEWMAKE "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
+foreach my $mod (sort keys %staticlib_dirs)
+{
+    printf NEWMAKE " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod;
+}
+foreach my $mod (sort keys %importlibs)
+{
+    my $dir = $directories{$mod};
+    my $def = $mod;
+    $def =~ s/\.(dll|drv)$//;
+    printf NEWMAKE " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def;
+    printf NEWMAKE " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def if $static_implibs{$mod};
+}
+print NEWMAKE "\n\n";
+print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n";
 
-foreach my $mod (keys %linkable_dlls)
+foreach my $mod (sort keys %importlibs)
 {
-    printf NEWMAKE "lib%s.\$(LIBEXT): %s\n", $mod, $directories{$mod};
-    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
+    my $dir = $directories{$mod};
+    my $lib = $importlibs{$mod};
+    my $spec = $mod;
+    $spec =~ s/\.dll$//;
+    printf NEWMAKE "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
+    printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib;
+    next unless $static_implibs{$mod};
+    printf NEWMAKE "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
+    printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
+}
+foreach my $mod (sort @lib_symlinks)
+{
+    my $dir = $directories{$mod};
+    my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)";
+    printf NEWMAKE "%s: %s/%s\n", $lib, $dir, $lib;
+    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
 }
 
 print NEWMAKE <<EOF;
-uninstall-links: dummy
-       \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
+\$(BUILDSUBDIRS): \$(IMPORT_LIBS)
+\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)
 
-install-links: uninstall-links dummy
-       cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
-       then \\
 EOF
-foreach my $mod (keys %linkable_dlls)
+
+################################################################
+# output the inter-dll dependencies and rules
+
+print NEWMAKE "# Map library name to the corresponding directory\n\n";
+
+foreach my $mod (sort keys %directories)
 {
-    printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
+    next unless needs_symlink($mod);
+    printf NEWMAKE "%s/%s.so: %s\n", $directories{$mod}, $mod, $directories{$mod};
 }
-print NEWMAKE "\telse \\\n";
-foreach my $mod (keys %linkable_dlls)
+foreach my $mod (sort keys %staticlib_dirs)
 {
-    printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
+    printf NEWMAKE "%s/%s: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
 }
-print NEWMAKE "\tfi\n\n";
 
 ################################################################
 # makefile trailer
 
 print NEWMAKE <<EOF;
+
+# Rules for auto documentation
+
+\$(SUBDIRS:%=%/__man__): dummy
+       cd `dirname \$@` && \$(MAKE) man
+
+man: \$(SUBDIRS:%=%/__man__)
+
+\$(SUBDIRS:%=%/__doc_html__): dummy
+       cd `dirname \$@` && \$(MAKE) doc-html
+
+doc-html: \$(SUBDIRS:%=%/__doc_html__)
+
+\$(SUBDIRS:%=%/__doc_sgml__): dummy
+       cd `dirname \$@` && \$(MAKE) doc-sgml
+
+doc-sgml: \$(SUBDIRS:%=%/__doc_sgml__)
+
+.PHONY: man doc-html doc-sgml \$(SUBDIRS:%=%/__man__) \$(SUBDIRS:%=%/__doc_html__) \$(SUBDIRS:%=%/__doc_sgml__)
+
 # Misc rules
 
-\$(BUILDSUBDIRS:%=%/__checklink__): dummy
-       \@cd `dirname \$\@` && \$(MAKE) checklink
+install-lib:: \$(INSTALLSUBDIRS:%=%/__install-lib__)
 
-install:: \$(BUILDSUBDIRS:%=%/__install__) install-links
+install-dev:: \$(INSTALLSUBDIRS:%=%/__install-dev__)
 
-uninstall:: \$(BUILDSUBDIRS:%=%/__uninstall__) uninstall-links
-       -rmdir \$(dlldir)
+uninstall::
+       -rmdir \$(DESTDIR)\$(dlldir)
+
+clean::
+       \$(RM) \$(IMPORT_SYMLINKS) \$(WIN16_FILES)
 
 check test:: \$(BUILDSUBDIRS:%=%/__test__)
 
+crosstest:: \$(BUILDSUBDIRS:%=%/__crosstest__)
+
 checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
+
+### Dependencies:
 EOF
 
 close NEWMAKE;
 rename "Makefile.in.new", "Makefile.in";
 printf "Successfully updated Makefile.in\n";
+
+################################################################
+# .gitignore file
+
+open GITIGNORE, ">.gitignore.new" or die "cannot create .gitignore.new";
+print GITIGNORE "# Automatically generated by make_dlls; DO NOT EDIT!!\n";
+
+my @ignores =
+(
+ "/Makedll.rules",
+ "/Makeimplib.rules",
+ "/Maketest.rules",
+);
+
+foreach my $mod (sort @lib_symlinks)
+{
+    push @ignores, "/$importlibs{$mod}.def";
+}
+foreach my $mod (sort keys %directories)
+{
+    next unless defined $altnames{$mod};
+    push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}};
+}
+foreach my $mod (sort keys %importlibs)
+{
+    my $dir = $directories{$mod};
+    my $def = $mod;
+    $def =~ s/\.(dll|drv)$//;
+    push @ignores, "$dir/lib$def.def";
+}
+
+print GITIGNORE join("\n", sort @ignores) . "\n";
+
+close GITIGNORE;
+rename ".gitignore.new", ".gitignore";
+printf "Successfully updated .gitignore\n";