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