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