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.ifndef PROG 31# They may have asked us to build just one 32.for t in ${PROGS} 33.if make($t) 34PROG ?= $t 35.endif 36.endfor 37.endif 38 39.if defined(PROG) 40# just one of many 41PROG_OVERRIDE_VARS += BINDIR DPSRCS MAN SRCS 42PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LIBADD LDFLAGS ${PROG_OVERRIDE_VARS} 43.for v in ${PROG_VARS:O:u} 44.if empty(${PROG_OVERRIDE_VARS:M$v}) 45.if defined(${v}.${PROG}) 46$v += ${${v}.${PROG}} 47.elif defined(${v}_${PROG}) 48$v += ${${v}_${PROG}} 49.endif 50.else 51$v ?= 52.endif 53.endfor 54 55# for meta mode, there can be only one! 56.if ${PROG} == ${UPDATE_DEPENDFILE_PROG} 57UPDATE_DEPENDFILE ?= yes 58.endif 59UPDATE_DEPENDFILE ?= NO 60 61# prog.mk will do the rest 62.else 63all: ${FILES} ${PROGS} ${SCRIPTS} 64 65# We cannot capture dependencies for meta mode here 66UPDATE_DEPENDFILE = NO 67# nor can we safely run in parallel. 68.NOTPARALLEL: 69.endif 70.endif 71 72# The non-recursive call to bsd.progs.mk will handle FILES; NUL out 73# FILESGROUPS so recursive calls don't duplicate the work 74.ifdef _RECURSING_PROGS 75FILESGROUPS= 76.endif 77 78# handle being called [bsd.]progs.mk 79.include <bsd.prog.mk> 80 81.ifndef _RECURSING_PROGS 82# tell progs.mk we might want to install things 83PROGS_TARGETS+= checkdpadd clean 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} && \ 93 DEPENDFILE=.depend.$p \ 94 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 95 SUBDIR= PROG=$p ${x.$p}) 96 97.for t in ${PROGS_TARGETS:O:u} 98$p.$t: .PHONY .MAKE 99 (cd ${.CURDIR} && \ 100 DEPENDFILE=.depend.$p \ 101 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 102 SUBDIR= PROG=$p ${x.$p} ${@:E}) 103.endfor 104.endfor 105 106.if !empty(PROGS) 107.for t in ${PROGS_TARGETS:O:u} 108$t: ${PROGS:%=%.$t} 109.endfor 110.endif 111 112.if empty(PROGS) && !empty(SCRIPTS) 113 114.for t in ${PROGS_TARGETS:O:u} 115scripts.$t: .PHONY .MAKE 116 (cd ${.CURDIR} && ${MAKE} -f ${MAKEFILE} SUBDIR= _RECURSING_PROGS= \ 117 $t) 118$t: scripts.$t 119.endfor 120 121.endif 122 123.endif 124