#! /bin/sh -e

# DP: There are two exception mechanisms to choose from: zero-cost and
# DP: setjump/longjump.  The Ada run-time library uses either of them
# DP: but not both.  Build both versions of the run-time library.

# This patch changes the way the upstream Makefiles build the run-time
# library.  Before the patch: libada/Makefile calls gcc/ada/Makefile,
# which builds the "rts" subdirectory containing symbolic links to
# most source files, and modified copies of a few source files (to
# take target dependencies into account, and also to select the
# exception handling mechanism in system.ads).  Then, gcc/ada/Makefile
# calls itself recursively but in the "rts" subdirectory and builds
# libgnat.a and libgnarl.a (and a couple other libraries:
# libgccprefix.a, libgmem.a).  Upon return from this recursive call,
# it deletes the source and object files from "rts", reconstructs the
# source files, and builds libgnat.so and libgnarl.so by calling
# itself recursively a second time in the "rts" directory.

# Furthermore, gcc/ada/Makefile disables parallel makes, so building
# the static and then shared versions of the RTS is entirely
# sequential even on SMP systems.

# As a consequence of the above, building the SJLJ version of the
# library would overwrite the ZCX version.  Thus it is necessary to
# manually save the previous version of the library before building the
# second one.

# After the patch: libada/Makefile calls gcc/ada/Makefile, which
# builds the source directory (named gnatlib-sources instead of rts),
# containing the symbolic links and target-dependent files.

# In a second step, libada/Makefile calls gcc/ada/Makefile again to
# build the targets gnatlib-shared-zcx, gnatlib-static-zcx and
# gnatlib-static-sjlj (we could also build gnatlib-shared-sjlj, but
# that triggers compiler errors on PowerPC).

# Each of these three targets copies the source directory "rts" into a
# new directory named rts-shared-zcx, rts-static-zcx or
# rts-static-sjlj.  In the new directory, they change the value of
# System.ZCX_By_Default, and then they call gcc/ada/Makefile
# recursively in the new directory to build the library.

# gcc/ada/Makefile.in has a .NOTPARALLEL directive preventing it from
# launching commands in parallel.  However, libada/Makefile has no
# such directive and can invoke up to three instances of
# gcc/ada/Makefile.in in parallel.  This is okay because each of them
# runs in a different directory.

# This patch also updates libgnat{vsn,prj}/Makefile and
# gnattools/Makefile to look for the shared ZCX version of the library
# in the appropriate directory, rather than just "rts", and updates
# the "make install" and binary targets as well.

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0


Index: src/libada/Makefile.in
===================================================================
--- src.orig/libada/Makefile.in
+++ src/libada/Makefile.in
@@ -16,7 +16,8 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 # Default target; must be first.
-all: gnatlib
+GNATLIB = gnatlib-static-zcx gnatlib-static-sjlj gnatlib-shared-zcx
+all: $(GNATLIB)
 
 # Standard autoconf-set variables.
 SHELL = @SHELL@
@@ -78,30 +79,38 @@
         "CFLAGS=$(CFLAGS) $(WARN_CFLAGS)"
 
 # Rules to build gnatlib.
-.PHONY: gnatlib gnatlib-plain gnatlib-sjlj gnatlib-zcx gnatlib-shared
-gnatlib: @default_gnatlib_target@
+.PHONY: $(GNATLIB)
 
-gnatlib-plain: $(GCC_DIR)/ada/Makefile
-	test -f stamp-libada || \
+$(GCC_DIR)/ada/gnatlib-sources-sjlj/a-except.ads:
 	$(MAKE) -C $(GCC_DIR)/ada $(FLAGS_TO_PASS) \
 	  GNATLIBFLAGS="$(GNATLIBFLAGS)" \
 	  GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
 	  TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
 	  THREAD_KIND="$(THREAD_KIND)" \
 	  TRACE="$(TRACE)" \
-	  gnatlib \
-	&& touch stamp-libada
+	  EH_MECHANISM="" \
+	  gnatlib-sources-sjlj/a-except.ads
 
-gnatlib-sjlj gnatlib-zcx gnatlib-shared: $(GCC_DIR)/ada/Makefile
-	test -f stamp-libada || \
+$(GCC_DIR)/ada/gnatlib-sources-zcx/a-except.ads:
 	$(MAKE) -C $(GCC_DIR)/ada $(FLAGS_TO_PASS) \
 	  GNATLIBFLAGS="$(GNATLIBFLAGS)" \
 	  GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
 	  TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
 	  THREAD_KIND="$(THREAD_KIND)" \
 	  TRACE="$(TRACE)" \
-	  $@ \
-	&& touch stamp-libada
+	  EH_MECHANISM="-gcc" \
+	  gnatlib-sources-zcx/a-except.ads
+
+$(GNATLIB): $(GCC_DIR)/ada/Makefile \
+$(GCC_DIR)/ada/gnatlib-sources-zcx/a-except.ads \
+$(GCC_DIR)/ada/gnatlib-sources-sjlj/a-except.ads
+	$(MAKE) -C $(GCC_DIR)/ada $(FLAGS_TO_PASS) \
+	  GNATLIBFLAGS="$(GNATLIBFLAGS)" \
+	  GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
+	  TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
+	  THREAD_KIND="$(THREAD_KIND)" \
+	  TRACE="$(TRACE)" \
+	  $@
 
 # Check uninstalled version.
 check:
Index: src/libada/configure
===================================================================
--- src.orig/libada/configure
+++ src/libada/configure
@@ -1552,17 +1552,6 @@
   *) x_ada_cflags= ;;
 esac
 
-
-# Determine what to build for 'gnatlib'
-if test $build = $target \
-   && test ${enable_shared} = yes ; then
-  # Note that build=target is almost certainly the wrong test; FIXME
-  default_gnatlib_target="gnatlib-shared"
-else
-  default_gnatlib_target="gnatlib-plain"
-fi
-
-
 # Output: create a Makefile.
           ac_config_files="$ac_config_files Makefile"
 
@@ -2222,7 +2211,6 @@
 s,@enable_shared@,$enable_shared,;t t
 s,@LN_S@,$LN_S,;t t
 s,@x_ada_cflags@,$x_ada_cflags,;t t
-s,@default_gnatlib_target@,$default_gnatlib_target,;t t
 s,@LIBOBJS@,$LIBOBJS,;t t
 s,@LTLIBOBJS@,$LTLIBOBJS,;t t
 CEOF
Index: src/gcc/ada/Makefile.in
===================================================================
--- src.orig/gcc/ada/Makefile.in
+++ src/gcc/ada/Makefile.in
@@ -1324,6 +1324,50 @@
   LIBRARY_VERSION := $(LIB_VERSION)
 endif
 
