xref: /freebsd/contrib/bmake/mk/ccm.dep.mk (revision 783d3ff6)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# RCSid:
4#	$Id: ccm.dep.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $
5#
6#	@(#) Copyright (c) 2024, Simon J. Gerraty
7#
8#	This file is provided in the hope that it will
9#	be of use.  There is absolutely NO WARRANTY.
10#	Permission to copy, redistribute or otherwise
11#	use this file is hereby granted provided that
12#	the above copyright notice and this notice are
13#	left intact.
14#
15#	Please send copies of changes and bug-fixes to:
16#	sjg@crufty.net
17#
18
19# C++ Modules need extra help - at least in a clean tree
20
21.if !target(__${_this}__)
22__${_this}__: .NOTMAIN
23
24# These should all be set by now
25CCM_SUFFIXES ?= ${.SUFFIXES:M*.c*m}
26PCM ?= .pcm
27OBJ_SUFFIXES ?= ${.SUFFIXES:M*o}
28
29.ccm_srcs := ${CCM_SUFFIXES:@s@${SRCS:M*$s}@}
30.if !empty(.ccm_srcs)
31.ccm_srcs += ${CXX_SUFFIXES:@s@${SRCS:M*$s}@}
32# this is likely overkill, but
33# with .dinclude it should not matter
34.ccm_depend: ${.ccm_srcs}
35	@rm -f ${.TARGET}
36.for s r e in ${.ccm_srcs:@x@$x ${x:T:R} ${x:E}@}
37	@mlist=`sed -n '/^import/s,.*[[:space:]]\([^[:space:];]*\);.*,\1,p' ${.ALLSRC:M*$s}`; \
38	for o in ${OBJ_SUFFIXES:O:u}; do \
39		for m in $$mlist; do \
40			echo $r$$o: $$m${PCM}; \
41		done; \
42	done >> ${.TARGET}
43.endfor
44
45.if make(depend)
46x != echo; rm -f .ccm_depend
47.endif
48
49.if !make(.ccm_depend)
50.if !exists(.ccm_depend)
51# ugly, but it does the trick
52x != echo; ${.MAKE} -B -C ${.CURDIR} -f ${MAKEFILE} .ccm_depend
53.endif
54
55CLEANFILES += .ccm_depend
56# the ${.OBJDIR}/ is necessary!
57.dinclude <${.OBJDIR}/.ccm_depend>
58.endif
59.endif
60.endif
61