xref: /freebsd/contrib/bmake/mk/progs.mk (revision 730cecb05aaf016ac52ef7cfc691ccec3a0408cd)
1# $Id: progs.mk,v 1.11 2012/11/06 17:18:54 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 += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD MAN SRCS
39.for v in ${PROG_VARS:O:u}
40$v += ${${v}_${PROG}:U${${v}.${PROG}}}
41.endfor
42
43# for meta mode, there can be only one!
44.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno}
45UPDATE_DEPENDFILE ?= yes
46.endif
47UPDATE_DEPENDFILE ?= NO
48
49# ensure that we don't clobber each other's dependencies
50DEPENDFILE?= .depend.${PROG}
51# prog.mk will do the rest
52.else
53all: ${PROGS}
54
55# We cannot capture dependencies for meta mode here
56UPDATE_DEPENDFILE = NO
57# nor can we safely run in parallel.
58.NOTPARALLEL:
59.endif
60.endif
61
62# handle being called [bsd.]progs.mk
63.include <${.PARSEFILE:S,progs,prog,}>
64
65.ifndef PROG
66PROGS_TARGETS += clean
67
68.for p in ${PROGS}
69.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
70# bsd.prog.mk may need to know this
71x.$p= PROG_CXX=$p
72.endif
73
74$p ${p}_p: .PHONY .MAKE
75	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p})
76
77.for t in ${PROGS_TARGETS:O:u}
78$p.$t: .PHONY .MAKE
79	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E})
80.endfor
81.endfor
82
83.for t in ${PROGS_TARGETS:O:u}
84$t: ${PROGS:%=%.$t}
85.endfor
86
87.endif
88