Add save/restore mapping context routines.
[wine] / dlls / make_dlls
index d097991..42d4145 100755 (executable)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
-$makefiles = `find . -name Makefile.in -print`;
+use strict;
 
-%imports = ();
-%directories = ();
-%altnames = ();
+my $makefiles = `find . -name Makefile.in -print`;
+
+my %imports = ();
+my %directories = ();
+my %altnames = ();
+my %linked_dlls = ();
 
 # list of special dlls that can be switched on or off by configure
-%special_dlls =
+my %special_dlls =
 (
   "ddraw"    => "XFILES",
   "glu32"    => "GLU32FILES",
@@ -35,15 +38,24 @@ $makefiles = `find . -name Makefile.in -print`;
   "x11drv"   => "XFILES"
 );
 
-foreach $i (split(/\s/,$makefiles))
+foreach my $i (split(/\s/,$makefiles))
 {
+    my $module;
+
     open MAKE,$i;
+
+    $module = undef;
     while (<MAKE>)
     {
         chop;
+        # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear
+        # at the very top of the Makefile.in
+        last if (/^\#\s*MKDLL_SKIP/);
+
         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
         {
             $module = $1;
+            $imports{$module} = [ ];
             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
             next;
         }
@@ -53,29 +65,21 @@ foreach $i (split(/\s/,$makefiles))
             $altnames{$module} = \@list;
             next;
         }
-    }
-}
-
-foreach $mod (sort keys %directories)
-{
-    my $spec = sprintf("%s/%s.spec", $directories{$mod}, $mod);
-    open SPEC,$spec or die "cannot open $spec";
-    $imports{$mod} = [ ];
-    while (<SPEC>)
-    {
-        if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_]+)\.dll/)
+        if (/^(DELAYIMPORTS|IMPORTS)\s*=\s*(.*)/)
         {
-            my $imp = $2;
-            push @{$imports{$mod}}, $imp;
+            my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$2);
+            push @{$imports{$module}}, @list;
             next;
         }
-        if (/^\#?import\s+(-delay\s+)?([a-zA-Z0-9_.]+)/)
+        if (/^LDIMPORTS\s*=\s*(.*)/)
         {
-            my $imp = $2;
-            push @{$imports{$mod}}, $imp;
+            my @list = map { /\./ ? $_ : $_ . ".dll"; } split(/\s/,$1);
+            $linked_dlls{$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";
@@ -90,7 +94,6 @@ TOPSRCDIR = \@top_srcdir\@
 TOPOBJDIR = ..
 SRCDIR    = \@srcdir\@
 VPATH     = \@srcdir\@
-LIBEXT    = \@LIBEXT\@
 
 EOF
 
@@ -99,56 +102,64 @@ EOF
 
 printf NEWMAKE "# special configure-dependent targets\n\n";
 my %specials = ();
-foreach $mod (sort keys %special_dlls)
+foreach my $mod (sort keys %special_dlls)
 {
     $specials{$special_dlls{$mod}} .= " " . $mod;
 }
-foreach $i (sort keys %specials)
+foreach my $i (sort keys %specials)
 {
     printf NEWMAKE "%s =%s\n", $i, $specials{$i};
 }
 printf NEWMAKE "EXTRADIRS =";
-foreach $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
+foreach my $i (sort keys %specials) { printf NEWMAKE " \@%s\@", $i; }
 printf NEWMAKE "\n\n";
 
 
 ################################################################
 # output the subdirs list
 
-print NEWMAKE <<EOF;
-# Subdir list
-
-SUBDIRS = \\
-EOF
-printf NEWMAKE "\t\$(EXTRADIRS)";
-foreach $dir (sort values %directories)
+print NEWMAKE "# Subdir list\n\nBASEDIRS =";
+foreach my $dir (sort values %directories)
 {
     next if defined($special_dlls{$dir});  # skip special dlls
     printf NEWMAKE " \\\n\t%s", $dir;
 }
-printf NEWMAKE "\n";
+
+printf NEWMAKE "\n\nSUBDIRS = \\\n\t\$(BASEDIRS)";
+foreach my $dir (sort keys %special_dlls)
+{
+    printf NEWMAKE " \\\n\t%s", $dir;
+}
+printf NEWMAKE <<EOF;
 
 
+BUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)
+
+INSTALLSUBDIRS = \$(BUILDSUBDIRS)
+EOF
+
 ################################################################
 # output the all: target
 
 my %targets = ();  # use a hash to get rid of duplicate target names
-foreach $mod (sort keys %directories)
+foreach my $mod (sort keys %directories)
 {
-    next if defined($special_dlls{$mod});  # skip special dlls
-    $targets{sprintf("lib%s.\$(LIBEXT)",$mod)} = 1;
+    next if defined($special_dlls{$directories{$mod}});  # skip special dlls
+    $targets{sprintf("%s\$(DLLEXT)",$mod)} = 1;
     next unless defined $altnames{$mod};
-    foreach $i (sort @{$altnames{$mod}})
+    foreach my $i (sort @{$altnames{$mod}})
     {
-        $targets{sprintf("lib%s.\$(LIBEXT)",$i)} = 1;
+        $targets{sprintf("%s\$(DLLEXT)",$i)} = 1;
     }
 }
 print NEWMAKE <<EOF;
 
 # Main target
 
+\@MAKE_RULES\@
+
 all: \\
-       \$(EXTRADIRS:%=lib%.\$(LIBEXT)) \\
+       \$(EXTRADIRS:%=%.dll\$(DLLEXT)) \\
 EOF
 printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
 
@@ -158,78 +169,133 @@ printf NEWMAKE "\t%s\n", join( " \\\n\t", sort keys %targets );
 
 print NEWMAKE <<EOF;
 
-\@MAKE_RULES\@
-
-# Map library name to directory
+# Map symlink name to the corresponding library
 
 EOF
 
-foreach $mod (sort keys %directories)
+foreach my $mod (sort keys %directories)
 {
-    printf NEWMAKE "lib%s.\$(LIBEXT)", $mod;
+    printf NEWMAKE "%s\$(DLLEXT)", $mod;
     if (defined $altnames{$mod})
     {
         my $count = 1;
-        foreach $i (sort @{$altnames{$mod}})
+        foreach my $i (sort @{$altnames{$mod}})
         {
             if (!($count++ % 3)) { printf NEWMAKE " \\\n "; }
-            printf NEWMAKE " lib%s.\$(LIBEXT)", $i;
+            printf NEWMAKE " %s\$(DLLEXT)", $i;
         }
     }
-    printf NEWMAKE ": %s/lib%s.\$(LIBEXT)\n", $directories{$mod}, $mod;
-    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/lib%s.\$(LIBEXT) \$@\n\n", $directories{$mod}, $mod;
+    printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
+    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
 }
 
 
 ################################################################
 # output the inter-dll dependencies and rules
 
-print NEWMAKE "# Inter-dll dependencies\n\n";
+print NEWMAKE "# Map library name to the corresponding directory\n\n";
+
+foreach my $mod (sort keys %directories)
+{
+    printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
+}
+
+print NEWMAKE "\n# Install dependencies\n\n";
+
+foreach my $mod (sort keys %directories)
+{
+    printf NEWMAKE "%s/__install__: %s\$(DLLEXT)\n", $directories{$mod}, $mod;
+}
+
+print NEWMAKE "\n# Inter-dll dependencies\n\n";
 
 my @depends = ();
-foreach $mod (sort keys %imports)
+foreach my $mod (sort keys %imports)
 {
-    my $count = 1;
-    my $dep = sprintf("%s/lib%s.\$(LIBEXT): dummy", $directories{$mod}, $mod);
-    foreach $i (@{$imports{$mod}})
+    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++ >= 3)
+        if ($count++ >= 4)
         {
-            $count = 0;
-            $dep .= " \\\n ";
+            $count = 1;
+            $dep .= " \\\n" . " " x 9;
         }
         $dep .= sprintf(" lib%s.\$(LIBEXT)", $i);
     }
-    $dep .= sprintf("\n\t\@cd %s && \$(MAKE) lib%s.\$(LIBEXT)\n\n",$directories{$mod}, $mod);
-    push @depends, $dep;
+    push @depends, $dep . "\n";
 }
 print NEWMAKE sort @depends;
 
 
