]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/bsd.progs.mk
MFC r284152:
[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 .if defined(PROG)
35 # just one of many
36 PROG_OVERRIDE_VARS +=   BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \
37                         PROGNAME SRCS STRIP WARNS
38 PROG_VARS +=    CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD LIBADD \
39                 LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
40 .for v in ${PROG_VARS:O:u}
41 .if empty(${PROG_OVERRIDE_VARS:M$v})
42 .if defined(${v}.${PROG})
43 $v += ${${v}.${PROG}}
44 .elif defined(${v}_${PROG})
45 $v += ${${v}_${PROG}}
46 .endif
47 .else
48 $v ?=
49 .endif
50 .endfor
51
52 # for meta mode, there can be only one!
53 .if ${PROG} == ${UPDATE_DEPENDFILE_PROG}
54 UPDATE_DEPENDFILE ?= yes
55 .endif
56 UPDATE_DEPENDFILE ?= NO
57
58 # ensure that we don't clobber each other's dependencies
59 DEPENDFILE?= .depend.${PROG}
60 # prog.mk will do the rest
61 .else # !defined(PROG)
62 all: ${PROGS}
63
64 # We cannot capture dependencies for meta mode here
65 UPDATE_DEPENDFILE = NO
66 # nor can we safely run in parallel.
67 .NOTPARALLEL:
68 .endif
69 .endif  # PROGS || PROGS_CXX
70
71 # These are handled by the main make process.
72 .ifdef _RECURSING_PROGS
73 _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS FILESGROUPS INCSGROUPS SCRIPTS
74 .for v in ${_PROGS_GLOBAL_VARS}
75 $v =
76 .endfor
77 .endif
78
79 # handle being called [bsd.]progs.mk
80 .include <bsd.prog.mk>
81
82 .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
83 # tell progs.mk we might want to install things
84 PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install
85
86 # Find common sources among the PROGS and depend on them before building
87 # anything.  This allows parallelization without them each fighting over
88 # the same objects.
89 _PROGS_COMMON_SRCS=
90 _PROGS_ALL_SRCS=
91 .for p in ${PROGS}
92 .for s in ${SRCS.${p}}
93 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
94 _PROGS_COMMON_SRCS+=    ${s}
95 .else
96 _PROGS_ALL_SRCS+=       ${s}
97 .endif
98 .endfor
99 .endfor
100 .if !empty(_PROGS_COMMON_SRCS)
101 _PROGS_COMMON_OBJS=     ${_PROGS_COMMON_SRCS:M*.[dhly]}
102 .if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
103 _PROGS_COMMON_OBJS+=    ${_PROGS_COMMON_SRCS:N*.[dhly]:R:S/$/.o/g}
104 .endif
105 ${PROGS}: ${_PROGS_COMMON_OBJS}
106 .endif
107
108 .for p in ${PROGS}
109 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
110 # bsd.prog.mk may need to know this
111 x.$p= PROG_CXX=$p
112 .endif
113
114 # Main PROG target
115 $p ${p}_p: .PHONY .MAKE
116         (cd ${.CURDIR} && \
117             NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
118             PROG=$p \
119             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
120             ${x.$p})
121
122 # Pseudo targets for PROG, such as 'install'.
123 .for t in ${PROGS_TARGETS:O:u}
124 $p.$t: .PHONY .MAKE
125         (cd ${.CURDIR} && \
126             NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
127             PROG=$p \
128             DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
129             ${x.$p} ${@:E})
130 .endfor
131 .endfor
132
133 # Depend main pseudo targets on all PROG.pseudo targets too.
134 .for t in ${PROGS_TARGETS:O:u}
135 .if make(${t})
136 $t: ${PROGS:%=%.$t}
137 .endif
138 .endfor
139 .endif  # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)