diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/emx-install gcc-3.0.4/gcc/config/i386/emx-install
--- gcc-3.0.4-orig/gcc/config/i386/emx-install	Thu Jan  1 00:00:00 1970
+++ gcc-3.0.4/gcc/config/i386/emx-install	Thu Aug 22 02:22:48 2002
@@ -0,0 +1,10 @@
+#!bash.exe
+emxload -qw
+./../install-sh -c $@
+ret=$?
+while [ -n "$1" ]; do
+	exename="$1"
+	shift
+done
+emxbind -s "$exename"
+exit $ret
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/os2.asm gcc-3.0.4/gcc/config/i386/os2.asm
--- gcc-3.0.4-orig/gcc/config/i386/os2.asm	Thu Jan  1 00:00:00 1970
+++ gcc-3.0.4/gcc/config/i386/os2.asm	Tue Oct 29 23:38:42 2002
@@ -0,0 +1,71 @@
+/* stuff needed for libgcc1 on os2. */
+
+#include <emx/asm386.h>
+
+	.global	__alloca
+__alloca:
+	pushl  %ecx		/* save temp */
+	movl   %esp,%ecx	/* get sp */
+	addl   $0x8,%ecx	/* and point to return addr */
+
+probe: 	cmpl   $0x1000,%eax	/* > 4k ?*/
+	jb    done		
+
+	subl   $0x1000,%ecx  		/* yes, move pointer down 4k*/
+	orl    $0x0,(%ecx)   		/* probe there */
+	subl   $0x1000,%eax  	 	/* decrement count */
+	jmp    probe           	 	/* and do it again */
+
+done: 	subl   %eax,%ecx	   
+	orl    $0x0,(%ecx)	/* less that 4k, just peek here */
+
+	movl   %esp,%eax
+	movl   %ecx,%esp	/* decrement stack */
+
+	movl   (%eax),%ecx	/* recover saved temp */
+	movl   4(%eax),%eax	/* get return address */
+	jmp    *%eax	
+
+
+        .globl ___probe
+
+/ void __probe (size_t n)
+
+/ Note: this function does not modify any registers and removes
+/       its argument from the stack.
+/       Do not call this function from a C program!
+
+        .text
+        ALIGN
+___probe:
+        xchgl   1*4(%esp), %ebx         /* save %ebx, put n into %ebx */
+        pushl   %eax                    /* save %eax */
+        movl    %esp, %eax
+        subl    %ebx, %eax              /* low address -> %eax */
+        andl    $-4, %eax               /* round down */
+        movl    %esp, %ebx              /* high address -> %ebx */
+        ALIGN
+1:      subl    $0x1000, %ebx           /* move down */
+        cmpl    %eax, %ebx              /* low address reached? */
+        jb      2f
+        testl   %eax, (%ebx)            /* reference the page */
+        jmp     1b                      /* repeat */
+
+        ALIGN
+2:      testl   %eax, (%eax)            /* reference last page */
+        popl    %eax                    /* restore %eax */
+        movl    1*4(%esp), %ebx         /* restore %ebx */
+        EPILOGUE_NO_RET(__probe)
+        ret     $4                      /* return, remove arg from stack */
+
+        .globl  ___eh_frame_init
+	.text
+	ALIGN
+___eh_frame_init:
+	ret
+
+        .globl  ___eh_frame_term
+	.text
+	ALIGN
+___eh_frame_term:
+	ret
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/os2.c gcc-3.0.4/gcc/config/i386/os2.c
--- gcc-3.0.4-orig/gcc/config/i386/os2.c	Thu Jan  1 00:00:00 1970
+++ gcc-3.0.4/gcc/config/i386/os2.c	Thu Oct 17 00:51:00 2002
@@ -0,0 +1 @@
+/* nothing */
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/os2.h gcc-3.0.4/gcc/config/i386/os2.h
--- gcc-3.0.4-orig/gcc/config/i386/os2.h	Wed Dec 16 22:03:46 1998
+++ gcc-3.0.4/gcc/config/i386/os2.h	Wed Oct 16 17:14:38 2002
@@ -20,6 +20,7 @@
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#ifndef __EMX__
 #ifndef DEFAULT_TARGET_MACHINE
 #define DEFAULT_TARGET_MACHINE "i386-os2"
 #endif
@@ -41,12 +42,35 @@
 #ifndef LOCAL_INCLUDE_DIR
 #define LOCAL_INCLUDE_DIR "\\gcc\\include"
 #endif
+#endif
+
+/* do not automatically add .exe suffix; be compatible with EMX */
+#undef NO_AUTO_EXE_SUFFIX
+#define NO_AUTO_EXE_SUFFIX
 
 #define YES_UNDERSCORES
 #include "i386/gstabs.h"
+#define NO_IMPLICIT_EXTERN_C
+
+/* Enable #pragma pack. */
+#define HANDLE_SYSV_PRAGMA
+
+/* wchar_t is unsigned short. */
+#define WCHAR_TYPE              "short unsigned int"
+#define WCHAR_TYPE_SIZE         16
+
+/* Bitfields may cross alignment boundaries. */
+#undef PCC_BITFIELD_TYPE_MATTERS
+#define PCC_BITFIELD_TYPE_MATTERS 0
+
+/* By default, return short structures in registers. */
+#define DEFAULT_PCC_STRUCT_RETURN 0
+
 
 #define USE_COLLECT
 
+#ifndef __EMX__
+
 #define BIGGEST_FIELD_ALIGNMENT \
   (maximum_field_alignment ? maximum_field_alignment : 32)
 
@@ -55,22 +79,200 @@
 #undef PCC_BITFIELD_TYPE_MATTERS
 #define PCC_BITFIELD_TYPE_MATTERS (maximum_field_alignment == 0)
 
+#endif
+
 /* Define this macro if it is advisable to hold scalars in registers
    in a wider mode than that declared by the program.  In such cases,
    the value is constrained to be within the bounds of the declared
    type, but kept valid in the wider mode.  The signedness of the
    extension may differ from that of the type.  */
 
