xref: /freebsd/share/mk/bsd.compat.mk (revision da759cfa320d5076b075d15ff3f00ab3ba5634fd)
1# $FreeBSD$
2
3.if !targets(__<${_this:T}>__)
4__<${_this:T}>__:
5
6.if defined(_LIBCOMPAT)
7COMPAT_ARCH?=	${TARGET_ARCH}
8COMPAT_CPUTYPE?= ${CPUTYPE_${_LIBCOMPAT}}
9.if (defined(WANT_COMPILER_TYPE) && ${WANT_COMPILER_TYPE} == gcc) || \
10    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
11COMPAT_COMPILER_TYPE=	gcc
12.else
13COMPAT_COMPILER_TYPE=	clang
14.endif
15.else
16COMPAT_ARCH=	${MACHINE_ARCH}
17COMPAT_CPUTYPE=	${CPUTYPE}
18.include <bsd.compiler.mk>
19COMPAT_COMPILER_TYPE=${COMPILER_TYPE}
20.endif
21
22# -------------------------------------------------------------------
23# 32 bit world
24.if ${COMPAT_ARCH} == "amd64"
25HAS_COMPAT=32
26.if empty(COMPAT_CPUTYPE)
27LIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
28.else
29LIB32CPUFLAGS=	-march=${COMPAT_CPUTYPE}
30.endif
31.if ${COMPAT_COMPILER_TYPE} == gcc
32.else
33LIB32CPUFLAGS+=	-target x86_64-unknown-freebsd13.0
34.endif
35LIB32CPUFLAGS+=	-m32
36LIB32_MACHINE=	i386
37LIB32_MACHINE_ARCH=	i386
38LIB32WMAKEENV=	MACHINE_CPU="i686 mmx sse sse2"
39LIB32WMAKEFLAGS=	\
40		AS="${XAS} --32" \
41		LD="${XLD} -m elf_i386_fbsd -L${LIBCOMPATTMP}/usr/lib32"
42
43.elif ${COMPAT_ARCH} == "powerpc64"
44HAS_COMPAT=32
45.if empty(COMPAT_CPUTYPE)
46LIB32CPUFLAGS=	-mcpu=powerpc
47.else
48LIB32CPUFLAGS=	-mcpu=${COMPAT_CPUTYPE}
49.endif
50
51.if ${COMPAT_COMPILER_TYPE} == "gcc"
52LIB32CPUFLAGS+=	-m32
53.else
54LIB32CPUFLAGS+=	-target powerpc-unknown-freebsd13.0
55
56# Use BFD to workaround ld.lld issues on PowerPC 32 bit
57LIB32CPUFLAGS+= -fuse-ld=${LD_BFD}
58.endif
59
60LIB32_MACHINE=	powerpc
61LIB32_MACHINE_ARCH=	powerpc
62LIB32WMAKEFLAGS=	\
63		LD="${LD_BFD} -m elf32ppc_fbsd"
64
65.elif ${COMPAT_ARCH:Mmips64*} != ""
66HAS_COMPAT=32
67.if ${COMPAT_COMPILER_TYPE} == gcc
68.if empty(COMPAT_CPUTYPE)
69LIB32CPUFLAGS=	-march=mips3
70.else
71LIB32CPUFLAGS=	-march=${COMPAT_CPUTYPE}
72.endif
73.else
74.if ${COMPAT_ARCH:Mmips64el*} != ""
75LIB32CPUFLAGS=  -target mipsel-unknown-freebsd13.0
76.else
77LIB32CPUFLAGS=  -target mips-unknown-freebsd13.0
78.endif
79.endif
80LIB32CPUFLAGS+= -mabi=32
81LIB32_MACHINE=	mips
82LIB32_MACHINE_ARCH:=	${COMPAT_ARCH:S/64//}
83.if ${COMPAT_ARCH:Mmips64el*} != ""
84_EMULATION=	elf32ltsmip_fbsd
85.else
86_EMULATION=	elf32btsmip_fbsd
87.endif
88LIB32WMAKEFLAGS= LD="${XLD} -m ${_EMULATION}"
89LIB32LDFLAGS=	-Wl,-m${_EMULATION}
90.endif
91
92LIB32WMAKEFLAGS+= NM="${XNM}"
93LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
94
95LIB32CFLAGS=	-DCOMPAT_32BIT
96LIB32DTRACE=	${DTRACE} -32
97LIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
98
99# -------------------------------------------------------------------
100# soft-fp world
101.if ${COMPAT_ARCH:Marmv[67]*} != ""
102HAS_COMPAT=SOFT
103LIBSOFTCFLAGS=        -DCOMPAT_SOFTFP
104LIBSOFTCPUFLAGS= -mfloat-abi=softfp
105LIBSOFT_MACHINE=	arm
106LIBSOFT_MACHINE_ARCH=	${COMPAT_ARCH}
107LIBSOFTWMAKEENV= CPUTYPE=soft
108LIBSOFTWMAKEFLAGS=        -DCOMPAT_SOFTFP
109.endif
110
111# -------------------------------------------------------------------
112# In the program linking case, select LIBCOMPAT
113.if defined(NEED_COMPAT)
114.ifndef HAS_COMPAT
115.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH}
116.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
117.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT ($HAS_COMPAT)
118.elif ${NEED_COMPAT} == "any"
119.endif
120.ifdef WANT_COMPAT
121.error Both WANT_COMPAT and NEED_COMPAT defined
122.endif
123WANT_COMPAT:=	${NEED_COMPAT}
124.endif
125
126.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
127.if ${WANT_COMPAT} == "any"
128_LIBCOMPAT:=	${HAS_COMPAT:[1]}
129.else
130_LIBCOMPAT:=	${WANT_COMPAT}
131.endif
132.endif
133
134
135# -------------------------------------------------------------------
136# Generic code for each type.
137# Set defaults based on type.
138libcompat=	${_LIBCOMPAT:tl}
139_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
140			_MACHINE _MACHINE_ARCH WMAKEENV WMAKEFLAGS WMAKE
141.for _var in ${_LIBCOMPAT_MAKEVARS}
142.if !empty(LIB${_LIBCOMPAT}${_var})
143LIBCOMPAT${_var}?=	${LIB${_LIBCOMPAT}${_var}}
144.endif
145.endfor
146
147# Shared flags
148LIBCOMPAT_OBJTOP?=	${OBJTOP}/obj-lib${libcompat}
149LIBCOMPATTMP?=		${LIBCOMPAT_OBJTOP}/tmp
150
151LIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
152			-L${LIBCOMPATTMP}/usr/lib${libcompat} \
153			--sysroot=${LIBCOMPATTMP} \
154			${BFLAGS}
155
156LIBCOMPATWMAKEENV+=	MACHINE=${LIBCOMPAT_MACHINE}
157LIBCOMPATWMAKEENV+=	MACHINE_ARCH=${LIBCOMPAT_MACHINE_ARCH}
158
159# -B is needed to find /usr/lib32/crti.o for GCC and /usr/libsoft/crti.o for
160# Clang/GCC.
161LIBCOMPATCFLAGS+=	-B${LIBCOMPATTMP}/usr/lib${libcompat}
162
163.if defined(WANT_COMPAT)
164LIBDIR_BASE:=	/usr/lib${libcompat}
165_LIB_OBJTOP=	${LIBCOMPAT_OBJTOP}
166CFLAGS+=	${LIBCOMPATCFLAGS}
167LDFLAGS+=	${CFLAGS} ${LIBCOMPATLDFLAGS}
168MACHINE=	${LIBCOMPAT_MACHINE}
169MACHINE_ARCH=	${LIBCOMPAT_MACHINE_ARCH}
170.endif
171
172.endif
173