diff mbox

gcc: Fix sysroot relative paths for MinGW

Message ID CAOj9pe9zHrAPx1NfweFSwLbf0CrmTRB+Rz5cq=S-QD7R7YusWQ@mail.gmail.com
State New
Headers show

Commit Message

Tadek Kijkowski Sept. 23, 2016, 6:31 a.m. UTC
Prevent paths relative to sysroot directory from being transformed to
Windows form with MSYS prefix.
See: http://www.mingw.org/wiki/Posix_path_conversion

2016-09-23  Tadek Kijkowski  <tkijkowski@gmail.com>

        * gcc/Makefile.in: Fix sysroot relative paths for MinGW


 # Directory in which the compiler finds executables
@@ -2751,14 +2763,14 @@
 PREPROCESSOR_DEFINES = \
   -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
   -DFIXED_INCLUDE_DIR=\"$(libsubdir)/include-fixed\" \
-  -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
+  -DGPLUSPLUS_INCLUDE_DIR=\"$(call
sysroot_relative_path,$(gcc_gxx_include_dir),$(filter-out
0,$(gcc_gxx_include_dir_add_sysroot)))\" \
   -DGPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT=$(gcc_gxx_include_dir_add_sysroot) \
-  -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\"
\
-  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
+  -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(call
sysroot_relative_path,$(gcc_gxx_include_dir)/$(target_noncanonical),$(filter-out
0,$(gcc_gxx_include_dir_add_sysroot)))\" \
+  -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(call
sysroot_relative_path,$(gcc_gxx_include_dir)/backward,$(filter-out
0,$(gcc_gxx_include_dir_add_sysroot)))\" \
   -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
-  -DNATIVE_SYSTEM_HEADER_DIR=\"$(NATIVE_SYSTEM_HEADER_DIR)\" \
+  -DNATIVE_SYSTEM_HEADER_DIR=\"$(call
sysroot_relative_path,$(NATIVE_SYSTEM_HEADER_DIR),yes)\" \
   -DPREFIX=\"$(prefix)/\" \
   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
   @TARGET_SYSTEM_ROOT_DEFINE@

Comments

Jeff Law Sept. 29, 2016, 7:16 p.m. UTC | #1
On 09/23/2016 12:31 AM, Tadek Kijkowski wrote:
> Prevent paths relative to sysroot directory from being transformed to
> Windows form with MSYS prefix.
> See: http://www.mingw.org/wiki/Posix_path_conversion
>
> 2016-09-23  Tadek Kijkowski  <tkijkowski@gmail.com>
>
>         * gcc/Makefile.in: Fix sysroot relative paths for MinGW
>
>
> Index: gcc/Makefile.in
> ===================================================================
> --- gcc/Makefile.in    (revision 240386)
> +++ gcc/Makefile.in    (working copy)
> @@ -603,6 +603,18 @@
>  # UNSORTED
>  # --------
>
> +# MSYS will zealously translate all paths to Windows form,
> +# so /usr/include becomes c:/msysX/usr/include.
> +# If sysroot is specified this is undesirable, so this function converts
> +# /usr/include to //usr\include, which will become /usr/include
> +# again when passed to gcc.
> +ifneq ($(and @TARGET_SYSTEM_ROOT@,$(filter %-mingw32,$(host))),)
> +sysroot_relative_path = $(if $(2),$$(echo '$(1)' | tr '/' '\\' | sed
> 's,^\\,//,'),$(1))
> +else
> +sysroot_relative_path = $(1)
> +endif
I'd really like to see the documentation here improved.

There's no mention of the second argument's purpose.  And one has to 
parse the ifneq line to understand what it's doing.  Those kinds of 
things should be made clear in a comment.


> +
> +
>  # Directory in which the compiler finds libraries etc.
>  libsubdir = $(libdir)/gcc/$(real_target_noncanonical)/$(version)$(accel_dir_suffix)
>  # Directory in which the compiler finds executables
> @@ -2751,14 +2763,14 @@
>  PREPROCESSOR_DEFINES = \
>    -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \
>    -DFIXED_INCLUDE_DIR=\"$(libsubdir)/include-fixed\" \
> -  -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
> +  -DGPLUSPLUS_INCLUDE_DIR=\"$(call
> sysroot_relative_path,$(gcc_gxx_include_dir),$(filter-out
> 0,$(gcc_gxx_include_dir_add_sysroot)))\" \
So why the $(filter-out 0, ....)?

I'd really like to avoid being too clever here and write this code in 
the most straightforward way possible.

Jeff
diff mbox

Patch

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in    (revision 240386)
+++ gcc/Makefile.in    (working copy)
@@ -603,6 +603,18 @@ 
 # UNSORTED
 # --------

+# MSYS will zealously translate all paths to Windows form,
+# so /usr/include becomes c:/msysX/usr/include.
+# If sysroot is specified this is undesirable, so this function converts
+# /usr/include to //usr\include, which will become /usr/include
+# again when passed to gcc.
+ifneq ($(and @TARGET_SYSTEM_ROOT@,$(filter %-mingw32,$(host))),)
+sysroot_relative_path = $(if $(2),$$(echo '$(1)' | tr '/' '\\' | sed
's,^\\,//,'),$(1))
+else
+sysroot_relative_path = $(1)
+endif
+
+
 # Directory in which the compiler finds libraries etc.
 libsubdir = $(libdir)/gcc/$(real_target_noncanonical)/$(version)$(accel_dir_suffix)