+################################################################
+# output the linkable dlls special links
+
+my %linkable_dlls = ();
+foreach my $mod (keys %imports)
+{
+    foreach my $i (@{$linked_dlls{$mod}}) { $linkable_dlls{$i} = 1; }
+}
+
+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 );
+
+foreach my $mod (keys %linkable_dlls)
+{
+    printf NEWMAKE "lib%s.\$(LIBEXT): %s\n", $mod, $directories{$mod};
+    printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
+}
+
+print NEWMAKE <<EOF;
+uninstall::
+       \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
+
+install::
+       \$(RM) \$(LINKABLE_DLLS:%=\$(libdir)/lib%.\$(LIBEXT))
+       cd \$(libdir) && if [ "\$(dlldir)" = "\$(libdir)/wine" ]; \\
+       then \\
+EOF
+foreach my $mod (keys %linkable_dlls)
+{
+    printf NEWMAKE "\t  \$(LN_S) wine/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
+}
+print NEWMAKE "\telse \\\n";
+foreach my $mod (keys %linkable_dlls)
+{
+    printf NEWMAKE "\t  \$(LN_S) \$(dlldir)/%s\$(DLLEXT) lib%s.\$(LIBEXT); \\\n", $mod, $mod;
+}
+print NEWMAKE "\tfi\n\n";
+
 ################################################################
 # makefile trailer
 
 print NEWMAKE <<EOF;
 # Misc rules
 
-\$(SUBDIRS:%=%/__test__): dummy
-       \@cd `dirname \$\@` && \$(MAKE) test
-
-\$(SUBDIRS:%=%/__checklink__): dummy
+\$(BUILDSUBDIRS:%=%/__checklink__): dummy
        \@cd `dirname \$\@` && \$(MAKE) checklink
 
-\$(SUBDIRS:%=%/__debug_channels__): dummy
-       \@cd `dirname \$\@` && \$(MAKE) debug_channels
-
-install:: \$(SUBDIRS:%=%/__install__)
+uninstall::
+       -rmdir \$(dlldir)
 
-uninstall:: \$(SUBDIRS:%=%/__uninstall__)
+check test:: \$(BUILDSUBDIRS:%=%/__test__)
 
-check test:: \$(SUBDIRS:%=%/__test__)
+checklink:: \$(BUILDSUBDIRS:%=%/__checklink__)
 
-checklink:: \$(SUBDIRS:%=%/__checklink__)
+.PHONY: checklink \$(BUILDSUBDIRS:%=%/__checklink__)
 
-debug_channels:: \$(SUBDIRS:%=%/__debug_channels__)
+### Dependencies:
 EOF
 
 close NEWMAKE;