xref: /freebsd/share/mk/local.dirdeps.mk (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
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.if ${RELDIR} == ${DEP_RELDIR} # Only do this for main build target
94.for _depfile in ${.MAKE.DEPENDFILE_PREFERENCE:T}
95.if !defined(_have_depfile) && exists(${.CURDIR}/${_depfile})
96_have_depfile=
97.endif
98.endfor
99.if !defined(_have_depfile)
100# KMOD does not use any stdlibs.
101.if !defined(KMOD)
102# Has C files. The C_DIRDEPS are shared with C++ files as well.
103C_DIRDEPS= \
104	gnu/lib/csu \
105	gnu/lib/libgcc \
106	include \
107	include/xlocale \
108	lib/${CSU_DIR} \
109	lib/libc \
110	lib/libcompiler_rt \
111
112.if !empty(SRCS:M*.c)
113DIRDEPS+= ${C_DIRDEPS}
114.endif
115# Has C++ files
116.if !empty(SRCS:M*.cc) || !empty(SRCS:M*.C) || !empty(SRCS:M*.cpp) || \
117    !empty(SRCS:M*.cxx)
118DIRDEPS+= ${C_DIRDEPS}
119.if ${MK_CLANG} == "yes"
120DIRDEPS+= lib/libc++ lib/libcxxrt
121.else
122DIRDEPS+= gnu/lib/libstdc++ gnu/lib/libsupc++
123.endif
124# XXX: Clang and GCC always adds -lm currently, even when not needed.
125DIRDEPS+= lib/msun
126.endif	# CXX
127.endif	# !defined(KMOD)
128# Has yacc files.
129.if !empty(SRCS:M*.y)
130DIRDEPS+=	usr.bin/yacc.host
131.endif
132# Gather PROGS dependencies
133.if !empty(PROGS)
134_PROGS_LIBADD=
135_PROGS_DPADD=
136.for _prog in ${PROGS}
137.if !empty(LIBADD.${_prog})
138_PROGS_LIBADD+=	${LIBADD.${_prog}}
139.endif
140.if !empty(DPADD.${_prog})
141_PROGS_DPADD+=	${DPADD.${_prog}}
142.endif
143.endfor
144.endif	# !empty(PROGS)
145.if !empty(DPADD)
146# Taken from meta.autodep.mk (where it only does something with
147# BUILD_AT_LEVEL0, which we don't use).
148# This only works for DPADD with full OBJ/SRC paths, which is mostly just
149# _INTERNALLIBS.
150_DPADD= ${DPADD} ${_PROGS_DPADD}
151_DP_DIRDEPS= \
152	${_DPADD:O:u:M${OBJTOP}*:H:N.:tA:C,${OBJTOP}[^/]*/,,:N.:O:u} \
153	${_DPADD:O:u:M${OBJROOT}*:N${OBJTOP}*:N${STAGE_ROOT}/*:H:S,${OBJROOT},,:C,^([^/]+)/(.*),\2.\1,:S,${HOST_TARGET}$,host,:N.*:O:u}
154# Resolve the paths to RELDIRs
155.if !empty(_DP_DIRDEPS)
156DIRDEPS+= ${_DP_DIRDEPS:C,^,${SRCTOP}/,:tA:C,^${SRCTOP}/,,}
157.endif
158.endif	# !empty(DPADD)
159.if !empty(LIBADD)
160# Also handle LIBADD for non-internal libraries.
161_ALL_LIBADD= ${LIBADD} ${_PROGS_LIBADD}
162.for _lib in ${_ALL_LIBADD:O:u}
163_lib${_lib}reldir= ${LIB${_lib:tu}DIR:C,${OBJTOP}/,,}
164.if defined(LIB${_lib:tu}DIR) && ${DIRDEPS:M${_lib${_lib}reldir}} == "" && \
165    exists(${SRCTOP}/${_lib${_lib}reldir})
166DIRDEPS+= ${_lib${_lib}reldir}
167.endif
168.endfor
169.endif	# !empty(LIBADD)
170.endif	# no Makefile.depend*
171.endif	# ${RELDIR} == ${DEP_RELDIR}
172
173.endif	# ${DEP_MACHINE} != "host"
174
175.if ${MK_STAGING} == "yes"
176# we need targets/pseudo/stage to prep the stage tree
177.if ${DEP_RELDIR} != "targets/pseudo/stage"
178DIRDEPS += targets/pseudo/stage
179.endif
180.endif
181
182DEP_MACHINE_ARCH = ${MACHINE_ARCH.${DEP_MACHINE}}
183CSU_DIR.${DEP_MACHINE_ARCH} ?= csu/${DEP_MACHINE_ARCH}
184CSU_DIR := ${CSU_DIR.${DEP_MACHINE_ARCH}}
185BOOT_MACHINE_DIR:= ${BOOT_MACHINE_DIR.${DEP_MACHINE}}
186KERNEL_NAME:= ${KERNEL_NAME.${DEP_MACHINE}}
187