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