Index: expect.c
===================================================================
--- expect.c	(revision 273575)
+++ expect.c	(working copy)
@@ -29,14 +29,11 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef __alpha_vxworks
-#include "vxWorks.h"
-#endif
-
 #ifdef IN_RTS
 #define POSIX
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
+#include <unistd.h>
+
 #else
 #include "config.h"
 #include "system.h"
Index: env.c
===================================================================
--- env.c	(revision 273575)
+++ env.c	(working copy)
@@ -30,15 +30,11 @@
  ****************************************************************************/
 
 #ifdef IN_RTS
-# include "tconfig.h"
-# include "tsystem.h"
+# include "runtime.h"
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
 
-# include <sys/stat.h>
-# include <fcntl.h>
-# include <time.h>
-# ifdef VMS
-#  include <unixio.h>
-# endif
 /* We don't have libiberty, so use malloc.  */
 # define xmalloc(S) malloc (S)
 #else /* IN_RTS */
@@ -109,89 +105,10 @@
   return;
 }
 
-/* VMS specific declarations for set_env_value.  */
-
-#ifdef VMS
-
-typedef struct _ile3
-{
-  unsigned short len, code;
-  __char_ptr32 adr;
-  __char_ptr32 retlen_adr;
-} ile_s;
-
-#endif
-
 void
 __gnat_setenv (char *name, char *value)
 {
-#if defined (VMS)
-  struct dsc$descriptor_s name_desc;
-  $DESCRIPTOR (table_desc, "LNM$PROCESS");
-  char *host_pathspec = value;
-  char *copy_pathspec;
-  int num_dirs_in_pathspec = 1;
-  char *ptr;
-  long status;
-
-  name_desc.dsc$w_length = strlen (name);
-  name_desc.dsc$b_dtype = DSC$K_DTYPE_T;
-  name_desc.dsc$b_class = DSC$K_CLASS_S;
-  name_desc.dsc$a_pointer = name; /* ??? Danger, not 64bit safe.  */
-
-  if (*host_pathspec == 0)
-    /* deassign */
-    {
-      status = LIB$DELETE_LOGICAL (&name_desc, &table_desc);
-      /* no need to check status; if the logical name is not
-         defined, that's fine. */
-      return;
-    }
-
-  ptr = host_pathspec;
-  while (*ptr++)
-    if (*ptr == ',')
-      num_dirs_in_pathspec++;
-
-  {
-    int i, status;
-    /* Alloca is guaranteed to be 32bit.  */
-    ile_s *ile_array = alloca (sizeof (ile_s) * (num_dirs_in_pathspec + 1));
-    char *copy_pathspec = alloca (strlen (host_pathspec) + 1);
-    char *curr, *next;
-
-    strcpy (copy_pathspec, host_pathspec);
-    curr = copy_pathspec;
-    for (i = 0; i < num_dirs_in_pathspec; i++)
-      {
-	next = strchr (curr, ',');
-	if (next == 0)
-	  next = strchr (curr, 0);
-
-	*next = 0;
-	ile_array[i].len = strlen (curr);
-
-	/* Code 2 from lnmdef.h means it's a string.  */
-	ile_array[i].code = 2;
-	ile_array[i].adr = curr;
-
-	/* retlen_adr is ignored.  */
-	ile_array[i].retlen_adr = 0;
-	curr = next + 1;
-      }
-
-    /* Terminating item must be zero.  */
-    ile_array[i].len = 0;
-    ile_array[i].code = 0;
-    ile_array[i].adr = 0;
-    ile_array[i].retlen_adr = 0;
-
-    status = LIB$SET_LOGICAL (&name_desc, 0, &table_desc, 0, ile_array);
-    if ((status & 1) != 1)
-      LIB$SIGNAL (status);
-  }
-
-#elif (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__)
+#if (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__)
   setenv (name, value, 1);
 
 #else
@@ -213,10 +130,7 @@
 char **
 __gnat_environ (void)
 {
-#if defined (VMS) || defined (RTX)
-  /* Not implemented */
-  return NULL;
-#elif defined (__MINGW32__)
+#if defined (__MINGW32__)
   return _environ;
 #elif defined (__sun__)
   extern char **_environ;
@@ -247,10 +161,7 @@
 
 void __gnat_unsetenv (char *name)
 {
-#if defined (VMS)
-  /* Not implemented */
-  return;
-#elif defined (__hpux__) || defined (__sun__) \
+#if defined (__hpux__) || defined (__sun__) \
      || (defined (__vxworks) && ! defined (__RTP__)) \
      || defined (_AIX) || defined (__Lynx__)
 
@@ -306,10 +217,7 @@
 
 void __gnat_clearenv (void)
 {
-#if defined (VMS)
-  /* not implemented */
-  return;
-#elif defined (__sun__) \
+#if defined (__sun__) \
   || (defined (__vxworks) && ! defined (__RTP__)) || defined (__Lynx__) \
   || defined (__PikeOS__)
   /* On Solaris, VxWorks (not RTPs), and Lynx there is no system
Index: aux-io.c
===================================================================
--- aux-io.c	(revision 273575)
+++ aux-io.c	(working copy)
@@ -31,10 +31,7 @@
 
 #include <stdio.h>
 
-#ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
-#else
+#ifndef IN_RTS
 #include "config.h"
 #include "system.h"
 #endif
Index: mkdir.c
===================================================================
--- mkdir.c	(revision 273575)
+++ mkdir.c	(working copy)
@@ -35,8 +35,7 @@
 #endif /* __vxworks */
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
 #include <sys/stat.h>
 #else
 #include "config.h"
Index: initialize.c
===================================================================
--- initialize.c	(revision 273575)
+++ initialize.c	(working copy)
@@ -41,8 +41,7 @@
 #endif
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
 /* We don't have libiberty, so use malloc.  */
 #define xmalloc(S) malloc (S)
 #define xrealloc(V,S) realloc (V,S)
Index: cstreams.c
===================================================================
--- cstreams.c	(revision 273575)
+++ cstreams.c	(working copy)
@@ -53,9 +53,7 @@
 #endif
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
-#include <sys/stat.h>
+#include <string.h>
 #else
 #include "config.h"
 #include "system.h"
Index: raise.c
===================================================================
--- raise.c	(revision 273575)
+++ raise.c	(working copy)
@@ -33,8 +33,7 @@
    is shared between all exception handling mechanisms.  */
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
 #else
 #include "config.h"
 #include "system.h"
@@ -56,16 +55,6 @@
 void
 __gnat_unhandled_terminate (void)
 {
-#ifdef VMS
-  /* Special termination handling for VMS */
-  long prvhnd;
-
-  /* Remove the exception vector so it won't intercept any errors
-     in the call to exit, and go into and endless loop */
-
-  SYS$SETEXV (1, 0, 3, &prvhnd);
-#endif
-
   /* Default termination handling */
   __gnat_os_exit (1);
 }
Index: tracebak.c
===================================================================
--- tracebak.c	(revision 273575)
+++ tracebak.c	(working copy)
@@ -50,14 +50,10 @@
 extern "C" {
 #endif
 
-#ifdef __alpha_vxworks
-#include "vxWorks.h"
-#endif
-
 #ifdef IN_RTS
 #define POSIX
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
+#include <stddef.h>
 #else
 #include "config.h"
 #include "system.h"
Index: adadecode.c
===================================================================
--- adadecode.c	(revision 273575)
+++ adadecode.c	(working copy)
@@ -29,15 +29,7 @@
  *                                                                          *
  ****************************************************************************/
 
-
-#if defined(IN_RTS)
-#include "tconfig.h"
-#include "tsystem.h"
-#elif defined(IN_GCC)
-#include "config.h"
-#include "system.h"
-#endif
-
+#include "runtime.h"
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
Index: init.c
===================================================================
--- init.c	(revision 273575)
+++ init.c	(working copy)
@@ -54,8 +54,14 @@
 #endif
 
 #ifdef IN_RTS
+
+#ifdef STANDALONE
+#include "runtime.h"
+#else
 #include "tconfig.h"
 #include "tsystem.h"
+#endif
+
 #include <sys/stat.h>
 
 /* We don't have libiberty, so use malloc.  */
@@ -463,6 +469,7 @@
 void
 __gnat_adjust_context_for_raise (int signo ATTRIBUTE_UNUSED, void *ucontext)
 {
+#ifndef STANDALONE
   mcontext_t *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
 
   /* On the i386 and x86-64 architectures, stack checking is performed by
@@ -513,6 +520,7 @@
     mcontext->arm_pc+=1;
 #endif
 #endif
+#endif
 }
 
 #endif
Index: raise-gcc.c
===================================================================
--- raise-gcc.c	(revision 273575)
+++ raise-gcc.c	(working copy)
@@ -39,11 +39,11 @@
   /* Don't use fancy_abort.  */
 # undef abort
 #else
-# ifndef CERT
+# if !defined(CERT) && !defined(STANDALONE)
 #  include "tconfig.h"
 #  include "tsystem.h"
 # else
-#  define ATTRIBUTE_UNUSED __attribute__((unused))
+#  include "runtime.h"
 #  define HAVE_GETIPINFO 1
 # endif
 #endif
@@ -115,6 +115,10 @@
 /* Called in case of error during propagation.  */
 extern void __gnat_raise_abort (void) __attribute__ ((noreturn));
 #define abort() __gnat_raise_abort()
+
+#elif defined(STANDALONE)
+#include <stdlib.h>
+#define inhibit_libc
 #endif
 
 #include "unwind-pe.h"
Index: Makefile.rtl
===================================================================
--- Makefile.rtl	(revision 273575)
+++ Makefile.rtl	(working copy)
@@ -2610,7 +2610,7 @@
 
 LIBGNAT_SRCS = $(patsubst %.o,%.c,$(LIBGNAT_OBJS))			\
   adadecode.h adaint.h env.h gsocket.h raise.h standard.ads.h		\
-  tb-gcc.c libgnarl/thread.c $(EXTRA_LIBGNAT_SRCS)
+  tb-gcc.c runtime.h libgnarl/thread.c $(EXTRA_LIBGNAT_SRCS)
 
 # memtrack.o is special as not put into libgnat.
 GNATRTL_OBJS = $(GNATRTL_NONTASKING_OBJS) $(GNATRTL_TASKING_OBJS) \
Index: argv.c
===================================================================
--- argv.c	(revision 273575)
+++ argv.c	(working copy)
@@ -43,9 +43,8 @@
    Ada.Command_Line.Environment package.  */
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
-#include <sys/stat.h>
+#include "runtime.h"
+#include <string.h>
 #else
 #include "config.h"
 #include "system.h"
Index: adaint.c
===================================================================
--- adaint.c	(revision 273575)
+++ adaint.c	(working copy)
@@ -88,8 +88,26 @@
 #endif
 
 #ifdef IN_RTS
+
+#ifdef STANDALONE
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* for CPU_SET/CPU_ZERO */
+#define _GNU_SOURCE
+#define __USE_GNU
+
+#include "runtime.h"
+
+#else
 #include "tconfig.h"
 #include "tsystem.h"
+#endif
+
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
Index: adaint.h
===================================================================
--- adaint.h	(revision 273575)
+++ adaint.h	(working copy)
@@ -51,7 +51,7 @@
    determine at compile time what support the system offers for large files.
    For now we just list the platforms we have manually tested. */
 
-#if defined (__GLIBC__) || defined (__sun__) || defined (__QNX__)
+#if (defined (__GLIBC__) && !defined(STANDALONE)) || defined (__sun__) || defined (__QNX__)
 #define GNAT_FOPEN fopen64
 #define GNAT_OPEN open64
 #define GNAT_STAT stat64
Index: ctrl_c.c
===================================================================
--- ctrl_c.c	(revision 273575)
+++ ctrl_c.c	(working copy)
@@ -29,11 +29,7 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
-#include <sys/stat.h>
-#else
+#ifndef IN_RTS
 #include "config.h"
 #include "system.h"
 #endif
Index: sysdep.c
===================================================================
--- sysdep.c	(revision 273575)
+++ sysdep.c	(working copy)
@@ -54,8 +54,10 @@
 
 #ifdef IN_RTS
 #define POSIX
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
+#include <string.h>
+#include <unistd.h>
+
 #include <fcntl.h>
 #include <sys/stat.h>
 #else
Index: runtime.h
===================================================================
--- runtime.h	(revision 0)
+++ runtime.h	(revision 0)
@@ -0,0 +1,44 @@
+/****************************************************************************
+ *                                                                          *
+ *                         GNAT COMPILER COMPONENTS                         *
+ *                                                                          *
+ *                                 RUNTIME                                  *
+ *                                                                          *
+ *                              C Header File                               *
+ *                                                                          *
+ *          Copyright (C) 2019, 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 3,  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.                                     *
+ *                                                                          *
+ * As a special exception under Section 7 of GPL version 3, you are granted *
+ * additional permissions described in the GCC Runtime Library Exception,   *
+ * version 3.1, as published by the Free Software Foundation.               *
+ *                                                                          *
+ * You should have received a copy of the GNU General Public License and    *
+ * a copy of the GCC Runtime Library Exception along with this program;     *
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
+ * <http://www.gnu.org/licenses/>.                                          *
+ *                                                                          *
+ * GNAT was originally developed  by the GNAT team at  New York University. *
+ * Extensive contributions were provided by Ada Core Technologies Inc.      *
+ *                                                                          *
+ ****************************************************************************/
+
+/* This file provides common definitions used by GNAT C runtime files.  */
+
+#ifdef __vxworks
+#include "vxWorks.h"
+#endif /* __vxworks */
+
+#ifndef ATTRIBUTE_UNUSED
+#define ATTRIBUTE_UNUSED __attribute__((unused))
+#endif
+
+#ifndef ATTRIBUTE_NORETURN
+#define ATTRIBUTE_NORETURN __attribute__((noreturn))
+#endif
Index: rtinit.c
===================================================================
--- rtinit.c	(revision 273575)
+++ rtinit.c	(working copy)
@@ -41,8 +41,6 @@
 #endif
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
 /* We don't have libiberty, so use malloc.  */
 #define xmalloc(S) malloc (S)
 #define xrealloc(V,S) realloc (V,S)
Index: cio.c
===================================================================
--- cio.c	(revision 273575)
+++ cio.c	(working copy)
@@ -30,8 +30,7 @@
  ****************************************************************************/
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
+#include "runtime.h"
 #include <sys/stat.h>
 #else
 #include "config.h"
Index: seh_init.c
===================================================================
--- seh_init.c	(revision 273575)
+++ seh_init.c	(working copy)
@@ -39,9 +39,9 @@
 #endif
 
 #ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
 
+#include "runtime.h"
+
 /* We don't have libiberty, so use malloc.  */
 #define xmalloc(S) malloc (S)
 
Index: exit.c
===================================================================
--- exit.c	(revision 273575)
+++ exit.c	(working copy)
@@ -29,21 +29,6 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef __alpha_vxworks
-#include "vxWorks.h"
-#endif
-
-#ifdef IN_RTS
-#include "tconfig.h"
-#include "tsystem.h"
-#include <sys/stat.h>
-#else
-#include "config.h"
-#include "system.h"
-#endif
-
-#include "adaint.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Index: targext.c
===================================================================
--- targext.c	(revision 273575)
+++ targext.c	(working copy)
@@ -36,14 +36,21 @@
     the file must be compiled with IN_GCC defined, even for the library.  */
 
 #ifdef IN_RTS
+
+#ifndef STANDALONE
 #include "tconfig.h"
 #include "tsystem.h"
+#endif
+
 #else
 #include "config.h"
 #include "system.h"
 #endif
+
+#ifndef STANDALONE
 #include "coretypes.h"
 #include "tm.h"
+#endif
 
 #ifndef TARGET_OBJECT_SUFFIX
 #define TARGET_OBJECT_SUFFIX ".o"
