xref: /freebsd/share/mk/local.dirdeps.mk (revision 608da65de9552d5678c1000776ed69da04a45983)
1.if !target(_DIRDEP_USE)
2# we are the 1st makefile
3
4.if !defined(MK_CLANG)
5.include "${SRCTOP}/share/mk/src.opts.mk"
6.endif
7
8# making universe is special
9.if defined(UNIVERSE_GUARD)
10# these should be done by now
11DIRDEPS_FILTER+= N*.host
12.endif
13
14# pseudo machines get no qualification
15.for m in ${PSEUDO_MACHINE_LIST:Nhost*}
16M_dep_qual_fixes += C;($m),[^/.,]*$$;\1;
17.endfor
18#.info M_dep_qual_fixes=${M_dep_qual_fixes}
19
20# Some things we never want to build for host
21DIRDEPS_FILTER.host = \
22	Ninclude* \
23	Nlib/csu* \
24	Nlib/libc \
25	Nlib/libcompiler_rt \
26	Nlib/[mn]* \
27	Nlib/lib[t]* \
28	Ngnu/lib/lib[a-r]* \
29	Nsecure/lib* \
30	Nusr.bin/xinstall* \
31
32.if ${.MAKE.OS} == "FreeBSD"
33# Host libraries should mostly be excluded from the build so the
34# host version in /usr/lib is used.
35# Internal libraries need to be allowed to be built though
36# since they are never installed.
37
38# Cheat for including src.libnames.mk
39__<bsd.init.mk>__:
40# Pull in _INTERNALLIBS
41.include <src.libnames.mk>
42
43_need_host_libs=
44.for lib in ${_INTERNALLIBS}
45_need_host_libs+= ${LIB${lib:tu}DIR:S,^${OBJTOP}/,,}
46.endfor
47.if ${MK_host_egacy} == "yes"
48_need_host_libs+= lib/libmd
49.endif
50
51N_host_libs:= ${cd ${SRCTOP} && echo lib/lib*:L:sh:${_need_host_libs:${M_ListToSkip}}:${M_ListToSkip}}
52DIRDEPS_FILTER.host+= ${N_host_libs}
53.endif
54
55DIRDEPS_FILTER.host32 = ${DIRDEPS_FILTER.host}
56
57DIRDEPS_FILTER+= \
58	Nbin/cat.host \
59	${DIRDEPS_FILTER.xtras:U}
60
61# Cleanup a buildworld's WORLDTMP so that any files generated from it
62# or using it will rebuild with the DIRDEPS SYSROOT.  Otherwise existing
63# object .meta files may still reference those directories and not be
64# rebuilt and lead to incorrect Makefile.depend files due to lack of
65# .dirdep files.
66.if !defined(NO_CLEANUP_WORLDTMP) && exists(${OBJTOP}/tmp/_worldtmp)
67cleanup_worldtmp: .PHONY .NOMETA
68	@echo "Cleaning leftover WORLDTMP from buildworld."
69	-rm -rf ${OBJTOP}/tmp/*
70	-chflags -R 0 ${OBJTOP}/tmp/*
71	rm -rf ${OBJTOP}/tmp
72beforedirdeps: cleanup_worldtmp
73.endif
74
75# pseudo option for building host tools on old or non-FreeBSD host
76# allows us to leverage Makefile.depend.options with
77# DIRDEPS_OPTIONS = host_egacy
78# dirdeps-options.mk will qualify with ${DEP_MACHINE} (and others)
79# before looking at the bare option.
80MK_host_egacy.host= ${MK_host_egacy}
81
82.endif				# !target(_DIRDEP_USE)
83
84# reset this each time
85DIRDEPS_FILTER.xtras=
86.if ${DEP_MACHINE:Npkgs*} != ""
87DIRDEPS_FILTER.xtras+= Nusr.bin/clang/clang.host
88.endif
89
90.if ${DEP_MACHINE:Nhost*} == ""
91.if ${MK_host_egacy} == "yes" && ${DEP_RELDIR:Ntools/build:Ntargets/*:N*/stage} != ""
92DIRDEPS += tools/build
93.endif
94.else
95MK_host_egacy.${DEP_MACHINE}= no
96
97# this is how we can handle optional dependencies
98.if ${DEP_RELDIR} == "lib/libc"
99DIRDEPS += lib/libc_nonshared
100.if ${MK_SSP:Uno} != "no"
101DIRDEPS += lib/libssp_nonshared
102.endif
103.else
104DIRDEPS_FILTER.xtras+= Nlib/libc_nonshared
105.endif
106
107# some optional things
108.if ${MK_CTF} == "yes" && ${DEP_RELDIR:Mcddl/usr.bin/ctf*} == ""
109DIRDEPS += \
110	cddl/usr.bin/ctfconvert.host \
111	cddl/usr.bin/ctfmerge.host
112.endif
113
114.if ${DEP_MACHINE:Nhost*} != ""
115# Add in proper libgcc (gnu or LLVM) if not building libcc and libc is needed.
116# Add both gcc_s and gcc_eh as dependencies as the decision to build
117# -static or not is not known here.
118.if ${DEP_RELDIR:M*libgcc*} == "" && ${DIRDEPS:U:Mlib/libc} != ""
119DIRDEPS+= \
120	lib/libgcc_eh \
121	lib/libgcc_s
122.endif
123.endif
124
125# Bootstrap support.  Give hints to DIRDEPS if there is no Makefile.depend*
126# generated yet.  This can be based on things such as SRC files and LIBADD.
127# These hints will not factor into the final Makefile.depend as only what is
128# used will be added in and handled via [local.]gendirdeps.mk.  This is not
129# done for MACHINE=host builds.
130# XXX: Include this in local.autodep.mk as well for gendirdeps without filemon.
131# Only do this for main build target
132.if ${RELDIR} == ${DEP_RELDIR} && !defined(_RECURSING_PROGS)
133.for _depfile in ${.MAKE.DEPENDFILE_PREFERENCE:T}
134.if !defined(_have_depfile) && exists(${.CURDIR}/${_depfile})
135_have_depfile=
136.endif
137.endfor
138.if !defined(_have_depfile)
139# KMOD does not use any stdlibs.
140.if !defined(KMOD)
141# Gather PROGS dependencies first
142.if !empty(PROGS)
143_PROGS_LIBADD=
144_PROGS_DPADD=
145_PROGS_SRCS=
146.for _prog in ${PROGS}
147.for s in . _
148.if !empty(LIBADD${s}${_prog})
149_PROGS_LIBADD+=	${LIBADD${s}${_prog}}
150.endif
151.if !empty(DPADD${s}${_prog})
152_PROGS_DPADD+=	${DPADD${s}${_prog}}
153.endif
154.if !empty(SRCS${s}${_prog})
155_PROGS_SRCS+=	${SRCS${s}${_prog}}
156.endif
157.endfor	# .for s in . _
158# Add in assumed source (bsd.prog.mk)
159.if !target(${_prog})
160.if defined(PROG_CXX)
161_PROGS_SRCS+=	${_prog}.cc
162.else
163_PROGS_SRCS+=	${_prog}.c
164.endif
165.endif	# !target(${_prog})
166.endfor	# .for _prog in ${PROGS}
167.endif	# !empty(PROGS)
168_SRCS= ${SRCS} ${_PROGS_SRCS}
169
170# Has C files. The C_DIRDEPS are shared with C++ files as well.
171C_DIRDEPS= \
172	include \
173	include/arpa \
174	include/protocols \
175	include/rpc  \
176	include/rpcsvc \
177	include/xlocale \
178	lib/${CSU_DIR} \
179	lib/libc \
180	lib/libcompiler_rt \
181
182# libgcc is needed as well but is added later.
183
184.if ${MK_GSSAPI} != "no"
185C_DIRDEPS+=  include/gssapi
186.endif
187
188.if !empty(_SRCS:M*.c)
189DIRDEPS+= ${C_DIRDEPS}
190.endif
191# Has C++ files
192.if !empty(_SRCS:M*.cc) || !empty(_SRCS:M*.C) || !empty(_SRCS:M*.cpp) || \
193    !empty(_SRCS:M*.cxx)
194DIRDEPS+= ${C_DIRDEPS}
195.if ${MK_CLANG} == "yes"
196DIRDEPS+= lib/libc++ lib/libcxxrt
197.endif
198# XXX: Clang and GCC always adds -lm currently, even when not needed.
199DIRDEPS+= lib/msun
200.endif	# CXX
201.endif	# !defined(KMOD)
202# Has yacc files.
203.if !empty(_SRCS:M*.y)
204DIRDEPS+=	usr.bin/yacc.host
205.endif
206_DPADD= ${DPADD} ${_PROGS_DPADD}
207.if !empty(_DPADD)
208# This only works for DPADD with full OBJ/SRC paths, which is mostly just
209# _INTERNALLIBS.
210_DP_DIRDEPS= \
211	${_DPADD:O:u:M${OBJTOP}*:H:N.:tA:C,${OBJTOP}[^/]*/,,:N.:O:u} \
212	${_DPADD:O:u:M${OBJROOT}*:N${OBJTOP}*:N${STAGE_ROOT}/*:H:S,${OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
213# Resolve the paths to RELDIRs
214.if !empty(_DP_DIRDEPS)
215DIRDEPS+= ${_DP_DIRDEPS:C,^,${SRCTOP}/,:tA:C,^${SRCTOP}/,,}
216.endif
217.endif	# !empty(DPADD)
218_ALL_LIBADD= ${LIBADD} ${_PROGS_LIBADD}
219.if !empty(_ALL_LIBADD)
220# Also handle LIBADD for non-internal libraries.
221.for _lib in ${_ALL_LIBADD:O:u}
222_lib${_lib}reldir= ${LIB${_lib:tu}DIR:C,${OBJTOP}/,,}
223.if defined(LIB${_lib:tu}DIR) && ${DIRDEPS:M${_lib${_lib}reldir}} == "" && \
224    exists(${SRCTOP}/${_lib${_lib}reldir})
225DIRDEPS+= ${_lib${_lib}reldir}
226.endif
227.endfor
228.endif	# !empty(LIBADD)
229.endif	# no Makefile.depend*
230.endif	# ${RELDIR} == ${DEP_RELDIR}
231
232.endif	# ${DEP_MACHINE} != "host"
233
234.if ${MK_STAGING} == "yes"
235# we need targets/pseudo/stage to prep the stage tree
236.if ${DEP_RELDIR:N.:N${SRCTOP}:N*pseudo/stage} != ""
237DIRDEPS += targets/pseudo/stage
238.endif
239.endif
240
241DEP_MACHINE_ARCH = ${MACHINE_ARCH.${DEP_MACHINE}}
242DEP_MACHINE_CPUARCH = ${DEP_MACHINE_ARCH:${__TO_CPUARCH}}
243CSU_DIR.${DEP_MACHINE_ARCH} ?= csu/${DEP_MACHINE_ARCH}
244CSU_DIR := ${CSU_DIR.${DEP_MACHINE_ARCH}}
245BOOT_MACHINE_DIR:= ${BOOT_MACHINE_DIR.${DEP_MACHINE}}
246KERNEL_NAME:= ${KERNEL_NAME.${DEP_MACHINE}}
247
248.-include <site.dirdeps.mk>
249