xref: /freebsd/Makefile.libcompat (revision 996e4759621dd7150cec5ad240e252b35a4d9db4)
1dba75e9fSBryan Drewery# $FreeBSD$
2dba75e9fSBryan Drewery
3dba75e9fSBryan Drewery.if !targets(__<${_this:T}>__)
4dba75e9fSBryan Drewery__<${_this:T}>__:
5dba75e9fSBryan Drewery
6dba75e9fSBryan Drewery# Makefile for the compatibility libraries.
769b4d461SJohn Baldwin# - 32-bit compat libraries on MIPS, PowerPC, and AMD64.
8dba75e9fSBryan Drewery
9dba75e9fSBryan Drewery# -------------------------------------------------------------------
10dba75e9fSBryan Drewery# 32 bit world
11dba75e9fSBryan Drewery.if ${TARGET_ARCH} == "amd64"
12dba75e9fSBryan Drewery.if empty(TARGET_CPUTYPE)
13dba75e9fSBryan DreweryLIB32CPUFLAGS=	-march=i686 -mmmx -msse -msse2
14dba75e9fSBryan Drewery.else
15dba75e9fSBryan DreweryLIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
16dba75e9fSBryan Drewery.endif
17452a3101SJohn BaldwinLIB32CPUFLAGS+=	-m32
18dba75e9fSBryan DreweryLIB32WMAKEENV=	MACHINE=i386 MACHINE_ARCH=i386 \
19dba75e9fSBryan Drewery		MACHINE_CPU="i686 mmx sse sse2"
20f661dbeeSBryan DreweryLIB32WMAKEFLAGS=	\
21dba75e9fSBryan Drewery		AS="${XAS} --32" \
22dfaedbb2SEd Maste		LD="${XLD} -m elf_i386_fbsd -L${LIBCOMPATTMP}/usr/lib32" \
23dba75e9fSBryan Drewery		OBJCOPY="${XOBJCOPY}"
24dba75e9fSBryan Drewery
25dba75e9fSBryan Drewery.elif ${TARGET_ARCH} == "powerpc64"
26dba75e9fSBryan Drewery.if empty(TARGET_CPUTYPE)
27dba75e9fSBryan DreweryLIB32CPUFLAGS=	-mcpu=powerpc
28dba75e9fSBryan Drewery.else
29dba75e9fSBryan DreweryLIB32CPUFLAGS=	-mcpu=${TARGET_CPUTYPE}
30dba75e9fSBryan Drewery.endif
31452a3101SJohn BaldwinLIB32CPUFLAGS+=	-m32
32dba75e9fSBryan DreweryLIB32WMAKEENV=	MACHINE=powerpc MACHINE_ARCH=powerpc
33f661dbeeSBryan DreweryLIB32WMAKEFLAGS=	\
34dba75e9fSBryan Drewery		LD="${XLD} -m elf32ppc_fbsd" \
35dba75e9fSBryan Drewery		OBJCOPY="${XOBJCOPY}"
3669b4d461SJohn Baldwin
3769b4d461SJohn Baldwin.elif ${TARGET_ARCH:Mmips64*} != ""
3869b4d461SJohn Baldwin.if empty(TARGET_CPUTYPE)
3969b4d461SJohn BaldwinLIB32CPUFLAGS=	-march=mips3
4069b4d461SJohn Baldwin.else
4169b4d461SJohn BaldwinLIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
4269b4d461SJohn Baldwin.endif
4369b4d461SJohn BaldwinLIB32CPUFLAGS+= -mabi=32
4469b4d461SJohn BaldwinLIB32WMAKEENV=	MACHINE=mips MACHINE_ARCH=mips
4569b4d461SJohn Baldwin.if ${TARGET_ARCH:Mmips64el*} != ""
4669b4d461SJohn BaldwinLIB32WMAKEFLAGS= LD="${XLD} -m elf32ltsmip_fbsd"
4769b4d461SJohn Baldwin.else
4869b4d461SJohn BaldwinLIB32WMAKEFLAGS= LD="${XLD} -m elf32btsmip_fbsd"
4969b4d461SJohn Baldwin.endif
5069b4d461SJohn BaldwinLIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
51dba75e9fSBryan Drewery.endif
52dba75e9fSBryan Drewery
53bdb691d4SEd MasteLIB32WMAKEFLAGS+= NM="${XNM}"
54bdb691d4SEd Maste
55dba75e9fSBryan Drewery
56452a3101SJohn BaldwinLIB32CFLAGS=	-DCOMPAT_32BIT
57dba75e9fSBryan DreweryLIB32DTRACE=	${DTRACE} -32
58dba75e9fSBryan DreweryLIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
59dba75e9fSBryan Drewery
60dba75e9fSBryan Drewery# -------------------------------------------------------------------
61bb52d711SWarner Losh# soft-fp world
620b972ac9SWarner Losh.if ${TARGET_ARCH:Marmv[67]*} != ""
63bb52d711SWarner LoshLIBSOFTCFLAGS=        -DCOMPAT_SOFTFP
64bb52d711SWarner LoshLIBSOFTCPUFLAGS= -mfloat-abi=softfp
650b972ac9SWarner LoshLIBSOFTWMAKEENV= CPUTYPE=soft MACHINE=arm MACHINE_ARCH=${TARGET_ARCH}
66bb52d711SWarner LoshLIBSOFTWMAKEFLAGS=        -DCOMPAT_SOFTFP
67bb52d711SWarner Losh.endif
68bb52d711SWarner Losh
69bb52d711SWarner Losh# -------------------------------------------------------------------
70dba75e9fSBryan Drewery# Generic code for each type.
71dba75e9fSBryan Drewery# Set defaults based on type.
72dba75e9fSBryan Drewerylibcompat=	${LIBCOMPAT:tl}
73dfa09989SBryan Drewery_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS WMAKEENV \
7417e3ebb1SBryan Drewery			WMAKEFLAGS WMAKE
75dba75e9fSBryan Drewery.for _var in ${_LIBCOMPAT_MAKEVARS}
76dba75e9fSBryan Drewery.if !empty(LIB${LIBCOMPAT}${_var})
77dba75e9fSBryan DreweryLIBCOMPAT${_var}?=	${LIB${LIBCOMPAT}${_var}}
78dba75e9fSBryan Drewery.endif
79dba75e9fSBryan Drewery.endfor
80dba75e9fSBryan Drewery
81dba75e9fSBryan Drewery# Shared flags
82dfa09989SBryan DreweryLIBCOMPAT_OBJTOP?=	${OBJTOP}/obj-lib${libcompat}
83dfa09989SBryan DreweryLIBCOMPATTMP?=		${LIBCOMPAT_OBJTOP}/tmp
84dba75e9fSBryan Drewery
85dba75e9fSBryan DreweryLIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
86dba75e9fSBryan Drewery			-L${LIBCOMPATTMP}/usr/lib${libcompat} \
8717e3ebb1SBryan Drewery			--sysroot=${LIBCOMPATTMP} \
8817e3ebb1SBryan Drewery			${BFLAGS}
891b337a34SBryan Drewery
901b337a34SBryan Drewery# -B is needed to find /usr/lib32/crti.o for GCC and /usr/libsoft/crti.o for
911b337a34SBryan Drewery# Clang/GCC.
921b337a34SBryan DreweryLIBCOMPATCFLAGS+=	-B${LIBCOMPATTMP}/usr/lib${libcompat}
9307394091SBryan Drewery
944d611b2bSBryan Drewery.if ${WANT_COMPILER_TYPE} == gcc || \
954d611b2bSBryan Drewery    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
9607394091SBryan Drewery# GCC requires -isystem when using a cross-compiler and --sysroot.  Note that
9707394091SBryan Drewery# Makefile.inc1 only applies this with an external compiler but libcompat
9807394091SBryan Drewery# always does since even in-tree GCC 4.2 needs this to override the built-in
9907394091SBryan Drewery# sysroot path which --sysroot does not actually do for headers.
100f661dbeeSBryan DreweryLIBCOMPATCFLAGS+=	-isystem ${LIBCOMPATTMP}/usr/include
101f661dbeeSBryan Drewery# Force using libc++ for external GCC.
1028422e09eSDimitry Andric.if ${X_COMPILER_TYPE} == gcc && ${X_COMPILER_VERSION} >= 40800 && \
10373371266SBryan Drewery    (${MK_CLANG_BOOTSTRAP} == "no" && ${MK_GCC_BOOTSTRAP} == "no")
104f661dbeeSBryan DreweryLIBCOMPATCXXFLAGS+=	-isystem ${LIBCOMPATTMP}/usr/include/c++/v1 -std=c++11 \
105646a9763SBaptiste Daroussin			-nostdinc++
106f661dbeeSBryan Drewery.endif
10707394091SBryan Drewery.endif
10817e3ebb1SBryan Drewery
109dba75e9fSBryan Drewery# Yes, the flags are redundant.
110dfa09989SBryan DreweryLIBCOMPATWMAKEENV+= \
111dba75e9fSBryan Drewery		INSTALL="sh ${.CURDIR}/tools/install.sh" \
112dba75e9fSBryan Drewery		PATH=${TMPPATH} \
11335fb812aSBryan Drewery		SYSROOT=${LIBCOMPATTMP} \
114dba75e9fSBryan Drewery		LIBDIR=/usr/lib${libcompat} \
115dba75e9fSBryan Drewery		SHLIBDIR=/usr/lib${libcompat} \
116dba75e9fSBryan Drewery		DTRACE="${LIB$COMPATDTRACE:U${DTRACE}}"
117d1dd034dSBryan Drewery.if ${MK_META_MODE} != "no"
118d1dd034dSBryan Drewery# Don't rebuild build-tools targets during normal build.
119dbbb03c2SBryan DreweryLIBCOMPATWMAKEENV+=	BUILD_TOOLS_META=.NOMETA
120d1dd034dSBryan Drewery.endif
121f661dbeeSBryan DreweryLIBCOMPATWMAKEFLAGS+= CC="${XCC} ${LIBCOMPATCFLAGS}" \
12276c5029cSBryan Drewery		CXX="${XCXX} ${LIBCOMPATCXXFLAGS} ${LIBCOMPATCFLAGS}" \
123f661dbeeSBryan Drewery		CPP="${XCPP} ${LIBCOMPATCFLAGS}" \
124dba75e9fSBryan Drewery		DESTDIR=${LIBCOMPATTMP} \
125dba75e9fSBryan Drewery		-DNO_CPU_CFLAGS \
126dba75e9fSBryan Drewery		MK_CTF=no \
127dba75e9fSBryan Drewery		-DNO_LINT \
128dba75e9fSBryan Drewery		MK_TESTS=no
129dba75e9fSBryan DreweryLIBCOMPATWMAKE+=	${LIBCOMPATWMAKEENV} ${MAKE} ${LIBCOMPATWMAKEFLAGS} \
1301031b94fSBryan Drewery			OBJTOP=${LIBCOMPAT_OBJTOP} \
1311031b94fSBryan Drewery			OBJROOT='$${OBJTOP}/' \
132*996e4759SBryan Drewery			MAKEOBJDIRPREFIX= \
133dba75e9fSBryan Drewery			MK_MAN=no MK_HTML=no
13491da7698SBryan DreweryLIBCOMPATIMAKE+=	${LIBCOMPATWMAKE:NINSTALL=*:NDESTDIR=*} \
135429882e6SBryan Drewery			MK_TOOLCHAIN=no ${IMAKE_INSTALL} \
136429882e6SBryan Drewery			-DLIBRARIES_ONLY
137dba75e9fSBryan Drewery
138dba75e9fSBryan Drewery_LC_LIBDIRS.yes=		lib gnu/lib
139048ce093SBryan Drewery_LC_LIBDIRS.${MK_CDDL:tl}+=	cddl/lib
140048ce093SBryan Drewery_LC_LIBDIRS.${MK_CRYPT:tl}+=	secure/lib
141048ce093SBryan Drewery_LC_LIBDIRS.${MK_KERBEROS:tl}+=	kerberos5/lib
142dba75e9fSBryan Drewery
1431b337a34SBryan Drewery_LC_INCDIRS=	\
1441b337a34SBryan Drewery		include \
1451b337a34SBryan Drewery		lib/ncurses/ncursesw \
1461b337a34SBryan Drewery		${_LC_LIBDIRS.yes}
1471b337a34SBryan Drewery
148dba75e9fSBryan Drewery# Shared logic
149dba75e9fSBryan Drewerybuild${libcompat}: .PHONY
150dba75e9fSBryan Drewery	@echo
151dba75e9fSBryan Drewery	@echo "--------------------------------------------------------------"
152dba75e9fSBryan Drewery	@echo ">>> stage 5.1: building lib${libcompat} shim libraries"
153dba75e9fSBryan Drewery	@echo "--------------------------------------------------------------"
15467d2f51aSBryan Drewery.if !defined(NO_CLEAN)
15567d2f51aSBryan Drewery	rm -rf ${LIBCOMPATTMP}
15667d2f51aSBryan Drewery.else
15767d2f51aSBryan Drewery.if exists(${LIBCOMPATTMP})
15867d2f51aSBryan Drewery	${_+_}cd ${.CURDIR}; ${WMAKE} -DBATCH_DELETE_OLD_FILES \
15967d2f51aSBryan Drewery	    DESTDIR=${LIBCOMPATTMP} \
16067d2f51aSBryan Drewery	    delete-old delete-old-libs >/dev/null
16167d2f51aSBryan Drewery.endif
16267d2f51aSBryan Drewery.endif	# !defined(NO_CLEAN)
16367d2f51aSBryan Drewery
164dba75e9fSBryan Drewery	mkdir -p ${LIBCOMPATTMP}/usr/include
165dba75e9fSBryan Drewery	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
166dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr >/dev/null
167dba75e9fSBryan Drewery	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
168dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/include >/dev/null
169dba75e9fSBryan Drewery	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
170dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr >/dev/null
171dba75e9fSBryan Drewery.if ${MK_DEBUG_FILES} != "no"
172dba75e9fSBryan Drewery	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
173dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/lib >/dev/null
174dba75e9fSBryan Drewery	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
175dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/lib/debug/usr >/dev/null
176dba75e9fSBryan Drewery.endif
177dba75e9fSBryan Drewery	mkdir -p ${WORLDTMP}
178dba75e9fSBryan Drewery	ln -sf ${.CURDIR}/sys ${WORLDTMP}
1796d75a7a8SBryan Drewery.for _t in ${_obj} includes
1801b337a34SBryan Drewery.for _dir in ${_LC_INCDIRS}
181ce6c8db5SBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATWMAKE} MK_INCLUDES=yes \
182ce6c8db5SBryan Drewery	    DIRPRFX=${_dir}/ ${_t}
183dba75e9fSBryan Drewery.endfor
184dba75e9fSBryan Drewery.endfor
185dba75e9fSBryan Drewery.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic
186dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; \
187dba75e9fSBryan Drewery	    WORLDTMP=${WORLDTMP} \
188dba75e9fSBryan Drewery	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
1891031b94fSBryan Drewery	    ${MAKE} SSP_CFLAGS= DESTDIR= \
1904dc89c4dSBryan Drewery	    OBJTOP=${LIBCOMPAT_OBJTOP} \
1914dc89c4dSBryan Drewery	    OBJROOT='$${OBJTOP}/' \
192*996e4759SBryan Drewery	    MAKEOBJDIRPREFIX= \
193dba75e9fSBryan Drewery	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
194dba75e9fSBryan Drewery	    build-tools
195dba75e9fSBryan Drewery.endfor
196dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}; \
197dba75e9fSBryan Drewery	    ${LIBCOMPATWMAKE} -f Makefile.inc1 -DNO_FSCHG libraries
19890d1f60eSEnji Cooper.if ${libcompat} == "32"
1996d75a7a8SBryan Drewery.for _t in ${_obj} all
20090d1f60eSEnji Cooper.if !defined(NO_RTLD)
201dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIBCOMPATWMAKE} \
202dba75e9fSBryan Drewery	    -DNO_FSCHG DIRPRFX=libexec/rtld-elf/ ${_t}
20390d1f60eSEnji Cooper.endif
204dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATWMAKE} \
205dba75e9fSBryan Drewery	    DIRPRFX=usr.bin/ldd ${_t}
206dba75e9fSBryan Drewery.endfor
207dba75e9fSBryan Drewery.endif
208dba75e9fSBryan Drewery
209dba75e9fSBryan Drewerydistribute${libcompat} install${libcompat}: .PHONY
210dba75e9fSBryan Drewery.for _dir in ${_LC_LIBDIRS.yes}
211dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATIMAKE} ${.TARGET:S/${libcompat}$//}
212dba75e9fSBryan Drewery.endfor
21390d1f60eSEnji Cooper.if ${libcompat} == "32"
21490d1f60eSEnji Cooper.if !defined(NO_RTLD)
215dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/libexec/rtld-elf; \
216dba75e9fSBryan Drewery	    PROG=ld-elf32.so.1 ${LIBCOMPATIMAKE} ${.TARGET:S/32$//}
21790d1f60eSEnji Cooper.endif
218dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATIMAKE} \
219dba75e9fSBryan Drewery	    ${.TARGET:S/32$//}
220dba75e9fSBryan Drewery.endif
221dba75e9fSBryan Drewery
222dba75e9fSBryan Drewery.endif
223