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