xref: /freebsd/Makefile.libcompat (revision 63d1fd5970ec814904aa0f4580b10a0d302d08b2)
1# $FreeBSD$
2
3.if !targets(__<${_this:T}>__)
4__<${_this:T}>__:
5
6# Makefile for the compatibility libraries.
7# - 32-bit compat libraries on MIPS, PowerPC, and AMD64.
8
9# -------------------------------------------------------------------
10# 32 bit world
11.if ${TARGET_ARCH} == "amd64"
12.if empty(TARGET_CPUTYPE)
13LIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
14.else
15LIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
16.endif
17LIB32CPUFLAGS+=	-m32
18LIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
19		MACHINE_CPU="i686 mmx sse sse2"
20LIB32WMAKEFLAGS=	\
21		AS="${XAS} --32" \
22		LD="${XLD} -m elf_i386_fbsd -L${LIBCOMPATTMP}/usr/lib32" \
23		OBJCOPY="${XOBJCOPY}"
24
25.elif ${TARGET_ARCH} == "powerpc64"
26.if empty(TARGET_CPUTYPE)
27LIB32CPUFLAGS=	-mcpu=powerpc
28.else
29LIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
30.endif
31LIB32CPUFLAGS+=	-m32
32LIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
33LIB32WMAKEFLAGS=	\
34		LD="${XLD} -m elf32ppc_fbsd" \
35		OBJCOPY="${XOBJCOPY}"
36
37.elif ${TARGET_ARCH:Mmips64*} != ""
38.if empty(TARGET_CPUTYPE)
39LIB32CPUFLAGS=	-march=mips3
40.else
41LIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
42.endif
43LIB32CPUFLAGS+= -mabi=32
44LIB32WMAKEENV=	MACHINE=mips MACHINE_ARCH=mips
45.if ${TARGET_ARCH:Mmips64el*} != ""
46LIB32WMAKEFLAGS= LD="${XLD} -m elf32ltsmip_fbsd"
47.else
48LIB32WMAKEFLAGS= LD="${XLD} -m elf32btsmip_fbsd"
49.endif
50LIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
51.endif
52
53
54LIB32CFLAGS=	-DCOMPAT_32BIT
55LIB32DTRACE=	${DTRACE} -32
56LIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
57
58# -------------------------------------------------------------------
59# soft-fp world
60.if ${TARGET_ARCH} == "armv6"
61LIBSOFTCFLAGS=        -DCOMPAT_SOFTFP
62LIBSOFTCPUFLAGS= -mfloat-abi=softfp
63LIBSOFTWMAKEENV= CPUTYPE=soft MACHINE=arm MACHINE_ARCH=armv6
64LIBSOFTWMAKEFLAGS=        -DCOMPAT_SOFTFP
65.endif
66
67# -------------------------------------------------------------------
68# Generic code for each type.
69# Set defaults based on type.
70libcompat=	${LIBCOMPAT:tl}
71_LIBCOMPAT_MAKEVARS=	_OBJTREE TMP CPUFLAGS CFLAGS CXXFLAGS WMAKEENV \
72			WMAKEFLAGS WMAKE
73.for _var in ${_LIBCOMPAT_MAKEVARS}
74.if !empty(LIB${LIBCOMPAT}${_var})
75LIBCOMPAT${_var}?=	${LIB${LIBCOMPAT}${_var}}
76.endif
77.endfor
78
79# Shared flags
80LIBCOMPAT_OBJTREE?=	${OBJTREE}${.CURDIR}/world${libcompat}
81LIBCOMPATTMP?=		${OBJTREE}${.CURDIR}/lib${libcompat}
82
83LIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
84			-L${LIBCOMPATTMP}/usr/lib${libcompat} \
85			--sysroot=${LIBCOMPATTMP} \
86			${BFLAGS}
87
88# -B is needed to find /usr/lib32/crti.o for GCC and /usr/libsoft/crti.o for
89# Clang/GCC.
90LIBCOMPATCFLAGS+=	-B${LIBCOMPATTMP}/usr/lib${libcompat}
91
92.if ${WANT_COMPILER_TYPE} == gcc || \
93    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
94# GCC requires -isystem when using a cross-compiler and --sysroot.  Note that
95# Makefile.inc1 only applies this with an external compiler but libcompat
96# always does since even in-tree GCC 4.2 needs this to override the built-in
97# sysroot path which --sysroot does not actually do for headers.
98LIBCOMPATCFLAGS+=	-isystem ${LIBCOMPATTMP}/usr/include
99# Force using libc++ for external GCC.
100# XXX: This should be checking MK_GNUCXX == no
101.if ${X_COMPILER_VERSION} >= 40800 && \
102    (${MK_CLANG_BOOTSTRAP} == "no" && ${MK_GCC_BOOTSTRAP} == "no")
103LIBCOMPATCXXFLAGS+=	-isystem ${LIBCOMPATTMP}/usr/include/c++/v1 -std=c++11 \
104			-nostdinc++
105.endif
106.endif
107
108# Yes, the flags are redundant.
109LIBCOMPATWMAKEENV+= MAKEOBJDIRPREFIX=${LIBCOMPAT_OBJTREE} \
110		INSTALL="sh ${.CURDIR}/tools/install.sh" \
111		PATH=${TMPPATH} \
112		LIBDIR=/usr/lib${libcompat} \
113		SHLIBDIR=/usr/lib${libcompat} \
114		DTRACE="${LIB$COMPATDTRACE:U${DTRACE}}"
115.if ${MK_META_MODE} != "no"
116# Don't rebuild build-tools targets during normal build.
117LIBCOMPATWMAKEENV+=	BUILD_TOOLS_META=.NOMETA_CMP
118.endif
119LIBCOMPATWMAKEFLAGS+= CC="${XCC} ${LIBCOMPATCFLAGS}" \
120		CXX="${XCXX} ${LIBCOMPATCXXFLAGS} ${LIBCOMPATCFLAGS}" \
121		CPP="${XCPP} ${LIBCOMPATCFLAGS}" \
122		DESTDIR=${LIBCOMPATTMP} \
123		-DNO_CPU_CFLAGS \
124		MK_CTF=no \
125		-DNO_LINT \
126		MK_TESTS=no
127LIBCOMPATWMAKE+=	${LIBCOMPATWMAKEENV} ${MAKE} ${LIBCOMPATWMAKEFLAGS} \
128			MK_MAN=no MK_HTML=no
129LIBCOMPATIMAKE+=	${LIBCOMPATWMAKE:NINSTALL=*:NDESTDIR=*} \
130			MK_TOOLCHAIN=no ${IMAKE_INSTALL} \
131			-DLIBRARIES_ONLY
132
133_LC_LIBDIRS.yes=		lib gnu/lib
134_LC_LIBDIRS.${MK_CDDL:tl}+=	cddl/lib
135_LC_LIBDIRS.${MK_CRYPT:tl}+=	secure/lib
136_LC_LIBDIRS.${MK_KERBEROS:tl}+=	kerberos5/lib
137
138_LC_INCDIRS=	\
139		include \
140		lib/ncurses/ncursesw \
141		${_LC_LIBDIRS.yes}
142
143# Shared logic
144build${libcompat}: .PHONY
145	@echo
146	@echo "--------------------------------------------------------------"
147	@echo ">>> stage 5.1: building lib${libcompat} shim libraries"
148	@echo "--------------------------------------------------------------"
149	mkdir -p ${LIBCOMPATTMP}/usr/include
150	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
151	    -p ${LIBCOMPATTMP}/usr >/dev/null
152	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
153	    -p ${LIBCOMPATTMP}/usr/include >/dev/null
154	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
155	    -p ${LIBCOMPATTMP}/usr >/dev/null
156.if ${MK_DEBUG_FILES} != "no"
157	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
158	    -p ${LIBCOMPATTMP}/usr/lib >/dev/null
159	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
160	    -p ${LIBCOMPATTMP}/usr/lib/debug/usr >/dev/null
161.endif
162	mkdir -p ${WORLDTMP}
163	ln -sf ${.CURDIR}/sys ${WORLDTMP}
164.for _t in obj includes
165.for _dir in ${_LC_INCDIRS}
166	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATWMAKE} MK_INCLUDES=yes \
167	    DIRPRFX=${_dir}/ ${_t}
168.endfor
169.endfor
170.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
171	${_+_}cd ${.CURDIR}/${_dir}; \
172	    WORLDTMP=${WORLDTMP} \
173	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
174	    MAKEOBJDIRPREFIX=${LIBCOMPAT_OBJTREE} ${MAKE} SSP_CFLAGS= DESTDIR= \
175	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
176	    build-tools
177.endfor
178	${_+_}cd ${.CURDIR}; \
179	    ${LIBCOMPATWMAKE} -f Makefile.inc1 -DNO_FSCHG libraries
180.if ${libcompat} == "32"
181.for _t in obj all
182	${_+_}cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIBCOMPATWMAKE} \
183	    -DNO_FSCHG DIRPRFX=libexec/rtld-elf/ ${_t}
184	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATWMAKE} \
185	    DIRPRFX=usr.bin/ldd ${_t}
186.endfor
187.endif
188
189distribute${libcompat} install${libcompat}: .PHONY
190.for _dir in ${_LC_LIBDIRS.yes}
191	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATIMAKE} ${.TARGET:S/${libcompat}$//}
192.endfor
193.if ${libcompat} == "32"
194	${_+_}cd ${.CURDIR}/libexec/rtld-elf; \
195	    PROG=ld-elf32.so.1 ${LIBCOMPATIMAKE} ${.TARGET:S/32$//}
196	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATIMAKE} \
197	    ${.TARGET:S/32$//}
198.endif
199
200.endif
201