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