Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 1 | From 667b302f637be0a4b6ef714b5eb0026c54425386 Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Richard Purdie <richard.purdie@linuxfoundation.org> |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 3 | Date: Sun, 31 Oct 2021 17:40:12 -0700 |
| 4 | Subject: [PATCH] Makefile.in: Ensure build CPP/CPPFLAGS is used for build |
| 5 | targets |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 6 | |
| 7 | During cross compiling, CPP is being set to the target compiler even for |
| 8 | build targets. As an example, when building a cross compiler targetting |
| 9 | mingw, the config.log for libiberty in |
| 10 | build.x86_64-pokysdk-mingw32.i586-poky-linux/build-x86_64-linux/libiberty/config.log |
| 11 | shows: |
| 12 | |
| 13 | configure:3786: checking how to run the C preprocessor |
| 14 | configure:3856: result: x86_64-pokysdk-mingw32-gcc -E --sysroot=[sysroot]/x86_64-nativesdk-mingw32-pokysdk-mingw32 |
| 15 | configure:3876: x86_64-pokysdk-mingw32-gcc -E --sysroot=[sysroot]/x86_64-nativesdk-mingw32-pokysdk-mingw32 conftest.c |
| 16 | configure:3876: $? = 0 |
| 17 | |
| 18 | This is libiberty being built for the build environment, not the target one |
| 19 | (i.e. in build-x86_64-linux). As such it should be using the build environment's |
| 20 | gcc and not the target one. In the mingw case the system headers are quite |
| 21 | different leading to build failures related to not being able to include a |
| 22 | process.h file for pem-unix.c. |
| 23 | |
| 24 | Further analysis shows the same issue occuring for CPPFLAGS too. |
| 25 | |
| 26 | Fix this by adding support for CPP_FOR_BUILD and CPPFLAGS_FOR_BUILD which |
| 27 | for example, avoids mixing the mingw headers for host binaries on linux |
| 28 | systems. |
| 29 | |
| 30 | 2021-10-27 Richard Purdie <richard.purdie@linuxfoundation.org> |
| 31 | |
| 32 | ChangeLog: |
| 33 | |
| 34 | * Makefile.tpl: Add CPP_FOR_BUILD and CPPFLAGS_FOR_BUILD support |
| 35 | * Makefile.in: Regenerate. |
| 36 | * configure: Regenerate. |
| 37 | * configure.ac: Add CPP_FOR_BUILD and CPPFLAGS_FOR_BUILD support |
| 38 | |
| 39 | gcc/ChangeLog: |
| 40 | |
| 41 | * configure: Regenerate. |
| 42 | * configure.ac: Use CPPFLAGS_FOR_BUILD for GMPINC |
| 43 | |
| 44 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 45 | |
| 46 | Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582727.html] |
| 47 | Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=84401ce5fb4ecab55decb472b168100e7593e01f] |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 48 | |
| 49 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 50 | --- |
| 51 | Makefile.in | 6 ++++++ |
| 52 | Makefile.tpl | 6 ++++++ |
| 53 | configure | 4 ++++ |
| 54 | configure.ac | 4 ++++ |
| 55 | gcc/configure | 2 +- |
| 56 | gcc/configure.ac | 2 +- |
| 57 | 6 files changed, 22 insertions(+), 2 deletions(-) |
| 58 | |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 59 | diff --git a/Makefile.in b/Makefile.in |
| 60 | index 20cbbe2906d..33476d53327 100644 |
| 61 | --- a/Makefile.in |
| 62 | +++ b/Makefile.in |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 63 | @@ -154,6 +154,8 @@ BUILD_EXPORTS = \ |
| 64 | CC="$(CC_FOR_BUILD)"; export CC; \ |
| 65 | CFLAGS="$(CFLAGS_FOR_BUILD)"; export CFLAGS; \ |
| 66 | CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ |
| 67 | + CPP="$(CPP_FOR_BUILD)"; export CPP; \ |
| 68 | + CPPFLAGS="$(CPPFLAGS_FOR_BUILD)"; export CPPFLAGS; \ |
| 69 | CXX="$(CXX_FOR_BUILD)"; export CXX; \ |
| 70 | CXXFLAGS="$(CXXFLAGS_FOR_BUILD)"; export CXXFLAGS; \ |
| 71 | GFORTRAN="$(GFORTRAN_FOR_BUILD)"; export GFORTRAN; \ |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 72 | @@ -202,6 +204,8 @@ HOST_EXPORTS = \ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 73 | AR="$(AR)"; export AR; \ |
| 74 | AS="$(AS)"; export AS; \ |
| 75 | CC_FOR_BUILD="$(CC_FOR_BUILD)"; export CC_FOR_BUILD; \ |
| 76 | + CPP_FOR_BUILD="$(CPP_FOR_BUILD)"; export CPP_FOR_BUILD; \ |
| 77 | + CPPFLAGS_FOR_BUILD="$(CPPFLAGS_FOR_BUILD)"; export CPPFLAGS_FOR_BUILD; \ |
| 78 | CXX_FOR_BUILD="$(CXX_FOR_BUILD)"; export CXX_FOR_BUILD; \ |
| 79 | DLLTOOL="$(DLLTOOL)"; export DLLTOOL; \ |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 80 | DSYMUTIL="$(DSYMUTIL)"; export DSYMUTIL; \ |
| 81 | @@ -360,6 +364,8 @@ AR_FOR_BUILD = @AR_FOR_BUILD@ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 82 | AS_FOR_BUILD = @AS_FOR_BUILD@ |
| 83 | CC_FOR_BUILD = @CC_FOR_BUILD@ |
| 84 | CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ |
| 85 | +CPP_FOR_BUILD = @CPP_FOR_BUILD@ |
| 86 | +CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@ |
| 87 | CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ |
| 88 | CXX_FOR_BUILD = @CXX_FOR_BUILD@ |
| 89 | DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@ |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 90 | diff --git a/Makefile.tpl b/Makefile.tpl |
| 91 | index 9adf4f94728..e39d85d1109 100644 |
| 92 | --- a/Makefile.tpl |
| 93 | +++ b/Makefile.tpl |
| 94 | @@ -157,6 +157,8 @@ BUILD_EXPORTS = \ |
| 95 | CC="$(CC_FOR_BUILD)"; export CC; \ |
| 96 | CFLAGS="$(CFLAGS_FOR_BUILD)"; export CFLAGS; \ |
| 97 | CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ |
| 98 | + CPP="$(CPP_FOR_BUILD)"; export CPP; \ |
| 99 | + CPPFLAGS="$(CPPFLAGS_FOR_BUILD)"; export CPPFLAGS; \ |
| 100 | CXX="$(CXX_FOR_BUILD)"; export CXX; \ |
| 101 | CXXFLAGS="$(CXXFLAGS_FOR_BUILD)"; export CXXFLAGS; \ |
| 102 | GFORTRAN="$(GFORTRAN_FOR_BUILD)"; export GFORTRAN; \ |
| 103 | @@ -205,6 +207,8 @@ HOST_EXPORTS = \ |
| 104 | AR="$(AR)"; export AR; \ |
| 105 | AS="$(AS)"; export AS; \ |
| 106 | CC_FOR_BUILD="$(CC_FOR_BUILD)"; export CC_FOR_BUILD; \ |
| 107 | + CPP_FOR_BUILD="$(CPP_FOR_BUILD)"; export CPP_FOR_BUILD; \ |
| 108 | + CPPFLAGS_FOR_BUILD="$(CPPFLAGS_FOR_BUILD)"; export CPPFLAGS_FOR_BUILD; \ |
| 109 | CXX_FOR_BUILD="$(CXX_FOR_BUILD)"; export CXX_FOR_BUILD; \ |
| 110 | DLLTOOL="$(DLLTOOL)"; export DLLTOOL; \ |
| 111 | DSYMUTIL="$(DSYMUTIL)"; export DSYMUTIL; \ |
| 112 | @@ -363,6 +367,8 @@ AR_FOR_BUILD = @AR_FOR_BUILD@ |
| 113 | AS_FOR_BUILD = @AS_FOR_BUILD@ |
| 114 | CC_FOR_BUILD = @CC_FOR_BUILD@ |
| 115 | CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ |
| 116 | +CPP_FOR_BUILD = @CPP_FOR_BUILD@ |
| 117 | +CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@ |
| 118 | CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ |
| 119 | CXX_FOR_BUILD = @CXX_FOR_BUILD@ |
| 120 | DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@ |
| 121 | diff --git a/configure b/configure |
| 122 | index 45744e6e471..ff0de8a68b4 100755 |
| 123 | --- a/configure |
| 124 | +++ b/configure |
| 125 | @@ -655,6 +655,8 @@ DSYMUTIL_FOR_BUILD |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 126 | DLLTOOL_FOR_BUILD |
| 127 | CXX_FOR_BUILD |
| 128 | CXXFLAGS_FOR_BUILD |
| 129 | +CPPFLAGS_FOR_BUILD |
| 130 | +CPP_FOR_BUILD |
| 131 | CFLAGS_FOR_BUILD |
| 132 | CC_FOR_BUILD |
| 133 | AS_FOR_BUILD |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 134 | @@ -4100,6 +4102,7 @@ if test "${build}" != "${host}" ; then |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 135 | AR_FOR_BUILD=${AR_FOR_BUILD-ar} |
| 136 | AS_FOR_BUILD=${AS_FOR_BUILD-as} |
| 137 | CC_FOR_BUILD=${CC_FOR_BUILD-gcc} |
| 138 | + CPP_FOR_BUILD="${CPP_FOR_BUILD-\$(CPP)}" |
| 139 | CXX_FOR_BUILD=${CXX_FOR_BUILD-g++} |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 140 | DSYMUTIL_FOR_BUILD=${DSYMUTIL_FOR_BUILD-dsymutil} |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 141 | GFORTRAN_FOR_BUILD=${GFORTRAN_FOR_BUILD-gfortran} |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 142 | @@ -9831,6 +9834,7 @@ esac |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 143 | # our build compiler if desired. |
| 144 | if test x"${build}" = x"${host}" ; then |
| 145 | CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD-${CFLAGS}} |
| 146 | + CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-${CPPFLAGS}} |
| 147 | CXXFLAGS_FOR_BUILD=${CXXFLAGS_FOR_BUILD-${CXXFLAGS}} |
| 148 | LDFLAGS_FOR_BUILD=${LDFLAGS_FOR_BUILD-${LDFLAGS}} |
| 149 | fi |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 150 | diff --git a/configure.ac b/configure.ac |
| 151 | index bf66b51373c..09fa3896dc7 100644 |
| 152 | --- a/configure.ac |
| 153 | +++ b/configure.ac |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 154 | @@ -1347,6 +1347,7 @@ if test "${build}" != "${host}" ; then |
| 155 | AR_FOR_BUILD=${AR_FOR_BUILD-ar} |
| 156 | AS_FOR_BUILD=${AS_FOR_BUILD-as} |
| 157 | CC_FOR_BUILD=${CC_FOR_BUILD-gcc} |
| 158 | + CPP_FOR_BUILD="${CPP_FOR_BUILD-\$(CPP)}" |
| 159 | CXX_FOR_BUILD=${CXX_FOR_BUILD-g++} |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 160 | DSYMUTIL_FOR_BUILD=${DSYMUTIL_FOR_BUILD-dsymutil} |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 161 | GFORTRAN_FOR_BUILD=${GFORTRAN_FOR_BUILD-gfortran} |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 162 | @@ -3336,6 +3337,7 @@ esac |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 163 | # our build compiler if desired. |
| 164 | if test x"${build}" = x"${host}" ; then |
| 165 | CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD-${CFLAGS}} |
| 166 | + CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-${CPPFLAGS}} |
| 167 | CXXFLAGS_FOR_BUILD=${CXXFLAGS_FOR_BUILD-${CXXFLAGS}} |
| 168 | LDFLAGS_FOR_BUILD=${LDFLAGS_FOR_BUILD-${LDFLAGS}} |
| 169 | fi |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 170 | @@ -3402,6 +3404,8 @@ AC_SUBST(AR_FOR_BUILD) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 171 | AC_SUBST(AS_FOR_BUILD) |
| 172 | AC_SUBST(CC_FOR_BUILD) |
| 173 | AC_SUBST(CFLAGS_FOR_BUILD) |
| 174 | +AC_SUBST(CPP_FOR_BUILD) |
| 175 | +AC_SUBST(CPPFLAGS_FOR_BUILD) |
| 176 | AC_SUBST(CXXFLAGS_FOR_BUILD) |
| 177 | AC_SUBST(CXX_FOR_BUILD) |
| 178 | AC_SUBST(DLLTOOL_FOR_BUILD) |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 179 | diff --git a/gcc/configure b/gcc/configure |
| 180 | index ec3c24482df..31a460dc9d0 100755 |
| 181 | --- a/gcc/configure |
| 182 | +++ b/gcc/configure |
| 183 | @@ -12740,7 +12740,7 @@ else |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 184 | CC="${CC_FOR_BUILD}" CFLAGS="${CFLAGS_FOR_BUILD}" \ |
| 185 | CXX="${CXX_FOR_BUILD}" CXXFLAGS="${CXXFLAGS_FOR_BUILD}" \ |
| 186 | LD="${LD_FOR_BUILD}" LDFLAGS="${LDFLAGS_FOR_BUILD}" \ |
| 187 | - GMPINC="" CPPFLAGS="${CPPFLAGS} -DGENERATOR_FILE" \ |
| 188 | + GMPINC="" CPPFLAGS="${CPPFLAGS_FOR_BUILD} -DGENERATOR_FILE" \ |
| 189 | ${realsrcdir}/configure \ |
| 190 | --enable-languages=${enable_languages-all} \ |
| 191 | ${enable_obsolete+--enable-obsolete="$enable_obsolete"} \ |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame] | 192 | diff --git a/gcc/configure.ac b/gcc/configure.ac |
| 193 | index ea794cd1763..b965eb036bc 100644 |
| 194 | --- a/gcc/configure.ac |
| 195 | +++ b/gcc/configure.ac |
| 196 | @@ -2054,7 +2054,7 @@ else |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 197 | CC="${CC_FOR_BUILD}" CFLAGS="${CFLAGS_FOR_BUILD}" \ |
| 198 | CXX="${CXX_FOR_BUILD}" CXXFLAGS="${CXXFLAGS_FOR_BUILD}" \ |
| 199 | LD="${LD_FOR_BUILD}" LDFLAGS="${LDFLAGS_FOR_BUILD}" \ |
| 200 | - GMPINC="" CPPFLAGS="${CPPFLAGS} -DGENERATOR_FILE" \ |
| 201 | + GMPINC="" CPPFLAGS="${CPPFLAGS_FOR_BUILD} -DGENERATOR_FILE" \ |
| 202 | ${realsrcdir}/configure \ |
| 203 | --enable-languages=${enable_languages-all} \ |
| 204 | ${enable_obsolete+--enable-obsolete="$enable_obsolete"} \ |