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