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