xref: /freebsd/tools/build/Makefile (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1# $FreeBSD$
2
3.PATH: ${.CURDIR}/../../include
4
5LIB=		egacy
6SRC=
7INCSGROUPS=	INCS SYSINCS
8INCS=
9
10SYSINCSDIR=	${INCLUDEDIR}/sys
11
12BOOTSTRAPPING?=	0
13
14_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true
15.if ${_WITH_PWCACHEDB} == 0
16.PATH: ${.CURDIR}/../../contrib/libc-pwcache
17CFLAGS+=	-I${.CURDIR}/../../contrib/libc-pwcache \
18		-I${.CURDIR}/../../lib/libc/include
19SRCS+=		pwcache.c
20.endif
21
22_WITH_STRSVIS!=	grep -c strsvis /usr/include/vis.h || true
23.if ${_WITH_STRSVIS} == 0
24.PATH: ${.CURDIR}/../../contrib/libc-vis
25SRCS+=		vis.c
26CFLAGS+=	-I${.CURDIR}/../../contrib/libc-vis \
27		-I${.CURDIR}/../../lib/libc/include
28.endif
29
30_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true
31.if ${_WITH_REALLOCARRAY} == 0
32.PATH: ${.CURDIR}/../../lib/libc/stdlib
33INCS+=		stdlib.h
34SRCS+=		reallocarray.c
35CFLAGS+=	-I${.CURDIR}/../../lib/libc/include
36.endif
37
38_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true
39.if ${_WITH_UTIMENS} == 0
40SYSINCS+=	stat.h
41SRCS+=		futimens.c utimensat.c
42.endif
43
44_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true
45.if ${_WITH_EXPLICIT_BZERO} == 0
46.PATH: ${SRCTOP}/sys/libkern
47INCS+=		strings.h
48SRCS+=		explicit_bzero.c
49.endif
50
51.if exists(/usr/include/capsicum_helpers.h)
52_WITH_CAPH_ENTER!= grep -c caph_enter /usr/include/capsicum_helpers.h || true
53.endif
54.if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0
55.PATH: ${SRCTOP}/lib/libcapsicum
56INCS+=		capsicum_helpers.h
57.PATH: ${SRCTOP}/lib/libcasper/libcasper
58INCS+=		libcasper.h
59.endif
60
61.if empty(SRCS)
62SRCS=		dummy.c
63.endif
64
65.if defined(CROSS_BUILD_TESTING)
66SUBDIR=		cross-build
67.endif
68
69# Needed to build config (since it uses libnv)
70SYSINCS+=	${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h
71
72# We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
73# accidentally run tools that are incompatible but happen to be in $PATH.
74# This is especially important when building on Linux/MacOS where many of the
75# programs used during the build accept different flags or generate different
76# output. On those platforms we only symlink the tools known to be compatible
77# (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others
78# from the FreeBSD sources during the bootstrap-tools stage.
79
80# basic commands: It is fine to use the host version for all of these even on
81# Linux/MacOS since we only use flags that are supported by all of them.
82_host_tools_to_symlink=	basename bzip2 bunzip2 chmod chown cmp comm cp date \
83	dirname echo env false find fmt gzip gunzip head hostname id ln ls \
84	mkdir mv nice patch rm realpath sh sleep stat tee touch tr true uname \
85	uniq wc which
86
87# We also need a symlink to the absolute path to the make binary used for
88# the toplevel makefile. This is not necessarily the same as `which make`
89# since e.g. on Linux and MacOS that will be GNU make.
90_make_abs!=	which "${MAKE}"
91_host_abs_tools_to_symlink=	${_make_abs}:make ${_make_abs}:bmake
92
93host-symlinks:
94	@echo "Linking host tools into ${DESTDIR}/bin"
95.for _tool in ${_host_tools_to_symlink}
96	@if [ ! -e "${DESTDIR}/bin/${_tool}" ]; then \
97		source_path=`which ${_tool}`; \
98		if [ ! -e "$${source_path}" ] ; then \
99			echo "Cannot find host tool '${_tool}'"; false; \
100		fi; \
101		ln -sfnv "$${source_path}" "${DESTDIR}/bin/${_tool}"; \
102	fi
103.endfor
104.for _tool in ${_host_abs_tools_to_symlink}
105	@source_path="${_tool:S/:/ /:[1]}"; \
106	target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \
107	if [ ! -e "$${target_path}" ] ; then \
108		if [ ! -e "$${source_path}" ] ; then \
109			echo "Host tool '${src_path}' is missing"; false; \
110		fi; \
111		ln -sfnv "$${source_path}" "$${target_path}"; \
112	fi
113.endfor
114
115# Create all the directories that are needed during the legacy, bootstrap-tools
116# and cross-tools stages. We do this here using mkdir since mtree may not exist
117# yet (this happens if we are crossbuilding from Linux/Mac).
118installdirs:
119.for _dir in bin usr/lib usr/include lib/geom lib/casper
120	mkdir -p "${DESTDIR}/${_dir}"
121.endfor
122# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a
123# bootstrap tool was added to WORLTMP with a symlink or by building it in the
124# bootstrap-tools phase. We could also overrride BINDIR when building bootstrap
125# tools but adding the symlinks is easier and means all tools are also
126# in the directory that they are installed to normally.
127
128.for _dir in sbin usr/sbin usr/bin
129# delete existing directories from before r340157
130	@if [ ! -L ${DESTDIR}/${_dir} ]; then \
131	    echo "removing old non-symlink ${DESTDIR}/${_dir}"; \
132	    rm -rf "${DESTDIR}/${_dir}"; \
133	fi
134.endfor
135	ln -sfn bin ${DESTDIR}/sbin
136	ln -sfn ../bin ${DESTDIR}/usr/bin
137	ln -sfn ../bin ${DESTDIR}/usr/sbin
138.for _group in ${INCSGROUPS:NINCS}
139	mkdir -p "${DESTDIR}/${${_group}DIR}"
140.endfor
141
142.include <bsd.lib.mk>
143