Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Sep 2023 06:28:23 GMT
From:      "Simon J. Gerraty" <sjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f9df60975087 - main - Add support for host32 for DIRDEPS_BUILD
Message-ID:  <202309230628.38N6SNw8008190@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=f9df609750876be2c054dfac953316f513ccffce

commit f9df609750876be2c054dfac953316f513ccffce
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2023-09-23 06:27:37 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2023-09-23 06:27:37 +0000

    Add support for host32 for DIRDEPS_BUILD
    
    Allow building 32bit libs for host.
    
    Move CFLAGS additions from local.sys.dirdeps.mk (which is too early
    and impacts CFLAGS defaults) to local.sys.mk
    
    Reviewed by:    stevek
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision:  https://reviews.freebsd.org/D41946
---
 share/mk/host-target.mk           | 44 ++++++++++++++++++++++++++++-----------
 share/mk/local.dirdeps.mk         |  6 ++++++
 share/mk/local.init.mk            |  6 +++---
 share/mk/local.sys.dirdeps.env.mk | 15 +++++++++++--
 share/mk/local.sys.dirdeps.mk     | 10 ++-------
 share/mk/local.sys.machine.mk     |  3 ++-
 share/mk/local.sys.mk             |  7 +++++++
 share/mk/src.init.linux.mk        |  3 +++
 share/mk/src.opts.mk              |  2 +-
 tools/build/Makefile              |  2 ++
 10 files changed, 71 insertions(+), 27 deletions(-)

diff --git a/share/mk/host-target.mk b/share/mk/host-target.mk
index f528db9c6d24..d8abea17fdac 100644
--- a/share/mk/host-target.mk
+++ b/share/mk/host-target.mk
@@ -1,32 +1,40 @@
 # RCSid:
-#	$Id: host-target.mk,v 1.11 2015/10/25 00:07:20 sjg Exp $
+#	$Id: host-target.mk,v 1.19 2023/09/21 06:44:53 sjg Exp $
 
 # Host platform information; may be overridden
+.if !target(__${.PARSEFILE}__)
+__${.PARSEFILE}__: .NOTMAIN
+
 .if !defined(_HOST_OSNAME)
-_HOST_OSNAME !=	uname -s
+# use .MAKE.OS if available
+_HOST_OSNAME := ${.MAKE.OS:U${uname -s:L:sh}}
 .export _HOST_OSNAME
 .endif
 .if !defined(_HOST_OSREL)
 _HOST_OSREL  !=	uname -r
 .export _HOST_OSREL
 .endif
-.if !defined(_HOST_MACHINE)
-_HOST_MACHINE != uname -m
-.export _HOST_MACHINE
-.endif
 .if !defined(_HOST_ARCH)
