xref: /freebsd/share/mk/bsd.compat.mk (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1
2.if !targets(__<${_this:T}>__)
3__<${_this:T}>__:
4
5.include <bsd.compat.pre.mk>
6
7.if defined(_LIBCOMPATS)
8COMPAT_ARCH?=	${TARGET_ARCH}
9.for _LIBCOMPAT in ${_ALL_LIBCOMPATS}
10LIB${_LIBCOMPAT}CPUTYPE?=	${CPUTYPE_${_LIBCOMPAT}}
11.endfor
12.if (defined(WANT_COMPILER_TYPE) && ${WANT_COMPILER_TYPE} == gcc) || \
13    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
14COMPAT_COMPILER_TYPE=	gcc
15.else
16COMPAT_COMPILER_TYPE=	clang
17.endif
18.else
19COMPAT_ARCH=	${MACHINE_ARCH}
20.for _LIBCOMPAT in ${_ALL_LIBCOMPATS}
21LIB${_LIBCOMPAT}CPUTYPE=	${CPUTYPE}
22.endfor
23.endif
24
25# -------------------------------------------------------------------
26# 32 bit world
27.if ${COMPAT_ARCH} == "amd64"
28HAS_COMPAT+=	32
29.if empty(LIB32CPUTYPE)
30LIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
31.else
32LIB32CPUFLAGS=	-march=${LIB32CPUTYPE}
33.endif
34LIB32CPUFLAGS.clang+=	-target x86_64-unknown-freebsd${OS_REVISION}
35LIB32CPUFLAGS+=	-m32
36LIB32_MACHINE=	i386
37LIB32_MACHINE_ARCH=	i386
38LIB32WMAKEENV=	MACHINE_CPU="i686 mmx sse sse2"
39LIB32WMAKEFLAGS=	\
40		LD="${XLD} -m elf_i386_fbsd"
41
42.elif ${COMPAT_ARCH} == "powerpc64"
43HAS_COMPAT+=	32
44.if empty(LIB32CPUTYPE)
45LIB32CPUFLAGS=	-mcpu=powerpc
46.else
47LIB32CPUFLAGS=	-mcpu=${LIB32CPUTYPE}
48.endif
49
50LIB32CPUFLAGS.gcc+=	-m32
51LIB32CPUFLAGS.clang+=	-target powerpc-unknown-freebsd${OS_REVISION}
52
53LIB32_MACHINE=	powerpc
54LIB32_MACHINE_ARCH=	powerpc
55LIB32WMAKEFLAGS=	\
56		LD="${XLD} -m elf32ppc_fbsd"
57
58.elif ${COMPAT_ARCH} == "aarch64"
59HAS_COMPAT+=	32
60.if empty(LIB32CPUTYPE)
61LIB32CPUFLAGS=	-march=armv7
62.else
63LIB32CPUFLAGS=	-mcpu=${LIB32CPUTYPE}
64.endif
65
66LIB32CPUFLAGS+=	-m32
67LIB32CPUFLAGS.clang+=	-target armv7-unknown-freebsd${OS_REVISION}-gnueabihf
68
69LIB32_MACHINE=	arm
70LIB32_MACHINE_ARCH=	armv7
71LIB32WMAKEFLAGS=	\
72		LD="${XLD} -m armelf_fbsd"
73.endif
74
75LIB32WMAKEFLAGS+= NM="${XNM}"
76LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
77
78LIB32DTRACE=	${DTRACE} -32
79LIB32_MACHINE_ABI=	${MACHINE_ABI:N*64} long32 ptr32
80.if ${COMPAT_ARCH} == "amd64"
81LIB32_MACHINE_ABI+=	time32
82.else
83LIB32_MACHINE_ABI+=	time64
84.endif
85
86# -------------------------------------------------------------------
87# In the program linking case, select LIBCOMPAT
88.if defined(NEED_COMPAT)
89.ifndef HAS_COMPAT
90.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH})
91.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
92.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT (${HAS_COMPAT})
93.elif ${NEED_COMPAT} == "any"
94.endif
95.ifdef WANT_COMPAT
96.error Both WANT_COMPAT and NEED_COMPAT defined
97.endif
98WANT_COMPAT:=	${NEED_COMPAT}
99.endif
100
101.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
102.if ${WANT_COMPAT} == "any"
103USE_COMPAT:=	${HAS_COMPAT:[1]}
104.else
105USE_COMPAT:=	${WANT_COMPAT}
106.endif
107
108_LIBCOMPATS=	${USE_COMPAT}
109.endif
110
111libcompats=	${_LIBCOMPATS:tl}
112
113# Update MACHINE and MACHINE_ARCH so they can be used in bsd.opts.mk via
114# bsd.compiler.mk
115.if defined(USE_COMPAT)
116_LIBCOMPAT_MAKEVARS=	_MACHINE _MACHINE_ARCH
117.for _var in ${_LIBCOMPAT_MAKEVARS}
118.if !empty(LIB${USE_COMPAT}${_var})
119LIBCOMPAT${_var}?=	${LIB${USE_COMPAT}${_var}}
120.endif
121.endfor
122
123MACHINE=	${LIBCOMPAT_MACHINE}
124MACHINE_ARCH=	${LIBCOMPAT_MACHINE_ARCH}
125.endif
126
127.if !defined(COMPAT_COMPILER_TYPE)
128.include <bsd.compiler.mk>
129COMPAT_COMPILER_TYPE=${COMPILER_TYPE}
130.endif
131
132# -------------------------------------------------------------------
133# Generic code for each type.
134# Set defaults based on type.
135.for _LIBCOMPAT _libcompat in ${_LIBCOMPATS:@v@${v} ${v:tl}@}
136WORLDTMP?=		${SYSROOT}
137
138# Shared flags
139LIB${_LIBCOMPAT}_OBJTOP?=	${OBJTOP}/obj-lib${_libcompat}
140
141LIB${_LIBCOMPAT}CFLAGS+=	${LIB${_LIBCOMPAT}CPUFLAGS} \
142				${LIB${_LIBCOMPAT}CPUFLAGS.${COMPAT_COMPILER_TYPE}} \
143				-DCOMPAT_LIBCOMPAT=\"${_LIBCOMPAT}\" \
144				-DCOMPAT_libcompat=\"${_libcompat}\" \
145				-DCOMPAT_LIB${_LIBCOMPAT} \
146				--sysroot=${WORLDTMP} \
147				${BFLAGS}
148
149LIB${_LIBCOMPAT}LDFLAGS+=	-L${WORLDTMP}/usr/lib${_libcompat}
150
151LIB${_LIBCOMPAT}WMAKEFLAGS+=	COMPAT_LIBCOMPAT=${_LIBCOMPAT} \
152				COMPAT_libcompat=${_libcompat}
153
154LIB${_LIBCOMPAT}WMAKEENV+=	MACHINE=${LIB${_LIBCOMPAT}_MACHINE}
155LIB${_LIBCOMPAT}WMAKEENV+=	MACHINE_ARCH=${LIB${_LIBCOMPAT}_MACHINE_ARCH}
156
157# -B is needed to find /usr/lib32/crti.o for gcc.
158LIB${_LIBCOMPAT}CFLAGS+=	-B${WORLDTMP}/usr/lib${_libcompat}
159.endfor
160
161.if defined(USE_COMPAT)
162LIB${USE_COMPAT}CPUFLAGS+= ${LIB${USE_COMPAT}CPUFLAGS.${COMPAT_COMPILER_TYPE}}
163
164libcompat=	${USE_COMPAT:tl}
165
166_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
167			_MACHINE_ABI \
168			WMAKEENV WMAKEFLAGS WMAKE WORLDTMP
169.for _var in ${_LIBCOMPAT_MAKEVARS}
170.if !empty(LIB${USE_COMPAT}${_var})
171LIBCOMPAT${_var}?=	${LIB${USE_COMPAT}${_var}}
172.endif
173.endfor
174
175LIBDIR_BASE:=	/usr/lib${libcompat}
176LIBDATADIR:=	/usr/lib${libcompat}
177_LIB_OBJTOP=	${LIBCOMPAT_OBJTOP}
178CFLAGS+=	${LIBCOMPATCFLAGS}
179LDFLAGS+=	${CFLAGS} ${LIBCOMPATLDFLAGS}
180.endif
181
182.endif
183