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
This commit is contained in:
Simon J. Gerraty 2023-09-22 23:27:37 -07:00
parent bb124a0f61
commit f9df609750
10 changed files with 71 additions and 27 deletions

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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