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