xref: /freebsd/contrib/bmake/mk/progs.mk (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: progs.mk,v 1.18 2024/04/09 17:18:24 sjg Exp $
4#
5#	@(#) Copyright (c) 2006, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18.MAIN: all
19
20.if defined(PROGS)
21
22# In meta mode, we can capture dependenices for _one_ of the progs.
23# if makefile doesn't nominate one, we use the first.
24.ifndef UPDATE_DEPENDFILE_PROG
25UPDATE_DEPENDFILE_PROG = ${PROGS:[1]}
26.export UPDATE_DEPENDFILE_PROG
27.endif
28
29.ifndef PROG
30# They may have asked us to build just one
31.for t in ${PROGS}
32.if make($t)
33PROG ?= $t
34.endif
35.endfor
36.endif
37
38.if defined(PROG)
39# just one of many
40PROG_VARS += \
41	BINDIR \
42	CXXFLAGS \
43	DPADD \
44	DPLIBS \
45	LDADD \
46	MAN \
47
48.ifndef SYS_OS_MK
49# assume we are not using init.mk, otherwise
50# we need to avoid overlap with its
51# QUALIFIED_VAR_LIST which includes these and its
52# VAR_QUALIFIER_LIST includes .TARGET which
53# would match PROG
54PROG_VARS += \
55	CFLAGS \
56	COPTS \
57	CPPFLAGS \
58	LDFLAGS \
59	SRCS \
60
61.endif
62
63.for v in ${PROG_VARS:O:u}
64.if defined(${v}.${PROG}) || defined(${v}_${PROG})
65$v += ${${v}_${PROG}:U${${v}.${PROG}}}
66.endif
67.endfor
68
69# for meta mode, there can be only one!
70.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno}
71UPDATE_DEPENDFILE ?= yes
72.endif
73UPDATE_DEPENDFILE ?= NO
74
75# ensure that we don't clobber each other's dependencies
76DEPENDFILE?= .depend.${PROG}
77# prog.mk will do the rest
78.else
79all: ${PROGS}
80
81# We cannot capture dependencies for meta mode here
82UPDATE_DEPENDFILE = NO
83# nor can we safely run in parallel.
84.NOTPARALLEL:
85.endif
86.endif
87
88# handle being called [bsd.]progs.mk
89.include <${.PARSEFILE:S,progs,prog,}>
90
91.ifndef PROG
92# tell progs.mk we might want to install things
93PROGS_TARGETS+= cleandepend cleandir cleanobj depend install
94
95.for p in ${PROGS}
96.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
97# bsd.prog.mk may need to know this
98x.$p= PROG_CXX=$p
99.endif
100
101$p ${p}_p: .PHONY .MAKE
102	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} -DWITHOUT_META_STATS)
103
104.for t in ${PROGS_TARGETS:O:u}
105$p.$t: .PHONY .MAKE
106	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E} -DWITHOUT_META_STATS)
107.endfor
108.endfor
109
110.for t in ${PROGS_TARGETS:O:u}
111$t: ${PROGS:%=%.$t}
112.endfor
113
114.if !defined(WITHOUT_META_STATS) && ${.MAKE.LEVEL} > 0
115.END: _reldir_finish
116.ERROR: _reldir_failed
117.endif
118
119.endif
120