diff mbox series

config-ml.in: Fix multi-os-dir search

Message ID 20240101164807.3812140-1-syq@gcc.gnu.org
State New
Headers show
Series config-ml.in: Fix multi-os-dir search | expand

Commit Message

YunQiang Su Jan. 1, 2024, 4:48 p.m. UTC
When building multilib libraries, CC/CXX etc are set with an option
-B*/lib/, instead of -B<something>/lib/<multi-os-directory>.
This will make some trouble in some case, for example building
cross toolchain based on Debian's cross packages:

  If we have libc6-dev-i386-amd64-cross packages installed on
  a non-x86 machine. This package will have the files in
  /usr/x86_4-linux-gnu/lib32.  The fellow configure will fail
  when build libgcc for i386, with complains the libc is not
  i386 ones:
     ../configure --enable-multilib --enable-multilib \
            --target=x86_64-linux-gnu

Let's insert a "-B*/lib/`CC ${flags} --print-multi-os-directory`"
before "-B*/lib/".

This patch is based on the patch used by Debian now.

ChangeLog

	* config-ml.in: Insert an -B option with multi-os-dir into
	compiler commands used to build libraries.
---
 config-ml.in | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Jeff Law Jan. 2, 2024, 4:59 p.m. UTC | #1
On 1/1/24 09:48, YunQiang Su wrote:
> When building multilib libraries, CC/CXX etc are set with an option
> -B*/lib/, instead of -B<something>/lib/<multi-os-directory>.
> This will make some trouble in some case, for example building
> cross toolchain based on Debian's cross packages:
> 
>    If we have libc6-dev-i386-amd64-cross packages installed on
>    a non-x86 machine. This package will have the files in
>    /usr/x86_4-linux-gnu/lib32.  The fellow configure will fail
>    when build libgcc for i386, with complains the libc is not
>    i386 ones:
>       ../configure --enable-multilib --enable-multilib \
>              --target=x86_64-linux-gnu
> 
> Let's insert a "-B*/lib/`CC ${flags} --print-multi-os-directory`"
> before "-B*/lib/".
> 
> This patch is based on the patch used by Debian now.
> 
> ChangeLog
> 
> 	* config-ml.in: Insert an -B option with multi-os-dir into
> 	compiler commands used to build libraries.
I would prefer this to wait for gcc-15.   I'll go ahead and ACK it for 
gcc-15 though.

What would also be valuable would be to extract out the rest of the 
multiarch patches from the Debian patches and get those into into GCC 
proper.

Jeff
YunQiang Su April 29, 2024, 3:15 a.m. UTC | #2
Jeff Law <jeffreyalaw@gmail.com> 于2024年1月3日周三 01:00写道:
>
>
>
> On 1/1/24 09:48, YunQiang Su wrote:
> > When building multilib libraries, CC/CXX etc are set with an option
> > -B*/lib/, instead of -B<something>/lib/<multi-os-directory>.
> > This will make some trouble in some case, for example building
> > cross toolchain based on Debian's cross packages:
> >
> >    If we have libc6-dev-i386-amd64-cross packages installed on
> >    a non-x86 machine. This package will have the files in
> >    /usr/x86_4-linux-gnu/lib32.  The fellow configure will fail
> >    when build libgcc for i386, with complains the libc is not
> >    i386 ones:
> >       ../configure --enable-multilib --enable-multilib \
> >              --target=x86_64-linux-gnu
> >
> > Let's insert a "-B*/lib/`CC ${flags} --print-multi-os-directory`"
> > before "-B*/lib/".
> >
> > This patch is based on the patch used by Debian now.
> >
> > ChangeLog
> >
> >       * config-ml.in: Insert an -B option with multi-os-dir into
> >       compiler commands used to build libraries.
> I would prefer this to wait for gcc-15.   I'll go ahead and ACK it for
> gcc-15 though.
>

I noticed that the gcc-14 branch has been created, and the basever has also
been 15.0 now.
Is it time for this patch now?

> What would also be valuable would be to extract out the rest of the
> multiarch patches from the Debian patches and get those into into GCC
> proper.
>
> Jeff
diff mbox series

Patch

diff --git a/config-ml.in b/config-ml.in
index 68854a4f16c..645cac822fd 100644
--- a/config-ml.in
+++ b/config-ml.in
@@ -514,7 +514,12 @@  multi-do:
 	    else \
 	      if [ -d ../$${dir}/$${lib} ]; then \
 		flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
-		if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
+		libsuffix_=`$${compiler} $${flags} --print-multi-os-directory`; \
+		if (cd ../$${dir}/$${lib}; $(MAKE) $(subst \
+				-B$(build_tooldir)/lib/, \
+				-B$(build_tooldir)/lib/$${libsuffix_}/ \
+				-B$(build_tooldir)/lib/, \
+				$(FLAGS_TO_PASS)) \
 				CFLAGS="$(CFLAGS) $${flags}" \
 				CCASFLAGS="$(CCASFLAGS) $${flags}" \
 				FCFLAGS="$(FCFLAGS) $${flags}" \
@@ -768,6 +773,7 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	# Create a regular expression that matches any string as long
 	# as ML_POPDIR.
 	popdir_rx=`echo "${ML_POPDIR}" | sed 's,.,.,g'`
+	multi_osdir=`${CC-gcc} ${flags} --print-multi-os-directory 2>/dev/null`
 	CC_=
 	for arg in ${CC}; do
 	  case $arg in
@@ -775,6 +781,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    CC_="${CC_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    CC_="${CC_}${arg} " ;;
 	  esac
@@ -787,6 +795,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    CXX_="${CXX_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    CXX_="${CXX_}${arg} " ;;
 	  esac
@@ -799,6 +809,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    F77_="${F77_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    F77_="${F77_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    F77_="${F77_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    F77_="${F77_}${arg} " ;;
 	  esac
@@ -811,6 +823,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    GFORTRAN_="${GFORTRAN_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    GFORTRAN_="${GFORTRAN_}${arg} " ;;
 	  esac
@@ -823,6 +837,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    GOC_="${GOC_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    GOC_="${GOC_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    GOC_="${GOC_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    GOC_="${GOC_}${arg} " ;;
 	  esac
@@ -835,6 +851,8 @@  if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
 	    GDC_="${GDC_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
 	  "${ML_POPDIR}"/*)
 	    GDC_="${GDC_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
+	  -B*/lib/)
+	    GDC_="${GDC_}${arg}${multi_osdir} ${arg} " ;;
 	  *)
 	    GDC_="${GDC_}${arg} " ;;
 	  esac