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