xref: /freebsd/tools/build/Makefile (revision b25c717954b929e80064b59d5e0d340731bf484d)
130aaff11SWarner Losh# $FreeBSD$
230aaff11SWarner Losh
330aaff11SWarner Losh.PATH: ${.CURDIR}/../../include
430aaff11SWarner Losh
51c62f923SWarner LoshLIB=		egacy
6c2774610SDavid E. O'BrienSRC=
7d80f1dd1SJilles TjoelkerINCSGROUPS=	INCS SYSINCS
830aaff11SWarner LoshINCS=
930aaff11SWarner Losh
10d80f1dd1SJilles TjoelkerSYSINCSDIR=	${INCLUDEDIR}/sys
11d80f1dd1SJilles Tjoelker
1230aaff11SWarner LoshBOOTSTRAPPING?=	0
1330aaff11SWarner Losh
14804baa38SBryan Drewery_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true
1579626055SBrooks Davis.if ${_WITH_PWCACHEDB} == 0
1679626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-pwcache
1779626055SBrooks DavisCFLAGS+=	-I${.CURDIR}/../../contrib/libc-pwcache \
1879626055SBrooks Davis		-I${.CURDIR}/../../lib/libc/include
1979626055SBrooks DavisSRCS+=		pwcache.c
2079626055SBrooks Davis.endif
2179626055SBrooks Davis
22804baa38SBryan Drewery_WITH_STRSVIS!=	grep -c strsvis /usr/include/vis.h || true
2379626055SBrooks Davis.if ${_WITH_STRSVIS} == 0
2479626055SBrooks Davis.PATH: ${.CURDIR}/../../contrib/libc-vis
2579626055SBrooks DavisSRCS+=		vis.c
2679626055SBrooks DavisCFLAGS+=	-I${.CURDIR}/../../contrib/libc-vis \
2779626055SBrooks Davis		-I${.CURDIR}/../../lib/libc/include
2879626055SBrooks Davis.endif
2979626055SBrooks Davis
30804baa38SBryan Drewery_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true
318e7e3163SDimitry Andric.if ${_WITH_REALLOCARRAY} == 0
328e7e3163SDimitry Andric.PATH: ${.CURDIR}/../../lib/libc/stdlib
338e7e3163SDimitry AndricINCS+=		stdlib.h
348e7e3163SDimitry AndricSRCS+=		reallocarray.c
358e7e3163SDimitry AndricCFLAGS+=	-I${.CURDIR}/../../lib/libc/include
368e7e3163SDimitry Andric.endif
378e7e3163SDimitry Andric
38d80f1dd1SJilles Tjoelker_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true
39d80f1dd1SJilles Tjoelker.if ${_WITH_UTIMENS} == 0
40d80f1dd1SJilles TjoelkerSYSINCS+=	stat.h
41d80f1dd1SJilles TjoelkerSRCS+=		futimens.c utimensat.c
42d80f1dd1SJilles Tjoelker.endif
43d80f1dd1SJilles Tjoelker
448d14ced6SAlex Richardson_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true
458d14ced6SAlex Richardson.if ${_WITH_EXPLICIT_BZERO} == 0
468d14ced6SAlex Richardson.PATH: ${SRCTOP}/sys/libkern
478d14ced6SAlex RichardsonINCS+=		strings.h
488d14ced6SAlex RichardsonSRCS+=		explicit_bzero.c
498d14ced6SAlex Richardson.endif
508d14ced6SAlex Richardson
5130aaff11SWarner Losh.if empty(SRCS)
5230aaff11SWarner LoshSRCS=		dummy.c
5330aaff11SWarner Losh.endif
5430aaff11SWarner Losh
55f09a3cc4SRuslan Ermilov.if defined(CROSS_BUILD_TESTING)
56f09a3cc4SRuslan ErmilovSUBDIR=		cross-build
57f09a3cc4SRuslan Ermilov.endif
58f09a3cc4SRuslan Ermilov
5963889bbdSAlex Richardson# Needed to build config (since it uses libnv)
6063889bbdSAlex RichardsonSYSINCS+=	${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h
6163889bbdSAlex Richardson
628f62bca4SAlex Richardson# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
638f62bca4SAlex Richardson# accidentally run tools that are incompatible but happen to be in $PATH.
648f62bca4SAlex Richardson# This is especially important when building on Linux/MacOS where many of the
658f62bca4SAlex Richardson# programs used during the build accept different flags or generate different
668f62bca4SAlex Richardson# output. On those platforms we only symlink the tools known to be compatible
678f62bca4SAlex Richardson# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
688f62bca4SAlex Richardson# from the FreeBSD sources during the bootstrap-tools stage.
698f62bca4SAlex Richardson
708f62bca4SAlex Richardson# basic commands: It is fine to use the host version for all of these even on
718f62bca4SAlex Richardson# Linux/MacOS since we only use flags that are supported by all of them.
728f62bca4SAlex Richardson_host_tools_to_symlink=	basename bzip2 bunzip2 chmod chown cmp comm cp date \
738f62bca4SAlex Richardson	dirname echo env false find fmt gzip gunzip head hostname id ln ls \
748f62bca4SAlex Richardson	mkdir mv nice patch rm realpath sh sleep stat tee touch tr true uname \
758f62bca4SAlex Richardson	uniq wc which
768f62bca4SAlex Richardson
778f62bca4SAlex Richardson# We also need a symlink to the absolute path to the make binary used for
788f62bca4SAlex Richardson# the toplevel makefile. This is not necessarily the same as `which make`
798f62bca4SAlex Richardson# since e.g. on Linux and MacOS that will be GNU make.
808f62bca4SAlex Richardson_make_abs!=	which "${MAKE}"
818f62bca4SAlex Richardson_host_abs_tools_to_symlink=	${_make_abs}:make ${_make_abs}:bmake
828f62bca4SAlex Richardson
838f62bca4SAlex Richardsonhost-symlinks:
848f62bca4SAlex Richardson	@echo "Linking host tools into ${DESTDIR}/bin"
858f62bca4SAlex Richardson.for _tool in ${_host_tools_to_symlink}
868f62bca4SAlex Richardson	@if [ ! -e "${DESTDIR}/bin/${_tool}" ]; then \
878f62bca4SAlex Richardson		source_path=`which ${_tool}`; \
888f62bca4SAlex Richardson		if [ ! -e "$${source_path}" ] ; then \
898f62bca4SAlex Richardson			echo "Cannot find host tool '${_tool}'"; false; \
908f62bca4SAlex Richardson		fi; \
918f62bca4SAlex Richardson		ln -sfnv "$${source_path}" "${DESTDIR}/bin/${_tool}"; \
928f62bca4SAlex Richardson	fi
938f62bca4SAlex Richardson.endfor
948f62bca4SAlex Richardson.for _tool in ${_host_abs_tools_to_symlink}
958f62bca4SAlex Richardson	@source_path="${_tool:S/:/ /:[1]}"; \
968f62bca4SAlex Richardson	target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \
978f62bca4SAlex Richardson	if [ ! -e "$${target_path}" ] ; then \
988f62bca4SAlex Richardson		if [ ! -e "$${source_path}" ] ; then \
998f62bca4SAlex Richardson			echo "Host tool '${src_path}' is missing"; false; \
1008f62bca4SAlex Richardson		fi; \
1018f62bca4SAlex Richardson		ln -sfnv "$${source_path}" "$${target_path}"; \
1028f62bca4SAlex Richardson	fi
1038f62bca4SAlex Richardson.endfor
1044acc8a67SAlex Richardson
1054acc8a67SAlex Richardson# Create all the directories that are needed during the legacy, bootstrap-tools
1064acc8a67SAlex Richardson# and cross-tools stages. We do this here using mkdir since mtree may not exist
1074acc8a67SAlex Richardson# yet (this happens if we are crossbuilding from Linux/Mac).
1084acc8a67SAlex Richardsoninstalldirs:
1098f62bca4SAlex Richardson.for _dir in bin usr/lib usr/include lib/geom lib/casper
1104acc8a67SAlex Richardson	mkdir -p "${DESTDIR}/${_dir}"
1114acc8a67SAlex Richardson.endfor
1128f62bca4SAlex Richardson# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a
1138f62bca4SAlex Richardson# bootstrap tool was added to WORLTMP with a symlink or by building it in the
1148f62bca4SAlex Richardson# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap
1158f62bca4SAlex Richardson# tools but adding the symlinks is easier and means all tools are also
1168f62bca4SAlex Richardson# in the directory that they are installed to normally.
117*b25c7179SAlex Richardson
118*b25c7179SAlex Richardson.for _dir in sbin usr/sbin usr/bin
119*b25c7179SAlex Richardson# delete existing directories from before r340157
120*b25c7179SAlex Richardson	@if [ ! -L ${DESTDIR}/${_dir} ]; then \
121*b25c7179SAlex Richardson	    echo "removing old non-symlink ${DESTDIR}/${_dir}"; \
122*b25c7179SAlex Richardson	    rm -rf "${DESTDIR}/${_dir}"; \
123*b25c7179SAlex Richardson	fi
124*b25c7179SAlex Richardson.endfor
125*b25c7179SAlex Richardson	ln -sfn bin ${DESTDIR}/sbin
126*b25c7179SAlex Richardson	ln -sfn ../bin ${DESTDIR}/usr/bin
127*b25c7179SAlex Richardson	ln -sfn ../bin ${DESTDIR}/usr/sbin
1284acc8a67SAlex Richardson.for _group in ${INCSGROUPS:NINCS}
1294acc8a67SAlex Richardson	mkdir -p "${DESTDIR}/${${_group}DIR}"
1304acc8a67SAlex Richardson.endfor
1314acc8a67SAlex Richardson
13230aaff11SWarner Losh.include <bsd.lib.mk>
133