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