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
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})
44 .elif defined(${v}_${PROG})
52 # for meta mode, there can be only one!
53 .if ${PROG} == ${UPDATE_DEPENDFILE_PROG}
54 UPDATE_DEPENDFILE ?= yes
56 UPDATE_DEPENDFILE ?= NO
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)
64 # We cannot capture dependencies for meta mode here
65 UPDATE_DEPENDFILE = NO
66 # nor can we safely run in parallel.
69 .endif # PROGS || PROGS_CXX
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}
79 # handle being called [bsd.]progs.mk
80 .include <bsd.prog.mk>
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
86 # Find common sources among the PROGS and depend on them before building
87 # anything. This allows parallelization without them each fighting over
92 .for s in ${SRCS.${p}}
93 .if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
94 _PROGS_COMMON_SRCS+= ${s}
96 _PROGS_ALL_SRCS+= ${s}
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}
105 ${PROGS}: ${_PROGS_COMMON_OBJS}
109 .if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
110 # bsd.prog.mk may need to know this
115 $p ${p}_p: .PHONY .MAKE
117 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
119 DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
122 # Pseudo targets for PROG, such as 'install'.
123 .for t in ${PROGS_TARGETS:O:u}
126 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
128 DEPENDFILE=.depend.$p .MAKE.DEPENDFILE=.depend.$p \
133 # Depend main pseudo targets on all PROG.pseudo targets too.
134 .for t in ${PROGS_TARGETS:O:u}
139 .endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)