]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/bsd.progs.mk
MFC r286822:
[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 BINGRP BINOWN BINMODE DPSRCS MAN PROGNAME \
46                         SRCS
47 PROG_VARS +=    CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LINKS \
48                 LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
49 .for v in ${PROG_VARS:O:u}
50 .if empty(${PROG_OVERRIDE_VARS:M$v})
51 .if defined(${v}.${PROG})
52 $v += ${${v}.${PROG}}
53 .elif defined(${v}_${PROG})
54 $v += ${${v}_${PROG}}
55 .endif
56 .else
57 $v ?=
58 .endif
59 .endfor
60
61 # for meta mode, there can be only one!
62 .if ${PROG} == ${UPDATE_DEPENDFILE_PROG}
63 UPDATE_DEPENDFILE ?= yes
64 .endif
65 UPDATE_DEPENDFILE ?= NO
66
67 # ensure that we don't clobber each other's dependencies
68 DEPENDFILE?= .depend.${PROG}
69 # prog.mk will do the rest
70 .else
71 all: ${PROGS}
72
73 # We cannot capture dependencies for meta mode here
74 UPDATE_DEPENDFILE = NO
75 # nor can we safely run in parallel.
76 .NOTPARALLEL:
77 .endif
78 .endif  # PROGS || PROGS_CXX
79
80 # These are handled by the main make process.
81 .ifdef _RECURSING_PROGS
82 _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS FILESGROUPS SCRIPTS
83 .for v in ${_PROGS_GLOBAL_VARS}
84 $v =
85 .endfor
86 .endif
87
88 # handle being called [bsd.]progs.mk
89 .include <bsd.prog.mk>
90
91 .if !empty(PROGS) && !defined(_RECURSING_PROGS)
92 # tell progs.mk we might want to install things
93 PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install
94
95 .for p in ${PROGS}
96 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
97 # bsd.prog.mk may need to know this
98 x.$p= PROG_CXX=$p
99 .endif
100
101 # Main PROG target
102 $p ${p}_p: .PHONY .MAKE
103         (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
104             SUBDIR= PROG=$p \
105             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
106             ${x.$p})
107
108 # Pseudo targets for PROG, such as 'install'.
109 .for t in ${PROGS_TARGETS:O:u}
110 $p.$t: .PHONY .MAKE
111         (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
112             SUBDIR= PROG=$p \
113             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
114             ${x.$p} ${@:E})
115 .endfor
116 .endfor
117
118 # Depend main pseudo targets on all PROG.pseudo targets too.
119 .for t in ${PROGS_TARGETS:O:u}
120 $t: ${PROGS:%=%.$t}
121 .endfor
122 .endif