progs.mk revision 255253
1356843Sdim# $Id: progs.mk,v 1.13 2013/08/02 18:28:48 sjg Exp $
2356843Sdim#
3356843Sdim#	@(#) Copyright (c) 2006, Simon J. Gerraty
4356843Sdim#
5356843Sdim#	This file is provided in the hope that it will
6356843Sdim#	be of use.  There is absolutely NO WARRANTY.
7356843Sdim#	Permission to copy, redistribute or otherwise
8356843Sdim#	use this file is hereby granted provided that 
9356843Sdim#	the above copyright notice and this notice are
10356843Sdim#	left intact. 
11356843Sdim#      
12356843Sdim#	Please send copies of changes and bug-fixes to:
13356843Sdim#	sjg@crufty.net
14356843Sdim#
15356843Sdim
16356843Sdim.MAIN: all
17356843Sdim
18356843Sdim.if defined(PROGS)
19356843Sdim
20356843Sdim# In meta mode, we can capture dependenices for _one_ of the progs.
21356843Sdim# if makefile doesn't nominate one, we use the first.
22356843Sdim.ifndef UPDATE_DEPENDFILE_PROG
23356843SdimUPDATE_DEPENDFILE_PROG = ${PROGS:[1]}
24356843Sdim.export UPDATE_DEPENDFILE_PROG
25356843Sdim.endif
26356843Sdim
27356843Sdim.ifndef PROG
28356843Sdim# They may have asked us to build just one
29356843Sdim.for t in ${PROGS}
30356843Sdim.if make($t)
31356843SdimPROG ?= $t
32356843Sdim.endif
33356843Sdim.endfor
34356843Sdim.endif
35356843Sdim
36356843Sdim.if defined(PROG)
37356843Sdim# just one of many
38356843SdimPROG_VARS += \
39356843Sdim	BINDIR \
40356843Sdim	CFLAGS \
41356843Sdim	COPTS \
42356843Sdim	CPPFLAGS \
43356843Sdim	CXXFLAGS \
44356843Sdim	DPADD \
45356843Sdim	DPLIBS \
46356843Sdim	LDADD \
47356843Sdim	LDFLAGS \
48356843Sdim	MAN \
49356843Sdim	SRCS
50356843Sdim
51356843Sdim.for v in ${PROG_VARS:O:u}
52356843Sdim.if defined(${v}.${PROG}) || defined(${v}_${PROG})
53356843Sdim$v += ${${v}_${PROG}:U${${v}.${PROG}}}
54356843Sdim.endif
55356843Sdim.endfor
56356843Sdim
57356843Sdim# for meta mode, there can be only one!
58356843Sdim.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno}
59356843SdimUPDATE_DEPENDFILE ?= yes
60356843Sdim.endif
61356843SdimUPDATE_DEPENDFILE ?= NO
62356843Sdim
63356843Sdim# ensure that we don't clobber each other's dependencies
64356843SdimDEPENDFILE?= .depend.${PROG}
65356843Sdim# prog.mk will do the rest
66356843Sdim.else
67356843Sdimall: ${PROGS}
68356843Sdim
69356843Sdim# We cannot capture dependencies for meta mode here
70356843SdimUPDATE_DEPENDFILE = NO
71356843Sdim# nor can we safely run in parallel.
72356843Sdim.NOTPARALLEL:
73356843Sdim.endif
74356843Sdim.endif
75356843Sdim
76356843Sdim# handle being called [bsd.]progs.mk
77356843Sdim.include <${.PARSEFILE:S,progs,prog,}>
78356843Sdim
79356843Sdim.ifndef PROG
80356843Sdim# tell progs.mk we might want to install things
81356843SdimPROGS_TARGETS+= cleandepend cleandir cleanobj depend install
82356843Sdim
83356843Sdim.for p in ${PROGS}
84356843Sdim.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
85356843Sdim# bsd.prog.mk may need to know this
86356843Sdimx.$p= PROG_CXX=$p
87356843Sdim.endif
88356843Sdim
89356843Sdim$p ${p}_p: .PHONY .MAKE
90356843Sdim	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p})
91356843Sdim
92356843Sdim.for t in ${PROGS_TARGETS:O:u}
93356843Sdim$p.$t: .PHONY .MAKE
94356843Sdim	(cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E})
95356843Sdim.endfor
96356843Sdim.endfor
97356843Sdim
98356843Sdim.for t in ${PROGS_TARGETS:O:u}
99356843Sdim$t: ${PROGS:%=%.$t}
100356843Sdim.endfor
101356843Sdim
102356843Sdim.endif
103356843Sdim