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