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