xref: /freebsd/contrib/bmake/mk/dep.mk (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1# $Id: dep.mk,v 1.22 2024/02/19 00:06:19 sjg Exp $
2
3# should be set properly in sys.mk
4_this ?= ${.PARSEFILE:S,bsd.,,}
5
6.if !target(__${_this}__)
7__${_this}__: .NOTMAIN
8
9# handle Proc*C as well...
10.if defined(SRCS)
11.if !empty(SRCS:M*.pc)
12.include <proc.mk>
13.endif
14
15.if ${MAKE_VERSION:U0} >= 20211212
16OBJ_SUFFIXES += ${.SUFFIXES:M*o}
17.else
18# it would be nice to be able to query .SUFFIXES
19OBJ_SUFFIXES += .o .po .lo ${PICO}
20.endif
21OBJ_SUFFIXES += ${PCM}
22
23# explicit dependencies help short-circuit .SUFFIX searches
24SRCS_DEP_FILTER+= N*.[hly]
25.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}}
26.for e in ${OBJ_SUFFIXES:O:u}
27.if !target(${s:T:R}$e)
28${s:T:R}$e: $s
29.endif
30.endfor
31.endfor
32.endif
33
34.if exists(/usr/bin/mkdep)
35MKDEP_CMD?=	mkdep
36.elif exists(/usr/local/share/bin/mkdeps.sh)
37MKDEP_CMD?=	/usr/local/share/bin/mkdeps.sh -N
38.endif
39MKDEP_CMD?=	mkdep
40
41MKDEP ?= ${MKDEP_CMD}
42
43.NOPATH:	.depend
44
45.if ${MKDEP_MK:Uno} == "auto.dep.mk" && make(depend)
46# auto.dep.mk does not "do" depend
47MK_AUTODEP= no
48.endif
49
50.if ${MK_AUTODEP} == yes
51MKDEP_MK ?= autodep.mk
52.include <${MKDEP_MK}>
53.else
54MKDEP_ENV_VARS += CC CXX
55.for v in ${MKDEP_ENV_VARS:O:u}
56.if !empty($v)
57MKDEP_ENV += $v='${$v}'
58.endif
59.endfor
60
61_MKDEP = ${MKDEP_ENV} ${MKDEP}
62
63# some of the rules involve .h sources, so remove them from mkdep line
64.if !target(depend)
65depend: beforedepend .depend _SUBDIRUSE afterdepend
66
67.if defined(SRCS)
68# libs can have too many SRCS for a single command line
69# so do them one at a time.
70.depend: ${SRCS} ${.PARSEDIR}/${.PASEFILE}
71	@rm -f .depend
72.ifdef LIB
73	@files="${.ALLSRC:M*.[sS]}"; \
74	set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
75	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$f; done
76	@files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \
77	set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
78	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done
79	@files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
80	set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \
81	    ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done
82.else
83	@files="${.ALLSRC:M*.[Ss]}"; \
84	case "$$files" in *.[Ss]*) \
85	  echo ${_MKDEP} -a ${MKDEPFLAGS} \
86	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files; \
87	  ${_MKDEP} -a ${MKDEPFLAGS} \
88	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files;; \
89	esac
90	@files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \
91	case "$$files" in *.c*) \
92	  echo ${_MKDEP} -a ${MKDEPFLAGS} \
93	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
94	  ${_MKDEP} -a ${MKDEPFLAGS} \
95	    ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \
96	esac
97	@files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \
98	case "$$files" in *.[Cc]*) \
99	  echo ${_MKDEP} -a ${MKDEPFLAGS} \
100	    ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \
101	  ${_MKDEP} -a ${MKDEPFLAGS} \
102	    ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \
103	esac
104.endif
105.-include <ccm.dep.mk>
106.else
107.depend:
108.endif
109.if !target(beforedepend)
110beforedepend:
111.endif
112.if !target(afterdepend)
113afterdepend:
114.endif
115.endif
116.endif
117
118.if !target(tags)
119.if defined(SRCS)
120tags: ${SRCS} _SUBDIRUSE
121	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \
122	    sed "s;\${.CURDIR}/;;" > tags
123.else
124tags:
125.endif
126.endif
127
128.if defined(SRCS)
129cleandir: cleandepend
130.if !target(cleandepend)
131cleandepend:
132	rm -f .depend ${.CURDIR}/tags
133.endif
134.endif
135
136.endif
137