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