+ifeq ($(strip $(filter-out mips linux%,$(arch) $(osys))),)
+  LIBGNAT_TARGET_PAIRS = \
+  a-intnam.ads<a-intnam-linux.ads \
+  g-soccon.ads<g-soccon-linux-mips.ads \
+  s-inmaop.adb<s-inmaop-posix.adb \
+  s-intman.adb<s-intman-posix.adb \
+  s-osinte.adb<s-osinte-posix.adb \
+  s-osinte.ads<s-osinte-linux.ads \
+  s-osprim.adb<s-osprim-posix.adb \
+  s-taprop.adb<s-taprop-linux.adb \
+  s-taspri.ads<s-taspri-posix.ads \
+  s-tpopsp.adb<s-tpopsp-posix-foreign.adb \
+  system.ads<system-linux-mips.ads
+
+  EH_MECHANISM=-gcc
+  THREADSLIB = -lpthread
+  GNATLIB_SHARED = gnatlib-shared-dual
+  GMEM_LIB = gmemlib
+  PREFIX_OBJS = $(PREFIX_REAL_OBJS)
+  LIBRARY_VERSION := $(LIB_VERSION)
+endif
+
+ifeq ($(strip $(filter-out mipsel linux%,$(arch) $(osys))),)
+  LIBGNAT_TARGET_PAIRS = \
+  a-intnam.ads<a-intnam-linux.ads \
+  g-soccon.ads<g-soccon-linux-mips.ads \
+  s-inmaop.adb<s-inmaop-posix.adb \
+  s-intman.adb<s-intman-posix.adb \
+  s-osinte.adb<s-osinte-posix.adb \
+  s-osinte.ads<s-osinte-linux.ads \
+  s-osprim.adb<s-osprim-posix.adb \
+  s-taprop.adb<s-taprop-linux.adb \
+  s-taspri.ads<s-taspri-posix.ads \
+  s-tpopsp.adb<s-tpopsp-posix-foreign.adb \
+  system.ads<system-linux-mipsel.ads
+
+  EH_MECHANISM=-gcc
+  THREADSLIB = -lpthread
+  GNATLIB_SHARED = gnatlib-shared-dual
+  GMEM_LIB = gmemlib
+  PREFIX_OBJS = $(PREFIX_REAL_OBJS)
+  LIBRARY_VERSION := $(LIB_VERSION)
+endif
+
 ifeq ($(strip $(filter-out sparc% linux%,$(arch) $(osys))),)
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads<a-intnam-linux.ads \
@@ -1563,53 +1607,79 @@
  a-[a-o]*.adb a-[p-z]*.adb a-[a-o]*.ads a-[p-z]*.ads g-*.ad? i-*.ad? \
  s-[a-o]*.adb s-[p-z]*.adb s-[a-o]*.ads s-[p-z]*.ads  
 
-../stamp-gnatlib:
-	@if [ ! -f stamp-gnatlib ] ; \
-	then \
-	  $(ECHO) You must first build the GNAT library: make gnatlib; \
-	  false; \
-	else \
-	  true; \
-	fi
+libgnat = libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
+libgnat-sjlj = libgnat$(hyphen)sjlj$(hyphen)$(LIBRARY_VERSION)$(soext)
 
-install-gnatlib: ../stamp-gnatlib
+install-gnatlib: rts-static-zcx/libgnat$(arext) rts-static-sjlj/libgnat$(arext)
+install-gnatlib: rts-shared-zcx/$(libgnat)
 #	Create the directory before deleting it, in case the directory is
 #	a list of directories (as it may be on VMS). This ensures we are
 #	deleting the right one.
