Index: trunk/src/emx/src/emxomf/emxomfld.c
===================================================================
--- trunk/src/emx/src/emxomf/emxomfld.c	(revision 937)
+++ trunk/src/emx/src/emxomf/emxomfld.c	(revision 938)
@@ -34,5 +34,5 @@
 #include <sys/utime.h>
 #include <sys/moddef.h>
-#include <emx/getopt.h>
+#include <getopt.h>
 #include <alloca.h>
 #include <sys/omflib.h>
@@ -178,36 +178,4 @@
 #endif
 extern int _System DosCopy (char *, char *, int);
-
-/* Tell the user how to run this program. */
-
-static void usage (void)
-{
-  fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION "\n"
-           "Copyright (c) 1992-1996 by Eberhard Mattes\n"
-           "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n\n");
-
-  fprintf (stderr,
-           "Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n"
-           "                [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
-           "                [-Z[no-]autoconv] [-O <option>] <file>...\n"
-           "\n"
-           "Options:\n"
-           " -Zno-autoconv / -Zautoconv:\n"
-           "    Turns off/on the automatic conversion of a.out libs and objs.\n"
-           "    default: -Zautoconv\n"
-           "\n"
-           "Environment variables:\n"
-           "  EMXOMFLD_TYPE:\n"
-           "    The type of linker we're using. Values: VAC365, VAC308, LINK386.\n"
-           "        VAC365   ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n"
-           "        VAC308   ilink.exe from Visual Age for C++ v3.08.\n"
-           "        LINK386  link386 form OS/2 install or DDK.\n"
-           "  EMXOMFLD_LINKER:\n"
-           "    Name of the linker to use and optionally extra parameters. Spaces in the\n"
-           "    linker name or path is not supported. Quotes are not supported either.\n"
-           "The default values for these two variables are VAC365 and ilink.exe.\n");
-  exit (1);
-}
-
 
 /* Allocate N bytes of memory.  Quit on failure.  This function is
@@ -1125,4 +1093,85 @@
 }
 
+/* Tell the user how to run this program. */
+
+static void usage (void)
+{
+  fprintf (stderr, "emxomfld " VERSION INNOTEK_VERSION "\n"
+           "Copyright (c) 1992-1996 by Eberhard Mattes\n"
+           "Copyright (c) 2003 by InnoTek Systemberatung GmbH\n\n");
+
+  fprintf (stderr,
+           "Usage: emxomfld -o <file> [-l <lib>] [-L <libdir>] [-T <base>] [-igtsS]\n"
+           "                [-Zexe] [-Zdll] [-Zstack <size>] [-Zmap[=<map_file>]]\n"
+           "                [-Z[no-]autoconv] [-O <option>] [-static] [-non_shared]\n"
+           "                [-Bstatic] [-dn] [call_shared] [-Bshared] [-dy] <file>...\n"
+           "\n"
+           "Options:\n"
+           " -Zno-autoconv / -Zautoconv:\n"
+           "    Turns off/on the automatic conversion of a.out libs and objs.\n"
+           "    default: -Zautoconv\n"
+           " -Bstatic, -non_shared, -dn, -static:\n"
+           "    Link with static libraries.\n"
+           "    The search order is then changed to: lib<name>_s.lib, <name>_s.lib,\n"
+           "    lib<name>.lib, <name>.lib\n"
+           " -Bshared, -call_shared, -dy:\n"
+           "    Link with shared libraries. This is default.\n"
+           "    The search order is then changed to: lib<name>_dll.lib, <name>_dll.lib,\n"
+           "    lib<name>.lib, <name>.lib, <name>.dll, lib<name>_s.lib, <name>_s.lib.\n"
+           "\n"
+           "Environment variables:\n"
+           "  EMXOMFLD_TYPE:\n"
+           "    The type of linker we're using. Values: VAC365, VAC308, LINK386.\n"
+           "        VAC365   ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n"
+           "        VAC308   ilink.exe from Visual Age for C++ v3.08.\n"
+           "        LINK386  link386 form OS/2 install or DDK.\n"
+           "  EMXOMFLD_LINKER:\n"
+           "    Name of the linker to use and optionally extra parameters. Spaces in the\n"
+           "    linker name or path is not supported. Quotes are not supported either.\n"
+           "The default values for these two variables are VAC365 and ilink.exe.\n"
+           );
+  exit (1);
+}
+
+
+
+static struct option longopts[] =
+{
+#define OPT_LIBS_STATIC     0x1000
+  {"Bstatic", 0, 0, OPT_LIBS_STATIC},
+  {"non_shared", 0, 0, OPT_LIBS_STATIC},
+  {"dn", 0, 0, OPT_LIBS_STATIC},
+  {"static", 0, 0, OPT_LIBS_STATIC},
+#define OPT_LIBS_SHARED     0x1001
+  {"Bshared", 0, 0, OPT_LIBS_SHARED},
+  {"call_shared", 0, 0, OPT_LIBS_SHARED},
+  {"dy", 0, 0, OPT_LIBS_SHARED},
+#define OPT_ZEXE            0x1002
+  {"Zexe", 0, 0, OPT_ZEXE},     /* Create .exe file, touch `output file' */
+#define OPT_ZDLL            0x1003
+  {"Zdll", 0, 0, OPT_ZDLL},     /* Create .dll file, touch `output file' */
+#define OPT_ZSTACK          0x1004
+  {"Zstack", 1, 0, OPT_ZSTACK}, /* Set stack size */
+#define OPT_ZMAP            0x1005
+  {"Zmap", 2, 0, OPT_ZMAP},     /* Create .map file */
+  {"Zmap=", 1, 0, OPT_ZMAP},
+#define OPT_ZAUTOCONV       0x1006
+  {"Zautoconv",0, 0, OPT_ZAUTOCONV},
+#define OPT_ZNO_AUTOCONV    0x1007
+  {"Zno-autoconv",0, 0, OPT_ZNO_AUTOCONV},
+/*  {"e", 1, 0, 'e'}, entry point */
+  {"i", 0, 0, 'i'},
+  {"o", 1, 0, 'o'},
+  {"O", 1, 0, 'O'},
+/*  {"u", 1, 0, 'u'}, reference symbol */
+  {"s", 0, 0, 's'},
+  {"S", 0, 0, 'S'},
+  {"t", 0, 0, 't'},
+  {"T", 1, 0, 'T'},
+  {"v", 0, 0, 'v'},
+  {"x", 0, 0, 'x'},
+  {"X", 0, 0, 'X'},
+  {NULL, 0, 0, 0}
+};
 
 /* Main function of emxomf.  Parse the command line and call the IBM/M$
@@ -1136,4 +1185,5 @@
   char execname[512];
   name_list *pcur;
+  int   longind;
 
   /* Get options from response files (@filename) and wildcard (*.o) on the command. */