-# for NetBSD prefer $MACHINE (amd64 rather than x86_64)
-.if ${_HOST_OSNAME:NNetBSD} == ""
-_HOST_ARCH := ${_HOST_MACHINE}
-.else
 _HOST_ARCH != uname -p 2> /dev/null || uname -m
 # uname -p may produce garbage on linux
 .if ${_HOST_ARCH:[\#]} > 1 || ${_HOST_ARCH:Nunknown} == ""
-_HOST_ARCH := ${_HOST_MACHINE}
-.endif
+_HOST_ARCH = ${_HOST_MACHINE}
+.elif ${_HOST_OSNAME:NDarwin} == "" && ${_HOST_ARCH:Narm:Ni386} == ""
+# _HOST_MACHINE is more explicit/useful
+_HOST_ARCH = ${_HOST_MACHINE}
 .endif
 .export _HOST_ARCH
 .endif
+.if !defined(_HOST_MACHINE)
+_HOST_MACHINE != uname -m
+# just in case
+_HOST_ARCH := ${_HOST_ARCH}
+# uname -m may produce garbage on darwin ppc
+.if ${_HOST_MACHINE:[\#]} > 1
+_HOST_MACHINE := ${_HOST_ARCH}
+.endif
+.export _HOST_MACHINE
+.endif
 .if !defined(HOST_MACHINE)
 HOST_MACHINE := ${_HOST_MACHINE}
 .export HOST_MACHINE
@@ -37,8 +45,20 @@ HOST_OSTYPE  :=	${_HOST_OSNAME:S,/,,g}-${_HOST_OSREL:C/\([^\)]*\)//}-${_HOST_ARC
 HOST_OS      :=	${_HOST_OSNAME}
 host_os      :=	${_HOST_OSNAME:tl}
 HOST_TARGET  := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH}
+# sometimes we want HOST_TARGET32
+MACHINE32.amd64 = i386
+MACHINE32.x86_64 = i386
+.if !defined(_HOST_ARCH32)
+_HOST_ARCH32 := ${MACHINE32.${_HOST_ARCH}:U${_HOST_ARCH:S,64$,,}}
+.export _HOST_ARCH32
+.endif
+HOST_TARGET32 := ${host_os:S,/,,g}${HOST_OSMAJOR}-${_HOST_ARCH32}
+
+.export HOST_TARGET HOST_TARGET32
 
 # tr is insanely non-portable, accommodate the lowest common denominator
 TR ?= tr
 toLower = ${TR} 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
 toUpper = ${TR} 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+
+.endif
diff --git a/share/mk/local.dirdeps.mk b/share/mk/local.dirdeps.mk
index 7b4a1fdf426d..99782b856d41 100644
--- a/share/mk/local.dirdeps.mk
+++ b/share/mk/local.dirdeps.mk
@@ -22,7 +22,9 @@ DIRDEPS_FILTER.host = \
 	Ninclude* \
 	Nlib/csu* \
 	Nlib/libc \
+	Nlib/libcompiler_rt \
 	Nlib/[mn]* \
+	Nlib/lib[t]* \
 	Ngnu/lib/lib[a-r]* \
 	Nsecure/lib* \
 	Nusr.bin/xinstall* \
@@ -50,6 +52,8 @@ N_host_libs:= ${cd ${SRCTOP} && echo lib/lib*:L:sh:${_need_host_libs:${M_ListToS
 DIRDEPS_FILTER.host+= ${N_host_libs}
 .endif
 
+DIRDEPS_FILTER.host32 = ${DIRDEPS_FILTER.host}
+
 DIRDEPS_FILTER+= \
 	Nbin/cat.host \
 	${DIRDEPS_FILTER.xtras:U}
@@ -107,6 +111,7 @@ DIRDEPS += \
 	cddl/usr.bin/ctfmerge.host
 .endif
 
+.if ${DEP_MACHINE:Nhost*} != ""
 # Add in proper libgcc (gnu or LLVM) if not building libcc and libc is needed.
 # Add both gcc_s and gcc_eh as dependencies as the decision to build
 # -static or not is not known here.
@@ -115,6 +120,7 @@ DIRDEPS+= \
 	lib/libgcc_eh \
 	lib/libgcc_s
 .endif
+.endif
 
 # Bootstrap support.  Give hints to DIRDEPS if there is no Makefile.depend*
 # generated yet.  This can be based on things such as SRC files and LIBADD.
diff --git a/share/mk/local.init.mk b/share/mk/local.init.mk
index d9477fd22827..758a3604d73a 100644
--- a/share/mk/local.init.mk
+++ b/share/mk/local.init.mk
@@ -13,7 +13,7 @@ __${_this}__:
 
 # XXX: This should be combined with external compiler support in Makefile.inc1
 # and local.meta.sys.mk (CROSS_TARGET_FLAGS)
-.if ${MK_SYSROOT} == "yes" && !empty(SYSROOT) && ${MACHINE} != "host"
+.if ${MK_SYSROOT} == "yes" && !empty(SYSROOT) && ${MACHINE:Nhost*} != ""
 CFLAGS_LAST+= --sysroot=${SYSROOT}
 CXXFLAGS_LAST+= --sysroot=${SYSROOT}
 LDADD+= --sysroot=${SYSROOT}
@@ -29,8 +29,8 @@ CFLAGS+= -isystem${ISYSTEM}
 LDADD+= -L${STAGE_LIBDIR}
 .endif
 
-.if ${MACHINE} == "host"
-.if ${.MAKE.DEPENDFILE:E} != "host"
+.if ${MACHINE:Nhost*} == ""
+.if ${.MAKE.DEPENDFILE:E:Nhost*} != ""
 UPDATE_DEPENDFILE?= no
 .endif
 HOST_CFLAGS+= -DHOSTPROG
diff --git a/share/mk/local.sys.dirdeps.env.mk b/share/mk/local.sys.dirdeps.env.mk
index bbac39935ad8..fdcb25b67e31 100644
--- a/share/mk/local.sys.dirdeps.env.mk
+++ b/share/mk/local.sys.dirdeps.env.mk
@@ -24,17 +24,28 @@ BOOT_MACHINE_DIR.$m ?= stand/$m
 .endfor
 
 HOST_OBJTOP ?= ${OBJROOT}${HOST_TARGET}
+HOST_OBJTOP32 ?= ${OBJROOT}${HOST_TARGET32}
 
+.if ${.MAKE.LEVEL} == 0
 .if ${REQUESTED_MACHINE:U${MACHINE}} == "host"
 MACHINE= host
 .if ${TARGET_MACHINE:Uno} == ${HOST_TARGET}
 # not what we want
 TARGET_MACHINE= host
 .endif
+.elif ${REQUESTED_MACHINE:U${MACHINE}} == "host32"
+MACHINE= host32
 .endif
-.if ${MACHINE} == "host"
-OBJTOP := ${HOST_OBJTOP}
+.endif
+
+.if ${MACHINE:Nhost*} == ""
 MACHINE_ARCH= ${MACHINE_ARCH_${MACHINE}}
+.if ${MACHINE} == "host32"
+.MAKE.DEPENDFILE_PREFERENCE= \
+	${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.host32 \
+	${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}.host \
+	${.CURDIR}/${.MAKE.DEPENDFILE_PREFIX}
+.endif
 .endif
 
 
diff --git a/share/mk/local.sys.dirdeps.mk b/share/mk/local.sys.dirdeps.mk
index ce4843482179..357b6e2aa5ff 100644
--- a/share/mk/local.sys.dirdeps.mk
+++ b/share/mk/local.sys.dirdeps.mk
@@ -43,7 +43,7 @@ LDFLAGS_LAST+= -L${STAGE_LIBDIR}
 
 .-include "local.toolchain.mk"
 
-.if ${.MAKE.LEVEL} > 0 && ${MACHINE} == "host" && ${.MAKE.DEPENDFILE:E} != "host"
+.if ${.MAKE.LEVEL} > 0 && ${MACHINE:Nhost*} == "" && ${.MAKE.DEPENDFILE:E} != "${MACHINE}"
 # we can use this but should not update it.
 UPDATE_DEPENDFILE?= NO
 .endif
@@ -115,16 +115,10 @@ ${var}=		${HOST_${var}}
 .endfor
 .endif
 
-.if ${MACHINE:Nhost:Ncommon} != "" && ${MACHINE} != ${HOST_MACHINE}
-# cross-building
 .if !defined(FREEBSD_REVISION)
 FREEBSD_REVISION!= sed -n '/^REVISION=/{s,.*=,,;s,",,g;p; }' ${SRCTOP}/sys/conf/newvers.sh
 .export FREEBSD_REVISION
 .endif
-CROSS_TARGET_FLAGS?= -target ${MACHINE_ARCH}-unknown-freebsd${FREEBSD_REVISION}
-CFLAGS+= ${CROSS_TARGET_FLAGS}
-ACFLAGS+= ${CROSS_TARGET_FLAGS}
-.endif
 
 # we set these here, rather than local.gendirdeps.mk
 # so we can ensure any DEP_* values that might be used in
@@ -150,7 +144,7 @@ $V?= ${${V:S,DEP_,,}}
 .endfor
 .endif
 
-.if ${MACHINE} == "host" && ${.MAKE.OS} != "FreeBSD"
+.if ${MACHINE:Nhost*} == "" && ${.MAKE.OS} != "FreeBSD"
 # some makefiles expect this
 BOOTSTRAPPING= 0
 .endif
diff --git a/share/mk/local.sys.machine.mk b/share/mk/local.sys.machine.mk
index fc801a7cd11c..5e40dfe805f9 100644
--- a/share/mk/local.sys.machine.mk
+++ b/share/mk/local.sys.machine.mk
@@ -1,10 +1,11 @@
 
 .-include <site.sys.machine.mk>
 
-PSEUDO_MACHINE_LIST?= common host
+PSEUDO_MACHINE_LIST?= common host host32
 TARGET_MACHINE_LIST?= amd64 arm arm64 i386 powerpc riscv
 
 MACHINE_ARCH_host?= ${_HOST_ARCH}
+MACHINE_ARCH_host32?= ${_HOST_ARCH32}
 
 MACHINE_ARCH_LIST_arm?= armv7 ${EXTRA_ARCHES_arm}
 MACHINE_ARCH_LIST_arm64?= aarch64
diff --git a/share/mk/local.sys.mk b/share/mk/local.sys.mk
index 59b1a7c14a7c..eb21380f051c 100644
--- a/share/mk/local.sys.mk
+++ b/share/mk/local.sys.mk
@@ -95,4 +95,11 @@ META_COOKIE_RM?=
 META_COOKIE_TOUCH?=
 META_DEPS+=	${META_NOPHONY}
 
+.if ${MACHINE:Nhost*:Ncommon} != "" && ${MACHINE} != ${HOST_MACHINE}
+# cross-building
+CROSS_TARGET_FLAGS?= -target ${MACHINE_ARCH}-unknown-freebsd${FREEBSD_REVISION}
+CFLAGS+= ${CROSS_TARGET_FLAGS}
+ACFLAGS+= ${CROSS_TARGET_FLAGS}
+.endif
+
 .endif
diff --git a/share/mk/src.init.linux.mk b/share/mk/src.init.linux.mk
index 1e351e1b41f6..536f32853d3c 100644
--- a/share/mk/src.init.linux.mk
+++ b/share/mk/src.init.linux.mk
@@ -1,5 +1,6 @@
 # We want to build some host tools (eg makefs, mkimg) for Linux
 # This only gets included during DIRDEPS_BUILD when MACHINE is "host"
+# or "host32"
 
 CFLAGS+= -I${SRCTOP}/tools/build/cross-build/include/linux
 
@@ -13,3 +14,5 @@ LIBADD+= egacy m
 # Bring in the full GNU namespace
 CFLAGS+= -D_GNU_SOURCE
 
+# for sane staging behavior
+LN= ln -L
diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk
index d7112cf57178..c234a9829fca 100644
--- a/share/mk/src.opts.mk
+++ b/share/mk/src.opts.mk
@@ -368,7 +368,7 @@ BROKEN_OPTIONS+= OFED
 .endif
 
 # MK_host_egacy is set by local.sys.mk so is valid here
-.if ${MACHINE} == "host" && ${MK_host_egacy} == "yes"
+.if ${MACHINE:Nhost*} == "" && ${MK_host_egacy} == "yes"
 # we cannot expect tests to work
 BROKEN_OPTIONS+= TESTS
 .endif
diff --git a/tools/build/Makefile b/tools/build/Makefile
index 8ad104f904ea..a19d2bf64bc6 100644
--- a/tools/build/Makefile
+++ b/tools/build/Makefile
@@ -126,6 +126,8 @@ CHACHA20INCS+=	${SRCTOP}/sys/crypto/chacha20/_chacha.h \
 
 .if ${MACHINE} == "host"
 _host_arch= ${_HOST_ARCH}
+.elif ${MACHINE} == "host32"
+_host_arch= ${_HOST_ARCH32}
 .else
 _host_arch=${MACHINE}
 .endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202309230628.38N6SNw8008190>