+/*
 #define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE)  \
   if (GET_MODE_CLASS (MODE) == MODE_INT         \
       && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
       (MODE) = SImode;
+*/
 
 /* Define this if function arguments should also be promoted using the above
    procedure.  */
 
+/*
 #define PROMOTE_FUNCTION_ARGS
+*/
 
 /* Likewise, if the function return value is promoted.  */
 
+/*
 #define PROMOTE_FUNCTION_RETURN
+*/
+
+#define DBX_CONTIN_LENGTH 0
+
+#ifdef __EMX__
+/*
+#define GCC_INCLUDE_DIR            "/emx/include"
+#define GPLUSPLUS_INCLUDE_DIR      "/emx/include.gpp"
+#define LOCAL_INCLUDE_DIR          "/usr/local/include"
+#define CROSS_INCLUDE_DIR          "/emx/include.sys"
+#define STANDARD_EXEC_PREFIX       "/emx/bin/"
+#define STANDARD_STARTFILE_PREFIX  "/emx/lib/"
+*/
+
+/* The -Zstack option takes an argument. */
+#define WORD_SWITCH_TAKES_ARG(STR) (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) \
+                                    || !strcmp (STR, "Zstack"))
+
+/* Predefine symbols `__32BIT__', `__EMX__', and `i386'. */
+#undef CPP_PREDEFINES
+#define CPP_PREDEFINES "-D__32BIT__ -D__EMX__ -Di386\
+  -Asystem(unix) -Asystem(emx) -Acpu(i386) -Amachine(i386)"
+
+/* Predefine the symbol `__MT__' for multi-threaded programs (-Zmt).
+   Pass -Zc++-comments and -ZC++-comments to the preprocessor. */
+#undef CPP_SPEC
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{Zmt:-D__MT__} \
+%{Zomf} %{ZC++-comments} %{Zc++-comments} %{pg:-D__GPROF__} \
+%{mepilogue:-D__EPILOGUE__}"
+
+/* Pass -Zomf and -s (as -Zstrip) to the assembler. */
+#define ASM_SPEC "%{Zomf} %{s:-Zstrip}"
+
+#define LINK_SPEC \
+  "%{Zexe} %{Zstack*} %{Zmap*} %{Zomf:%{Zdll}}" \
+  "%{!o*:-o %b.%{Zdll:dll}%{!Zdll:exe}} " \
+  "%{static:%{Zcrtdll=*:%e-static and -Zcrtdll are incompatible}}" \
+  "%{Zdll:%{Zexe:%e-Zdll and -Zexe are incompatible}}" \
+  "%{Zso:%{!Zsys:%e-Zso requires -Zsys}}" \
+  "%{Zso:%{!Zdll:%e-Zso requires -Zdll}}" \
+  "%{Zno-rte:%{!Zdll:%e-Zno-rte requires -Zdll}}" \
+  "%{Zno-rte:%{!Zomf:%e-Zno-rte requires -Zomf}}" \
+  "%{Zno-rte:%{Zsys:%e-Zno-rte and -Zsys are incompatible}}" \
+  "%{Zno-rte:%{Zso:%e-Zno-rte and -Zso are incompatible}}" \
+  "%{Zno-rte:%{Zcrtdll=*:%e-Zcrtdll and -Zno-rte are incompatible}}" \
+  "%{Zno-rte:%{Zmt:%e-Zmt and -Zno-rte are incompatible}}" \
+  "%{Zsys:%{Zcrtdll=*:%e-Zcrtdll and -Zsys are incompatible}}" \
+  "%{Zsys:%{!Zomf:%e-Zsys requires -Zomf}}" \
+  "%{Zsys:%{Zbsd-signals:%e-Zbsd-signals and -Zsys are incompatible}}" \
+  "%{Zsys:%{Zsysv-signals:%e-Zsysv-signals and -Zsys are incompatible}}" \
+  "%{Zbsd-signals:%{Zsysv-signals:%e-Zbsd-signals and -Zsysv-signals are incompatible}}" \
+  "%{Zsmall-conv:%{Zcrtdll=*:%e-Zsmall-conv and -Zcrtdll are incompatible}}"
+
+#define LIBGCC_SPEC "-lgcc%{pg:_p}"
+
+#define LIB_SPEC \
+  "%{g*:-lg} " \
+  "%{p:-lc_p}%{pg:-lc_p} -lc " \
+  "%{Zdll:%{Zso:-lc_dllso}%{Zno-rte:-lc_dllnrt}" \
+         "%{!Zso:%{!Zno-rte:-lc_dllrt}}}" \
+  "%{!Zdll:-lc_app%{pg:_p}} %{p:-lc_p}%{pg:-lc_p} -lc"
+
+#define STARTFILE_SPEC \
+  "%{Zdll:dll0%O%s}" \
+  "%{!Zdll:%{pg:gcrt0%O%s}" \
+         "%{!pg:%{pn:gcrt0%O%s}%{!pn:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" \
+         " %{Zsysv-signals:sigsysv%O%s} %{Zbsd-signals:sigbsd%O%s}" \
+         " %{Zbin-files:binmode%O%s}%{Zsmall-conv:smallcnv%O%s}}"
+
+
+#undef TARGET_DEFAULT
+#define TARGET_DEFAULT \
+   (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS /*| MASK_STACK_PROBE*/) 
+
+/* Output assembler code to FILE to increment profiler label # LABELNO
+   for profiling a function entry.  */
+
+#undef FUNCTION_PROFILER
+#define FUNCTION_PROFILER(FILE, LABELNO)  \
+{									\
+  fprintf (FILE, "\tcall __mcount\n");					\
+}
+
+/* Calling conventions */
+
+/*
+
+I haven't seen these anywhere in EMX source files, so I just don't implement
+them	-- mikulas
+
+#undef VALID_MACHINE_TYPE_ATTRIBUTE
+#define VALID_MACHINE_TYPE_ATTRIBUTE(TYPE, ATTRIBUTES, NAME, ARGS)	\
+  ((TREE_CODE ((TYPE)) == FUNCTION_TYPE					\
+   || TREE_CODE ((TYPE)) == METHOD_TYPE					\
+   || TREE_CODE ((TYPE)) == FIELD_DECL					\
+   || TREE_CODE ((TYPE)) == TYPE_DECL)					\
+  && (is_attribute_p ("emxcall", (NAME))				\
+   || is_attribute_p ("system", (NAME))) ? (ARGS) == NULL_TREE :	\
+   ix86_valid_type_attribute_p ((TYPE), (ATTRIBUTES), (NAME), (ARGS)))
+
+#undef RETURN_POPS_ARGS
+#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \
+  (emx_return_pops_args (FUNDECL, FUNTYPE, SIZE))
+*/
+
+#define LINK_COMMAND_SPEC "\
+%{!fsyntax-only: \
+ %{!c:%{!M:%{!MM:%{!E:%{!S:%{!Zomf:ld}%{Zomf:emxomfld}\
+			%l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
+			%{r} %{s} %{t} %{u*} %{x} %{z} %{Z}\
+			%{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
+			%{static:} %{L*} %D %{T*} %o\
+                        %{fbounds-checking:-lcheck} \
+			%{!nostdlib:%{!nodefaultlibs:\
+			  -lc_alias \
+			  %{Zcrtdll=*:-lc_static -l%* -los2%{pg:_p} -lemx2}\
+			  %{!Zcrtdll:%{!Zcrtdll=*:%G %L %G\
+			     %{Zno-rte:-los2%{pg:_p}}\
+			     %{!Zno-rte:%{Zsys:-lsys -los2}\
+					%{!Zsys:-lemx -los2%{pg:_p} -lemx2}}}}\
+			  %{Zomf:-lend}}}\
+			%{!A:%{!nostdlib:%{!nostartfiles:%E}}}\n }}}}}}"
+
+#define TARGET_CPP_OPTIONS 					\
+	DEF_OPT("ZC++-comments", 0, OPT_ZCpp_comments)		\
+	DEF_OPT("Zc++-comments", 0, OPT_Zcpp_comments)		\
+	DEF_OPT("Zomf", 0, OPT_Zomf)
+
+#define TARGET_CPP_PROCESS_OPTIONS 					\
+	case OPT_Zomf: omf = 1;						\
+		       break;						\
+        case OPT_ZCpp_comments:						\
+        case OPT_Zcpp_comments: CPP_OPTION (pfile, cplusplus_comments) = 1;\
+				break;
+
+#define TARGET_MULTILIB						\
+static const char *const multilib_raw[] = {			\
+"st !Zmt;",							\
+"mt Zmt;",							\
+NULL								\
+};								\
+								\
+static const char *const multilib_matches_raw[] = {		\
+"Zmtd Zmt;",							\
+"Zmts Zmt;",							\
+"Zmt Zmt;",							\
+NULL								\
+};								\
+								\
+static const char *multilib_extra = "";				\
+								\
+static const char *const multilib_exclusions_raw[] = {		\
+NULL								\
+};								\
+
+#undef DO_GLOBAL_DTORS_BODY
+#define DO_GLOBAL_DTORS_BODY					\
+do {								\
+	extern void __ctordtorTerm (void);			\
+	__ctordtorTerm ();					\
+} while(0);
+
+#undef DO_GLOBAL_CTORS_BODY
+#define DO_GLOBAL_CTORS_BODY					\
+do {								\
+	extern void __ctordtorInit (void);			\
+	__ctordtorInit ();					\
+} while(0);
+
+#endif
+
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/t-os2 gcc-3.0.4/gcc/config/i386/t-os2
--- gcc-3.0.4-orig/gcc/config/i386/t-os2	Thu Jan  1 00:00:00 1970
+++ gcc-3.0.4/gcc/config/i386/t-os2	Thu Aug 22 02:22:46 2002
@@ -0,0 +1,23 @@
+DUMMY_ := $(shell emxload -qw)
+
+LIBGCC1 = libgcc1-asm.a
+CROSS_LIBGCC1 = libgcc1-asm.a
+LIB1ASMSRC = i386/os2.asm
+LIB1ASMFUNCS = __probe
+
+os2.o: $(srcdir)/config/i386/os2.c
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/i386/os2.c
+
+RANLIB_TEST_FOR_TARGET = true
+RANLIB_FOR_TARGET = true
+
+INSTALL_LIBGCC = install-os2-libgcc
+
+install-os2-libgcc : install-libgcc
+	mv $(libsubdir)/st/libgcc.a $(libsubdir)/st/gcc.a
+	mv $(libsubdir)/mt/libgcc.a $(libsubdir)/mt/gcc.a
+	emxomf -s $(libsubdir)/st/gcc.a
+	emxomf -s $(libsubdir)/mt/gcc.a
+	cp $(libsubdir)/st/gcc.a $(libsubdir)/st/gcc_p.a
+
+override INSTALL_PROGRAM = sh ./config/i386/emx-install
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/x-os2 gcc-3.0.4/gcc/config/i386/x-os2
--- gcc-3.0.4-orig/gcc/config/i386/x-os2	Thu Jan  1 00:00:00 1970
+++ gcc-3.0.4/gcc/config/i386/x-os2	Thu Aug 22 02:22:46 2002
@@ -0,0 +1,7 @@
+# Location of EMX header directory.
+SYSTEM_HEADER_DIR=$(C_INCLUDE)
+
+# on OS/2 the 'ln -s' does not work correctly
+LN = cp -p
+LN_S = cp -p
+
diff -r -u -N gcc-3.0.4-orig/gcc/config/i386/xm-os2.h gcc-3.0.4/gcc/config/i386/xm-os2.h
--- gcc-3.0.4-orig/gcc/config/i386/xm-os2.h	Mon Aug 21 19:01:50 2000
+++ gcc-3.0.4/gcc/config/i386/xm-os2.h	Wed Oct 16 17:14:38 2002
@@ -34,12 +34,31 @@
 #define mktemp tmpnam
 #else
 #ifdef __EMX__
+#include <sys/emxload.h>
 #define EMX
 #define USG
-#define HAVE_PUTENV
-#define HAVE_VPRINTF
-#define HAVE_STRERROR
+#ifndef HAVE_PUTENV
+#define HAVE_PUTENV 1
+#endif
+#ifndef HAVE_VPRINTF
+#define HAVE_VPRINTF 1
+#endif
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR 1
+#endif
 #define strcasecmp stricmp
+#ifndef HAVE_STRCASECMP
+#define HAVE_STRCASECMP 1
+#endif
+#ifndef HAVE_SYS_STAT_H
+#define HAVE_SYS_STAT_H	1
+#endif
+#ifndef HAVE_PRINTF_PTR
+#define HAVE_PRINTF_PTR	1
+#endif
+#ifndef S_ISBLK
+#define S_ISBLK(x) 0
+#endif
 #else
 #define ____386BSD____
 int spawnv (int modeflag, char *path, char *argv[]);
@@ -65,6 +84,9 @@
 /* The EMX compiler uses regular .o files */
 #ifndef __EMX__
 #define OBJECT_SUFFIX ".obj"
+#else
+extern int omf;
+#define OBJECT_SUFFIX (!omf ? ".o" : ".obj")
 #endif
 
 /* Tell GCC about OS/2's bit bucket. */
@@ -72,3 +94,33 @@
 #define HOST_BIT_BUCKET "NUL"
 
 #include "i386/xm-i386.h"
+
+#ifdef __EMX__
+
+#undef GCC_DRIVER_HOST_INITIALIZATION
+#define GCC_DRIVER_HOST_INITIALIZATION					\
+  _emxload_env ("GCCLOAD");						\
+  _envargs (&argc, (char ***)&argv, "GCCOPT");				\
+  _response (&argc, (char ***)&argv);					\
+  _wildcard (&argc, (char ***)&argv);					\
+									\
+  /* pipe() is supported under OS/2 and by RSX.  */			\
+  pipes_supported = _osmode != DOS_MODE || (_emx_env & 0x1000);
+
+#undef CC_HOST_INITIALIZATION
+#define CC_HOST_INITIALIZATION						\
+  _emxload_env ("GCCLOAD");
+
+#undef COLLECT2_HOST_INITIALIZATION
+#define COLLECT2_HOST_INITIALIZATION					\
+  _emxload_env ("GCCLOAD");
+
+#undef CPP_HOST_INITIALIZATION
+#define CPP_HOST_INITIALIZATION						\
+  _emxload_env ("GCCLOAD");
+
+#undef TRADCPP_HOST_INITIALIZATION
+#define TRADCPP_HOST_INITIALIZATION					\
+  _emxload_env ("GCCLOAD");
+
+#endif /* __EMX__ */
diff -r -u -N gcc-3.0.4-orig/gcc/config.gcc gcc-3.0.4/gcc/config.gcc
--- gcc-3.0.4-orig/gcc/config.gcc	Fri Feb 15 15:42:52 2002
+++ gcc-3.0.4/gcc/config.gcc	Wed Oct 16 17:14:38 2002
@@ -1261,6 +1261,17 @@
 	tmake_file=i386/t-i386bare
 	xmake_file=x-lynx
 	;;
+i[34567]86-*-os2*)
+	xm_file=i386/xm-os2.h
+	tm_file=i386/os2.h
+	tmake_file=i386/t-os2
+	xmake_file=i386/x-os2
+	extra_objs=os2.o
+	gnu_ld=yes
+	gas=yes
+	exeext=.exe
+	float_format=none
+	;;
 i[34567]86-*-mach*)
 	tm_file=i386/mach.h
 #	tmake_file=t-libc-ok
