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