2 # $Id: progs.mk,v 1.11 2012/11/06 17:18:54 sjg Exp $
4 # @(#) Copyright (c) 2006, Simon J. Gerraty
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
13 # Please send copies of changes and bug-fixes to:
19 .if defined(PROGS) || defined(PROGS_CXX)
20 # we really only use PROGS below...
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
31 UPDATE_DEPENDFILE_PROG?= no
35 # They may have asked us to build just one
38 .if ${PROGS_CXX:U:M${t}}
48 PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \
50 PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LINKS \
51 LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
52 .for v in ${PROG_VARS:O:u}
53 .if empty(${PROG_OVERRIDE_VARS:M$v})
54 .if defined(${v}.${PROG})
56 .elif defined(${v}_${PROG})
64 # for meta mode, there can be only one!
65 .if ${PROG} == ${UPDATE_DEPENDFILE_PROG}
66 UPDATE_DEPENDFILE ?= yes
68 UPDATE_DEPENDFILE ?= NO
70 # ensure that we don't clobber each other's dependencies
71 DEPENDFILE?= .depend.${PROG}
72 # prog.mk will do the rest
73 .else # !defined(PROG)
76 # We cannot capture dependencies for meta mode here
77 UPDATE_DEPENDFILE = NO
78 # nor can we safely run in parallel.
81 .endif # PROGS || PROGS_CXX
83 # These are handled by the main make process.
84 .ifdef _RECURSING_PROGS
85 _PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS FILESGROUPS SCRIPTS
86 .for v in ${_PROGS_GLOBAL_VARS}
91 # handle being called [bsd.]progs.mk
92 .include <bsd.prog.mk>
94 .if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
95 # tell progs.mk we might want to install things
96 PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install
98 # Find common sources among the PROGS and depend on them before building
99 # anything. This allows parallelization without them each fighting over
104 .for s in ${SRCS.${p}}
105 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
106 _PROGS_COMMON_SRCS+= ${s}
108 _PROGS_ALL_SRCS+= ${s}
112 .if !empty(_PROGS_COMMON_SRCS)
113 _PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]}
114 .if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
115 _PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:R:S/$/.o/g}
117 ${PROGS}: ${_PROGS_COMMON_OBJS}
121 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
122 # bsd.prog.mk may need to know this
127 $p ${p}_p: .PHONY .MAKE
129 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
131 DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
134 # Pseudo targets for PROG, such as 'install'.
135 .for t in ${PROGS_TARGETS:O:u}
138 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \
140 DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
145 # Depend main pseudo targets on all PROG.pseudo targets too.
146 .for t in ${PROGS_TARGETS:O:u}
149 .endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)