diff -r -u -N gcc-3.0.4-orig/gcc/cppfiles.c gcc-3.0.4/gcc/cppfiles.c
--- gcc-3.0.4-orig/gcc/cppfiles.c	Tue May 22 12:53:10 2001
+++ gcc-3.0.4/gcc/cppfiles.c	Wed Oct 16 17:14:38 2002
@@ -444,6 +444,10 @@
       inc->st.st_size = offset;
     }
 
+  /* 26 is used as file-termination character on OS/2 and DOS -- mikulas */
+#ifdef EMX
+  if (inc->st.st_size > 0 && buf[inc->st.st_size - 1] == 26) inc->st.st_size--;
+#endif
   inc->buffer = buf;
   return 0;
 
diff -r -u -N gcc-3.0.4-orig/gcc/cppinit.c gcc-3.0.4/gcc/cppinit.c
--- gcc-3.0.4-orig/gcc/cppinit.c	Sat Nov 24 14:44:14 2001
+++ gcc-3.0.4/gcc/cppinit.c	Wed Oct 16 17:14:38 2002
@@ -49,6 +49,11 @@
 # endif
 #endif
 
+  /* use extension .obj instead of .o when printing depencies  -- mikulas */
+#ifdef EMX
+int omf = 0;
+#endif
+
 /* Internal structures and prototypes.  */
 
 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
