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