xref: /freebsd/share/mk/local.dirdeps.mk (revision 5eadfbfcd01e23d3de1958c013ca556dbf0b5458)
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	Nusr.bin/xinstall* \
46
47
48DIRDEPS_FILTER+= \
49	Nbin/cat.host \
50	${DIRDEPS_FILTER.xtras:U}
51.endif
52
53# reset this each time
54DIRDEPS_FILTER.xtras=
55.if ${DEP_MACHINE:Npkgs*} != ""
56DIRDEPS_FILTER.xtras+= Nusr.bin/clang/clang.host
57.endif
58
59.if ${DEP_MACHINE} != "host"
60
61# this is how we can handle optional dependencies
62.if ${DEP_RELDIR} == "lib/libc"
63DIRDEPS += lib/libc_nonshared
64.if ${MK_SSP:Uno} != "no"
65DIRDEPS += gnu/lib/libssp/libssp_nonshared
66.endif
67.else
68DIRDEPS_FILTER.xtras+= Nlib/libc_nonshared
69.endif
70
71# some optional things
72.if ${MK_CTF} == "yes" && ${DEP_RELDIR:Mcddl/usr.bin/ctf*} == ""
73DIRDEPS += \
74	cddl/usr.bin/ctfconvert.host \
75	cddl/usr.bin/ctfmerge.host
76.endif
77
78# Bootstrap support.  Give hints to DIRDEPS if there is no Makefile.depend*
79# generated yet.  This can be based on things such as SRC files and LIBADD.
80# These hints will not factor into the final Makefile.depend as only what is
81# used will be added in and handled via [local.]gendirdeps.mk.  This is not
82# done for MACHINE=host builds.
83# XXX: Include this in local.autodep.mk as well for gendirdeps without filemon.
84# Only do this for main build target
85.if ${RELDIR} == ${DEP_RELDIR} && !defined(_RECURSING_PROGS)
86.for _depfile in ${.MAKE.DEPENDFILE_PREFERENCE:T}
87.if !defined(_have_depfile) && exists(${.CURDIR}/${_depfile})
88_have_depfile=
89.endif
90.endfor
91.if !defined(_have_depfile)
92# KMOD does not use any stdlibs.
93.if !defined(KMOD)
94# Gather PROGS dependencies first
95.if !empty(PROGS)
96_PROGS_LIBADD=
97_PROGS_DPADD=
98_PROGS_SRCS=
99.for _prog in ${PROGS}
100.for s in . _
101.if !empty(LIBADD${s}${_prog})
102_PROGS_LIBADD+=	${LIBADD${s}${_prog}}
103.endif
104.if !empty(DPADD${s}${_prog})
105_PROGS_DPADD+=	${DPADD${s}${_prog}}
106.endif
107.if !empty(SRCS${s}${_prog})
108_PROGS_SRCS+=	${SRCS${s}${_prog}}
109.endif
110.endfor	# .for s in . _
111# Add in assumed source (bsd.prog.mk)
112.if !target(${_prog})
113.if defined(PROG_CXX)
114_PROGS_SRCS+=	${_prog}.cc
115.else
116_PROGS_SRCS+=	${_prog}.c
117.endif
118.endif	# !target(${_prog})
119.endfor	# .for _prog in ${PROGS}
120.endif	# !empty(PROGS)
121_SRCS= ${SRCS} ${_PROGS_SRCS}
122
123# Has C files. The C_DIRDEPS are shared with C++ files as well.
124C_DIRDEPS= \
125	gnu/lib/csu \
126	gnu/lib/libgcc \
127	include \
128	include/arpa \
129	include/protocols \
130	include/rpc  \
131	include/rpcsvc \
132	include/xlocale \
133	lib/${CSU_DIR} \
134	lib/libc \
135	lib/libcompiler_rt \
136
137
138.if ${MK_GSSAPI} != "no"
139C_DIRDEPS+=  include/gssapi
140.endif
141
142.if !empty(_SRCS:M*.c)
143DIRDEPS+= ${C_DIRDEPS}
144.endif
145# Has C++ files
146.if !empty(_SRCS:M*.cc) || !empty(_SRCS:M*.C) || !empty(_SRCS:M*.cpp) || \
147    !empty(_SRCS:M*.cxx)
148DIRDEPS+= ${C_DIRDEPS}
149.if ${MK_CLANG} == "yes"
150DIRDEPS+= lib/libc++ lib/libcxxrt
151.else
152DIRDEPS+= gnu/lib/libstdc++ gnu/lib/libsupc++
153.endif
154# XXX: Clang and GCC always adds -lm currently, even when not needed.
155DIRDEPS+= lib/msun
156.endif	# CXX
157.endif	# !defined(KMOD)
158# Has yacc files.
159.if !empty(_SRCS:M*.y)
160DIRDEPS+=	usr.bin/yacc.host
161.endif
162_DPADD= ${DPADD} ${_PROGS_DPADD}
163.if !empty(_DPADD)
164# Taken from meta.autodep.mk (where it only does something with
165# BUILD_AT_LEVEL0, which we don't use).
166# This only works for DPADD with full OBJ/SRC paths, which is mostly just
167# _INTERNALLIBS.
168_DP_DIRDEPS= \
169	${_DPADD:O:u:M${OBJTOP}*:H:N.:tA:C,${OBJTOP}[^/]*/,,:N.:O:u} \
170	${_DPADD:O:u:M${OBJROOT}*:N${OBJTOP}*:N${STAGE_ROOT}/*:H:S,${OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
171# Resolve the paths to RELDIRs
172.if !empty(_DP_DIRDEPS)
173DIRDEPS+= ${_DP_DIRDEPS:C,^,${SRCTOP}/,:tA:C,^${SRCTOP}/,,}
174.endif
175.endif	# !empty(DPADD)
176_ALL_LIBADD= ${LIBADD} ${_PROGS_LIBADD}
177.if !empty(_ALL_LIBADD)
178# Also handle LIBADD for non-internal libraries.
179.for _lib in ${_ALL_LIBADD:O:u}
180_lib${_lib}reldir= ${LIB${_lib:tu}DIR:C,${OBJTOP}/,,}
181.if defined(LIB${_lib:tu}DIR) && ${DIRDEPS:M${_lib${_lib}reldir}} == "" && \
182    exists(${SRCTOP}/${_lib${_lib}reldir})
183DIRDEPS+= ${_lib${_lib}reldir}
184.endif
185.endfor
186.endif	# !empty(LIBADD)
187.endif	# no Makefile.depend*
188.endif	# ${RELDIR} == ${DEP_RELDIR}
189
190.endif	# ${DEP_MACHINE} != "host"
191
192.if ${MK_STAGING} == "yes"
193# we need targets/pseudo/stage to prep the stage tree
194.if ${DEP_RELDIR} != "targets/pseudo/stage"
195DIRDEPS += targets/pseudo/stage
196.endif
197.endif
198
199DEP_MACHINE_ARCH = ${MACHINE_ARCH.${DEP_MACHINE}}
200CSU_DIR.${DEP_MACHINE_ARCH} ?= csu/${DEP_MACHINE_ARCH}
201CSU_DIR := ${CSU_DIR.${DEP_MACHINE_ARCH}}
202BOOT_MACHINE_DIR:= ${BOOT_MACHINE_DIR.${DEP_MACHINE}}
203KERNEL_NAME:= ${KERNEL_NAME.${DEP_MACHINE}}
204