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