xref: /freebsd/Makefile.libcompat (revision 52f9bacb0e3933d924fa14a045026dbb0e005edc)
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*} != ""
38a1554bbaSJohn Baldwin.if ${WANT_COMPILER_TYPE} == gcc || \
39a1554bbaSJohn Baldwin    (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc)
4069b4d461SJohn Baldwin.if empty(TARGET_CPUTYPE)
4169b4d461SJohn BaldwinLIB32CPUFLAGS=	-march=mips3
4269b4d461SJohn Baldwin.else
4369b4d461SJohn BaldwinLIB32CPUFLAGS=	-march=${TARGET_CPUTYPE}
4469b4d461SJohn Baldwin.endif
45a1554bbaSJohn Baldwin.else
46a1554bbaSJohn Baldwin.if ${TARGET_ARCH:Mmips64el*} != ""
47a1554bbaSJohn BaldwinLIB32CPUFLAGS=  -target mipsel-unknown-freebsd12.0
48a1554bbaSJohn Baldwin.else
49a1554bbaSJohn BaldwinLIB32CPUFLAGS=  -target mips-unknown-freebsd12.0
50a1554bbaSJohn Baldwin.endif
518d286bb9SJohn Baldwin.endif
5269b4d461SJohn BaldwinLIB32CPUFLAGS+= -mabi=32
5369b4d461SJohn BaldwinLIB32WMAKEENV=	MACHINE=mips MACHINE_ARCH=mips
5469b4d461SJohn Baldwin.if ${TARGET_ARCH:Mmips64el*} != ""
5569b4d461SJohn BaldwinLIB32WMAKEFLAGS= LD="${XLD} -m elf32ltsmip_fbsd"
5669b4d461SJohn Baldwin.else
5769b4d461SJohn BaldwinLIB32WMAKEFLAGS= LD="${XLD} -m elf32btsmip_fbsd"
5869b4d461SJohn Baldwin.endif
5969b4d461SJohn BaldwinLIB32WMAKEFLAGS+= OBJCOPY="${XOBJCOPY}"
60dba75e9fSBryan Drewery.endif
61dba75e9fSBryan Drewery
62bdb691d4SEd MasteLIB32WMAKEFLAGS+= NM="${XNM}"
63bdb691d4SEd Maste
64dba75e9fSBryan Drewery
65452a3101SJohn BaldwinLIB32CFLAGS=	-DCOMPAT_32BIT
66dba75e9fSBryan DreweryLIB32DTRACE=	${DTRACE} -32
67dba75e9fSBryan DreweryLIB32WMAKEFLAGS+=	-DCOMPAT_32BIT
68dba75e9fSBryan Drewery
69dba75e9fSBryan Drewery# -------------------------------------------------------------------
70bb52d711SWarner Losh# soft-fp world
710b972ac9SWarner Losh.if ${TARGET_ARCH:Marmv[67]*} != ""
72bb52d711SWarner LoshLIBSOFTCFLAGS=        -DCOMPAT_SOFTFP
73bb52d711SWarner LoshLIBSOFTCPUFLAGS= -mfloat-abi=softfp
740b972ac9SWarner LoshLIBSOFTWMAKEENV= CPUTYPE=soft MACHINE=arm MACHINE_ARCH=${TARGET_ARCH}
75bb52d711SWarner LoshLIBSOFTWMAKEFLAGS=        -DCOMPAT_SOFTFP
76bb52d711SWarner Losh.endif
77bb52d711SWarner Losh
78bb52d711SWarner Losh# -------------------------------------------------------------------
79dba75e9fSBryan Drewery# Generic code for each type.
80dba75e9fSBryan Drewery# Set defaults based on type.
81dba75e9fSBryan Drewerylibcompat=	${LIBCOMPAT:tl}
82dfa09989SBryan Drewery_LIBCOMPAT_MAKEVARS=	_OBJTOP TMP CPUFLAGS CFLAGS CXXFLAGS WMAKEENV \
8317e3ebb1SBryan Drewery			WMAKEFLAGS WMAKE
84dba75e9fSBryan Drewery.for _var in ${_LIBCOMPAT_MAKEVARS}
85dba75e9fSBryan Drewery.if !empty(LIB${LIBCOMPAT}${_var})
86dba75e9fSBryan DreweryLIBCOMPAT${_var}?=	${LIB${LIBCOMPAT}${_var}}
87dba75e9fSBryan Drewery.endif
88dba75e9fSBryan Drewery.endfor
89dba75e9fSBryan Drewery
90dba75e9fSBryan Drewery# Shared flags
91dfa09989SBryan DreweryLIBCOMPAT_OBJTOP?=	${OBJTOP}/obj-lib${libcompat}
92dfa09989SBryan DreweryLIBCOMPATTMP?=		${LIBCOMPAT_OBJTOP}/tmp
93dba75e9fSBryan Drewery
94dba75e9fSBryan DreweryLIBCOMPATCFLAGS+=	${LIBCOMPATCPUFLAGS} \
95dba75e9fSBryan Drewery			-L${LIBCOMPATTMP}/usr/lib${libcompat} \
9617e3ebb1SBryan Drewery			--sysroot=${LIBCOMPATTMP} \
9717e3ebb1SBryan Drewery			${BFLAGS}
981b337a34SBryan Drewery
991b337a34SBryan Drewery# -B is needed to find /usr/lib32/crti.o for GCC and /usr/libsoft/crti.o for
1001b337a34SBryan Drewery# Clang/GCC.
1011b337a34SBryan DreweryLIBCOMPATCFLAGS+=	-B${LIBCOMPATTMP}/usr/lib${libcompat}
10207394091SBryan Drewery
103dba75e9fSBryan Drewery# Yes, the flags are redundant.
104dfa09989SBryan DreweryLIBCOMPATWMAKEENV+= \
105dba75e9fSBryan Drewery		INSTALL="sh ${.CURDIR}/tools/install.sh" \
106dba75e9fSBryan Drewery		PATH=${TMPPATH} \
10735fb812aSBryan Drewery		SYSROOT=${LIBCOMPATTMP} \
108dba75e9fSBryan Drewery		LIBDIR=/usr/lib${libcompat} \
109dba75e9fSBryan Drewery		SHLIBDIR=/usr/lib${libcompat} \
110dba75e9fSBryan Drewery		DTRACE="${LIB$COMPATDTRACE:U${DTRACE}}"
111d1dd034dSBryan Drewery.if ${MK_META_MODE} != "no"
112d1dd034dSBryan Drewery# Don't rebuild build-tools targets during normal build.
113dbbb03c2SBryan DreweryLIBCOMPATWMAKEENV+=	BUILD_TOOLS_META=.NOMETA
114d1dd034dSBryan Drewery.endif
115f661dbeeSBryan DreweryLIBCOMPATWMAKEFLAGS+= CC="${XCC} ${LIBCOMPATCFLAGS}" \
11676c5029cSBryan Drewery		CXX="${XCXX} ${LIBCOMPATCXXFLAGS} ${LIBCOMPATCFLAGS}" \
117f661dbeeSBryan Drewery		CPP="${XCPP} ${LIBCOMPATCFLAGS}" \
118dba75e9fSBryan Drewery		DESTDIR=${LIBCOMPATTMP} \
119dba75e9fSBryan Drewery		-DNO_CPU_CFLAGS \
120dba75e9fSBryan Drewery		MK_CTF=no \
121dba75e9fSBryan Drewery		-DNO_LINT \
122dba75e9fSBryan Drewery		MK_TESTS=no
123dba75e9fSBryan DreweryLIBCOMPATWMAKE+=	${LIBCOMPATWMAKEENV} ${MAKE} ${LIBCOMPATWMAKEFLAGS} \
1241031b94fSBryan Drewery			OBJTOP=${LIBCOMPAT_OBJTOP} \
1251031b94fSBryan Drewery			OBJROOT='$${OBJTOP}/' \
126996e4759SBryan Drewery			MAKEOBJDIRPREFIX= \
127dba75e9fSBryan Drewery			MK_MAN=no MK_HTML=no
12891da7698SBryan DreweryLIBCOMPATIMAKE+=	${LIBCOMPATWMAKE:NINSTALL=*:NDESTDIR=*} \
129*52f9bacbSJohn Baldwin			${IMAKE_INSTALL} \
130429882e6SBryan Drewery			-DLIBRARIES_ONLY
131dba75e9fSBryan Drewery
132ad91146cSEd Maste_LC_LIBDIRS.yes=		lib
1330d849865SEd Maste_LC_LIBDIRS.yes+=		gnu/lib
134048ce093SBryan Drewery_LC_LIBDIRS.${MK_CDDL:tl}+=	cddl/lib
135048ce093SBryan Drewery_LC_LIBDIRS.${MK_CRYPT:tl}+=	secure/lib
136048ce093SBryan Drewery_LC_LIBDIRS.${MK_KERBEROS:tl}+=	kerberos5/lib
137dba75e9fSBryan Drewery
1381b337a34SBryan Drewery_LC_INCDIRS=	\
1391b337a34SBryan Drewery		include \
1401b337a34SBryan Drewery		lib/ncurses/ncursesw \
1411b337a34SBryan Drewery		${_LC_LIBDIRS.yes}
1421b337a34SBryan Drewery
143127b666cSBryan Drewery.if ${MK_FILE} != "no"
144127b666cSBryan Drewery_libmagic=	lib/libmagic
145127b666cSBryan Drewery.endif
1466f1f2b19SBryan Drewery.if ${MK_PMC} != "no" && ${TARGET_ARCH} == "amd64"
1476f1f2b19SBryan Drewery_jevents=	lib/libpmc/pmu-events
1486f1f2b19SBryan Drewery.endif
1496f1f2b19SBryan Drewery
1506f1f2b19SBryan Drewery
151dba75e9fSBryan Drewery# Shared logic
152dba75e9fSBryan Drewerybuild${libcompat}: .PHONY
153dba75e9fSBryan Drewery	@echo
154dba75e9fSBryan Drewery	@echo "--------------------------------------------------------------"
155dba75e9fSBryan Drewery	@echo ">>> stage 5.1: building lib${libcompat} shim libraries"
156dba75e9fSBryan Drewery	@echo "--------------------------------------------------------------"
15767d2f51aSBryan Drewery.if !defined(NO_CLEAN)
15867d2f51aSBryan Drewery	rm -rf ${LIBCOMPATTMP}
15967d2f51aSBryan Drewery.else
1606e6be2bbSBryan Drewery	${_+_}@if [ -e "${LIBCOMPATTMP}" ]; then \
1616e6be2bbSBryan Drewery		echo ">>> Deleting stale files in build${libcompat} tree..."; \
1626e6be2bbSBryan Drewery		cd ${.CURDIR}; ${WMAKE} -DBATCH_DELETE_OLD_FILES \
16367d2f51aSBryan Drewery		    DESTDIR=${LIBCOMPATTMP} \
1646e6be2bbSBryan Drewery		    delete-old delete-old-libs >/dev/null; \
1656e6be2bbSBryan Drewery	fi
16667d2f51aSBryan Drewery.endif	# !defined(NO_CLEAN)
16767d2f51aSBryan Drewery
168dba75e9fSBryan Drewery	mkdir -p ${LIBCOMPATTMP}/usr/include
16955a5b46aSAlex Richardson	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
170dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr >/dev/null
17155a5b46aSAlex Richardson	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.include.dist \
172dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/include >/dev/null
17355a5b46aSAlex Richardson	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
174dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr >/dev/null
175dba75e9fSBryan Drewery.if ${MK_DEBUG_FILES} != "no"
17655a5b46aSAlex Richardson	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
177dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/lib >/dev/null
17855a5b46aSAlex Richardson	${WORLDTMP_MTREE} -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \
179dba75e9fSBryan Drewery	    -p ${LIBCOMPATTMP}/usr/lib/debug/usr >/dev/null
180dba75e9fSBryan Drewery.endif
181dba75e9fSBryan Drewery	mkdir -p ${WORLDTMP}
182dba75e9fSBryan Drewery	ln -sf ${.CURDIR}/sys ${WORLDTMP}
1836d75a7a8SBryan Drewery.for _t in ${_obj} includes
1841b337a34SBryan Drewery.for _dir in ${_LC_INCDIRS}
185ce6c8db5SBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATWMAKE} MK_INCLUDES=yes \
186ce6c8db5SBryan Drewery	    DIRPRFX=${_dir}/ ${_t}
187dba75e9fSBryan Drewery.endfor
188dba75e9fSBryan Drewery.endfor
189127b666cSBryan Drewery.for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw ${_libmagic} ${_jevents}
190c4273800SBryan Drewery.for _t in ${_obj} build-tools
191dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; \
192dba75e9fSBryan Drewery	    WORLDTMP=${WORLDTMP} \
193dba75e9fSBryan Drewery	    MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
1941031b94fSBryan Drewery	    ${MAKE} SSP_CFLAGS= DESTDIR= \
1954dc89c4dSBryan Drewery	    OBJTOP=${LIBCOMPAT_OBJTOP} \
1964dc89c4dSBryan Drewery	    OBJROOT='$${OBJTOP}/' \
197996e4759SBryan Drewery	    MAKEOBJDIRPREFIX= \
198dba75e9fSBryan Drewery	    DIRPRFX=${_dir}/ -DNO_LINT -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \
199c4273800SBryan Drewery	    ${_t}
200c4273800SBryan Drewery.endfor
201dba75e9fSBryan Drewery.endfor
202dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}; \
203dba75e9fSBryan Drewery	    ${LIBCOMPATWMAKE} -f Makefile.inc1 -DNO_FSCHG libraries
20490d1f60eSEnji Cooper.if ${libcompat} == "32"
2056d75a7a8SBryan Drewery.for _t in ${_obj} all
20690d1f60eSEnji Cooper.if !defined(NO_RTLD)
207dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIBCOMPATWMAKE} \
208dba75e9fSBryan Drewery	    -DNO_FSCHG DIRPRFX=libexec/rtld-elf/ ${_t}
20990d1f60eSEnji Cooper.endif
210dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATWMAKE} \
211dba75e9fSBryan Drewery	    DIRPRFX=usr.bin/ldd ${_t}
212dba75e9fSBryan Drewery.endfor
213dba75e9fSBryan Drewery.endif
214dba75e9fSBryan Drewery
215dba75e9fSBryan Drewerydistribute${libcompat} install${libcompat}: .PHONY
216dba75e9fSBryan Drewery.for _dir in ${_LC_LIBDIRS.yes}
217dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/${_dir}; ${LIBCOMPATIMAKE} ${.TARGET:S/${libcompat}$//}
218dba75e9fSBryan Drewery.endfor
21990d1f60eSEnji Cooper.if ${libcompat} == "32"
22090d1f60eSEnji Cooper.if !defined(NO_RTLD)
221dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/libexec/rtld-elf; \
222dba75e9fSBryan Drewery	    PROG=ld-elf32.so.1 ${LIBCOMPATIMAKE} ${.TARGET:S/32$//}
22390d1f60eSEnji Cooper.endif
224dba75e9fSBryan Drewery	${_+_}cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIBCOMPATIMAKE} \
225dba75e9fSBryan Drewery	    ${.TARGET:S/32$//}
226dba75e9fSBryan Drewery.endif
227dba75e9fSBryan Drewery
228dba75e9fSBryan Drewery.endif
229