2012-11-07 21:44:04 +00:00
|
|
|
# $Id: progs.mk,v 1.11 2012/11/06 17:18:54 sjg Exp $
|
|
|
|
#
|
|
|
|
# @(#) Copyright (c) 2006, Simon J. Gerraty
|
|
|
|
#
|
|
|
|
# This file is provided in the hope that it will
|
|
|
|
# be of use. There is absolutely NO WARRANTY.
|
|
|
|
# Permission to copy, redistribute or otherwise
|
|
|
|
# use this file is hereby granted provided that
|
|
|
|
# the above copyright notice and this notice are
|
|
|
|
# left intact.
|
|
|
|
#
|
|
|
|
# Please send copies of changes and bug-fixes to:
|
|
|
|
# sjg@crufty.net
|
|
|
|
#
|
|
|
|
|
|
|
|
.MAIN: all
|
|
|
|
|
2013-11-13 15:10:32 +00:00
|
|
|
.if defined(PROGS) || defined(PROGS_CXX)
|
|
|
|
# we really only use PROGS below...
|
|
|
|
PROGS += ${PROGS_CXX}
|
2012-11-07 21:44:04 +00:00
|
|
|
|
|
|
|
.if defined(PROG)
|
|
|
|
# just one of many
|
2019-03-29 18:49:08 +00:00
|
|
|
PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE CSTD CXXSTD DPSRCS MAN \
|
2021-08-02 08:48:21 +00:00
|
|
|
NO_SHARED MK_WERROR PROGNAME SRCS STRIP WARNS MK_ASAN MK_UBSAN
|
2016-08-11 17:06:48 +00:00
|
|
|
PROG_VARS += CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD LIBADD \
|
|
|
|
LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS}
|
2012-11-07 21:44:04 +00:00
|
|
|
.for v in ${PROG_VARS:O:u}
|
2014-09-24 04:45:35 +00:00
|
|
|
.if empty(${PROG_OVERRIDE_VARS:M$v})
|
|
|
|
.if defined(${v}.${PROG})
|
|
|
|
$v += ${${v}.${PROG}}
|
|
|
|
.elif defined(${v}_${PROG})
|
|
|
|
$v += ${${v}_${PROG}}
|
|
|
|
.endif
|
2013-11-13 15:10:32 +00:00
|
|
|
.else
|
PROG_OVERRIDE_VARS should override default values if specified
The behavior prior to this change would not override default values if set in
`bsd.own.mk`, or (in the more general case) globally before `bsd.progs.mk` was
included. This affected `bsd.test.mk` as well, since it consumes
`bsd.progs.mk`.
Some examples of this failing behavior are as follows:
* `BINMODE` defaults to 0555 per `bsd.own.mk`. If someone wanted to set the
`BINMODE` to `NOBINMODE` (0444) for `prog`, for example, like
`BINMODE.prog= ${NOBINMODE}`, `bsd.progs.mk` would not honor the per-PROG
setting.
* An application, `prog`, does not build at `WARNS?= 6`. Before this change,
setting to a lower `WARNS` value, e.g., `WARNS.prog= 3`, would have been
impossible, requiring that `prog` be built from another directory,
the global `WARNS` be lowered, or a per-PROG value needing to be set
across the board. None of the above workarounds is desirable.
This change unbreaks variables defined in `PROG_OVERRIDE_VARS` which have
defaults set before `bsd.progs.mk` is included, by setting them to their
defined values if set on a per-PROG basis.
Reviewed by: asomers
Approved by: emaste (mentor)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D19755
2019-03-30 00:57:33 +00:00
|
|
|
.if defined(${v}.${PROG})
|
|
|
|
$v = ${${v}.${PROG}}
|
|
|
|
.elif defined(${v}_${PROG})
|
|
|
|
$v = ${${v}_${PROG}}
|
|
|
|
.endif
|
2013-11-13 15:10:32 +00:00
|
|
|
$v ?=
|
2013-04-22 18:11:29 +00:00
|
|
|
.endif
|
2012-11-07 21:44:04 +00:00
|
|
|
.endfor
|
2012-10-22 01:18:41 +00:00
|
|
|
|
2016-03-09 03:22:08 +00:00
|
|
|
.if ${MK_DIRDEPS_BUILD} == "yes"
|
|
|
|
# Leave updating the Makefile.depend to the parent.
|
|
|
|
UPDATE_DEPENDFILE = NO
|
|
|
|
|
|
|
|
# Record our meta files for the parent to use.
|
|
|
|
CLEANFILES+= ${PROG}.meta_files
|
|
|
|
${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this}
|
|
|
|
@echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}"
|
|
|
|
@echo ${.MAKE.META.FILES} > ${.TARGET}
|
|
|
|
|
|
|
|
.if !defined(_SKIP_BUILD)
|
|
|
|
.END: ${PROG}.meta_files
|
2012-10-22 01:18:41 +00:00
|
|
|
.endif
|
2016-03-09 03:22:08 +00:00
|
|
|
.endif # ${MK_DIRDEPS_BUILD} == "yes"
|
2012-11-07 21:44:04 +00:00
|
|
|
|
|
|
|
# prog.mk will do the rest
|
2015-10-14 05:50:16 +00:00
|
|
|
.else # !defined(PROG)
|
2016-02-26 22:13:48 +00:00
|
|
|
.if !defined(_SKIP_BUILD)
|
2015-09-23 23:20:49 +00:00
|
|
|
all: ${PROGS}
|
2016-02-26 22:13:48 +00:00
|
|
|
.endif
|
2012-11-07 21:44:04 +00:00
|
|
|
|
2016-03-09 03:22:08 +00:00
|
|
|
META_XTRAS+= ${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh}
|
2016-02-26 22:13:52 +00:00
|
|
|
|
2016-03-09 03:22:20 +00:00
|
|
|
.if ${MK_STAGING} != "no" && !empty(PROGS)
|
|
|
|
# Stage from parent while respecting PROGNAME and BINDIR overrides.
|
|
|
|
.for _prog in ${PROGS}
|
|
|
|
STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}}
|
|
|
|
STAGE_AS_SETS+= prog.${_prog}
|
|
|
|
STAGE_AS_prog.${_prog}= ${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}}
|
|
|
|
stage_as.prog.${_prog}: ${_prog}
|
|
|
|
.endfor
|
|
|
|
.endif # ${MK_STAGING} != "no" && !empty(PROGS)
|
2012-10-22 01:18:41 +00:00
|
|
|
.endif
|
2015-09-23 23:20:49 +00:00
|
|
|
.endif # PROGS || PROGS_CXX
|
2012-10-22 01:18:41 +00:00
|
|
|
|
2015-09-23 23:20:49 +00:00
|
|
|
# These are handled by the main make process.
|
2014-11-04 05:02:22 +00:00
|
|
|
.ifdef _RECURSING_PROGS
|
2016-02-26 22:13:52 +00:00
|
|
|
MK_STAGING= no
|
|
|
|
|
2018-09-17 22:15:06 +00:00
|
|
|
_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS DIRS FILESGROUPS INCSGROUPS \
|
2016-02-24 20:28:48 +00:00
|
|
|
SCRIPTS
|
2015-09-23 23:20:49 +00:00
|
|
|
.for v in ${_PROGS_GLOBAL_VARS}
|
|
|
|
$v =
|
|
|
|
.endfor
|
2014-11-04 05:02:22 +00:00
|
|
|
.endif
|
|
|
|
|
2012-11-07 21:44:04 +00:00
|
|
|
# handle being called [bsd.]progs.mk
|
2013-11-13 15:10:32 +00:00
|
|
|
.include <bsd.prog.mk>
|
2012-10-22 01:18:41 +00:00
|
|
|
|
2019-09-04 18:32:11 +00:00
|
|
|
.if !defined(_SKIP_BUILD)
|
2017-05-09 18:45:34 +00:00
|
|
|
# Find common sources among the PROGS to depend on them before building
|
2015-10-14 04:42:05 +00:00
|
|
|
# anything. This allows parallelization without them each fighting over
|
|
|
|
# the same objects.
|
2019-06-10 19:38:35 +00:00
|
|
|
_PROGS_COMMON_SRCS= ${DPSRCS}
|
2015-10-14 04:42:05 +00:00
|
|
|
_PROGS_ALL_SRCS=
|
|
|
|
.for p in ${PROGS}
|
|
|
|
.for s in ${SRCS.${p}}
|
|
|
|
.if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}}
|
|
|
|
_PROGS_COMMON_SRCS+= ${s}
|
|
|
|
.else
|
|
|
|
_PROGS_ALL_SRCS+= ${s}
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
.if !empty(_PROGS_COMMON_SRCS)
|
2015-11-25 22:40:14 +00:00
|
|
|
_PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:M*.[dhly]}
|
|
|
|
.if !empty(_PROGS_COMMON_SRCS:N*.[dhly])
|
2017-11-10 08:00:09 +00:00
|
|
|
_PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g}
|
2015-11-25 22:32:16 +00:00
|
|
|
.endif
|
2017-05-09 18:45:34 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# When recursing, ensure common sources are not rebuilt in META_MODE.
|
|
|
|
.if defined(_RECURSING_PROGS) && !empty(_PROGS_COMMON_OBJS) && \
|
|
|
|
!empty(.MAKE.MODE:Mmeta)
|
|
|
|
${_PROGS_COMMON_OBJS}: .NOMETA
|
|
|
|
.endif
|
2019-09-04 18:32:11 +00:00
|
|
|
.endif
|
2017-05-09 18:45:34 +00:00
|
|
|
|
|
|
|
.if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
|
|
|
|
# tell progs.mk we might want to install things
|
2017-07-24 17:54:03 +00:00
|
|
|
PROGS_TARGETS+= checkdpadd clean depend install
|
|
|
|
# Only handle removing depend files from the main process.
|
|
|
|
_PROG_MK.cleandir= CLEANDEPENDFILES= CLEANDEPENDDIRS=
|
|
|
|
_PROG_MK.cleanobj= CLEANDEPENDFILES= CLEANDEPENDDIRS=
|
|
|
|
# Only recurse on these if there is no objdir, meaning a normal
|
|
|
|
# 'clean' gets ran via the target defined in bsd.obj.mk.
|
|
|
|
# Same check from cleanobj: in bsd.obj.mk
|
|
|
|
.if ${CANONICALOBJDIR} == ${.CURDIR} || !exists(${CANONICALOBJDIR}/)
|
|
|
|
PROGS_TARGETS+= cleandir cleanobj
|
|
|
|
.endif
|
2017-05-09 18:45:34 +00:00
|
|
|
|
2012-11-07 21:44:04 +00:00
|
|
|
.for p in ${PROGS}
|
|
|
|
.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
|
|
|
|
# bsd.prog.mk may need to know this
|
|
|
|
x.$p= PROG_CXX=$p
|
2012-10-22 01:18:41 +00:00
|
|
|
.endif
|
|
|
|
|
2015-09-23 23:20:49 +00:00
|
|
|
# Main PROG target
|
2019-09-04 18:32:11 +00:00
|
|
|
$p ${p}_p: .PHONY .MAKE ${_PROGS_COMMON_OBJS}
|
2015-06-11 21:11:33 +00:00
|
|
|
(cd ${.CURDIR} && \
|
|
|
|
DEPENDFILE=.depend.$p \
|
2016-01-27 01:24:08 +00:00
|
|
|
NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
|
2015-10-21 00:25:18 +00:00
|
|
|
PROG=$p ${x.$p})
|
2012-10-22 01:18:41 +00:00
|
|
|
|
2015-09-23 23:20:49 +00:00
|
|
|
# Pseudo targets for PROG, such as 'install'.
|
2012-11-07 21:44:04 +00:00
|
|
|
.for t in ${PROGS_TARGETS:O:u}
|
2019-09-04 18:32:11 +00:00
|
|
|
$p.$t: .PHONY .MAKE ${_PROGS_COMMON_OBJS}
|
2015-06-11 21:11:33 +00:00
|
|
|
(cd ${.CURDIR} && \
|
|
|
|
DEPENDFILE=.depend.$p \
|
2016-01-27 01:24:08 +00:00
|
|
|
NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \
|
2017-07-24 17:54:03 +00:00
|
|
|
${_PROG_MK.${t}} PROG=$p ${x.$p} ${@:E})
|
2012-10-22 01:18:41 +00:00
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
|
2015-09-23 23:20:49 +00:00
|
|
|
# Depend main pseudo targets on all PROG.pseudo targets too.
|
2012-11-07 21:44:04 +00:00
|
|
|
.for t in ${PROGS_TARGETS:O:u}
|
2016-02-24 17:18:28 +00:00
|
|
|
.if make(${t})
|
2012-11-07 21:44:04 +00:00
|
|
|
$t: ${PROGS:%=%.$t}
|
2016-02-24 17:18:28 +00:00
|
|
|
.endif
|
2012-10-22 01:18:41 +00:00
|
|
|
.endfor
|
2015-10-14 05:50:16 +00:00
|
|
|
.endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG)
|