xref: /freebsd/share/mk/bsd.progs.mk (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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)
56all: ${PROGS}
57
58# We cannot capture dependencies for meta mode here
59UPDATE_DEPENDFILE = NO
60.endif
61.endif	# PROGS || PROGS_CXX
62
63# These are handled by the main make process.
64.ifdef _RECURSING_PROGS
65_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS FILESGROUPS INCSGROUPS \
66		    SCRIPTS
67.for v in ${_PROGS_GLOBAL_VARS}
68$v =
69.endfor
70.endif
71
72# handle being called [bsd.]progs.mk
73.include <bsd.prog.mk>
74
75.if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
76# tell progs.mk we might want to install things
77PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install
78
79# Find common sources among the PROGS and depend on them before building
80# anything.  This allows parallelization without them each fighting over
81# the same objects.
82_PROGS_COMMON_SRCS=
83_PROGS_ALL_SRCS=
84.for p in ${PROGS}
85.for s in ${SRCS.${p}}
86.if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
87_PROGS_COMMON_SRCS+=	${s}
88.else
89_PROGS_ALL_SRCS+=	${s}
90.endif
91.endfor
92.endfor
93.if !empty(_PROGS_COMMON_SRCS)
94_PROGS_COMMON_OBJS=	${_PROGS_COMMON_SRCS:M*.[dhly]}
95.if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
96_PROGS_COMMON_OBJS+=	${_PROGS_COMMON_SRCS:N*.[dhly]:R:S/$/.o/g}
97.endif
98${PROGS}: ${_PROGS_COMMON_OBJS}
99.endif
100
101.for p in ${PROGS}
102.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
103# bsd.prog.mk may need to know this
104x.$p= PROG_CXX=$p
105.endif
106
107# Main PROG target
108$p ${p}_p: .PHONY .MAKE
109	(cd ${.CURDIR} && \
110	    DEPENDFILE=.depend.$p \
111	    NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
112	    PROG=$p ${x.$p})
113
114# Pseudo targets for PROG, such as 'install'.
115.for t in ${PROGS_TARGETS:O:u}
116$p.$t: .PHONY .MAKE
117	(cd ${.CURDIR} && \
118	    DEPENDFILE=.depend.$p \
119	    NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
120	    PROG=$p ${x.$p} ${@:E})
121.endfor
122.endfor
123
124# Depend main pseudo targets on all PROG.pseudo targets too.
125.for t in ${PROGS_TARGETS:O:u}
126.if make(${t})
127$t: ${PROGS:%=%.$t}
128.endif
129.endfor
130.endif	# !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
131