@@ -1056,6 +1061,10 @@
 #define no_num N_("Number missing after %s")
 #define no_tgt N_("Target missing after %s")
 
+#ifndef TARGET_CPP_OPTIONS
+#define TARGET_CPP_OPTIONS
+#endif
+
 /* This is the list of all command line options, with the leading
    "-" removed.  It must be sorted in ASCII collating order.  */
 #define COMMAND_LINE_OPTIONS                                                  \
@@ -1081,6 +1090,7 @@
   DEF_OPT("P",                        0,      OPT_P)                          \
   DEF_OPT("U",                        no_mac, OPT_U)                          \
   DEF_OPT("W",                        no_arg, OPT_W)  /* arg optional */      \
+  TARGET_CPP_OPTIONS							      \
   DEF_OPT("d",                        no_arg, OPT_d)                          \
   DEF_OPT("fleading-underscore",      0,      OPT_fleading_underscore)        \
   DEF_OPT("fno-leading-underscore",   0,      OPT_fno_leading_underscore)     \
@@ -1655,6 +1665,9 @@
 	  else if (!strcmp (argv[i], "-Wno-system-headers"))
 	    CPP_OPTION (pfile, warn_system_headers) = 0;
 	  break;
+#ifdef TARGET_CPP_PROCESS_OPTIONS
+	TARGET_CPP_PROCESS_OPTIONS;
+#endif
  	}
     }
   return i + 1;
