bsd.progs.mk revision 304144
1# $FreeBSD: stable/11/share/mk/bsd.progs.mk 304144 2016-08-15 09:37:58Z bdrewery $
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...
21PROGS += ${PROGS_CXX}
22
23.if defined(PROG)
24# just one of many
25PROG_OVERRIDE_VARS +=	BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \
26			PROGNAME SRCS STRIP WARNS
27PROG_VARS +=	CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD LIBADD \
28		LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
29.for v in ${PROG_VARS:O:u}
30.if empty(${PROG_OVERRIDE_VARS:M$v})
31.if defined(${v}.${PROG})
32$v += ${${v}.${PROG}}
33.elif defined(${v}_${PROG})
34$v += ${${v}_${PROG}}
35.endif
36.else
37$v ?=
38.endif
39.endfor
40
41.if ${MK_DIRDEPS_BUILD} == "yes"
42# Leave updating the Makefile.depend to the parent.
43UPDATE_DEPENDFILE = NO
44
45# Record our meta files for the parent to use.
46CLEANFILES+= ${PROG}.meta_files
47${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this}
48	@echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}"
49	@echo ${.MAKE.META.FILES} > ${.TARGET}
50
51.if !defined(_SKIP_BUILD)
52.END: ${PROG}.meta_files
53.endif
54.endif	# ${MK_DIRDEPS_BUILD} == "yes"
55
56# prog.mk will do the rest
57.else # !defined(PROG)
58.if !defined(_SKIP_BUILD)
59all: ${PROGS}
60.endif
61
62META_XTRAS+=	${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh}
63
64.if ${MK_STAGING} != "no" && !empty(PROGS)
65# Stage from parent while respecting PROGNAME and BINDIR overrides.
66.for _prog in ${PROGS}
67STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}}
68STAGE_AS_SETS+=	prog.${_prog}
69STAGE_AS_prog.${_prog}=	${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}}
70stage_as.prog.${_prog}: ${_prog}
71.endfor
72.endif	# ${MK_STAGING} != "no" && !empty(PROGS)
73.endif
74.endif	# PROGS || PROGS_CXX
75
76# These are handled by the main make process.
77.ifdef _RECURSING_PROGS
78MK_STAGING= no
79
80_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS FILESGROUPS INCSGROUPS \
81		    SCRIPTS
82.for v in ${_PROGS_GLOBAL_VARS}
83$v =
84.endfor
85.endif
86
87# handle being called [bsd.]progs.mk
88.include <bsd.prog.mk>
89
90.if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
91# tell progs.mk we might want to install things
92PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install
93
94# Find common sources among the PROGS and depend on them before building
95# anything.  This allows parallelization without them each fighting over
96# the same objects.
97_PROGS_COMMON_SRCS=
98_PROGS_ALL_SRCS=
99.for p in ${PROGS}
100.for s in ${SRCS.${p}}
101.if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
102_PROGS_COMMON_SRCS+=	${s}
103.else
104_PROGS_ALL_SRCS+=	${s}
105.endif
106.endfor
107.endfor
108.if !empty(_PROGS_COMMON_SRCS)
109_PROGS_COMMON_OBJS=	${_PROGS_COMMON_SRCS:M*.[dhly]}
110.if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
111_PROGS_COMMON_OBJS+=	${_PROGS_COMMON_SRCS:N*.[dhly]:R:S/$/.o/g}
112.endif
113${PROGS}: ${_PROGS_COMMON_OBJS}
114.endif
115
116.for p in ${PROGS}
117.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
118# bsd.prog.mk may need to know this
119x.$p= PROG_CXX=$p
120.endif
121
122# Main PROG target
123$p ${p}_p: .PHONY .MAKE
124	(cd ${.CURDIR} && \
125	    DEPENDFILE=.depend.$p \
126	    NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
127	    PROG=$p ${x.$p})
128
129# Pseudo targets for PROG, such as 'install'.
130.for t in ${PROGS_TARGETS:O:u}
131$p.$t: .PHONY .MAKE
132	(cd ${.CURDIR} && \
133	    DEPENDFILE=.depend.$p \
134	    NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
135	    PROG=$p ${x.$p} ${@:E})
136.endfor
137.endfor
138
139# Depend main pseudo targets on all PROG.pseudo targets too.
140.for t in ${PROGS_TARGETS:O:u}
141.if make(${t})
142$t: ${PROGS:%=%.$t}
143.endif
144.endfor
145.endif	# !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
146