Index: trunk/src/emx/ChangeLog.LIBC
===================================================================
--- trunk/src/emx/ChangeLog.LIBC	(revision 2095)
+++ trunk/src/emx/ChangeLog.LIBC	(revision 2096)
@@ -1,3 +1,9 @@
 /* $Id$ */
+
+2005-06-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
+    - emxomfld, ld:
+        o Generate .def-file for dlls without one. (This only makes sense for
+          emxomfld since ld doesn't implement __declspec(dllexport) yet, but
+          anyway.)
 
 2005-06-26: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: trunk/src/emx/src/emxomf/emxomfld.c
===================================================================
--- trunk/src/emx/src/emxomf/emxomfld.c	(revision 2095)
+++ trunk/src/emx/src/emxomf/emxomfld.c	(revision 2096)
@@ -1185,4 +1185,40 @@
 }
 
+/* Generates a definition file for a dll which doesn't have one. */
+static void gen_deffile(void)
+{
+    char *psz = xmalloc(_MAX_PATH);
+    if (!make_tempfile(psz, "lddef", ".def", NULL))
+    {
+        FILE *pFile = fopen(psz, "w");
+        if (pFile)
+        {
+            const char *pszName = _getname(output_fname);
+            size_t cchName = strlen(pszName);
+            if (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll"))
+                cchName -= 4;
+            fprintf(pFile,
+                    ";; Autogenerated by emxomfld\n"
+                    "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
+                    "DATA MULTIPLE\n"
+                    "CODE SHARED\n"
+                    "\n",
+                    cchName, pszName);
+            fclose(pFile);
+            def_fname = psz;
+            if (opt_t)
+                fprintf(stderr,
+                        "--- Generated def-file %s:\n"
+                        ";; Autogenerated by emxomfld\n"
+                        "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
+                        "DATA MULTIPLE NONSHARED\n"
+                        "CODE SINGLE SHARED\n"
+                        "---- End of generated def-file.\n",
+                        psz, cchName, pszName);
+            return;
+        }
+    }
+    free(psz);
+}
 
 /* -t output. We dump the commandline and responsefile. */
@@ -1661,4 +1697,8 @@
     }
 
+  /* generate .def-file for dlls. */
+
+  if (!def_fname && dll_flag)
+    gen_deffile();
 
   /* Do the weak prelinking unless GCC_WEAKSYMS are set.
Index: trunk/src/emx/src/ld/ld.c
===================================================================
--- trunk/src/emx/src/ld/ld.c	(revision 2095)
+++ trunk/src/emx/src/ld/ld.c	(revision 2096)
@@ -929,4 +929,5 @@
 int assign_string_table_index (char *name);
 unsigned long check_each_file (register unsigned long (*function)(), register int arg);
+static int      make_tempfile(char *pszFile, const char *pszPrefix, const char *pszSuffix);
 
 
@@ -3906,4 +3907,43 @@
 }
 
+/* Generates a definition file for a dll which doesn't have one. */
+
+static void gen_deffile(void)
+{
+    char *psz = xmalloc(_MAX_PATH);
+    if (!make_tempfile(psz, "lddef", ".def"))
+    {
+        FILE *pFile = fopen(psz, "w");
+        if (pFile)
+        {
+            const char *pszName = _getname(exe_filename);
+            size_t cchName = strlen(pszName);
+            if (cchName > 4 && !stricmp(pszName + cchName - 4, ".dll"))
+                cchName -= 4;
+            fprintf(pFile,
+                    ";; Autogenerated by ld\n"
+                    "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
+                    "DATA MULTIPLE\n"
+                    "CODE SHARED\n"
+                    "\n",
+                    cchName, pszName);
+            if (trace_files)
+                fprintf(stderr,
+                        "--- Generated def-file %s:\n"
+                        ";; Autogenerated by ld\n"
+                        "LIBRARY %.*s INITINSTANCE TERMINSTANCE\n"
+                        "DATA MULTIPLE NONSHARED\n"
+                        "CODE SINGLE SHARED\n"
+                        "---- End of generated def-file.\n",
+                        psz, cchName, pszName);
+            fclose(pFile);
+            def_filename = psz;
+            return;
+        }
+    }
+    free(psz);
+}
+
+
 /* Write the output file */
 
@@ -3979,4 +4019,6 @@
       if (emxbind_strip)
         nargv[i++] = "-s";
+      if (dll_flag && !def_filename)
+          gen_deffile();
       if (def_filename != NULL)
 	{
@@ -3987,5 +4029,5 @@
 	}
       else if (dll_flag)
-	nargv[i++] = "-d";
+	  nargv[i++] = "-d";
       if (stack_size != 0)
 	{
@@ -4019,4 +4061,11 @@
       nargv[i++] = output_filename;
       nargv[i] = NULL;
+      if (trace_files)
+        {
+          fprintf(stderr, "Invoking emxbind:");
+          for (i = 0; nargv[i]; i++)
+            fprintf(stderr, " %s", nargv[i]);
+          fprintf(stderr, "\n");
+        }
       i = spawnvp (P_WAIT, "emxbind", nargv);
       saved_errno = errno; unlink (output_filename); errno = saved_errno;
