1# SPDX-License-Identifier: BSD-2-Clause 2# 3# $Id: progs.mk,v 1.17 2024/02/17 17:26:57 sjg Exp $ 4# 5# @(#) Copyright (c) 2006, Simon J. Gerraty 6# 7# This file is provided in the hope that it will 8# be of use. There is absolutely NO WARRANTY. 9# Permission to copy, redistribute or otherwise 10# use this file is hereby granted provided that 11# the above copyright notice and this notice are 12# left intact. 13# 14# Please send copies of changes and bug-fixes to: 15# sjg@crufty.net 16# 17 18.MAIN: all 19 20.if defined(PROGS) 21 22# In meta mode, we can capture dependenices for _one_ of the progs. 23# if makefile doesn't nominate one, we use the first. 24.ifndef UPDATE_DEPENDFILE_PROG 25UPDATE_DEPENDFILE_PROG = ${PROGS:[1]} 26.export UPDATE_DEPENDFILE_PROG 27.endif 28 29.ifndef PROG 30# They may have asked us to build just one 31.for t in ${PROGS} 32.if make($t) 33PROG ?= $t 34.endif 35.endfor 36.endif 37 38.if defined(PROG) 39# just one of many 40PROG_VARS += \ 41 BINDIR \ 42 CFLAGS \ 43 COPTS \ 44 CPPFLAGS \ 45 CXXFLAGS \ 46 DPADD \ 47 DPLIBS \ 48 LDADD \ 49 LDFLAGS \ 50 MAN \ 51 SRCS 52 53.for v in ${PROG_VARS:O:u} 54.if defined(${v}.${PROG}) || defined(${v}_${PROG}) 55$v += ${${v}_${PROG}:U${${v}.${PROG}}} 56.endif 57.endfor 58 59# for meta mode, there can be only one! 60.if ${PROG} == ${UPDATE_DEPENDFILE_PROG:Uno} 61UPDATE_DEPENDFILE ?= yes 62.endif 63UPDATE_DEPENDFILE ?= NO 64 65# ensure that we don't clobber each other's dependencies 66DEPENDFILE?= .depend.${PROG} 67# prog.mk will do the rest 68.else 69all: ${PROGS} 70 71# We cannot capture dependencies for meta mode here 72UPDATE_DEPENDFILE = NO 73# nor can we safely run in parallel. 74.NOTPARALLEL: 75.endif 76.endif 77 78# handle being called [bsd.]progs.mk 79.include <${.PARSEFILE:S,progs,prog,}> 80 81.ifndef PROG 82# tell progs.mk we might want to install things 83PROGS_TARGETS+= cleandepend cleandir cleanobj depend install 84 85.for p in ${PROGS} 86.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 87# bsd.prog.mk may need to know this 88x.$p= PROG_CXX=$p 89.endif 90 91$p ${p}_p: .PHONY .MAKE 92 (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} -DWITHOUT_META_STATS) 93 94.for t in ${PROGS_TARGETS:O:u} 95$p.$t: .PHONY .MAKE 96 (cd ${.CURDIR} && ${.MAKE} -f ${MAKEFILE} PROG=$p ${x.$p} ${@:E} -DWITHOUT_META_STATS) 97.endfor 98.endfor 99 100.for t in ${PROGS_TARGETS:O:u} 101$t: ${PROGS:%=%.$t} 102.endfor 103 104.if !defined(WITHOUT_META_STATS) && ${.MAKE.LEVEL} > 0 105.END: _reldir_finish 106.ERROR: _reldir_failed 107.endif 108 109.endif 110