-	-$(MKDIR) $(DESTDIR)$(ADA_RTL_OBJ_DIR)
-	-$(MKDIR) $(DESTDIR)$(ADA_INCLUDE_DIR)
-	$(RMDIR) $(DESTDIR)$(ADA_RTL_OBJ_DIR)
-	$(RMDIR) $(DESTDIR)$(ADA_INCLUDE_DIR)
-	-$(MKDIR) $(DESTDIR)$(ADA_RTL_OBJ_DIR)
-	-$(MKDIR) $(DESTDIR)$(ADA_INCLUDE_DIR)
-	for file in rts/*.ali; do \
-	    $(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
+	-$(MKDIR) $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR)
+	$(RMDIR) $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR)
+	$(RMDIR) $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR)
+
+	-$(MKDIR) $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR)
+	$(RMDIR) $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR)
+	$(RMDIR) $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR)
+	-$(MKDIR) $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR)
+
+	for file in rts-shared-zcx/*.ali; do \
+	$(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR); \
+	done
+	for file in rts-static-sjlj/*.ali; do \
+	$(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR); \
+	done
+
+	-cd rts-static-zcx; for file in *$(arext);do \
+	$(INSTALL_DATA) $$file $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR); \
+	$(RANLIB_FOR_TARGET) $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR)/$$file; \
 	done
-	-cd rts; for file in *$(arext);do \
-	    $(INSTALL_DATA) $$file $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
-	    $(RANLIB_FOR_TARGET) $(DESTDIR)$(ADA_RTL_OBJ_DIR)/$$file; \
+	-cd rts-static-sjlj; for file in *$(arext);do \
+	$(INSTALL_DATA) $$file $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR); \
+	$(RANLIB_FOR_TARGET) $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR)/$$file; \
 	done
+
+	-$(foreach file, $(EXTRA_ADALIB_FILES), \
+	    $(INSTALL_DATA_DATE) rts-static-zcx/$(file) $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR) && \
+	) true
 	-$(foreach file, $(EXTRA_ADALIB_FILES), \
-	    $(INSTALL_DATA_DATE) rts/$(file) $(DESTDIR)$(ADA_RTL_OBJ_DIR) && \
+	    $(INSTALL_DATA_DATE) rts-static-sjlj/$(file) $(DESTDIR)$(ADA_SJLJ_RTL_OBJ_DIR) && \
 	) true
+
 #     Install the shared libraries, if any, using $(INSTALL) instead
 #     of $(INSTALL_DATA). The latter may force a mode inappropriate
 #     for shared libraries on some targets, e.g. on HP-UX where the x
 #     permission is required.
 	for file in gnat gnarl; do \
-	   if [ -f rts/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext) ]; then \
-	      $(INSTALL) rts/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
-			 $(DESTDIR)$(ADA_RTL_OBJ_DIR); \
+	   if [ -f rts-shared-zcx/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext).1 ]; then \
+	      $(INSTALL) rts-shared-zcx/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
+			 $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR); \
 	      $(LN_S) lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
-	      $(DESTDIR)$(ADA_RTL_OBJ_DIR)/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext); \
+	      $(DESTDIR)$(ADA_NATIVE_RTL_OBJ_DIR)/lib$${file}$(hyphen)$(LIBRARY_VERSION)$(soext); \
 	   fi; \
 	done
+
 # This copy must be done preserving the date on the original file.
-	for file in rts/*.ad?; do \
-	    $(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_INCLUDE_DIR); \
+	for file in rts-shared-zcx/*.adb rts-shared-zcx/*.ads; do \
+	    $(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR); \
+	done
+	$(CHMOD) u=rw,go=r $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR)/*.adb
+	$(CHMOD) u=rw,go=r $(DESTDIR)$(ADA_NATIVE_INCLUDE_DIR)/*.ads
+	for file in rts-static-sjlj/*.adb rts-static-sjlj/*.ads; do \
+	    $(INSTALL_DATA_DATE) $$file $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR); \
 	done
-	cd $(DESTDIR)$(ADA_INCLUDE_DIR); $(CHMOD) a-wx *.adb
-	cd $(DESTDIR)$(ADA_INCLUDE_DIR); $(CHMOD) a-wx *.ads
+	$(CHMOD) u=rw,go=r $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR)/*.adb
+	$(CHMOD) u=rw,go=r $(DESTDIR)$(ADA_SJLJ_INCLUDE_DIR)/*.ads
+
+	(cd $(DESTDIR)$(libsubdir); \
+	ln -s rts-native/adainclude adainclude; \
+	ln -s rts-native/adalib     adalib;)
 
 # NOTE: The $(foreach ...) commands assume ";" is the valid separator between
 #       successive target commands. Although the Gnu make documentation
@@ -1620,23 +1690,30 @@
 
 # GNULLI Begin ###########################################################
 
-../stamp-gnatlib1: Makefile
-	$(RMDIR) rts
-	$(MKDIR) rts
-	$(CHMOD) u+w rts
+replace_zcx_by_default=\
+'s/ZCX_By_Default.*/ZCX_By_Default            : constant Boolean := $(zcx_by_default);/'
+
+gnatlib-sources-zcx/a-except.ads: dir=$(dir $@)
+gnatlib-sources-zcx/a-except.ads: zcx_by_default=True
+
+gnatlib-sources-sjlj/a-except.ads: dir=$(dir $@)
+gnatlib-sources-sjlj/a-except.ads: zcx_by_default=False
+
+gnatlib-sources-zcx/a-except.ads gnatlib-sources-sjlj/a-except.ads:
+	$(MKDIR) $(dir)
+	$(CHMOD) u+w $(dir)
 # Copy target independent sources
 	$(foreach f,$(ADA_INCLUDE_SRCS) $(LIBGNAT_SRCS), \
-	  $(LN_S) $(fsrcpfx)$(f) rts ;) true
+	  $(LN_S) $(fsrcpfx)$(f) $(dir) ;) true
 # Remove files to be replaced by target dependent sources
 	$(RM) $(foreach PAIR,$(LIBGNAT_TARGET_PAIRS), \
-	                rts/$(word 1,$(subst <, ,$(PAIR))))
-	$(RM) rts/*-*-*.ads rts/*-*-*.adb
+	                $(dir)/$(word 1,$(subst <, ,$(PAIR))))
+	$(RM) $(dir)/*-*-*.ads $(dir)/*-*-*.adb
 # Copy new target dependent sources
 	$(foreach PAIR,$(LIBGNAT_TARGET_PAIRS), \
 	          $(LN_S) $(fsrcpfx)$(word 2,$(subst <, ,$(PAIR))) \
-	                rts/$(word 1,$(subst <, ,$(PAIR)));)
-	$(RM) ../stamp-gnatlib
-	touch ../stamp-gnatlib1
+	                $(dir)/$(word 1,$(subst <, ,$(PAIR)));)
+	sed -e $(replace_zcx_by_default) $(dir)/system.ads > $(dir)/s.ads
 
 # GNULLI End #############################################################
 
@@ -1646,57 +1723,60 @@
 # Example: cd rts; ar rc libfoo.a $(LONG_LIST_OF_OBJS)
 # is guaranteed to overflow the buffer.
 
-gnatlib: ../stamp-gnatlib1
-	$(MAKE) -C rts \
+%/libgnat$(arext): build_dir = $(dir $@)
+%/libgnat$(arext): libgnarl = $(subst libgnat,libgnarl,$@)
+%/libgnat$(arext): libgnala = $(subst libgnat,libgnala,$@)
+%/libgnat$(arext): %
+	$(MAKE) -C $(build_dir) \
 		CC="`echo \"$(GCC_FOR_TARGET)\" \
 		| sed -e 's,^\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'`" \
-	        INCLUDES="$(INCLUDES_FOR_SUBDIR) -I./../.." \
-                CFLAGS="$(GNATLIBCFLAGS_FOR_C)" \
-	        FORCE_DEBUG_ADAFLAGS="$(FORCE_DEBUG_ADAFLAGS)" \
+		INCLUDES="$(INCLUDES_FOR_SUBDIR) -I./../.." \
+		CFLAGS="$(GNATLIBCFLAGS_FOR_C)" \
 		srcdir=$(fsrcdir) \
-	        -f ../Makefile $(LIBGNAT_OBJS)
-	$(MAKE) -C rts \
+		-f ../Makefile $(LIBGNAT_OBJS)
+	$(MAKE) -C $(build_dir) \
 		CC="`echo \"$(GCC_FOR_TARGET)\" \
 		| sed -e 's,^\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'`" \
-	        ADA_INCLUDES="" \
-                CFLAGS="$(GNATLIBCFLAGS)" \
-	        ADAFLAGS="$(GNATLIBFLAGS)" \
-	        FORCE_DEBUG_ADAFLAGS="$(FORCE_DEBUG_ADAFLAGS)" \
+		ADA_INCLUDES="" \
+		CFLAGS="$(GNATLIBCFLAGS)" \
+		ADAFLAGS="$(GNATLIBFLAGS)" \
 		srcdir=$(fsrcdir) \
-	        -f ../Makefile \
-	        $(GNATRTL_OBJS)
-	$(RM) rts/libgnat$(arext) rts/libgnarl$(arext)
-	$(AR_FOR_TARGET) $(AR_FLAGS) rts/libgnat$(arext) \
-	   $(addprefix rts/,$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) g-trasym.o convert_addresses.o)
+		-f ../Makefile \
+		$(GNATRTL_OBJS)
+	$(RM) $@ $(libgnarl)
+	$(AR_FOR_TARGET) $(AR_FLAGS) $@ \
+	   $(addprefix $(build_dir),$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) g-trasym.o convert_addresses.o)
         ifneq ($(PREFIX_OBJS),)
-		$(AR_FOR_TARGET) $(AR_FLAGS) rts/libgccprefix$(arext) \
+		$(AR_FOR_TARGET) $(AR_FLAGS) $(build_dir)libgccprefix$(arext) \
 		  $(PREFIX_OBJS);
-		$(RANLIB_FOR_TARGET) rts/libgccprefix$(arext)
+		$(RANLIB_FOR_TARGET) $(build_dir)libgccprefix$(arext)
         endif
-	$(RANLIB_FOR_TARGET) rts/libgnat$(arext)
-	$(AR_FOR_TARGET) $(AR_FLAGS) rts/libgnarl$(arext) \
-	   $(addprefix rts/,$(GNATRTL_TASKING_OBJS))
-	$(RANLIB_FOR_TARGET) rts/libgnarl$(arext)
-	$(AR_FOR_TARGET) $(AR_FLAGS) rts/libgnala$(arext) \
-	   $(addprefix rts/,$(GNATRTL_LINEARALGEBRA_OBJS))
-	$(RANLIB_FOR_TARGET) rts/libgnala$(arext)
+	$(RANLIB_FOR_TARGET) $@
+	$(AR_FOR_TARGET) $(AR_FLAGS) $(libgnarl) \
+	   $(addprefix $(build_dir),$(GNATRTL_TASKING_OBJS))
+	$(RANLIB_FOR_TARGET) $(libgnarl)
+	$(AR_FOR_TARGET) $(AR_FLAGS) $(libgnala) \
+	   $(addprefix $(build_dir),$(GNATRTL_LINEARALGEBRA_OBJS))
+	$(RANLIB_FOR_TARGET) $(libgnala)
         ifeq ($(GMEM_LIB),gmemlib)
-		$(AR_FOR_TARGET) $(AR_FLAGS) rts/libgmem$(arext) \
-		  rts/memtrack.o
-		$(RANLIB_FOR_TARGET) rts/libgmem$(arext)
+		$(AR_FOR_TARGET) $(AR_FLAGS) $(build_dir)libgmem$(arext) \
+		  $(build_dir)memtrack.o
+		$(RANLIB_FOR_TARGET) $(build_dir)libgmem$(arext)
         endif
-	touch ../stamp-gnatlib
 
 # Warning: this target assumes that LIBRARY_VERSION has been set correctly.
-gnatlib-shared-default: ../stamp-gnatlib1
-	$(MAKE) -C rts \
+%/$(libgnat) %/$(libgnat-sjlj): build_dir = $(dir $@)
+%/$(libgnat) %/$(libgnat-sjlj): libgnarl = $(notdir $(subst libgnat,libgnarl,$@))
+%/$(libgnat) %/$(libgnat-sjlj): libgnala = $(notdir $(subst libgnat,libgnala,$@))
+%/$(libgnat) %/$(libgnat-sjlj): %
+	$(MAKE) -C $(build_dir) \
 		CC="`echo \"$(GCC_FOR_TARGET)\" \
 		| sed -e 's,^\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'`" \
 	        INCLUDES="$(INCLUDES_FOR_SUBDIR) -I./../.." \
                 CFLAGS="$(GNATLIBCFLAGS_FOR_C)" \
 		srcdir=$(fsrcdir) \
 	        -f ../Makefile $(LIBGNAT_OBJS)
-	$(MAKE) -C rts \
+	$(MAKE) -C $(build_dir) \
 		CC="`echo \"$(GCC_FOR_TARGET)\" \
 		| sed -e 's,^\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'`" \
 	        ADA_INCLUDES="" \
@@ -1706,157 +1786,75 @@
 		srcdir=$(fsrcdir) \
 	        -f ../Makefile \
 	        $(GNATRTL_OBJS)
-	$(RM) rts/libgna*$(soext) rts/libgna*$(soext).1
-	cd rts; ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
+	$(RM) $(build_dir)/libgna*$(soext) $(build_dir)/libgna*$(soext).1
+	cd $(build_dir); ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
 		$(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
+		-o $(notdir $@).1 \
 		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
 		g-trasym.o convert_addresses.o \
-		$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
+		$(SO_OPTS)$(notdir $@).1 \
 		$(MISCLIB) -lm
-	cd rts; ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
+	cd $(build_dir); $(LN_S) $(notdir $@).1 $(notdir $@)
+	cd $(build_dir); ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
 		$(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
+		-o $(libgnarl).1 \
 		$(GNATRTL_TASKING_OBJS) \
-		$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext).1 \
+		$(SO_OPTS)$(libgnarl).1 \
 		$(THREADSLIB)
-	cd rts; for lib in gnat gnarl; do \
-		l=lib$${lib}$(hyphen)$(LIBRARY_VERSION)$(soext); \
-		$(LN_S) $$l.1 $$l; \
-	done
-# Delete the object files, lest they be linked statically into the tools
-# executables.  Only the .ali, .a and .so files must remain.
-	rm -f rts/*.o
-	$(CHMOD) a-wx rts/*.ali
-
-gnatlib-shared-dual:
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib
-	$(RM) rts/*.o rts/*.ali
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib-shared-default
-
-gnatlib-shared-dual-win32:
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib
-	$(RM) rts/*.o rts/*.ali
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib-shared-win32
-
-# ??? we need to add the option to support auto-import of arrays/records to
-# the GNATLIBFLAGS when this will be supported by GNAT. At this point we will
-# use the gnatlib-shared-dual-win32 target to build the GNAT runtimes on
-# Windows.
-gnatlib-shared-win32:
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib
-	$(RM) rts/libgna*$(soext)
-	cd rts; ../../xgcc -B../../ -shared $(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
-		$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) $(MISCLIB)
-	cd rts; ../../xgcc -B../../ -shared $(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		$(GNATRTL_TASKING_OBJS) \
-		$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		$(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
-
-gnatlib-shared-darwin:
-	$(MAKE) $(FLAGS_TO_PASS) \
-	     GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS) \
-	                    -fno-common" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-	     gnatlib
-	$(RM) rts/libgnat$(soext) rts/libgnarl$(soext)
-	cd rts; ../../xgcc -B../../ -dynamiclib $(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
-		$(SO_OPTS) \
-		$(MISCLIB) -lm
-	cd rts; ../../xgcc -B../../ -dynamiclib $(TARGET_LIBGCC2_CFLAGS) \
-		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		$(GNATRTL_TASKING_OBJS) \
-		$(SO_OPTS) \
-		$(THREADSLIB) -Wl,libgnat$(hyphen)$(LIBRARY_VERSION)$(soext)
-	cd rts; $(LN_S) libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		libgnat$(soext)
-	cd rts; $(LN_S) libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
-		libgnarl$(soext)
-
-gnatlib-shared-vms:
-	$(MAKE) $(FLAGS_TO_PASS) \
-             GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
-	     THREAD_KIND="$(THREAD_KIND)" \
-             gnatlib
-	$(RM) rts/libgna*$(soext)
-	cd rts && echo "case_sensitive=yes" > SYMVEC_$$$$.opt && \
-	objdump --syms $(LIBGNAT_OBJS) $(GNATRTL_NONTASKING_OBJS) | \
-	$(SHLIB_SYMVEC) >> SYMVEC_$$$$.opt && \
-	echo "case_sensitive=NO" >> SYMVEC_$$$$.opt && \
-	../../xgcc -g -B../../ -shared -shared-libgcc \
-	   -o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) libgnat.a \
-	   sys\$$library:trace.exe \
-	   --for-linker=/noinform \
-	   --for-linker=SYMVEC_$$$$.opt \
-	   --for-linker=gsmatch=equal,$(GSMATCH_VERSION)
-	cd rts && echo "case_sensitive=yes" > SYMVEC_$$$$.opt && \
-	objdump --syms $(GNATRTL_TASKING_OBJS) | \
-	$(SHLIB_SYMVEC) >> SYMVEC_$$$$.opt && \
-	echo "case_sensitive=NO" >> SYMVEC_$$$$.opt && \
-	../../xgcc -g -B../../ -shared -shared-libgcc \
-	   -o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
-	   libgnarl.a libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
-	   sys\$$library:trace.exe \
-	   --for-linker=/noinform \
-	   --for-linker=SYMVEC_$$$$.opt \
-	   --for-linker=gsmatch=equal,$(GSMATCH_VERSION)
+	cd $(build_dir); $(LN_S) $(libgnarl).1 $(libgnarl)
+# TODO: enable building the shared libgnala
+ifeq (libgnala-shared-enabled,yes)
+	cd $(build_dir); ../../xgcc -B../../ -shared $(GNATLIBCFLAGS) \
+		$(TARGET_LIBGCC2_CFLAGS) \
+		-o $(libgnala).1 \
+		$(GNATRTL_LINEARALGEBRA_OBJS) \
+		$(SO_OPTS)$(libgnala).1
+	cd $(build_dir); $(LN_S) $(libgnala).1 $(libgnala)
+endif
 
-gnatlib-shared:
+gnatlib-shared-dual: gnatlib-static-zcx gnatlib-static-sjlj gnatlib-shared-zcx
+
+gnatlib-shared-zcx: rts = $(subst gnatlib,rts,$@)
+gnatlib-shared-zcx: gnatlib-sources-zcx/a-except.ads
+	if [ ! -d $(rts) ] ; then \
+	    cp -a gnatlib-sources-zcx $(rts); \
+	    $(MV) $(rts)/s.ads $(rts)/system.ads; \
+	fi
 	$(MAKE) $(FLAGS_TO_PASS) \
+	     EH_MECHANISM="-gcc" \
              GNATLIBFLAGS="$(GNATLIBFLAGS)" \
 	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
 	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
-             $(GNATLIB_SHARED)
+             $(rts)/$(libgnat)
 
-gnatlib-sjlj:
-	$(MAKE) $(FLAGS_TO_PASS) EH_MECHANISM="" ../stamp-gnatlib1
-	sed -e 's/ZCX_By_Default.*/ZCX_By_Default            : constant Boolean := False;/' rts/system.ads > rts/s.ads
-	$(MV) rts/s.ads rts/system.ads
+gnatlib-static-sjlj: rts = $(subst gnatlib,rts,$@)
+gnatlib-static-sjlj: gnatlib-sources-sjlj/a-except.ads
+	if [ ! -d $(rts) ] ; then \
+	    cp -a gnatlib-sources-sjlj $(rts); \
+	    $(MV) $(rts)/s.ads $(rts)/system.ads; \
+	fi
 	$(MAKE) $(FLAGS_TO_PASS) \
 	     EH_MECHANISM="" \
 	     GNATLIBFLAGS="$(GNATLIBFLAGS)" \
 	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
