Update to bmake-20131001 on the vendor branch
[dragonfly.git] / contrib / bmake / mk / progs.mk
1 # $Id: progs.mk,v 1.13 2013/08/02 18:28:48 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
23 UPDATE_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)
31 PROG ?= $t
32 .endif
33 .endfor
34 .endif
35
36 .if defined(PROG)
37 # just one of many
38 PROG_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}
59 UPDATE_DEPENDFILE ?= yes
60 .endif
61 UPDATE_DEPENDFILE ?= NO
62
63 # ensure that we don't clobber each other's dependencies
64 DEPENDFILE?= .depend.${PROG}
65 # prog.mk will do the rest
66 .else
67 all: ${PROGS}
68
69 # We cannot capture dependencies for meta mode here
70 UPDATE_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
81 PROGS_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
86 x.$p= PROG_CXX=$p
87 .endif
88
89 $p ${p}_p: .PHONY .MAKE
90         (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p})
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})
95 .endfor
96 .endfor
97
98 .for t in ${PROGS_TARGETS:O:u}
99 $t: ${PROGS:%=%.$t}
100 .endfor
101
102 .endif