1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-04 09:09:56 +00:00
freebsd/share/mk/bsd.compat.mk
Brooks Davis 426fc376af bsd.cpu.mk: Introduce MACHINE_ABI
MACHINE_ABI is a list of properties of the ABI used for MACHINE_ARCH.
It should be used in place of long conditionals on MACHINE_ARCH where
practical.

The following properties are indicated with one of the follow values:

Byte order:                  big-endian, little-endian
Floating point ABI:          soft-float, hard-float
Size of long (size_t, etc):  long32, long64
Pointer type:                ptr32, ptr64
Size of time_t:              time32, time64

For example, i386 targets will be:
MACHINE_ABI=	big-endian hard-float long32 ptr32 time32

Reviewed by:	imp
Obtained from:	CheriBSD
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D36421
2022-10-05 17:27:44 +01:00

140 lines
3.5 KiB
Makefile

# $FreeBSD$
.if !targets(__<${_this:T}>__)
__<${_this:T}>__:
.if defined(_LIBCOMPAT)
COMPAT_ARCH?= ${TARGET_ARCH}
COMPAT_CPUTYPE?= ${CPUTYPE_${_LIBCOMPAT}}
.if (defined(WANT_COMPILER_TYPE) && ${WANT_COMPILER_TYPE} == gcc) || \
(defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
COMPAT_COMPILER_TYPE= gcc
.else
COMPAT_COMPILER_TYPE= clang
.endif
.else
COMPAT_ARCH= ${MACHINE_ARCH}
COMPAT_CPUTYPE= ${CPUTYPE}
.include <bsd.compiler.mk>
COMPAT_COMPILER_TYPE=${COMPILER_TYPE}
.endif
# -------------------------------------------------------------------
# 32 bit world
.if ${COMPAT_ARCH} == "amd64"
HAS_COMPAT=32
.if empty(COMPAT_CPUTYPE)
LIB32CPUFLAGS= -march=i686 -mmmx -msse -msse2
.else
LIB32CPUFLAGS= -march=${COMPAT_CPUTYPE}
.endif
.if ${COMPAT_COMPILER_TYPE} == gcc
.else
LIB32CPUFLAGS+= -target x86_64-unknown-freebsd${OS_REVISION}
.endif
LIB32CPUFLAGS+= -m32
LIB32_MACHINE= i386
LIB32_MACHINE_ARCH= i386
LIB32WMAKEENV= MACHINE_CPU="i686 mmx sse sse2"
LIB32WMAKEFLAGS= \
AS="${XAS} --32" \
LD="${XLD} -m elf_i386_fbsd"
.elif ${COMPAT_ARCH} == "powerpc64"
HAS_COMPAT=32
.if empty(COMPAT_CPUTYPE)
LIB32CPUFLAGS= -mcpu=powerpc
.else
LIB32CPUFLAGS= -mcpu=${COMPAT_CPUTYPE}
.endif
.if ${COMPAT_COMPILER_TYPE} == "gcc"
LIB32CPUFLAGS+= -m32
.else
LIB32CPUFLAGS+= -target powerpc-unknown-freebsd${OS_REVISION}
.endif
LIB32_MACHINE= powerpc
LIB32_MACHINE_ARCH= powerpc
LIB32WMAKEFLAGS= \
LD="${XLD} -m elf32ppc_fbsd"
.endif
LIB32WMAKEFLAGS+= NM="${XNM}"
LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
LIB32CFLAGS= -DCOMPAT_32BIT
LIB32DTRACE= ${DTRACE} -32
LIB32WMAKEFLAGS+= -DCOMPAT_32BIT
LIB32_MACHINE_ABI= ${MACHINE_ABI:N*64} long32 ptr32
.if ${COMPAT_ARCH} == "amd64"
LIB32_MACHINE_ABI+= time32
.else
LIB32_MACHINE_ABI+= time64
.endif
# -------------------------------------------------------------------
# In the program linking case, select LIBCOMPAT
.if defined(NEED_COMPAT)
.ifndef HAS_COMPAT
.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH})
.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT (${HAS_COMPAT})
.elif ${NEED_COMPAT} == "any"
.endif
.ifdef WANT_COMPAT
.error Both WANT_COMPAT and NEED_COMPAT defined
.endif
WANT_COMPAT:= ${NEED_COMPAT}
.endif
.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
.if ${WANT_COMPAT} == "any"
_LIBCOMPAT:= ${HAS_COMPAT:[1]}
.else
_LIBCOMPAT:= ${WANT_COMPAT}
.endif
.endif
# -------------------------------------------------------------------
# Generic code for each type.
# Set defaults based on type.
libcompat= ${_LIBCOMPAT:tl}
_LIBCOMPAT_MAKEVARS= _OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
_MACHINE _MACHINE_ARCH _MACHINE_ABI \
WMAKEENV WMAKEFLAGS WMAKE WORLDTMP
.for _var in ${_LIBCOMPAT_MAKEVARS}
.if !empty(LIB${_LIBCOMPAT}${_var})
LIBCOMPAT${_var}?= ${LIB${_LIBCOMPAT}${_var}}
.endif
.endfor
WORLDTMP?= ${SYSROOT}
# Shared flags
LIBCOMPAT_OBJTOP?= ${OBJTOP}/obj-lib${libcompat}
LIBCOMPATCFLAGS+= ${LIBCOMPATCPUFLAGS} \
--sysroot=${WORLDTMP} \
${BFLAGS}
LIBCOMPATLDFLAGS+= -L${WORLDTMP}/usr/lib${libcompat}
LIBCOMPATWMAKEENV+= MACHINE=${LIBCOMPAT_MACHINE}
LIBCOMPATWMAKEENV+= MACHINE_ARCH=${LIBCOMPAT_MACHINE_ARCH}
# -B is needed to find /usr/lib32/crti.o for gcc.
LIBCOMPATCFLAGS+= -B${WORLDTMP}/usr/lib${libcompat}
.if defined(WANT_COMPAT)
LIBDIR_BASE:= /usr/lib${libcompat}
LIBDATADIR:= /usr/lib${libcompat}
_LIB_OBJTOP= ${LIBCOMPAT_OBJTOP}
CFLAGS+= ${LIBCOMPATCFLAGS}
LDFLAGS+= ${CFLAGS} ${LIBCOMPATLDFLAGS}
MACHINE= ${LIBCOMPAT_MACHINE}
MACHINE_ARCH= ${LIBCOMPAT_MACHINE_ARCH}
.endif
.endif