-	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" gnatlib
+	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
+	     $(rts)/libgnat$(arext)
 
-gnatlib-zcx:
-	$(MAKE) $(FLAGS_TO_PASS) EH_MECHANISM="-gcc" ../stamp-gnatlib1
-	sed -e 's/ZCX_By_Default.*/ZCX_By_Default            : constant Boolean := True;/' rts/system.ads > rts/s.ads
-	$(MV) rts/s.ads rts/system.ads
+gnatlib-static-zcx: rts = $(subst gnatlib,rts,$@)
+gnatlib-static-zcx: gnatlib-sources-zcx/a-except.ads
+	if [ ! -d $(rts) ] ; then \
+	    cp -a gnatlib-sources-zcx $(rts); \
+	    $(MV) $(rts)/s.ads $(rts)/system.ads; \
+	fi
 	$(MAKE) $(FLAGS_TO_PASS) \
 	     EH_MECHANISM="-gcc" \
 	     GNATLIBFLAGS="$(GNATLIBFLAGS)" \
 	     GNATLIBCFLAGS="$(GNATLIBCFLAGS)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
-	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" gnatlib
+	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
+	     $(rts)/libgnat$(arext)
 
 # .s files for cross-building
 gnat-cross: force
@@ -1864,6 +1862,10 @@
 
 ADA_INCLUDE_DIR = $(libsubdir)/adainclude
 ADA_RTL_OBJ_DIR = $(libsubdir)/adalib
