Index: /branches/libc-0.6/src/emx/src/emxomf/emxomfld.c
===================================================================
--- /branches/libc-0.6/src/emx/src/emxomf/emxomfld.c	(revision 3025)
+++ /branches/libc-0.6/src/emx/src/emxomf/emxomfld.c	(revision 3026)
@@ -152,4 +152,6 @@
    the defaults of emxbind. */
 static long stack_size = 1024;
+/* Indicates that we've seen -Zstack. */
+static int stack_size_flag = 0;
 
 /* The name of the linker to use.  By default, ilink is used.  This
@@ -1508,8 +1510,8 @@
          "    lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n"
          " -Zdll-search:\n"
-         "    Enables dlls as valid libraries from shared linking. (default disabled)\n", 
+         "    Enables dlls as valid libraries from shared linking. (default disabled)\n",
          stderr);
   fputs (" -Zsym:"
-         "    Invoke mapsym.cmd on the mapfile to produce a .sym file. Requires -Zmap.\n" 
+         "    Invoke mapsym.cmd on the mapfile to produce a .sym file. Requires -Zmap.\n"
          "\n", stderr);
   fputs ("Environment variables:\n"
@@ -1738,4 +1740,5 @@
           if (errno != 0 || *t != 0 || t == optarg)
             return 1;
+          stack_size_flag = 1;
           break;
 
@@ -2052,10 +2055,97 @@
   else /* wlink */
     {
+      unsigned uPMType = 0;
+
       open_response_file ();
 
+      /* convert common ilink/link386 command line arguments. */
+
+      for (pcur = options; pcur; pcur = pcur->next)
+        {
+          size_t cchOpt;
+          const char *pszVal;
+          size_t cchVal;
+
+          if (pcur->name [0] != '-' && pcur->name [0] != '/')
+            continue;
+          if (strchr (&pcur->name[1], '='))
+            continue;
+          pszVal = strchr (&pcur->name[1], ':');
+          cchOpt = pszVal ? pszVal - &pcur->name[1] : strlen (&pcur->name[1]);
+          if (pszVal && pszVal[1])
+            cchVal = strlen (++pszVal);
+          else
+            pszVal = NULL, cchVal = 0;
+#define MAX(a,b) ((a) <= (b) ? (a) : (b))
+          if (!strnicmp (&pcur->name[1], "PMtype", cchOpt)
+           && cchVal)
+            {
+              if (!strnicmp (pszVal, "PM", cchVal))
+                uPMType = _MD_WINDOWAPI;
+              else if (!strnicmp (pszVal, "VIO", cchVal))
+                uPMType = _MD_WINDOWCOMPAT;
+              else if (!strnicmp (pszVal, "NOVIO", MAX (cchVal, 3)))
+                uPMType = _MD_NOTWINDOWCOMPAT;
+              else
+                continue;
+            }
+          else if (!strnicmp (&pcur->name[1], "PDD", MAX (cchOpt, 3)))
+            uPMType = _MD_PHYSICAL;
+          else if (!strnicmp (&pcur->name[1], "VDD", MAX (cchOpt, 3)))
+            uPMType = _MD_VIRTUAL;
+          else if (!strnicmp (&pcur->name[1], "STACK", MAX (cchOpt, 2))
+                && cchVal && !stack_size_flag)
+            {
+              errno = 0;
+              stack_size = strtol (pszVal, &t, 0);
+              if (errno || *t)
+                {
+                  fprintf(stderr, "emxomfld: Number conversion failed: '%s'\n", pcur->name);
+                  return 1;
+                }
+              stack_size = (stack_size + 0xfff) / 1024;
+            }
+          /* ignore these */
+          else if (!strnicmp (&pcur->name[1], "PACKCODE", MAX (cchOpt, 5))
+                || !strnicmp (&pcur->name[1], "NOPACKCODE", MAX (cchOpt, 3))
+                || !strnicmp (&pcur->name[1], "EXEPACK", MAX (cchOpt, 1))
+                || !strnicmp (&pcur->name[1], "NOEXEPACK", MAX (cchOpt, 5))
+                || !strnicmp (&pcur->name[1], "DBGPACK", MAX (cchOpt, 2))
+                || !strnicmp (&pcur->name[1], "NODBGPACK", MAX (cchOpt, 4))
+                )
+            fprintf(stderr, "emxomfld: warning: ignoring ilink option '%s'\n", pcur->name);
+          else
+            continue;
+          pcur->name = NULL;
+#undef MAX
+        }
+
       /* figure out what format options we're gonna use */
 
       if (!def_fname && !dll_flag)
-        fprintf (response_file, "FORMAT OS2 LX PMCompatible\n");
+        {
+          switch (uPMType)
+            {
+              case 0:
+              case _MD_WINDOWCOMPAT:
+              default:
+                fprintf (response_file, "FORMAT OS2 LX PMCompatible\n");
+                break;
+              case _MD_WINDOWAPI:
+                fprintf (response_file, "FORMAT OS2 LX PM\n");
+                break;
+              case _MD_NOTWINDOWCOMPAT:
+                fprintf (response_file, "FORMAT OS2 LX FULLscreen\n");
+                break;
+              case _MD_PHYSICAL:
+                dll_flag = TRUE;
+                fprintf (response_file, "FORMAT OS2 LX PHYSdevice\n");
+                break;
+              case _MD_VIRTUAL:
+                dll_flag = TRUE;
+                fprintf (response_file, "FORMAT OS2 LX VIRTdevice\n");
+                break;
+            }
+        }
       else if (!def_fname && dll_flag)
         fprintf (response_file, "FORMAT OS2 LX DLL INITINSTANCE TERMINSTANCE\n");
@@ -2106,7 +2196,12 @@
             {
               if (token == _MD_NAME)
+                {
+                  /* (ignores uPMType and uses the .def-file) */
                   token = _md_next_token (pMd);
-              if (token == _MD_quote || token == _MD_word)
-                  token = _md_next_token (pMd);
+                  if (token == _MD_quote || token == _MD_word)
+                    token = _md_next_token (pMd);
+                }
+              else
+                token = uPMType;
               switch (token)
                 {
@@ -2165,5 +2260,6 @@
 
       for (pcur = options; pcur; pcur = pcur->next)
-        fprintf (response_file, "%s\n", pcur->name);
+        if (pcur->name)
+          fprintf (response_file, "%s\n", pcur->name);
 
       /* Put the object file names onto the command line. */
