]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/bsd.progs.mk
MFC r274077:
[FreeBSD/stable/10.git] / share / mk / bsd.progs.mk
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) || defined(PROGS_CXX)
20 # we really only use PROGS below...
21 PROGS += ${PROGS_CXX}
22
23 # In meta mode, we can capture dependenices for _one_ of the progs.
24 # if makefile doesn't nominate one, we use the first.
25 .if defined(.PARSEDIR)
26 .ifndef UPDATE_DEPENDFILE_PROG
27 UPDATE_DEPENDFILE_PROG = ${PROGS:[1]}
28 .export UPDATE_DEPENDFILE_PROG
29 .endif
30 .else
31 UPDATE_DEPENDFILE_PROG?= no
32 .endif
33
34 .ifndef PROG
35 # They may have asked us to build just one
36 .for t in ${PROGS}
37 .if make($t)
38 PROG ?= $t
39 .endif
40 .endfor
41 .endif
42
43 .if defined(PROG)
44 # just one of many
45 PROG_OVERRIDE_VARS += BINDIR MAN SRCS
46 PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LDFLAGS ${PROG_OVERRIDE_VARS}
47 .for v in ${PROG_VARS:O:u}
48 .if empty(${PROG_OVERRIDE_VARS:M$v})
49 .if defined(${v}.${PROG})
50 $v += ${${v}.${PROG}}
51 .elif defined(${v}_${PROG})
52 $v += ${${v}_${PROG}}
53 .endif
54 .else
55 $v ?=
56 .endif
57 .endfor
58
59 # for meta mode, there can be only one!
60 .if ${PROG} == ${UPDATE_DEPENDFILE_PROG}
61 UPDATE_DEPENDFILE ?= yes
62 .endif
63 UPDATE_DEPENDFILE ?= NO
64
65 # ensure that we don't clobber each other's dependencies
66 DEPENDFILE?= .depend.${PROG}
67 # prog.mk will do the rest
68 .else
69 all: ${FILES} ${PROGS} ${SCRIPTS}
70
71 # We cannot capture dependencies for meta mode here
72 UPDATE_DEPENDFILE = NO
73 # nor can we safely run in parallel.
74 .NOTPARALLEL:
75 .endif
76 .endif
77
78 # handle being called [bsd.]progs.mk
79 .include <bsd.prog.mk>
80
81 .ifndef _RECURSING_PROGS
82 # tell progs.mk we might want to install things
83 PROGS_TARGETS+= checkdpadd clean cleandepend cleandir cleanobj depend install
84
85 .for p in ${PROGS}
86 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
87 # bsd.prog.mk may need to know this
88 x.$p= PROG_CXX=$p
89 .endif
90
91 $p ${p}_p: .PHONY .MAKE
92         (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
93             SUBDIR= PROG=$p \
94             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
95             ${x.$p})
96
97 .for t in ${PROGS_TARGETS:O:u}
98 $p.$t: .PHONY .MAKE
99         (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
100             SUBDIR= PROG=$p \
101             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
102             ${x.$p} ${@:E})
103 .endfor
104 .endfor
105
106 .if !empty(PROGS)
107 .for t in ${PROGS_TARGETS:O:u}
108 $t: ${PROGS:%=%.$t}
109 .endfor
110 .endif
111
112 .if empty(PROGS) && !empty(SCRIPTS)
113
114 .for t in ${PROGS_TARGETS:O:u}
115 scripts.$t: .PHONY .MAKE
116         (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} SUBDIR= _RECURSING_PROGS= \
117             $t)
118 $t: scripts.$t
119 .endfor
120
121 .endif
122
123 .endif