1*c59c3bf3SSimon J. Gerraty# $Id: dep.mk,v 1.22 2024/02/19 00:06:19 sjg Exp $ 23cbdda60SSimon J. Gerraty 3*c59c3bf3SSimon J. Gerraty# should be set properly in sys.mk 4*c59c3bf3SSimon J. Gerraty_this ?= ${.PARSEFILE:S,bsd.,,} 5*c59c3bf3SSimon J. Gerraty 6*c59c3bf3SSimon J. Gerraty.if !target(__${_this}__) 7*c59c3bf3SSimon J. Gerraty__${_this}__: .NOTMAIN 83cbdda60SSimon J. Gerraty 93cbdda60SSimon J. Gerraty# handle Proc*C as well... 103cbdda60SSimon J. Gerraty.if defined(SRCS) 113cbdda60SSimon J. Gerraty.if !empty(SRCS:M*.pc) 123cbdda60SSimon J. Gerraty.include <proc.mk> 133cbdda60SSimon J. Gerraty.endif 143cbdda60SSimon J. Gerraty 15*c59c3bf3SSimon J. Gerraty.if ${MAKE_VERSION:U0} >= 20211212 16*c59c3bf3SSimon J. GerratyOBJ_SUFFIXES += ${.SUFFIXES:M*o} 17*c59c3bf3SSimon J. Gerraty.else 183cbdda60SSimon J. Gerraty# it would be nice to be able to query .SUFFIXES 19*c59c3bf3SSimon J. GerratyOBJ_SUFFIXES += .o .po .lo ${PICO} 20*c59c3bf3SSimon J. Gerraty.endif 21*c59c3bf3SSimon J. GerratyOBJ_SUFFIXES += ${PCM} 223cbdda60SSimon J. Gerraty 233cbdda60SSimon J. Gerraty# explicit dependencies help short-circuit .SUFFIX searches 243cbdda60SSimon J. GerratySRCS_DEP_FILTER+= N*.[hly] 253cbdda60SSimon J. Gerraty.for s in ${SRCS:${SRCS_DEP_FILTER:O:u:ts:}} 26*c59c3bf3SSimon J. Gerraty.for e in ${OBJ_SUFFIXES:O:u} 273cbdda60SSimon J. Gerraty.if !target(${s:T:R}$e) 283cbdda60SSimon J. Gerraty${s:T:R}$e: $s 293cbdda60SSimon J. Gerraty.endif 303cbdda60SSimon J. Gerraty.endfor 313cbdda60SSimon J. Gerraty.endfor 323cbdda60SSimon J. Gerraty.endif 333cbdda60SSimon J. Gerraty 343cbdda60SSimon J. Gerraty.if exists(/usr/bin/mkdep) 353cbdda60SSimon J. GerratyMKDEP_CMD?= mkdep 363cbdda60SSimon J. Gerraty.elif exists(/usr/local/share/bin/mkdeps.sh) 373cbdda60SSimon J. GerratyMKDEP_CMD?= /usr/local/share/bin/mkdeps.sh -N 383cbdda60SSimon J. Gerraty.endif 393cbdda60SSimon J. GerratyMKDEP_CMD?= mkdep 403cbdda60SSimon J. Gerraty 413cbdda60SSimon J. GerratyMKDEP ?= ${MKDEP_CMD} 423cbdda60SSimon J. Gerraty 433cbdda60SSimon J. Gerraty.NOPATH: .depend 443cbdda60SSimon J. Gerraty 45db29cad8SSimon J. Gerraty.if ${MKDEP_MK:Uno} == "auto.dep.mk" && make(depend) 463cbdda60SSimon J. Gerraty# auto.dep.mk does not "do" depend 473cbdda60SSimon J. GerratyMK_AUTODEP= no 483cbdda60SSimon J. Gerraty.endif 493cbdda60SSimon J. Gerraty 503cbdda60SSimon J. Gerraty.if ${MK_AUTODEP} == yes 51db29cad8SSimon J. GerratyMKDEP_MK ?= autodep.mk 52db29cad8SSimon J. Gerraty.include <${MKDEP_MK}> 533cbdda60SSimon J. Gerraty.else 543cbdda60SSimon J. GerratyMKDEP_ENV_VARS += CC CXX 553cbdda60SSimon J. Gerraty.for v in ${MKDEP_ENV_VARS:O:u} 563cbdda60SSimon J. Gerraty.if !empty($v) 573cbdda60SSimon J. GerratyMKDEP_ENV += $v='${$v}' 583cbdda60SSimon J. Gerraty.endif 593cbdda60SSimon J. Gerraty.endfor 603cbdda60SSimon J. Gerraty 613cbdda60SSimon J. Gerraty_MKDEP = ${MKDEP_ENV} ${MKDEP} 623cbdda60SSimon J. Gerraty 633cbdda60SSimon J. Gerraty# some of the rules involve .h sources, so remove them from mkdep line 643cbdda60SSimon J. Gerraty.if !target(depend) 653cbdda60SSimon J. Gerratydepend: beforedepend .depend _SUBDIRUSE afterdepend 663cbdda60SSimon J. Gerraty 673cbdda60SSimon J. Gerraty.if defined(SRCS) 683cbdda60SSimon J. Gerraty# libs can have too many SRCS for a single command line 693cbdda60SSimon J. Gerraty# so do them one at a time. 703cbdda60SSimon J. Gerraty.depend: ${SRCS} ${.PARSEDIR}/${.PASEFILE} 713cbdda60SSimon J. Gerraty @rm -f .depend 723cbdda60SSimon J. Gerraty.ifdef LIB 733cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.[sS]}"; \ 743cbdda60SSimon J. Gerraty set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ 753cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$f; done 763cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \ 773cbdda60SSimon J. Gerraty set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ 783cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done 793cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \ 803cbdda60SSimon J. Gerraty set -x; for f in $$files; do ${_MKDEP} -a ${MKDEPFLAGS} \ 813cbdda60SSimon J. Gerraty ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$f; done 823cbdda60SSimon J. Gerraty.else 833cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.[Ss]}"; \ 843cbdda60SSimon J. Gerraty case "$$files" in *.[Ss]*) \ 853cbdda60SSimon J. Gerraty echo ${_MKDEP} -a ${MKDEPFLAGS} \ 863cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files; \ 873cbdda60SSimon J. Gerraty ${_MKDEP} -a ${MKDEPFLAGS} \ 883cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files;; \ 893cbdda60SSimon J. Gerraty esac 903cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.c} ${.ALLSRC:M*.pc:T:.pc=.c}"; \ 913cbdda60SSimon J. Gerraty case "$$files" in *.c*) \ 923cbdda60SSimon J. Gerraty echo ${_MKDEP} -a ${MKDEPFLAGS} \ 933cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ 943cbdda60SSimon J. Gerraty ${_MKDEP} -a ${MKDEPFLAGS} \ 953cbdda60SSimon J. Gerraty ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \ 963cbdda60SSimon J. Gerraty esac 973cbdda60SSimon J. Gerraty @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cxx}"; \ 983cbdda60SSimon J. Gerraty case "$$files" in *.[Cc]*) \ 993cbdda60SSimon J. Gerraty echo ${_MKDEP} -a ${MKDEPFLAGS} \ 1003cbdda60SSimon J. Gerraty ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ 1013cbdda60SSimon J. Gerraty ${_MKDEP} -a ${MKDEPFLAGS} \ 1023cbdda60SSimon J. Gerraty ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files;; \ 1033cbdda60SSimon J. Gerraty esac 1043cbdda60SSimon J. Gerraty.endif 105*c59c3bf3SSimon J. Gerraty.-include <ccm.dep.mk> 1063cbdda60SSimon J. Gerraty.else 1073cbdda60SSimon J. Gerraty.depend: 1083cbdda60SSimon J. Gerraty.endif 1093cbdda60SSimon J. Gerraty.if !target(beforedepend) 1103cbdda60SSimon J. Gerratybeforedepend: 1113cbdda60SSimon J. Gerraty.endif 1123cbdda60SSimon J. Gerraty.if !target(afterdepend) 1133cbdda60SSimon J. Gerratyafterdepend: 1143cbdda60SSimon J. Gerraty.endif 1153cbdda60SSimon J. Gerraty.endif 1163cbdda60SSimon J. Gerraty.endif 1173cbdda60SSimon J. Gerraty 1183cbdda60SSimon J. Gerraty.if !target(tags) 1193cbdda60SSimon J. Gerraty.if defined(SRCS) 1203cbdda60SSimon J. Gerratytags: ${SRCS} _SUBDIRUSE 1213cbdda60SSimon J. Gerraty -cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \ 1223cbdda60SSimon J. Gerraty sed "s;\${.CURDIR}/;;" > tags 1233cbdda60SSimon J. Gerraty.else 1243cbdda60SSimon J. Gerratytags: 1253cbdda60SSimon J. Gerraty.endif 1263cbdda60SSimon J. Gerraty.endif 1273cbdda60SSimon J. Gerraty 1283cbdda60SSimon J. Gerraty.if defined(SRCS) 1293cbdda60SSimon J. Gerratycleandir: cleandepend 1303cbdda60SSimon J. Gerraty.if !target(cleandepend) 1313cbdda60SSimon J. Gerratycleandepend: 1323cbdda60SSimon J. Gerraty rm -f .depend ${.CURDIR}/tags 1333cbdda60SSimon J. Gerraty.endif 1343cbdda60SSimon J. Gerraty.endif 1353cbdda60SSimon J. Gerraty 1363cbdda60SSimon J. Gerraty.endif 137