xref: /freebsd/share/mk/bsd.compat.mk (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
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-freebsd${OS_REVISION}
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"
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-freebsd${OS_REVISION}
55.endif
56
57LIB32_MACHINE=	powerpc
58LIB32_MACHINE_ARCH=	powerpc
59LIB32WMAKEFLAGS=	\
60		LD="${XLD} -m elf32ppc_fbsd"
61.endif
62
63LIB32WMAKEFLAGS+= NM="${XNM}"
64LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
65
66LIB32CFLAGS=	-DCOMPAT_32BIT
67LIB32DTRACE=	${DTRACE} -32
68LIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
69LIB32_MACHINE_ABI=	${MACHINE_ABI:N*64} long32 ptr32
70.if ${COMPAT_ARCH} == "amd64"
71LIB32_MACHINE_ABI+=	time32
72.else
73LIB32_MACHINE_ABI+=	time64
74.endif
75
76# -------------------------------------------------------------------
77# In the program linking case, select LIBCOMPAT
78.if defined(NEED_COMPAT)
79.ifndef HAS_COMPAT
80.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH})
81.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
82.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT (${HAS_COMPAT})
83.elif ${NEED_COMPAT} == "any"
84.endif
85.ifdef WANT_COMPAT
86.error Both WANT_COMPAT and NEED_COMPAT defined
87.endif
88WANT_COMPAT:=	${NEED_COMPAT}
89.endif
90
91.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
92.if ${WANT_COMPAT} == "any"
93_LIBCOMPAT:=	${HAS_COMPAT:[1]}
94.else
95_LIBCOMPAT:=	${WANT_COMPAT}
96.endif
97.endif
98
99# -------------------------------------------------------------------
100# Generic code for each type.
101# Set defaults based on type.
102libcompat=	${_LIBCOMPAT:tl}
103_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
104			_MACHINE _MACHINE_ARCH _MACHINE_ABI \
105			WMAKEENV WMAKEFLAGS WMAKE WORLDTMP
106.for _var in ${_LIBCOMPAT_MAKEVARS}
107.if !empty(LIB${_LIBCOMPAT}${_var})
108LIBCOMPAT${_var}?=	${LIB${_LIBCOMPAT}${_var}}
109.endif
110.endfor
111
112WORLDTMP?=		${SYSROOT}
113
114# Shared flags
115LIBCOMPAT_OBJTOP?=	${OBJTOP}/obj-lib${libcompat}
116
117LIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
118			--sysroot=${WORLDTMP} \
119			${BFLAGS}
120
121LIBCOMPATLDFLAGS+=	-L${WORLDTMP}/usr/lib${libcompat}
122
123LIBCOMPATWMAKEENV+=	MACHINE=${LIBCOMPAT_MACHINE}
124LIBCOMPATWMAKEENV+=	MACHINE_ARCH=${LIBCOMPAT_MACHINE_ARCH}
125
126# -B is needed to find /usr/lib32/crti.o for gcc.
127LIBCOMPATCFLAGS+=	-B${WORLDTMP}/usr/lib${libcompat}
128
129.if defined(WANT_COMPAT)
130LIBDIR_BASE:=	/usr/lib${libcompat}
131LIBDATADIR:=	/usr/lib${libcompat}
132_LIB_OBJTOP=	${LIBCOMPAT_OBJTOP}
133CFLAGS+=	${LIBCOMPATCFLAGS}
134LDFLAGS+=	${CFLAGS} ${LIBCOMPATLDFLAGS}
135MACHINE=	${LIBCOMPAT_MACHINE}
136MACHINE_ARCH=	${LIBCOMPAT_MACHINE_ARCH}
137.endif
138
139.endif
140