@@ -1149,154 +1199,158 @@
 
   files = 0;
-  opterr = FALSE; optmode = GETOPT_KEEP;
+  opterr = FALSE;
+  /*optmode = GETOPT_KEEP; */
   if (argc < 2)
     usage ();
 
   /* Parse the command line options and other arguments. */
-
-  while ((c = getopt (argc, argv, "o:O:itl:vL:T:sSxXZ:")) != EOF)
-    switch (c)
-      {
-      case 't':
-      case 'i':                 /* Trace the linking process, sending /INFO to the IBM/M$ linker. */
-        opt_t = TRUE;
-        break;
-
-      case 'l':                 /* Add library */
-        add_name_list (&add_lib_fnames, optarg);
-        break;
-
-      case 'o':                 /* Set output file name */
-        output_fname = optarg;
-        break;
-
-      case 'L':                 /* Add library directory */
-        add_name_list (&add_libdirs, optarg);
-        break;
-
-      case 'T':                 /* Set base address */
-        base = optarg;
-        break;
-
-      case 's':                 /* Strip all symbols */
-      case 'S':                 /* Strip debugging symbols */
-        strip_symbols = TRUE;
-        break;
-
-      case 'x':                 /* Discard all local symbols */
-      case 'X':                 /* Discard local symbols starting with L */
-        break;
-
-      case 'v':                 /* For compatibility */
-        break;
-
-      case 'O':                 /* Specify Linker option */
-        add_name_list (&add_options, optarg);
-        break;
-
-      case 'Z':                 /* -Zdll, -Zexe, -Zmap, and -Zstack */
-        if (strcmp (optarg, "dll") == 0)
+  //while ((c = getopt_long (argc, argv, "o:O:itl:vL:T:sSxX", longopts, &longind)) != EOF)
+  while ((c = getopt_long_only (argc, argv, "-l:y:L:", longopts, &longind)) != EOF)
+    {
+      if (c == 0)
+        c = longopts[longind].val;
+      switch (c)
+        {
+        case '?':
+          usage();
+          break;
+
+        case 0:                   /* Non-option argument */
+
+          /* Extract the extension to see what to do with this
+             argument. */
+
+          ext = _getext (optarg);
+
+          if (ext == NULL)
+            {
+              /* GCC's temporary files don't have an extension.  Add a
+                 dot to the end of the name to prevent the linker from
+                 adding `.obj'. */
+
+              sprintf (tmp, "%s.", optarg);
+              add_name_list (&add_obj_fnames, tmp);
+            }
+
+          /* If it's a .def file, use it as module definition file
+             (input). */
+
+          else if (stricmp (ext, ".def") == 0)
+            {
+              if (def_fname != NULL)
+                {
+                  fprintf (stderr,
+                           "emxomfld: multiple module definition files\n");
+                  usage ();
+                }
+              def_fname = optarg;
+            }
+
+          /* If it's a .res file, use it as binary resource file
+             (input). */
+
+          else if (stricmp (ext, ".res") == 0)
+            {
+              if (res_fname != NULL)
+                {
+                  fprintf (stderr,
+                           "emxomfld: multiple binary resource files\n");
+                  usage ();
+                }
+              res_fname = optarg;
+            }
+
+          /* If it's a .lib file, use it as library file.  We also
+             accept .a files for those who use OMF files disguised as
+             a.out files (to simplify their make files). */
+
+          else if (stricmp (ext, ".lib") == 0 || stricmp (ext, ".a") == 0 || stricmp (ext, ".dll") == 0)
+            add_name_list (&add_lib_fnames, optarg);
+
+          /* Otherwise, assume it's an object file. */
+
+          else
+            add_name_list (&add_obj_fnames, optarg);
+          ++files;
+          break;
+
+        case 't':
+        case 'i':                 /* Trace the linking process, sending /INFO to the IBM/M$ linker. */
+          opt_t = TRUE;
+          break;
+
+        case 'l':                 /* Add library */
+          add_name_list (&add_lib_fnames, optarg);
+          break;
+
+        case 'o':                 /* Set output file name */
+          output_fname = optarg;
+          break;
+
+        case 'L':                 /* Add library directory */
+          add_name_list (&add_libdirs, optarg);
+          break;
+
+        case 'T':                 /* Set base address */
+          base = optarg;
+          break;
+
+        case 's':                 /* Strip all symbols */
+        case 'S':                 /* Strip debugging symbols */
+          strip_symbols = TRUE;
+          break;
+
+        case 'x':                 /* Discard all local symbols */
+        case 'X':                 /* Discard local symbols starting with L */
+          break;
+
+        case 'v':                 /* For compatibility */
+          break;
+
+        case 'O':                 /* Specify Linker option */
+          add_name_list (&add_options, optarg);
+          break;
+
+        case OPT_ZDLL:
           dll_flag = TRUE;
-        else if (strcmp (optarg, "exe") == 0)
+          break;
+
+        case OPT_ZEXE:
           exe_flag = TRUE;
-        else if (strcmp (optarg, "map") == 0)
+          break;
+
+        case OPT_ZMAP:
           map_flag = TRUE;
-        else if (strncmp (optarg, "map=", 4) == 0)
-          {
-            if (map_fname != NULL)
-              {
-                fprintf (stderr, "emxomfld: multiple map files files\n");
-                usage ();
-              }
-            map_fname = optarg + 4;
-            map_flag = TRUE;
-          }
-        else if (strcmp (optarg, "stack") == 0)
-          {
-            /* This makes assumptions on the internals of getopt(). */
-
-            if (optind >= argc || argv[optind][0] == '-')
-              usage ();
-            errno = 0;
-            stack_size = strtol (argv[optind], &t, 0);
-            if (errno != 0 || *t != 0 || t == argv[optind])
-              usage ();
-            ++optind;
-          }
-        else if (strcmp (optarg, "autoconv") == 0)
+          if (optarg)
+            {
+              if (map_fname != NULL)
+                {
+                  fprintf (stderr, "emxomfld: multiple map files files\n");
+                  usage ();
+                }
+            map_fname = optarg;
+            }
+          break;
+
+        case OPT_ZSTACK:
+          if (!optarg)
+            usage ();
+          errno = 0;
+          stack_size = strtol (argv[optind], &t, 0);
+          if (errno != 0 || *t != 0 || t == argv[optind])
+            usage ();
+          break;
+
+        case OPT_ZAUTOCONV:
           autoconvert_flag = 1;
-        else if (strcmp (optarg, "no-autoconv") == 0)
+          break;
+        case OPT_ZNO_AUTOCONV:
           autoconvert_flag = 0;
-        else
-          {
-            fprintf (stderr, "emxomfld: invalid option (%s)\n", optarg);
-            usage ();
-          }
-        break;
-
-      case 0:                   /* Non-option argument */
-
-        /* Extract the extension to see what to do with this
-           argument. */
-
-        ext = _getext (optarg);
-
-        if (ext == NULL)
-          {
-            /* GCC's temporary files don't have an extension.  Add a
-               dot to the end of the name to prevent the linker from
-               adding `.obj'. */
-
-            sprintf (tmp, "%s.", optarg);
-            add_name_list (&add_obj_fnames, tmp);
-          }
-
-        /* If it's a .def file, use it as module definition file
-           (input). */
-
-        else if (stricmp (ext, ".def") == 0)
-          {
-            if (def_fname != NULL)
-              {
-                fprintf (stderr,
-                         "emxomfld: multiple module definition files\n");
-                usage ();
-              }
-            def_fname = optarg;
-          }
-
-        /* If it's a .res file, use it as binary resource file
-           (input). */
-
-        else if (stricmp (ext, ".res") == 0)
-          {
-            if (res_fname != NULL)
-              {
-                fprintf (stderr,
-                         "emxomfld: multiple binary resource files\n");
-                usage ();
-              }
-            res_fname = optarg;
-          }
-
-        /* If it's a .lib file, use it as library file.  We also
-           accept .a files for those who use OMF files disguised as
-           a.out files (to simplify their make files). */
-
-        else if (stricmp (ext, ".lib") == 0 || stricmp (ext, ".a") == 0 || stricmp (ext, ".dll") == 0)
-          add_name_list (&add_lib_fnames, optarg);
-
-        /* Otherwise, assume it's an object file. */
-
-        else
-          add_name_list (&add_obj_fnames, optarg);
-        ++files;
-        break;
-
-      default:
-        fprintf (stderr, "emxomfld: invalid option (%s)\n", argv[optind - 1]);
-        usage ();
-      }
-
+
+        default:
+          fprintf (stderr, "emxomfld: invalid option (%s)\n", argv[optind - 1]);
+          usage ();
+        }
+    }
   /* Set default value for output file. */
 
