xref: /freebsd/tools/build/Makefile (revision 33176cdc87a6c7d2993b4e6b95e9ce8b016454b4)
130aaff11SWarner Losh# $FreeBSD$
230aaff11SWarner Losh
330aaff11SWarner Losh.PATH: ${.CURDIR}/../../include
430aaff11SWarner Losh
51c62f923SWarner LoshLIB=		egacy
6c2774610SDavid E. O'BrienSRC=
7162ae9c8SAlex RichardsonINCSGROUPS=	INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS
830aaff11SWarner LoshINCS=
930aaff11SWarner Losh
10d80f1dd1SJilles TjoelkerSYSINCSDIR=	${INCLUDEDIR}/sys
11d5f4dd1bSMariusz ZaborskiCASPERINCDIR=	${INCLUDEDIR}/casper
12162ae9c8SAlex Richardson# Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool
13162ae9c8SAlex RichardsonUFSINCSDIR=	${INCLUDEDIR}/ufs/ufs
14162ae9c8SAlex RichardsonFFSINCSDIR=	${INCLUDEDIR}/ufs/ffs
15162ae9c8SAlex RichardsonMSDOSFSINCSDIR=	${INCLUDEDIR}/fs/msdosfs
16162ae9c8SAlex RichardsonDISKINCSDIR=	${INCLUDEDIR}/sys/disk
17d80f1dd1SJilles Tjoelker
1830aaff11SWarner LoshBOOTSTRAPPING?=	0
1930aaff11SWarner Losh
20804baa38SBryan Drewery_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true
2179626055SBrooks Davis.if ${_WITH_PWCACHEDB} == 0
2279626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-pwcache
2379626055SBrooks DavisCFLAGS+=	-I${.CURDIR}/../../contrib/libc-pwcache \
2479626055SBrooks Davis		-I${.CURDIR}/../../lib/libc/include
2579626055SBrooks DavisSRCS+=		pwcache.c
2679626055SBrooks Davis.endif
2779626055SBrooks Davis
28804baa38SBryan Drewery_WITH_STRSVIS!=	grep -c strsvis /usr/include/vis.h || true
2979626055SBrooks Davis.if ${_WITH_STRSVIS} == 0
3079626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-vis
3179626055SBrooks DavisSRCS+=		vis.c
3279626055SBrooks DavisCFLAGS+=	-I${.CURDIR}/../../contrib/libc-vis \
3379626055SBrooks Davis		-I${.CURDIR}/../../lib/libc/include
3479626055SBrooks Davis.endif
3579626055SBrooks Davis
36804baa38SBryan Drewery_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true
378e7e3163SDimitry Andric.if ${_WITH_REALLOCARRAY} == 0
388e7e3163SDimitry Andric.PATH: ${.CURDIR}/../../lib/libc/stdlib
398e7e3163SDimitry AndricINCS+=		stdlib.h
408e7e3163SDimitry AndricSRCS+=		reallocarray.c
418e7e3163SDimitry AndricCFLAGS+=	-I${.CURDIR}/../../lib/libc/include
428e7e3163SDimitry Andric.endif
438e7e3163SDimitry Andric
44d80f1dd1SJilles Tjoelker_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true
45d80f1dd1SJilles Tjoelker.if ${_WITH_UTIMENS} == 0
46d80f1dd1SJilles TjoelkerSYSINCS+=	stat.h
47d80f1dd1SJilles TjoelkerSRCS+=		futimens.c utimensat.c
48d80f1dd1SJilles Tjoelker.endif
49d80f1dd1SJilles Tjoelker
508d14ced6SAlex Richardson_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true
518d14ced6SAlex Richardson.if ${_WITH_EXPLICIT_BZERO} == 0
528d14ced6SAlex Richardson.PATH: ${SRCTOP}/sys/libkern
538d14ced6SAlex RichardsonINCS+=		strings.h
548d14ced6SAlex RichardsonSRCS+=		explicit_bzero.c
558d14ced6SAlex Richardson.endif
568d14ced6SAlex Richardson
573b7e9bfeSAlex Richardson.if exists(/usr/include/capsicum_helpers.h)
583b7e9bfeSAlex Richardson_WITH_CAPH_ENTER!= grep -c caph_enter /usr/include/capsicum_helpers.h || true
59fbe12f20SMark Johnston_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit /usr/include/capsicum_helpers.h || true
603b7e9bfeSAlex Richardson.endif
61fbe12f20SMark Johnston.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0
623b7e9bfeSAlex Richardson.PATH: ${SRCTOP}/lib/libcapsicum
633b7e9bfeSAlex RichardsonINCS+=		capsicum_helpers.h
643b7e9bfeSAlex Richardson.PATH: ${SRCTOP}/lib/libcasper/libcasper
653b7e9bfeSAlex RichardsonINCS+=		libcasper.h
663b7e9bfeSAlex Richardson.endif
673b7e9bfeSAlex Richardson
68d5f4dd1bSMariusz ZaborskiCASPERINC+=	${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h
69d5f4dd1bSMariusz Zaborski
7030aaff11SWarner Losh.if empty(SRCS)
7130aaff11SWarner LoshSRCS=		dummy.c
7230aaff11SWarner Losh.endif
7330aaff11SWarner Losh
74f09a3cc4SRuslan Ermilov.if defined(CROSS_BUILD_TESTING)
75f09a3cc4SRuslan ErmilovSUBDIR=		cross-build
76f09a3cc4SRuslan Ermilov.endif
77f09a3cc4SRuslan Ermilov
78162ae9c8SAlex Richardson# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems:
79162ae9c8SAlex RichardsonUFSINCS+=	${SRCTOP}/sys/ufs/ufs/dinode.h
80162ae9c8SAlex RichardsonUFSINCS+=	${SRCTOP}/sys/ufs/ufs/dir.h
81162ae9c8SAlex RichardsonFFSINCS+=	${SRCTOP}/sys/ufs/ffs/fs.h
82162ae9c8SAlex Richardson
83162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/bootsect.h
84162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/bpb.h
85162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/denode.h
86162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/direntry.h
87162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/fat.h
88162ae9c8SAlex RichardsonMSDOSFSINCS+=	${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h
89162ae9c8SAlex RichardsonDISKINCS+=	${SRCTOP}/sys/sys/disk/bsd.h
90162ae9c8SAlex Richardson
9163889bbdSAlex Richardson# Needed to build config (since it uses libnv)
92c36f4276SMarius StroblSYSINCS+=	${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \
93c36f4276SMarius Strobl		${SRCTOP}/sys/sys/dnv.h
9463889bbdSAlex Richardson
95e7fd9688SToomas Soome# vtfontcvt is using sys/font.h
96e7fd9688SToomas SoomeSYSINCS+=	${SRCTOP}/sys/sys/font.h
97e7fd9688SToomas Soome
988f62bca4SAlex Richardson# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
998f62bca4SAlex Richardson# accidentally run tools that are incompatible but happen to be in $PATH.
1008f62bca4SAlex Richardson# This is especially important when building on Linux/MacOS where many of the
1018f62bca4SAlex Richardson# programs used during the build accept different flags or generate different
1028f62bca4SAlex Richardson# output. On those platforms we only symlink the tools known to be compatible
1038f62bca4SAlex Richardson# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
1048f62bca4SAlex Richardson# from the FreeBSD sources during the bootstrap-tools stage.
1058f62bca4SAlex Richardson
1068f62bca4SAlex Richardson# basic commands: It is fine to use the host version for all of these even on
1078f62bca4SAlex Richardson# Linux/MacOS since we only use flags that are supported by all of them.
108ea6c594cSAlex Richardson_host_tools_to_symlink=	basename bzip2 bunzip2 chmod chown cmp comm cp date dd \
1098f62bca4SAlex Richardson	dirname echo env false find fmt gzip gunzip head hostname id ln ls \
1108f62bca4SAlex Richardson	mkdir mv nice patch rm realpath sh sleep stat tee touch tr true uname \
1118f62bca4SAlex Richardson	uniq wc which
1128f62bca4SAlex Richardson
1138f62bca4SAlex Richardson# We also need a symlink to the absolute path to the make binary used for
1148f62bca4SAlex Richardson# the toplevel makefile. This is not necessarily the same as `which make`
1158f62bca4SAlex Richardson# since e.g. on Linux and MacOS that will be GNU make.
1168f62bca4SAlex Richardson_make_abs!=	which "${MAKE}"
1178f62bca4SAlex Richardson_host_abs_tools_to_symlink=	${_make_abs}:make ${_make_abs}:bmake
1188f62bca4SAlex Richardson
1198f62bca4SAlex Richardsonhost-symlinks:
1208f62bca4SAlex Richardson	@echo "Linking host tools into ${DESTDIR}/bin"
1218f62bca4SAlex Richardson.for _tool in ${_host_tools_to_symlink}
122*33176cdcSWarner Losh	@source_path=`which ${_tool}`; \
1238f62bca4SAlex Richardson	if [ ! -e "$${source_path}" ] ; then \
1248f62bca4SAlex Richardson		echo "Cannot find host tool '${_tool}'"; false; \
1258f62bca4SAlex Richardson	fi; \
126*33176cdcSWarner Losh	rm -f "${DESTDIR}/bin/${_tool}"; \
127*33176cdcSWarner Losh	cp -f "$${source_path}" "${DESTDIR}/bin/${_tool}"
1288f62bca4SAlex Richardson.endfor
1298f62bca4SAlex Richardson.for _tool in ${_host_abs_tools_to_symlink}
1308f62bca4SAlex Richardson	@source_path="${_tool:S/:/ /:[1]}"; \
1318f62bca4SAlex Richardson	target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \
1328f62bca4SAlex Richardson	if [ ! -e "$${source_path}" ] ; then \
1338f62bca4SAlex Richardson		echo "Host tool '${src_path}' is missing"; false; \
1348f62bca4SAlex Richardson	fi; \
135*33176cdcSWarner Losh	rm -f "$${target_path}"; \
136*33176cdcSWarner Losh	cp -f "$${source_path}" "$${target_path}"
1378f62bca4SAlex Richardson.endfor
1384f47920eSKyle Evans.if exists(/usr/libexec/flua)
139*33176cdcSWarner Losh	rm -f ${DESTDIR}/usr/libexec/flua
140*33176cdcSWarner Losh	cp -f /usr/libexec/flua ${DESTDIR}/usr/libexec/flua
1414f47920eSKyle Evans.endif
1424acc8a67SAlex Richardson
1434acc8a67SAlex Richardson# Create all the directories that are needed during the legacy, bootstrap-tools
1444acc8a67SAlex Richardson# and cross-tools stages. We do this here using mkdir since mtree may not exist
1454acc8a67SAlex Richardson# yet (this happens if we are crossbuilding from Linux/Mac).
14617adf17bSSimon J. GerratyINSTALLDIR_LIST= \
14717adf17bSSimon J. Gerraty	bin \
14817adf17bSSimon J. Gerraty	lib/casper \
14917adf17bSSimon J. Gerraty	lib/geom \
15017adf17bSSimon J. Gerraty	usr/include/casper \
15194a82666SRyan Moeller	usr/include/private/ucl \
15217adf17bSSimon J. Gerraty	usr/include/private/zstd \
15317adf17bSSimon J. Gerraty	usr/lib \
154f22a5921SKyle Evans	usr/libexec
15517adf17bSSimon J. Gerraty
1564acc8a67SAlex Richardsoninstalldirs:
15717adf17bSSimon J. Gerraty	mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,}
15817adf17bSSimon J. Gerraty
1598f62bca4SAlex Richardson# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a
1608f62bca4SAlex Richardson# bootstrap tool was added to WORLTMP with a symlink or by building it in the
1618f62bca4SAlex Richardson# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap
1628f62bca4SAlex Richardson# tools but adding the symlinks is easier and means all tools are also
1638f62bca4SAlex Richardson# in the directory that they are installed to normally.
164b25c7179SAlex Richardson
165b25c7179SAlex Richardson.for _dir in sbin usr/sbin usr/bin
166b25c7179SAlex Richardson# delete existing directories from before r340157
167b25c7179SAlex Richardson	@if [ ! -L ${DESTDIR}/${_dir} ]; then \
168b25c7179SAlex Richardson	    echo "removing old non-symlink ${DESTDIR}/${_dir}"; \
169b25c7179SAlex Richardson	    rm -rf "${DESTDIR}/${_dir}"; \
170b25c7179SAlex Richardson	fi
171b25c7179SAlex Richardson.endfor
172b25c7179SAlex Richardson	ln -sfn bin ${DESTDIR}/sbin
173b25c7179SAlex Richardson	ln -sfn ../bin ${DESTDIR}/usr/bin
174b25c7179SAlex Richardson	ln -sfn ../bin ${DESTDIR}/usr/sbin
1754acc8a67SAlex Richardson.for _group in ${INCSGROUPS:NINCS}
1764acc8a67SAlex Richardson	mkdir -p "${DESTDIR}/${${_group}DIR}"
1774acc8a67SAlex Richardson.endfor
1784acc8a67SAlex Richardson
17930aaff11SWarner Losh.include <bsd.lib.mk>
180