Extend locations where to seach for Fortran pre-include.
authorMartin Liska <mliska@suse.cz>
Wed, 16 Jan 2019 09:38:21 +0000 (10:38 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 16 Jan 2019 09:38:21 +0000 (09:38 +0000)
2019-01-16  Martin Liska  <mliska@suse.cz>

* Makefile.in: Set TOOL_INCLUDE_DIR and NATIVE_SYSTEM_HEADER_DIR
for GCC driver.
* config/gnu-user.h (TARGET_F951_OPTIONS): Add 'finclude%s/' as
a new argument.
* gcc.c (add_sysrooted_hdrs_prefix): New function.
(path_prefix_reset): Move up in the source file.
(find_fortran_preinclude_file): Make complex search for the
fortran header files.

From-SVN: r267967

gcc/ChangeLog
gcc/Makefile.in
gcc/config/gnu-user.h
gcc/gcc.c

index 153a5ab0951c633b809399095d5bb21e43781440..17f2195eff334475eec6f9aa9f2fb7224fc7f1ac 100644 (file)
@@ -1,3 +1,14 @@
+2019-01-16  Martin Liska  <mliska@suse.cz>
+
+       * Makefile.in: Set TOOL_INCLUDE_DIR and NATIVE_SYSTEM_HEADER_DIR
+       for GCC driver.
+       * config/gnu-user.h (TARGET_F951_OPTIONS): Add 'finclude%s/' as
+       a new argument.
+       * gcc.c (add_sysrooted_hdrs_prefix): New function.
+       (path_prefix_reset): Move up in the source file.
+       (find_fortran_preinclude_file): Make complex search for the
+       fortran header files.
+
 2019-01-15  Nikhil Benesch  <nikhil.benesch@gmail.com>
 
         * godump.c (go_output_typedef): When outputting a typedef, refer
index d3f62cfcfeea76bd676d3ae3a46de7a07d64db70..508c674cbdc59299eca3465e2cad240157ce1cae 100644 (file)
@@ -2172,7 +2172,9 @@ DRIVER_DEFINES = \
   @TARGET_SYSTEM_ROOT_DEFINE@ \
   $(VALGRIND_DRIVER_DEFINES) \
   $(if $(SHLIB),$(if $(filter yes,@enable_shared@),-DENABLE_SHARED_LIBGCC)) \
-  -DCONFIGURE_SPECS="\"@CONFIGURE_SPECS@\""
+  -DCONFIGURE_SPECS="\"@CONFIGURE_SPECS@\"" \
+  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
+  -DNATIVE_SYSTEM_HEADER_DIR=\"$(NATIVE_SYSTEM_HEADER_DIR)\"
 
 CFLAGS-gcc.o += $(DRIVER_DEFINES) -DBASEVER=$(BASEVER_s)
 gcc.o: $(BASEVER)
index ba1469216555641c8135cb7e1243d4f6be09dd29..055a4f0afeca4a6339fd156db1bf1daf1aae0994 100644 (file)
@@ -151,4 +151,4 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #undef TARGET_F951_OPTIONS
 #define TARGET_F951_OPTIONS "%{!nostdinc:\
-  %:fortran-preinclude-file(-fpre-include= math-vector-fortran.h)}"
+  %:fortran-preinclude-file(-fpre-include= math-vector-fortran.h finclude%s/)}"
index bcd04df1691827c7b050f8fdc20ea12779131138..797ed36616f6e605179b74463a2912d504a20924 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -2976,6 +2976,44 @@ add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
   add_prefix (pprefix, prefix, component, priority,
              require_machine_suffix, os_multilib);
 }
+
+/* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix.  */
+
+static void
+add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
+                          const char *component,
+                          /* enum prefix_priority */ int priority,
+                          int require_machine_suffix, int os_multilib)
+{
+  if (!IS_ABSOLUTE_PATH (prefix))
+    fatal_error (input_location, "system path %qs is not absolute", prefix);
+
+  if (target_system_root)
+    {
+      char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
+      size_t sysroot_len = strlen (target_system_root);
+
+      if (sysroot_len > 0
+         && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
+       sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
+
+      if (target_sysroot_hdrs_suffix)
+       prefix = concat (sysroot_no_trailing_dir_separator,
+                        target_sysroot_hdrs_suffix, prefix, NULL);
+      else
+       prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
+
+      free (sysroot_no_trailing_dir_separator);
+
+      /* We have to override this because GCC's notion of sysroot
+        moves along with GCC.  */
+      component = "GCC";
+    }
+
+  add_prefix (pprefix, prefix, component, priority,
+             require_machine_suffix, os_multilib);
+}
+
 \f
 /* Execute the command specified by the arguments on the current line of spec.
    When using pipes, this includes several piped-together commands
@@ -9896,20 +9934,61 @@ debug_level_greater_than_spec_func (int argc, const char **argv)
   return NULL;
 }
 
-/* The function takes 2 arguments: OPTION name and file name.
+static void
+path_prefix_reset (path_prefix *prefix)
+{
+  struct prefix_list *iter, *next;
+  iter = prefix->plist;
+  while (iter)
+    {
+      next = iter->next;
+      free (const_cast <char *> (iter->prefix));
+      XDELETE (iter);
+      iter = next;
+    }
+  prefix->plist = 0;
+  prefix->max_len = 0;
+}
+
+/* The function takes 3 arguments: OPTION name, file name and location
+   where we search for Fortran modules.
    When the FILE is found by find_file, return OPTION=path_to_file.  */
 
 static const char *
 find_fortran_preinclude_file (int argc, const char **argv)
 {
-  if (argc != 2)
+  char *result = NULL;
+  if (argc != 3)
     return NULL;
 
+  struct path_prefix prefixes = { 0, 0, "preinclude" };
+
+  /* Search first for 'finclude' folder location for a header file
+     installed by the compiler (similar to omp_lib.h).  */
+  add_prefix (&prefixes, argv[2], NULL, 0, 0, false);
+#ifdef TOOL_INCLUDE_DIR
+  /* Then search: <prefix>/<target>/<include>/finclude */
+  add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
+             NULL, 0, 0, false);
+#endif
+#ifdef NATIVE_SYSTEM_HEADER_DIR
+  /* Then search: <sysroot>/usr/include/finclude/<multilib> */
+  add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
+                            NULL, 0, 0, false);
+#endif
+
   const char *path = find_a_file (&include_prefixes, argv[1], R_OK, true);
   if (path != NULL)
-    return concat (argv[0], path, NULL);
+    result = concat (argv[0], path, NULL);
+  else
+    {
+      path = find_a_file (&prefixes, argv[1], R_OK, true);
+      if (path != NULL)
+       result = concat (argv[0], path, NULL);
+    }
 
-  return NULL;
+  path_prefix_reset (&prefixes);
+  return result;
 }
 
 
@@ -9961,22 +10040,6 @@ convert_white_space (char *orig)
     return orig;
 }
 
-static void
-path_prefix_reset (path_prefix *prefix)
-{
-  struct prefix_list *iter, *next;
-  iter = prefix->plist;
-  while (iter)
-    {
-      next = iter->next;
-      free (const_cast <char *> (iter->prefix));
-      XDELETE (iter);
-      iter = next;
-    }
-  prefix->plist = 0;
-  prefix->max_len = 0;
-}
-
 /* Restore all state within gcc.c to the initial state, so that the driver
    code can be safely re-run in-process.