diff -r -u -N gcc-3.0.4-orig/gcc/cppmain.c gcc-3.0.4/gcc/cppmain.c
--- gcc-3.0.4-orig/gcc/cppmain.c	Thu May 10 01:11:02 2001
+++ gcc-3.0.4/gcc/cppmain.c	Wed Oct 16 17:14:38 2002
@@ -73,6 +73,11 @@
 {
   general_init (argv[0]);
 
+#if defined (CPP_HOST_INITIALIZATION)
+/* Perform system dependent initialization, if neccessary.  */
+  CPP_HOST_INITIALIZATION;
+#endif
+
   /* Contruct a reader with default language GNU C89.  */
   pfile = cpp_create_reader (CLK_GNUC89);
   options = cpp_get_options (pfile);
diff -r -u -N gcc-3.0.4-orig/gcc/gcc.c gcc-3.0.4/gcc/gcc.c
--- gcc-3.0.4-orig/gcc/gcc.c	Wed Jan  2 22:03:38 2002
+++ gcc-3.0.4/gcc/gcc.c	Wed Oct 16 17:14:40 2002
@@ -220,6 +220,17 @@
 /* Forward declaration for prototypes.  */
 struct path_prefix;
 
+#ifdef EMX
+/* Nonzero means create .obj files instead of .o files.  */
+int omf;
+
+/* Nonzero means pipes are supported.  */
+static int pipes_supported;
+
+/* Name of first input file, for defaulting the output file. */
+static char *first_infile;
+#endif /* EMX */
+
 static void init_spec		PARAMS ((void));
 #ifndef VMS
 static char **split_directories	PARAMS ((const char *, int *));
@@ -637,7 +648,12 @@
 static const char *multilib_matches;
 static const char *multilib_defaults;
 static const char *multilib_exclusions;
+
+#ifndef TARGET_MULTILIB
 #include "multilib.h"
+#else
+TARGET_MULTILIB
+#endif
 
 /* Check whether a particular argument is a default argument.  */
 
@@ -1028,6 +1044,38 @@
 	  i++;
 	}
 
+#ifdef EMX
+      /* Handle abbreviations.  Note that no abbreviation must expand
+         to more than two options.  */
+      else if (!strcmp (argv[i], "-Zmts"))
+	{
+	  newv[newindex++] = "-Zmt";
+	  newv[newindex++] = "-static";
+	  i++;
+	}
+      else if (!strcmp (argv[i], "-Zmtd"))
+	{
+	  newv[newindex++] = "-Zmt";
+	  newv[newindex++] = "-Zcrtdll=c_import";
+	  i++;
+	}
+      else if (!strcmp (argv[i], "-Zcrtdll"))
+	{
+	  newv[newindex++] = "-Zcrtdll=c_import";
+	  i++;
+	}
+      else if (!strcmp (argv[i], "-mprobe"))
+	{
+	  newv[newindex++] = "-mstack-arg-probe";
+	  i++;
+	}
+      else if (!strcmp (argv[i], "-mno-probe"))
+	{
+	  newv[newindex++] = "-mno-stack-arg-probe";
+	  i++;
+	}
+#endif /* EMX */
+
       /* Handle old-fashioned options--just copy them through,
 	 with their arguments.  */
       else if (argv[i][0] == '-')
@@ -1045,6 +1093,10 @@
 	    nskip += 1;
 	  else if (! strcmp (p, "Xlinker"))
 	    nskip += 1;
+#ifdef EMX
+	  else if (! strcmp (p, "Zlinker"))
+	    nskip += 1;
+#endif /* EMX */
 
 	  /* Watch out for an option at the end of the command line that
 	     is missing arguments, and avoid skipping past the end of the
@@ -2511,7 +2563,8 @@
 enum path_prefix_priority
 {
   PREFIX_PRIORITY_B_OPT,
-  PREFIX_PRIORITY_LAST
+  PREFIX_PRIORITY_LAST,
+  PREFIX_PRIORITY_REALLY_LAST
 };
 
 /* Add an entry for PREFIX in PLIST.  The PLIST is kept in assending
@@ -2608,9 +2661,13 @@
   for (n_commands = 1, i = 0; i < argbuf_index; i++)
     if (strcmp (argbuf[i], "|") == 0)
       {				/* each command.  */
-#if defined (__MSDOS__) || defined (OS2) || defined (VMS)
+#if defined (__MSDOS__) || (defined (OS2) && !defined(__EMX__)) || defined (VMS)
 	fatal ("-pipe not supported");
 #endif
+#ifdef __EMX__
+        if (!pipes_supported)
+          fatal ("-pipe not supported");
+#endif /* __EMX__ */
 	argbuf[i] = 0;	/* termination of command args.  */
 	commands[n_commands].prog = argbuf[i + 1];
 	commands[n_commands].argv = &argbuf[i + 1];
@@ -3133,8 +3190,13 @@
 		}
 	      else
 		nstore[endp - startp] = 0;
+#ifndef EMX		/* on EMX we must search first gcc-lib/... -- mikulas */
 	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
 			  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
+#else
+	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
+			  PREFIX_PRIORITY_REALLY_LAST, 0, NULL_PTR);
+#endif
 	      if (*endp == 0)
 		break;
 	      endp = startp = endp + 1;
@@ -3166,8 +3228,13 @@
 		}
 	      else
 		nstore[endp - startp] = 0;
+#ifndef EMX		/* on EMX we must search first gcc-lib/... -- mikulas */
 	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
 			  PREFIX_PRIORITY_LAST, 0, NULL_PTR);
