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