xref: /freebsd/share/mk/bsd.compat.mk (revision 960b4327f49cb84f1555d147aa7e16a070e4e82b)
1bbcf7eddSBrooks Davis
2bbcf7eddSBrooks Davis.if !targets(__<${_this:T}>__)
3bbcf7eddSBrooks Davis__<${_this:T}>__:
4bbcf7eddSBrooks Davis
55d6cb793SJessica Clarke.include <bsd.compat.pre.mk>
691d7edd5SJessica Clarke
791d7edd5SJessica Clarke.if defined(_LIBCOMPATS)
8dc0a7e13SJustin HibbitsCOMPAT_ARCH?=	${TARGET_ARCH}
991d7edd5SJessica Clarke.for _LIBCOMPAT in ${_ALL_LIBCOMPATS}
1091d7edd5SJessica ClarkeLIB${_LIBCOMPAT}CPUTYPE?=	${CPUTYPE_${_LIBCOMPAT}}
1191d7edd5SJessica Clarke.endfor
12a4330302SBrooks Davis.if (defined(WANT_COMPILER_TYPE) && ${WANT_COMPILER_TYPE} == gcc) || \
13a4330302SBrooks Davis    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
14a4330302SBrooks DavisCOMPAT_COMPILER_TYPE=	gcc
15a4330302SBrooks Davis.else
16a4330302SBrooks DavisCOMPAT_COMPILER_TYPE=	clang
17a4330302SBrooks Davis.endif
18c09aa214SBrooks Davis.else
19c09aa214SBrooks DavisCOMPAT_ARCH=	${MACHINE_ARCH}
2091d7edd5SJessica Clarke.for _LIBCOMPAT in ${_ALL_LIBCOMPATS}
2191d7edd5SJessica ClarkeLIB${_LIBCOMPAT}CPUTYPE=	${CPUTYPE}
2291d7edd5SJessica Clarke.endfor
23c09aa214SBrooks Davis.endif
24c09aa214SBrooks Davis
25bbcf7eddSBrooks Davis# -------------------------------------------------------------------
26bbcf7eddSBrooks Davis# 32 bit world
27c09aa214SBrooks Davis.if ${COMPAT_ARCH} == "amd64"
2891d7edd5SJessica ClarkeHAS_COMPAT+=	32
2991d7edd5SJessica Clarke.if empty(LIB32CPUTYPE)
30bbcf7eddSBrooks DavisLIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
31bbcf7eddSBrooks Davis.else
3291d7edd5SJessica ClarkeLIB32CPUFLAGS=	-march=${LIB32CPUTYPE}
33bbcf7eddSBrooks Davis.endif
34*960b4327SAndrew TurnerLIB32CPUFLAGS.clang+=	-target x86_64-unknown-freebsd${OS_REVISION}
35bbcf7eddSBrooks DavisLIB32CPUFLAGS+=	-m32
36a4330302SBrooks DavisLIB32_MACHINE=	i386
37a4330302SBrooks DavisLIB32_MACHINE_ARCH=	i386
38a4330302SBrooks DavisLIB32WMAKEENV=	MACHINE_CPU="i686 mmx sse sse2"
39bbcf7eddSBrooks DavisLIB32WMAKEFLAGS=	\
40e2ec0743SJohn Baldwin		LD="${XLD} -m elf_i386_fbsd"
41bbcf7eddSBrooks Davis
42c09aa214SBrooks Davis.elif ${COMPAT_ARCH} == "powerpc64"
4391d7edd5SJessica ClarkeHAS_COMPAT+=	32
4491d7edd5SJessica Clarke.if empty(LIB32CPUTYPE)
45bbcf7eddSBrooks DavisLIB32CPUFLAGS=	-mcpu=powerpc
46bbcf7eddSBrooks Davis.else
4791d7edd5SJessica ClarkeLIB32CPUFLAGS=	-mcpu=${LIB32CPUTYPE}
48bbcf7eddSBrooks Davis.endif
49b451cd45SJustin Hibbits
50*960b4327SAndrew TurnerLIB32CPUFLAGS.gcc+=	-m32
51*960b4327SAndrew TurnerLIB32CPUFLAGS.clang+=	-target powerpc-unknown-freebsd${OS_REVISION}
52b451cd45SJustin Hibbits
53a4330302SBrooks DavisLIB32_MACHINE=	powerpc
54a4330302SBrooks DavisLIB32_MACHINE_ARCH=	powerpc
554d94781bSBrandon BergrenLIB32WMAKEFLAGS=	\
564d94781bSBrandon Bergren		LD="${XLD} -m elf32ppc_fbsd"
57a1b67573SMike Karels
58a1b67573SMike Karels.elif ${COMPAT_ARCH} == "aarch64"
59a1b67573SMike KarelsHAS_COMPAT+=	32
60a1b67573SMike Karels.if empty(LIB32CPUTYPE)
61a1b67573SMike KarelsLIB32CPUFLAGS=	-march=armv7
62a1b67573SMike Karels.else
63a1b67573SMike KarelsLIB32CPUFLAGS=	-mcpu=${LIB32CPUTYPE}
64a1b67573SMike Karels.endif
65a1b67573SMike Karels
66a1b67573SMike KarelsLIB32CPUFLAGS+=	-m32
67*960b4327SAndrew TurnerLIB32CPUFLAGS.clang+=	-target armv7-unknown-freebsd${OS_REVISION}-gnueabihf
68a1b67573SMike Karels
69a1b67573SMike KarelsLIB32_MACHINE=	arm
70a1b67573SMike KarelsLIB32_MACHINE_ARCH=	armv7
71a1b67573SMike KarelsLIB32WMAKEFLAGS=	\
72a1b67573SMike Karels		LD="${XLD} -m armelf_fbsd"
73bbcf7eddSBrooks Davis.endif
74bbcf7eddSBrooks Davis
75bbcf7eddSBrooks DavisLIB32WMAKEFLAGS+= NM="${XNM}"
76bbcf7eddSBrooks DavisLIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
77bbcf7eddSBrooks Davis
78bbcf7eddSBrooks DavisLIB32DTRACE=	${DTRACE} -32
79426fc376SBrooks DavisLIB32_MACHINE_ABI=	${MACHINE_ABI:N*64} long32 ptr32
80426fc376SBrooks Davis.if ${COMPAT_ARCH} == "amd64"
81426fc376SBrooks DavisLIB32_MACHINE_ABI+=	time32
82426fc376SBrooks Davis.else
83426fc376SBrooks DavisLIB32_MACHINE_ABI+=	time64
84426fc376SBrooks Davis.endif
85bbcf7eddSBrooks Davis
86bbcf7eddSBrooks Davis# -------------------------------------------------------------------
876b53d510SBrooks Davis# In the program linking case, select LIBCOMPAT
886b53d510SBrooks Davis.if defined(NEED_COMPAT)
896b53d510SBrooks Davis.ifndef HAS_COMPAT
90ffe74ab7SJohn Baldwin.warning NEED_COMPAT defined, but no LIBCOMPAT is available (COMPAT_ARCH == ${COMPAT_ARCH})
916b53d510SBrooks Davis.elif !${HAS_COMPAT:M${NEED_COMPAT}} && ${NEED_COMPAT} != "any"
92ffe74ab7SJohn Baldwin.error NEED_COMPAT (${NEED_COMPAT}) defined, but not in HAS_COMPAT (${HAS_COMPAT})
936b53d510SBrooks Davis.elif ${NEED_COMPAT} == "any"
946b53d510SBrooks Davis.endif
956b53d510SBrooks Davis.ifdef WANT_COMPAT
966b53d510SBrooks Davis.error Both WANT_COMPAT and NEED_COMPAT defined
976b53d510SBrooks Davis.endif
986b53d510SBrooks DavisWANT_COMPAT:=	${NEED_COMPAT}
996b53d510SBrooks Davis.endif
1006b53d510SBrooks Davis
1016b53d510SBrooks Davis.if defined(HAS_COMPAT) && defined(WANT_COMPAT)
1026b53d510SBrooks Davis.if ${WANT_COMPAT} == "any"
10391d7edd5SJessica ClarkeUSE_COMPAT:=	${HAS_COMPAT:[1]}
1046b53d510SBrooks Davis.else
10591d7edd5SJessica ClarkeUSE_COMPAT:=	${WANT_COMPAT}
1066b53d510SBrooks Davis.endif
10791d7edd5SJessica Clarke
10891d7edd5SJessica Clarke_LIBCOMPATS=	${USE_COMPAT}
1096b53d510SBrooks Davis.endif
1106b53d510SBrooks Davis
11191d7edd5SJessica Clarkelibcompats=	${_LIBCOMPATS:tl}
11291d7edd5SJessica Clarke
113*960b4327SAndrew Turner# Update MACHINE and MACHINE_ARCH so they can be used in bsd.opts.mk via
114*960b4327SAndrew Turner# bsd.compiler.mk
115*960b4327SAndrew Turner.if defined(USE_COMPAT)
116*960b4327SAndrew Turner_LIBCOMPAT_MAKEVARS=	_MACHINE _MACHINE_ARCH
117*960b4327SAndrew Turner.for _var in ${_LIBCOMPAT_MAKEVARS}
118*960b4327SAndrew Turner.if !empty(LIB${USE_COMPAT}${_var})
119*960b4327SAndrew TurnerLIBCOMPAT${_var}?=	${LIB${USE_COMPAT}${_var}}
120*960b4327SAndrew Turner.endif
121*960b4327SAndrew Turner.endfor
122*960b4327SAndrew Turner
123*960b4327SAndrew TurnerMACHINE=	${LIBCOMPAT_MACHINE}
124*960b4327SAndrew TurnerMACHINE_ARCH=	${LIBCOMPAT_MACHINE_ARCH}
125*960b4327SAndrew Turner.endif
126*960b4327SAndrew Turner
127*960b4327SAndrew Turner.if !defined(COMPAT_COMPILER_TYPE)
128*960b4327SAndrew Turner.include <bsd.compiler.mk>
129*960b4327SAndrew TurnerCOMPAT_COMPILER_TYPE=${COMPILER_TYPE}
130*960b4327SAndrew Turner.endif
131*960b4327SAndrew Turner
132bbcf7eddSBrooks Davis# -------------------------------------------------------------------
133bbcf7eddSBrooks Davis# Generic code for each type.
134bbcf7eddSBrooks Davis# Set defaults based on type.
13591d7edd5SJessica Clarke.for _LIBCOMPAT _libcompat in ${_LIBCOMPATS:@v@${v} ${v:tl}@}
13691d7edd5SJessica ClarkeWORLDTMP?=		${SYSROOT}
13791d7edd5SJessica Clarke
13891d7edd5SJessica Clarke# Shared flags
13991d7edd5SJessica ClarkeLIB${_LIBCOMPAT}_OBJTOP?=	${OBJTOP}/obj-lib${_libcompat}
14091d7edd5SJessica Clarke
14191d7edd5SJessica ClarkeLIB${_LIBCOMPAT}CFLAGS+=	${LIB${_LIBCOMPAT}CPUFLAGS} \
142*960b4327SAndrew Turner				${LIB${_LIBCOMPAT}CPUFLAGS.${COMPAT_COMPILER_TYPE}} \
1438fad2cdaSJessica Clarke				-DCOMPAT_LIBCOMPAT=\"${_LIBCOMPAT}\" \
1448fad2cdaSJessica Clarke				-DCOMPAT_libcompat=\"${_libcompat}\" \
1458fad2cdaSJessica Clarke				-DCOMPAT_LIB${_LIBCOMPAT} \
14691d7edd5SJessica Clarke				--sysroot=${WORLDTMP} \
14791d7edd5SJessica Clarke				${BFLAGS}
14891d7edd5SJessica Clarke
14991d7edd5SJessica ClarkeLIB${_LIBCOMPAT}LDFLAGS+=	-L${WORLDTMP}/usr/lib${_libcompat}
15091d7edd5SJessica Clarke
1518fad2cdaSJessica ClarkeLIB${_LIBCOMPAT}WMAKEFLAGS+=	COMPAT_LIBCOMPAT=${_LIBCOMPAT} \
1528fad2cdaSJessica Clarke				COMPAT_libcompat=${_libcompat}
1538fad2cdaSJessica Clarke
15491d7edd5SJessica ClarkeLIB${_LIBCOMPAT}WMAKEENV+=	MACHINE=${LIB${_LIBCOMPAT}_MACHINE}
15591d7edd5SJessica ClarkeLIB${_LIBCOMPAT}WMAKEENV+=	MACHINE_ARCH=${LIB${_LIBCOMPAT}_MACHINE_ARCH}
15691d7edd5SJessica Clarke
15791d7edd5SJessica Clarke# -B is needed to find /usr/lib32/crti.o for gcc.
15891d7edd5SJessica ClarkeLIB${_LIBCOMPAT}CFLAGS+=	-B${WORLDTMP}/usr/lib${_libcompat}
15991d7edd5SJessica Clarke.endfor
16091d7edd5SJessica Clarke
16191d7edd5SJessica Clarke.if defined(USE_COMPAT)
162*960b4327SAndrew TurnerLIB${USE_COMPAT}CPUFLAGS+= ${LIB${USE_COMPAT}CPUFLAGS.${COMPAT_COMPILER_TYPE}}
163*960b4327SAndrew Turner
16491d7edd5SJessica Clarkelibcompat=	${USE_COMPAT:tl}
16591d7edd5SJessica Clarke
166a4330302SBrooks Davis_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS LDFLAGS \
167*960b4327SAndrew Turner			_MACHINE_ABI \
168724123b9SBrooks Davis			WMAKEENV WMAKEFLAGS WMAKE WORLDTMP
169bbcf7eddSBrooks Davis.for _var in ${_LIBCOMPAT_MAKEVARS}
17091d7edd5SJessica Clarke.if !empty(LIB${USE_COMPAT}${_var})
17191d7edd5SJessica ClarkeLIBCOMPAT${_var}?=	${LIB${USE_COMPAT}${_var}}
172bbcf7eddSBrooks Davis.endif
173bbcf7eddSBrooks Davis.endfor
174bbcf7eddSBrooks Davis
1756b53d510SBrooks DavisLIBDIR_BASE:=	/usr/lib${libcompat}
176ac175bd3SAlex RichardsonLIBDATADIR:=	/usr/lib${libcompat}
1776b53d510SBrooks Davis_LIB_OBJTOP=	${LIBCOMPAT_OBJTOP}
1786b53d510SBrooks DavisCFLAGS+=	${LIBCOMPATCFLAGS}
179a4330302SBrooks DavisLDFLAGS+=	${CFLAGS} ${LIBCOMPATLDFLAGS}
1806b53d510SBrooks Davis.endif
1816b53d510SBrooks Davis
182bbcf7eddSBrooks Davis.endif
183