+#else
+	      add_prefix (&startfile_prefixes, nstore, NULL_PTR,
+			  PREFIX_PRIORITY_REALLY_LAST, 0, NULL_PTR);
+#endif
 	      if (*endp == 0)
 		break;
 	      endp = startp = endp + 1;
@@ -3309,6 +3376,16 @@
 	  n_infiles++;
 	  i++;
 	}
+#ifdef EMX
+      else if (strcmp (argv[i], "-Zlinker") == 0)
+	{
+	  if (i + 1 == argc)
+	    fatal ("argument to `-Zlinker' is missing");
+
+	  n_infiles += 2;
+	  i++;
+	}
+#endif /* EMX */
       else if (strncmp (argv[i], "-l", 2) == 0)
 	n_infiles++;
       else if (strcmp (argv[i], "-save-temps") == 0)
@@ -3560,6 +3637,10 @@
 		i += SWITCH_TAKES_ARG (c) - (p[1] != 0);
 	      else if (WORD_SWITCH_TAKES_ARG (p))
 		i += WORD_SWITCH_TAKES_ARG (p);
+#ifdef EMX
+	      if (!strcmp (p, "Zomf"))
+		omf = 1;
+#endif /* EMX */
 	    }
 	}
       else
@@ -3578,14 +3659,14 @@
      (such as cpp) rather than those of the host system.  */
   /* Use 2 as fourth arg meaning try just the machine as a suffix,
      as well as trying the machine and the version.  */
-#ifndef OS2
+/*#ifndef OS2*/
   add_prefix (&exec_prefixes, standard_exec_prefix, "GCC",
 	      PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
   add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
 	      PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
   add_prefix (&exec_prefixes, standard_exec_prefix_1, "BINUTILS",
 	      PREFIX_PRIORITY_LAST, 2, warn_std_ptr);
-#endif
+/*#endif*/
 
   add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
 	      PREFIX_PRIORITY_LAST, 1, warn_std_ptr);
@@ -3719,6 +3800,15 @@
 	  infiles[n_infiles].language = "*";
 	  infiles[n_infiles++].name = argv[++i];
 	}
+#ifdef EMX
+      else if (strcmp (argv[i], "-Zlinker") == 0)
+	{
+	  infiles[n_infiles].language = "*";
+	  infiles[n_infiles++].name = "-O";
+	  infiles[n_infiles].language = "*";
+	  infiles[n_infiles++].name = argv[++i];
+	}
+#endif /* EMX */
       else if (strncmp (argv[i], "-l", 2) == 0)
 	{
 	  infiles[n_infiles].language = "*";
@@ -3835,6 +3925,10 @@
 	    {
 	      infiles[n_infiles].language = spec_lang;
 	      infiles[n_infiles++].name = argv[i];
+#ifdef EMX
+	      if (!first_infile)
+		first_infile = argv[i];
+#endif /* EMX */
 	    }
 	}
     }
@@ -5970,6 +6064,24 @@
 	 for collect.  */
       putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH");
       putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV);
+
+#ifdef EMX
+      /* Substitute the basename of the first input file for %b in
+	 link_command_spec. */
+
+      input_basename = first_infile;
+      for (p = input_basename; *p; p++)
+	if (*p == '/')
+	  input_basename = p + 1;
+
+      /* Find a suffix starting with the last period,
+	 and set basename_length to exclude that suffix.  */
+      basename_length = strlen (input_basename);
+      p = input_basename + basename_length;
+      while (p != input_basename && *p != '.') --p;
+      if (*p == '.' && p != input_basename)
+	basename_length = p - input_basename;
+#endif /* EMX */
 
       value = do_spec (link_command_spec);
       if (value < 0)
diff -r -u -N gcc-3.0.4-orig/gcc/po/Makefile gcc-3.0.4/gcc/po/makefile
--- gcc-3.0.4-orig/gcc/po/Makefile	Sat Apr 27 15:45:50 2002
+++ gcc-3.0.4/gcc/po/makefile	Wed Oct 16 17:14:40 2002
@@ -12,12 +12,12 @@
 
 SHELL = /bin/sh
 STAMP = echo timestamp >
-
+MAKE=d:/prg/emx/bin/make.exe
 
 srcdir = .
 top_srcdir = ..
 
-prefix = /usr/local
+prefix = g:/prg/gcc/
 exec_prefix = ${prefix}
 datadir = $(prefix)/share
 localedir = $(datadir)/locale
@@ -25,19 +25,19 @@
 gettextsrcdir = $(prefix)/share/gettext/po
 subdir = po
 
-INSTALL = /usr/bin/install -c
+INSTALL = ./../install-sh -c
 INSTALL_DATA = ${INSTALL} -m 644
 MKINSTALLDIRS = $(top_srcdir)/./../mkinstalldirs
 
-CC = gcc.r
+CC = g:/prg/gcc/bin/gcc.exe
 GENCAT = 
 GMSGFMT = PATH=../src:$$PATH 
 MSGFMT = 
-XGETTEXT = PATH=../src:$$PATH AWK='mawk' $(SHELL) $(top_srcdir)/exgettext 
+XGETTEXT = PATH=../src:$$PATH AWK='' $(SHELL) $(top_srcdir)/exgettext 
 MSGMERGE = PATH=../src:$$PATH msgmerge
 
 DEFS = -DHAVE_CONFIG_H
-CFLAGS = -O9 -mpentium -mpreferred-stack-boundary=2 -fomit-frame-pointer
+CFLAGS = -O3 -mcpu=pentium -mpreferred-stack-boundary=2 -fomit-frame-pointer
 CPPFLAGS = 
 
 INCLUDES = -I.. -I$(top_srcdir)/intl
diff -r -u -N gcc-3.0.4-orig/gcc/po/Makefile.in gcc-3.0.4/gcc/po/makefile.in
--- gcc-3.0.4-orig/gcc/po/Makefile.in	Sat Apr 27 15:45:34 2002
+++ gcc-3.0.4/gcc/po/makefile.in	Wed Oct 16 17:14:40 2002
@@ -12,12 +12,12 @@
 
 SHELL = /bin/sh
 STAMP = echo timestamp >