+ADA_NATIVE_INCLUDE_DIR = $(libsubdir)/rts-native/adainclude
+ADA_NATIVE_RTL_OBJ_DIR = $(libsubdir)/rts-native/adalib
+ADA_SJLJ_INCLUDE_DIR = $(libsubdir)/rts-sjlj/adainclude
+ADA_SJLJ_RTL_OBJ_DIR = $(libsubdir)/rts-sjlj/adalib
 
 # force no sibling call optimization on s-traceb.o so the number of stack
 # frames to be skipped when computing a call chain is not modified by
Index: src/gnattools/Makefile.in
===================================================================
--- src.orig/gnattools/Makefile.in
+++ src/gnattools/Makefile.in
@@ -34,12 +34,13 @@
 LN_S=@LN_S@
 target_noncanonical=@target_noncanonical@
 
+RTS=../gcc/ada/rts-shared-zcx
 CFLAGS=-O2 -Wall
 ADA_CFLAGS=-O2 -gnatn
-ADA_INCLUDES=-nostdinc -I- -I. -I../gcc/ada/rts -I../libgnatvsn -I../libgnatprj
+ADA_INCLUDES=-nostdinc -I- -I. -I$(RTS) -I../libgnatvsn -I../libgnatprj
 LIB_VERSION=$(strip $(shell grep ' Library_Version :' \
               ../libgnatvsn/gnatvsn.ads | sed -e 's/.*"\(.*\)".*/\1/'))
-ADA_LIBS := -L../gcc/ada/rts -lgnat-$(LIB_VERSION)
+ADA_LIBS := -L$(RTS) -lgnat-$(LIB_VERSION)
 ADA_LIBS += -L../libgnatvsn -lgnatvsn
 ADA_LIBS += -L../libgnatprj -lgnatprj
 
@@ -109,6 +110,7 @@
 
 .PHONY: gnattools gnattools-native gnattools-cross regnattools
 gnattools: @default_gnattools_target@
