xref: /freebsd/share/mk/bsd.compat.mk (revision 8b238f4126d32df3e70056bc32536b7248ebffa0)
1# $FreeBSD$
2
3.if !targets(__<${_this:T}>__)
4__<${_this:T}>__:
5
6.if defined(_LIBCOMPAT)
7COMPAT_ARCH=	${TARGET_ARCH}
8COMPAT_CPUTYPE=	${TARGET_CPUTYPE}
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
50LIB32CPUFLAGS+=	-m32
51LIB32_MACHINE=	powerpc
52LIB32_MACHINE_ARCH=	powerpc
53LIB32WMAKEFLAGS=	\
54		LD="${XLD} -m elf32ppc_fbsd"
55
56.elif ${COMPAT_ARCH:Mmips64*} != ""
57HAS_COMPAT=32
58.if ${COMPAT_COMPILER_TYPE} == gcc
59.if empty(COMPAT_CPUTYPE)
60LIB32CPUFLAGS=	-march=mips3
61.else
62LIB32CPUFLAGS=	-march=${COMPAT_CPUTYPE}
63.endif
64.else
65.if ${COMPAT_ARCH:Mmips64el*} != ""
66LIB32CPUFLAGS=  -target mipsel-unknown-freebsd13.0
67.else
68LIB32CPUFLAGS=  -target mips-unknown-freebsd13.0
69.endif
70.endif
71LIB32CPUFLAGS+= -mabi=32
72LIB32_MACHINE=	mips
73LIB32_MACHINE_ARCH=	mips
74.if ${COMPAT_ARCH:Mmips64el*} != ""
75_EMULATION=	elf32ltsmip_fbsd
76.else
77_EMULATION=	elf32btsmip_fbsd
78.endif
79LIB32WMAKEFLAGS= LD="${XLD} -m ${_EMULATION}"
80LIB32LDFLAGS=	-Wl,-m${_EMULATION}
81.endif
82
83LIB32WMAKEFLAGS+= NM="${XNM}"
84LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
85
86LIB32CFLAGS=	-DCOMPAT_32BIT
87LIB32DTRACE=	${DTRACE} -32
88LIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
89
90# -------------------------------------------------------------------
91# soft-fp world
92.if ${COMPAT_ARCH:Marmv[67]*} != ""
93HAS_COMPAT=SOFT
94LIBSOFTCFLAGS=        -DCOMPAT_SOFTFP
95LIBSOFTCPUFLAGS= -mfloat-abi=softfp
96LIBSOFT_MACHINE=	arm
97LIBSOFT_MACHINE_ARCH=	${COMPAT_ARCH}
98LIBSOFTWMAKEENV= CPUTYPE=soft
99LIBSOFTWMAKEFLAGS=        -DCOMPAT_SOFTFP
100.endif
101
102# -------------------------------------------------------------------
103# In the program linking case, select LIBCOMPAT
104.if defined(NEED_COMPAT)
105.ifndef HAS_COMPAT
106.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH}
107.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
108.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT ($HAS_COMPAT)
109.elif ${NEED_COMPAT} == "any"
110.endif
111.ifdef WANT_COMPAT
112.error Both WANT_COMPAT and NEED_COMPAT defined
113.endif
114WANT_COMPAT:=	${NEED_COMPAT}
115.endif
116
117.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
118.if ${WANT_COMPAT} == "any"
119_LIBCOMPAT:=	${HAS_COMPAT:[1]}
120.else
121_LIBCOMPAT:=	${WANT_COMPAT}
122.endif
123.endif
124
125
126# -------------------------------------------------------------------
127# Generic code for each type.
128# Set defaults based on type.
129libcompat=	${_LIBCOMPAT:tl}
130_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
131			_MACHINE _MACHINE_ARCH WMAKEENV WMAKEFLAGS WMAKE
132.for _var in ${_LIBCOMPAT_MAKEVARS}
133.if !empty(LIB${_LIBCOMPAT}${_var})
134LIBCOMPAT${_var}?=	${LIB${_LIBCOMPAT}${_var}}
135.endif
136.endfor
137
138# Shared flags
139LIBCOMPAT_OBJTOP?=	${OBJTOP}/obj-lib${libcompat}
140LIBCOMPATTMP?=		${LIBCOMPAT_OBJTOP}/tmp
141
142LIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
143			-L${LIBCOMPATTMP}/usr/lib${libcompat} \
144			--sysroot=${LIBCOMPATTMP} \
145			${BFLAGS}
146
147LIBCOMPATWMAKEENV+=	MACHINE=${LIBCOMPAT_MACHINE}
148LIBCOMPATWMAKEENV+=	MACHINE_ARCH=${LIBCOMPAT_MACHINE_ARCH}
149
150# -B is needed to find /usr/lib32/crti.o for GCC and /usr/libsoft/crti.o for
151# Clang/GCC.
152LIBCOMPATCFLAGS+=	-B${LIBCOMPATTMP}/usr/lib${libcompat}
153
154.if defined(WANT_COMPAT)
155LIBDIR_BASE:=	/usr/lib${libcompat}
156_LIB_OBJTOP=	${LIBCOMPAT_OBJTOP}
157CFLAGS+=	${LIBCOMPATCFLAGS}
158LDFLAGS+=	${CFLAGS} ${LIBCOMPATLDFLAGS}
159MACHINE=	${LIBCOMPAT_MACHINE}
160MACHINE_ARCH=	${LIBCOMPAT_MACHINE_ARCH}
161.endif
162
163.endif
164