-
+MAKE=d:/prg/emx/bin/make.exe
 
 srcdir = .
 top_srcdir = ..
 
-prefix = /usr/local
+prefix = g:/prg/gcc/
 exec_prefix = ${prefix}
 datadir = $(prefix)/share
 localedir = $(datadir)/locale
@@ -25,19 +25,19 @@
 gettextsrcdir = $(prefix)/share/gettext/po
 subdir = po
 
-INSTALL = /usr/bin/install -c
+INSTALL = ./../install-sh -c
 INSTALL_DATA = ${INSTALL} -m 644
 MKINSTALLDIRS = $(top_srcdir)/./../mkinstalldirs
 
-CC = gcc.r
+CC = g:/prg/gcc/bin/gcc.exe
 GENCAT = 
 GMSGFMT = PATH=../src:$$PATH 
 MSGFMT = 
-XGETTEXT = PATH=../src:$$PATH AWK='mawk' $(SHELL) $(top_srcdir)/exgettext 
+XGETTEXT = PATH=../src:$$PATH AWK='' $(SHELL) $(top_srcdir)/exgettext 
 MSGMERGE = PATH=../src:$$PATH msgmerge
 
 DEFS = -DHAVE_CONFIG_H
-CFLAGS = -O9 -mpentium -mpreferred-stack-boundary=2 -fomit-frame-pointer
+CFLAGS = -O3 -mcpu=pentium -mpreferred-stack-boundary=2 -fomit-frame-pointer
 CPPFLAGS = 
 
 INCLUDES = -I.. -I$(top_srcdir)/intl
diff -r -u -N gcc-3.0.4-orig/gcc/tm.h gcc-3.0.4/gcc/tm.h
--- gcc-3.0.4-orig/gcc/tm.h	Sat Apr 27 15:46:50 2002
+++ gcc-3.0.4/gcc/tm.h	Wed Oct 16 17:14:40 2002
@@ -1,10 +1,6 @@
-#define TARGET_CPU_DEFAULT (2)
 #ifdef IN_GCC
 # include "gansidecl.h"
-# include "i386/i386.h"
-# include "i386/att.h"
-# include "linux.h"
-# include "i386/linux.h"
+# include "i386/os2.h"
 # include "defaults.h"
 #endif
 #ifndef GENERATOR_FILE
diff -r -u -N gcc-3.0.4-orig/gcc/toplev.c gcc-3.0.4/gcc/toplev.c
--- gcc-3.0.4-orig/gcc/toplev.c	Sun Oct 28 21:11:10 2001
+++ gcc-3.0.4/gcc/toplev.c	Wed Oct 16 17:14:40 2002
@@ -4645,6 +4645,11 @@
 
   xmalloc_set_program_name (progname);
 
+#ifdef CC_HOST_INITIALIZATION
+  /* Perform host dependant initialization when needed.  */
+  CC_HOST_INITIALIZATION;
+#endif
+
 /* LC_CTYPE determines the character set used by the terminal so it has be set
    to output messages correctly.  */
 
diff -r -u -N gcc-3.0.4-orig/gcc/tradcpp.c gcc-3.0.4/gcc/tradcpp.c
--- gcc-3.0.4-orig/gcc/tradcpp.c	Mon Jan 21 09:42:26 2002
+++ gcc-3.0.4/gcc/tradcpp.c	Wed Oct 16 17:14:40 2002
@@ -68,6 +68,14 @@
 
 int deps_missing_files = 0;
        
+#ifdef EMX
+/* Nonzero means use .obj instead of .o for target file when printing
+   dependencies. */
+
+int omf = 0;
+
+#endif /* EMX */
+
 /* Nonzero means don't output line number information.  */
 
 int no_line_commands;
@@ -529,6 +537,11 @@
 
   progname = argv[0];
 
+#if defined (TRADCPP_HOST_INITIALIZATION)
+/* Perform system dependent initialization, if neccessary.  */
+  TRADCPP_HOST_INITIALIZATION;
+#endif
+
   in_fname = NULL;
   out_fname = NULL;
 
@@ -763,6 +776,18 @@
 	no_standard_includes = 1;
 	break;
 