+	(cd $(RTS); if [ -d obj ]; then mv obj/* .; rmdir obj; fi)
 
 BODIES := $(foreach f,$(OBJECTS),$(wildcard $(patsubst %.o,@srcdir@/../gcc/ada/%.adb,$(f))))
 SPECS  := $(foreach f,$(OBJECTS),$(wildcard $(patsubst %.o,@srcdir@/../gcc/ada/%.ads,$(f))))
@@ -119,9 +121,12 @@
 	for file in $(BODIES) $(SPECS); do \
 	   $(LN_S) -f $$file .; \
 	done
+# Move the RTS object files away lest they be linked statically into the
+# tools.  Only the .ali, .a and .so files must remain.
+	(cd $(RTS); mkdir obj; mv *.o obj; chmod a-wx *.ali)
 	touch $@
 
-gnattools-native: ../gcc/ada/rts/libgnat-$(LIB_VERSION).so
+gnattools-native: $(RTS)/libgnat-$(LIB_VERSION).so
 gnattools-native: ../libgnatvsn/libgnatvsn.so
 gnattools-native: stamp-gnattools-sources
 gnattools-native: $(TOOLS) gnatbl
@@ -137,7 +142,7 @@
 	$(GCC) -o $@ $^ \
 	   ../libgnatprj/libgnatprj.a \
 	   ../libgnatvsn/libgnatvsn.a \
-	   ../gcc/ada/rts/libgnat.a \
+	   ../gcc/ada/rts-static-zcx/libgnat.a \
 	   ../libiberty/libiberty.a
 
 gnatlink: $(GNATLINK_OBJS) b_gnatl.o
@@ -155,7 +160,7 @@
 	$(GCC) -o $@ $(ADA_CFLAGS) $^ \
 	   ../libgnatprj/libgnatprj.a \
 	   ../libgnatvsn/libgnatvsn.a \
-	   ../gcc/ada/rts/libgnat.a \
+	   ../gcc/ada/rts-static-zcx/libgnat.a \
 	   ../libiberty/libiberty.a
 
 gnatmake: $(GNATMAKE_OBJS) b_gnatm.o
Index: src/libgnatprj/Makefile.in
===================================================================
--- src.orig/libgnatprj/Makefile.in
+++ src/libgnatprj/Makefile.in
@@ -25,7 +25,8 @@
                  @srcdir@/../gcc/ada/gnatvsn.ads | \
 	         sed -e 's/.*"\(.*\)".*/\1/'))
 GCC:=../gcc/xgcc -B../gcc/
-LIBGNAT_JUST_BUILT := -nostdinc -I../gcc/ada/rts
+RTS:=../gcc/ada/rts-shared-zcx
+LIBGNAT_JUST_BUILT := -nostdinc -I$(RTS)
 LIBGNATVSN := -I../libgnatvsn
 CFLAGS := -g -O2
 ADAFLAGS := -g -O2 -gnatn
@@ -65,7 +66,7 @@
 libgnatprj.so.$(LIB_VERSION): $(addprefix obj-shared/,$(OBJECTS))
 	: # Make libgnatprj.so
 	$(GCC) -o $@ -shared -fPIC -Wl,--soname,$@ $^ \
-	   -L../gcc/ada/rts -lgnat-$(LIB_VERSION) \
+	   -L$(RTS) -lgnat-$(LIB_VERSION) \
 	   -L../libgnatvsn -lgnatvsn
 	$(LN_S) -f libgnatprj.so.$(LIB_VERSION) libgnatprj.so
 	chmod a=r obj-shared/*.ali
Index: src/libgnatvsn/Makefile.in
===================================================================
--- src.orig/libgnatvsn/Makefile.in
+++ src/libgnatvsn/Makefile.in
@@ -25,7 +25,8 @@
                  @srcdir@/../gcc/ada/gnatvsn.ads | \
 	         sed -e 's/.*"\(.*\)".*/\1/'))
 GCC:=../gcc/xgcc -B../gcc/
-LIBGNAT_JUST_BUILT := -nostdinc -I../gcc/ada/rts
+RTS:=../gcc/ada/rts-shared-zcx
+LIBGNAT_JUST_BUILT := -nostdinc -I$(RTS)
 CFLAGS := -g -O2 -gnatn
 BASEVER := $(shell cat @srcdir@/../gcc/BASE-VER)
 DEVPHASE := $(shell cat @srcdir@/../gcc/DEV-PHASE)
@@ -64,7 +65,7 @@
 libgnatvsn.so.$(LIB_VERSION): $(addprefix obj-shared/,$(OBJECTS))
 	: # Make libgnatvsn.so
 	$(GCC) -o $@ -shared -fPIC -Wl,--soname,$@ $^ \
-	   -L../gcc/ada/rts -lgnat-$(LIB_VERSION)
+	   -L$(RTS) -lgnat-$(LIB_VERSION)
 	ln -s libgnatvsn.so.$(LIB_VERSION) libgnatvsn.so
 	chmod a=r obj-shared/*.ali
 # Make the .ali files, but not the .o files, visible to the gnat tools.
Index: src/gcc/ada/Make-lang.in
===================================================================
--- src.orig/gcc/ada/Make-lang.in
+++ src/gcc/ada/Make-lang.in
@@ -62,7 +62,8 @@
 	"ADA_FOR_TARGET=$(ADA_FOR_TARGET)"	\
 	"INSTALL=$(INSTALL)" 			\
 	"INSTALL_DATA=$(INSTALL_DATA)"		\
-	"INSTALL_PROGRAM=$(INSTALL_PROGRAM)"
+	"INSTALL_PROGRAM=$(INSTALL_PROGRAM)"	\
+	"GCC_FOR_TARGET=$(GCC_FOR_TARGET)"
 
 # Say how to compile Ada programs.
 .SUFFIXES: .ada .adb .ads
Index: src/gcc/ada/system-linux-mips.ads
===================================================================
--- /dev/null
+++ src/gcc/ada/system-linux-mips.ads
@@ -0,0 +1,154 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                        GNAT RUN-TIME COMPONENTS                          --
+--                                                                          --
+--                               S Y S T E M                                --
+--                                                                          --
+--                                 S p e c                                  --
+--                          (GNU-Linux/MIPS Version)                        --
+--                                                                          --
+--          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
+-- for  more details.  You should have  received  a copy of the GNU General --
+-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
+--                                                                          --
+-- As a special exception,  if other files  instantiate  generics from this --
+-- unit, or you link  this unit with other files  to produce an executable, --
+-- this  unit  does not  by itself cause  the resulting  executable  to  be --
+-- covered  by the  GNU  General  Public  License.  This exception does not --
+-- however invalidate  any other reasons why  the executable file  might be --
+-- covered by the  GNU Public License.                                      --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+package System is
+   pragma Pure;
+   --  Note that we take advantage of the implementation permission to make
+   --  this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada
+   --  2005, this is Pure in any case (AI-362).
+
+   type Name is (SYSTEM_NAME_GNAT);
+   System_Name : constant Name := SYSTEM_NAME_GNAT;
+
+   --  System-Dependent Named Numbers
+
+   Min_Int               : constant := Long_Long_Integer'First;
+   Max_Int               : constant := Long_Long_Integer'Last;
+
+   Max_Binary_Modulus    : constant := 2 ** Long_Long_Integer'Size;
+   Max_Nonbinary_Modulus : constant := Integer'Last;
+
+   Max_Base_Digits       : constant := Long_Long_Float'Digits;
+   Max_Digits            : constant := Long_Long_Float'Digits;
+
+   Max_Mantissa          : constant := 63;
+   Fine_Delta            : constant := 2.0 ** (-Max_Mantissa);
+
+   Tick                  : constant := 0.000_001;
+
+   --  Storage-related Declarations
+
+   type Address is private;
+   Null_Address : constant Address;
+
+   Storage_Unit : constant := 8;
+   Word_Size    : constant := 32;
+   Memory_Size  : constant := 2 ** 32;
+
+   --  Address comparison
+
+   function "<"  (Left, Right : Address) return Boolean;
+   function "<=" (Left, Right : Address) return Boolean;
+   function ">"  (Left, Right : Address) return Boolean;
+   function ">=" (Left, Right : Address) return Boolean;
+   function "="  (Left, Right : Address) return Boolean;
+
+   pragma Import (Intrinsic, "<");
+   pragma Import (Intrinsic, "<=");
+   pragma Import (Intrinsic, ">");
+   pragma Import (Intrinsic, ">=");
+   pragma Import (Intrinsic, "=");
+
+   --  Other System-Dependent Declarations
+
+   type Bit_Order is (High_Order_First, Low_Order_First);
+   Default_Bit_Order : constant Bit_Order := High_Order_First;
+   pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning
+
+   --  Priority-related Declarations (RM D.1)
+
+   Max_Priority           : constant Positive := 30;
+   Max_Interrupt_Priority : constant Positive := 31;
+
+   subtype Any_Priority       is Integer      range  0 .. 31;
+   subtype Priority           is Any_Priority range  0 .. 30;
+   subtype Interrupt_Priority is Any_Priority range 31 .. 31;
+
+   Default_Priority : constant Priority := 15;
+
+private
+
+   type Address is mod Memory_Size;
+   Null_Address : constant Address := 0;
+
+   --------------------------------------
+   -- System Implementation Parameters --
+   --------------------------------------
+
+   --  These parameters provide information about the target that is used
+   --  by the compiler. They are in the private part of System, where they
+   --  can be accessed using the special circuitry in the Targparm unit
+   --  whose source should be consulted for more detailed descriptions
+   --  of the individual switch values.
+
+   AAMP                      : constant Boolean := False;
+   Backend_Divide_Checks     : constant Boolean := False;
+   Backend_Overflow_Checks   : constant Boolean := False;
+   Command_Line_Args         : constant Boolean := True;
+   Compiler_System_Version   : constant Boolean := False;
+   Configurable_Run_Time     : constant Boolean := False;
+   Denorm                    : constant Boolean := True;
+   Duration_32_Bits          : constant Boolean := False;
+   Exit_Status_Supported     : constant Boolean := True;
+   Fractional_Fixed_Ops      : constant Boolean := False;
+   Frontend_Layout           : constant Boolean := False;
+   Functions_Return_By_DSP   : constant Boolean := False;
+   Machine_Overflows         : constant Boolean := False;
+   Machine_Rounds            : constant Boolean := True;
+   OpenVMS                   : constant Boolean := False;
+   Preallocated_Stacks       : constant Boolean := False;
+   Signed_Zeros              : constant Boolean := True;
+   Stack_Check_Default       : constant Boolean := False;
+   Stack_Check_Probes        : constant Boolean := False;
+   Support_64_Bit_Divides    : constant Boolean := True;
+   Support_Aggregates        : constant Boolean := True;
+   Support_Composite_Assign  : constant Boolean := True;
+   Support_Composite_Compare : constant Boolean := True;
+   Support_Long_Shifts       : constant Boolean := True;
+   Suppress_Standard_Library : constant Boolean := False;
+   Use_Ada_Main_Program_Name : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
+   Front_End_ZCX_Support     : constant Boolean := False;
+
+   --  Obsolete entries, to be removed eventually (bootstrap issues!)
+
+   High_Integrity_Mode       : constant Boolean := False;
+   Long_Shifts_Inlined       : constant Boolean := True;
+
+end System;
Index: src/gcc/ada/system-linux-mipsel.ads
===================================================================
--- /dev/null
+++ src/gcc/ada/system-linux-mipsel.ads
@@ -0,0 +1,154 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                        GNAT RUN-TIME COMPONENTS                          --
+--                                                                          --
+--                               S Y S T E M                                --
+--                                                                          --
+--                                 S p e c                                  --
+--                        (GNU-Linux/MIPSEL Version)                        --
+--                                                                          --
+--          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
+-- for  more details.  You should have  received  a copy of the GNU General --
+-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
+--                                                                          --
+-- As a special exception,  if other files  instantiate  generics from this --
+-- unit, or you link  this unit with other files  to produce an executable, --
+-- this  unit  does not  by itself cause  the resulting  executable  to  be --
+-- covered  by the  GNU  General  Public  License.  This exception does not --
+-- however invalidate  any other reasons why  the executable file  might be --
+-- covered by the  GNU Public License.                                      --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+package System is
+   pragma Pure;
+   --  Note that we take advantage of the implementation permission to make
+   --  this unit Pure instead of Preelaborable; see RM 13.7.1(15). In Ada
+   --  2005, this is Pure in any case (AI-362).
+
+   type Name is (SYSTEM_NAME_GNAT);
+   System_Name : constant Name := SYSTEM_NAME_GNAT;
+
+   --  System-Dependent Named Numbers
+
+   Min_Int               : constant := Long_Long_Integer'First;
+   Max_Int               : constant := Long_Long_Integer'Last;
+
+   Max_Binary_Modulus    : constant := 2 ** Long_Long_Integer'Size;
+   Max_Nonbinary_Modulus : constant := Integer'Last;
+
+   Max_Base_Digits       : constant := Long_Long_Float'Digits;
+   Max_Digits            : constant := Long_Long_Float'Digits;
+
+   Max_Mantissa          : constant := 63;
+   Fine_Delta            : constant := 2.0 ** (-Max_Mantissa);
+
+   Tick                  : constant := 0.000_001;
+
+   --  Storage-related Declarations
+
+   type Address is private;
+   Null_Address : constant Address;
+
+   Storage_Unit : constant := 8;
+   Word_Size    : constant := 32;
+   Memory_Size  : constant := 2 ** 32;
+
+   --  Address comparison
+
+   function "<"  (Left, Right : Address) return Boolean;
+   function "<=" (Left, Right : Address) return Boolean;
+   function ">"  (Left, Right : Address) return Boolean;
+   function ">=" (Left, Right : Address) return Boolean;
+   function "="  (Left, Right : Address) return Boolean;
+
+   pragma Import (Intrinsic, "<");
+   pragma Import (Intrinsic, "<=");
+   pragma Import (Intrinsic, ">");
+   pragma Import (Intrinsic, ">=");
+   pragma Import (Intrinsic, "=");
+
+   --  Other System-Dependent Declarations
+
+   type Bit_Order is (High_Order_First, Low_Order_First);
+   Default_Bit_Order : constant Bit_Order := Low_Order_First;
+   pragma Warnings (Off, Default_Bit_Order); -- kill constant condition warning
+
+   --  Priority-related Declarations (RM D.1)
+
+   Max_Priority           : constant Positive := 30;
+   Max_Interrupt_Priority : constant Positive := 31;
+
+   subtype Any_Priority       is Integer      range  0 .. 31;
+   subtype Priority           is Any_Priority range  0 .. 30;
+   subtype Interrupt_Priority is Any_Priority range 31 .. 31;
+
+   Default_Priority : constant Priority := 15;
+
+private
+
+   type Address is mod Memory_Size;
+   Null_Address : constant Address := 0;
+
+   --------------------------------------
+   -- System Implementation Parameters --
+   --------------------------------------
+
+   --  These parameters provide information about the target that is used
+   --  by the compiler. They are in the private part of System, where they
+   --  can be accessed using the special circuitry in the Targparm unit
+   --  whose source should be consulted for more detailed descriptions
+   --  of the individual switch values.
+
+   AAMP                      : constant Boolean := False;
+   Backend_Divide_Checks     : constant Boolean := False;
+   Backend_Overflow_Checks   : constant Boolean := False;
+   Command_Line_Args         : constant Boolean := True;
+   Compiler_System_Version   : constant Boolean := False;
+   Configurable_Run_Time     : constant Boolean := False;
+   Denorm                    : constant Boolean := True;
+   Duration_32_Bits          : constant Boolean := False;
+   Exit_Status_Supported     : constant Boolean := True;
+   Fractional_Fixed_Ops      : constant Boolean := False;
+   Frontend_Layout           : constant Boolean := False;
+   Functions_Return_By_DSP   : constant Boolean := False;
+   Machine_Overflows         : constant Boolean := False;
+   Machine_Rounds            : constant Boolean := True;
+   OpenVMS                   : constant Boolean := False;
+   Preallocated_Stacks       : constant Boolean := False;
+   Signed_Zeros              : constant Boolean := True;
+   Stack_Check_Default       : constant Boolean := False;
+   Stack_Check_Probes        : constant Boolean := False;
+   Support_64_Bit_Divides    : constant Boolean := True;
+   Support_Aggregates        : constant Boolean := True;
+   Support_Composite_Assign  : constant Boolean := True;
+   Support_Composite_Compare : constant Boolean := True;
+   Support_Long_Shifts       : constant Boolean := True;
+   Suppress_Standard_Library : constant Boolean := False;
+   Use_Ada_Main_Program_Name : constant Boolean := False;
+   ZCX_By_Default            : constant Boolean := True;
+   GCC_ZCX_Support           : constant Boolean := True;
+   Front_End_ZCX_Support     : constant Boolean := False;
+
+   --  Obsolete entries, to be removed eventually (bootstrap issues!)
+
+   High_Integrity_Mode       : constant Boolean := False;
+   Long_Shifts_Inlined       : constant Boolean := True;
+
+end System;
Index: src/gcc/ada/g-soccon-linux-mips.ads
===================================================================
--- /dev/null
+++ src/gcc/ada/g-soccon-linux-mips.ads
@@ -0,0 +1,184 @@
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT COMPILER COMPONENTS                         --
+--                                                                          --
+--               G N A T . S O C K E T S . C O N S T A N T S                --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--          Copyright (C) 2000-2005, Free Software Foundation, Inc.         --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
+-- for  more details.  You should have  received  a copy of the GNU General --
+-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
+--                                                                          --
+-- As a special exception,  if other files  instantiate  generics from this --
+-- unit, or you link  this unit with other files  to produce an executable, --
+-- this  unit  does not  by itself cause  the resulting  executable  to  be --
+-- covered  by the  GNU  General  Public  License.  This exception does not --
+-- however invalidate  any other reasons why  the executable file  might be --
+-- covered by the  GNU Public License.                                      --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This package provides target dependent definitions of constant for use
+--  by the GNAT.Sockets package (g-socket.ads). This package should not be
+--  directly with'ed by an applications program.
+
+--  This is the version for mips-linux, manually edited for the first shot
+--  no mips hardware at hand
+--  using http://www.gelato.unsw.edu.au/lxr/source/include/asm-mips/socket.h
+--  in order to find differents values
+--  This file is generated automatically, do not modify it by hand! Instead,
+--  make changes to gen-soccon.c and re-run it on each target.
+
+package GNAT.Sockets.Constants is
+
+   --------------
+   -- Families --
+   --------------
+
+   AF_INET            : constant :=            2; --  IPv4 address family
+   AF_INET6           : constant :=           10; --  IPv6 address family
+
+   -----------
+   -- Modes --
+   -----------
+
+   SOCK_STREAM        : constant :=            1; --  Stream socket
+   SOCK_DGRAM         : constant :=            2; --  Datagram socket
+
+   -------------------
+   -- Socket errors --
+   -------------------
+
+   EACCES             : constant :=           13; --  Permission denied
+   EADDRINUSE         : constant :=           98; --  Address already in use
+   EADDRNOTAVAIL      : constant :=           99; --  Cannot assign address
+   EAFNOSUPPORT       : constant :=           97; --  Addr family not supported
+   EALREADY           : constant :=          114; --  Operation in progress
+   EBADF              : constant :=            9; --  Bad file descriptor
+   ECONNABORTED       : constant :=          103; --  Connection aborted
+   ECONNREFUSED       : constant :=          111; --  Connection refused
+   ECONNRESET         : constant :=          104; --  Connection reset by peer
+   EDESTADDRREQ       : constant :=           89; --  Destination addr required
+   EFAULT             : constant :=           14; --  Bad address
+   EHOSTDOWN          : constant :=          112; --  Host is down
+   EHOSTUNREACH       : constant :=          113; --  No route to host
+   EINPROGRESS        : constant :=          115; --  Operation now in progress
+   EINTR              : constant :=            4; --  Interrupted system call
+   EINVAL             : constant :=           22; --  Invalid argument
+   EIO                : constant :=            5; --  Input output error
+   EISCONN            : constant :=          106; --  Socket already connected
+   ELOOP              : constant :=           40; --  Too many symbolic lynks
+   EMFILE             : constant :=           24; --  Too many open files
+   EMSGSIZE           : constant :=           90; --  Message too long
+   ENAMETOOLONG       : constant :=           36; --  Name too long
+   ENETDOWN           : constant :=          100; --  Network is down
+   ENETRESET          : constant :=          102; --  Disconn. on network reset
+   ENETUNREACH        : constant :=          101; --  Network is unreachable
+   ENOBUFS            : constant :=          105; --  No buffer space available
+   ENOPROTOOPT        : constant :=           92; --  Protocol not available
+   ENOTCONN           : constant :=          107; --  Socket not connected
+   ENOTSOCK           : constant :=           88; --  Operation on non socket
+   EOPNOTSUPP         : constant :=           95; --  Operation not supported
+   EPFNOSUPPORT       : constant :=           96; --  Unknown protocol family
+   EPROTONOSUPPORT    : constant :=           93; --  Unknown protocol
+   EPROTOTYPE         : constant :=           91; --  Unknown protocol type
+   ESHUTDOWN          : constant :=          108; --  Cannot send once shutdown
+   ESOCKTNOSUPPORT    : constant :=           94; --  Socket type not supported
+   ETIMEDOUT          : constant :=          110; --  Connection timed out
+   ETOOMANYREFS       : constant :=          109; --  Too many references
+   EWOULDBLOCK        : constant :=           11; --  Operation would block
+
+   -----------------
+   -- Host errors --
+   -----------------
+
+   HOST_NOT_FOUND     : constant :=            1; --  Unknown host
+   TRY_AGAIN          : constant :=            2; --  Host name lookup failure
+   NO_DATA            : constant :=            4; --  No data record for name
+   NO_RECOVERY        : constant :=            3; --  Non recoverable errors
+
+   -------------------
+   -- Control flags --
+   -------------------
+
+   FIONBIO            : constant :=     16#667e#; --  Set/clear non-blocking io
+   FIONREAD           : constant :=     16#467f#; --  How many bytes to read
+
+   --------------------
+   -- Shutdown modes --
+   --------------------
+
+   SHUT_RD            : constant :=            0; --  No more recv
+   SHUT_WR            : constant :=            1; --  No more send
+   SHUT_RDWR          : constant :=            2; --  No more recv/send
+
+   ---------------------
+   -- Protocol levels --
+   ---------------------
+
+   SOL_SOCKET         : constant :=            1; --  Options for socket level
+   IPPROTO_IP         : constant :=            0; --  Dummy protocol for IP
+   IPPROTO_UDP        : constant :=           17; --  UDP
+   IPPROTO_TCP        : constant :=            6; --  TCP
+
+   -------------------
+   -- Request flags --
+   -------------------
+
+   MSG_OOB            : constant :=            1; --  Process out-of-band data
+   MSG_PEEK           : constant :=            2; --  Peek at incoming data
+   MSG_EOR            : constant :=          128; --  Send end of record
+   MSG_WAITALL        : constant :=          256; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=        16384; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant := MSG_NOSIGNAL;
+   --  Flags set on all send(2) calls
+
+   --------------------
+   -- Socket options --
+   --------------------
+
+   TCP_NODELAY        : constant :=            1; --  Do not coalesce packets
+   SO_REUSEADDR       : constant :=            4; --  Bind reuse local address
+   SO_KEEPALIVE       : constant :=            8; --  Enable keep-alive msgs
+   SO_LINGER          : constant :=       16#80#; --  Defer close to flush data
+   SO_BROADCAST       : constant :=       16#20#; --  Can send broadcast msgs
+   SO_SNDBUF          : constant :=     16#1001#; --  Set/get send buffer size
+   SO_RCVBUF          : constant :=     16#1002#; --  Set/get recv buffer size
+   SO_SNDTIMEO        : constant :=     16#1005#; --  Emission timeout
+   SO_RCVTIMEO        : constant :=     16#1006#; --  Reception timeout
+   SO_ERROR           : constant :=     16#1007#; --  Get/clear error status
+   IP_MULTICAST_IF    : constant :=           32; --  Set/get mcast interface
+   IP_MULTICAST_TTL   : constant :=           33; --  Set/get multicast TTL
+   IP_MULTICAST_LOOP  : constant :=           34; --  Set/get mcast loopback
+   IP_ADD_MEMBERSHIP  : constant :=           35; --  Join a multicast group
+   IP_DROP_MEMBERSHIP : constant :=           36; --  Leave a multicast group
+
+   -------------------
+   -- System limits --
+   -------------------
+
+   IOV_MAX            : constant :=   2147483647; --  Maximum writev iovcnt
+
+   ----------------------
+   -- Type definitions --
+   ----------------------
+
+   --  Sizes (in bytes) of the components of struct timeval
+
+   SIZEOF_tv_sec      : constant :=            4; --  tv_sec
+   SIZEOF_tv_usec     : constant :=            4; --  tv_usec
+
+end GNAT.Sockets.Constants;