+#ifdef EMX
+      case 'Z':
+	if (!strcmp (argv[i], "-Zomf"))
+	  omf = 1;
+	else if (!strcmp (argv[i], "-Zc++-comments")
+		 || !strcmp (argv[i], "-ZC++-comments"))
+	  fatal ("C++ comments not supported with -traditional");
+	else
+	  fatal ("Invalid option `%s'", argv[i]);
+	break;
+#endif /* EMX */
+
       case '\0': /* JF handle '-' as file name meaning stdin or stdout */
 	if (in_fname == NULL) {
 	  in_fname = "";
@@ -809,6 +834,57 @@
       make_undef (pend[i].arg);
     else if (pend[i].type == PD_ASSERTION)
       make_assertion (pend[i].arg);
+
+/* Unfortunately, tradcpp ignores C_INCLUDE_PATH.
+   shoudn't this be enabled for all archs? -- mikulas */
+#ifdef EMX
+  { /* read the appropriate environment variable and if it exists
+       replace cpp_include_defaults with the listed path. */
+    char *epath = getenv ("C_INCLUDE_PATH");
+    /* If the environment var for this language is set,
+       add to the default list of include directories.  */
+    if (epath) {
+      char *startp, *endp;
+
+      startp = endp = epath;
+      while (1) {
+        /* Handle cases like c:/usr/lib:d:/gcc/lib */
+        if ((*endp == PATH_SEPARATOR
+#if 0 /* Obsolete, now that we use semicolons as the path separator.  */
+#ifdef __MSDOS__
+	     && (endp-startp != 1 || !isalpha (*startp))
+#endif
+#endif
+	     )
+            || *endp == 0) {
+	  struct file_name_list *dirtmp;
+	  char *nstore = (char *) xmalloc (endp - startp + 2);
+	  strncpy (nstore, startp, endp-startp);
+	  if (endp == startp)
+	    strcpy (nstore, ".");
+	  else
+	    nstore[endp-startp] = '\0';
+
+	  dirtmp = (struct file_name_list *)
+	    xmalloc (sizeof (struct file_name_list));
+	  dirtmp->next = 0;		/* New one goes on the end */
+	  if (include == 0)
+	    include = dirtmp;
+	  else
+	    last_include->next = dirtmp;
+	  last_include = dirtmp;	/* Tail follows the last one */
+	  dirtmp->fname = nstore;
+	  if (strlen (dirtmp->fname) > max_include_len)
+	    max_include_len = strlen (dirtmp->fname);
+	  if (*endp == '\0')
+	    break;
+	  endp = startp = endp + 1;
+	} else
+	  endp++;
+      }
+    }
+  }
+#endif
 
   /* Unless -fnostdinc,
      tack on the standard include file dirs to the specified list */
diff -r -u -N gcc-3.0.4-orig/libiberty/getpwd.c gcc-3.0.4/libiberty/getpwd.c
--- gcc-3.0.4-orig/libiberty/getpwd.c	Tue Aug 31 21:33:12 1999
+++ gcc-3.0.4/libiberty/getpwd.c	Wed Oct 16 17:14:40 2002
@@ -20,7 +20,7 @@
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#if HAVE_SYS_STAT_H
+#if defined(HAVE_SYS_STAT_H) || defined(__EMX__)
 #include <sys/stat.h>
 #endif
 
diff -r -u -N gcc-3.0.4-orig/libiberty/pexecute.c gcc-3.0.4/libiberty/pexecute.c
--- gcc-3.0.4-orig/libiberty/pexecute.c	Fri Dec  8 04:00:26 2000
+++ gcc-3.0.4/libiberty/pexecute.c	Wed Oct 16 17:14:40 2002
@@ -45,6 +45,10 @@
 #include <sys/wait.h>
 #endif
 
+#ifdef __EMX__
+#define OS2
+#endif
+
 #include "libiberty.h"
 #include "safe-ctype.h"
 
@@ -470,9 +474,9 @@
 
 #ifdef OS2
 
-/* ??? Does OS2 have process.h?  */
-extern int spawnv ();
-extern int spawnvp ();
+#include <process.h>
+#include <io.h>
+#include <fcntl.h>
 
 int
 pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
@@ -484,11 +488,71 @@
      int flags;
 {
   int pid;
+  int pdes[2], org_stdin, org_stdout;
+  int input_desc, output_desc;
+  int retries, sleep_interval;
+
+  /* Pipe waiting from last process, to be used as input for the next one.
+     Value is STDIN_FILE_NO if no pipe is waiting
+     (i.e. the next command is the first of a group).  */
+  static int last_pipe_input;
+
+  /* If this is the first process, initialize.  */
+  if (flags & PEXECUTE_FIRST)
+    last_pipe_input = STDIN_FILE_NO;
+
+  input_desc = last_pipe_input;
+
+  /* If this isn't the last process, make a pipe for its output,
+     and record it as waiting to be the input to the next process.  */
+  if (! (flags & PEXECUTE_LAST))
+    {
+      if (pipe (pdes) < 0)
+	{
+	  *errmsg_fmt = "pipe";
+	  *errmsg_arg = NULL;
+	  return -1;
+	}
+      output_desc = pdes[WRITE_PORT];
+      last_pipe_input = pdes[READ_PORT];
+      setmode(output_desc, O_BINARY);
+      setmode(last_pipe_input, O_BINARY);
+    }
+  else
+    {
+      /* Last process.  */
+      output_desc = STDOUT_FILE_NO;
+      last_pipe_input = STDIN_FILE_NO;
+    }
+
+  if (input_desc != STDIN_FILE_NO)
+    {
+      org_stdin = dup (STDIN_FILE_NO);
+      dup2 (input_desc, STDIN_FILE_NO);
+      close (input_desc); 
+    }
+
+  if (output_desc != STDOUT_FILE_NO)
+    {
+      org_stdout = dup (STDOUT_FILE_NO);
+      dup2 (output_desc, STDOUT_FILE_NO);
+      close (output_desc);
+    }
+
+  pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_NOWAIT, program, argv);
+
+  if (input_desc != STDIN_FILE_NO)
+    {
+      dup2 (org_stdin, STDIN_FILE_NO);
+      close (org_stdin);
+    }
+
+  if (output_desc != STDOUT_FILE_NO)
+    {
+      dup2 (org_stdout, STDOUT_FILE_NO);
+      close (org_stdout);
+    }
 
-  if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
-    abort ();
-  /* ??? Presumably 1 == _P_NOWAIT.  */
-  pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv);
   if (pid == -1)
     {
       *errmsg_fmt = install_error_msg;
diff -r -u -N gcc-3.0.4-orig/libiberty/strerror.c gcc-3.0.4/libiberty/strerror.c
--- gcc-3.0.4-orig/libiberty/strerror.c	Tue Jun 12 06:05:08 2001
+++ gcc-3.0.4/libiberty/strerror.c	Wed Oct 16 17:14:40 2002
@@ -467,8 +467,10 @@
 
 #else
 
+#ifndef __EMX__
 extern int sys_nerr;
 extern char *sys_errlist[];
+#endif
 
 #endif
 
diff -r -u -N gcc-3.0.4-orig/mkinstalldirs gcc-3.0.4/mkinstalldirs
--- gcc-3.0.4-orig/mkinstalldirs	Fri Apr  3 17:22:04 1998
+++ gcc-3.0.4/mkinstalldirs	Wed Oct 16 17:14:40 2002
@@ -8,6 +8,11 @@
 errstatus=0
 
 for file in ${1+"$@"} ; do 
+   if test -n "$OS2_SHELL" ; then
+   	mkdir -p "$file"
+	continue
+   fi
+
    set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
    shift
 
