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 BINGRP BINOWN BINMODE DPSRCS MAN PROGNAME \ 42 SRCS 43PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LIBADD LINKS \ 44 LDFLAGS MLINKS ${PROG_OVERRIDE_VARS} 45.for v in ${PROG_VARS:O:u} 46.if empty(${PROG_OVERRIDE_VARS:M$v}) 47.if defined(${v}.${PROG}) 48$v += ${${v}.${PROG}} 49.elif defined(${v}_${PROG}) 50$v += ${${v}_${PROG}} 51.endif 52.else 53$v ?= 54.endif 55.endfor 56 57# for meta mode, there can be only one! 58.if ${PROG} == ${UPDATE_DEPENDFILE_PROG} 59UPDATE_DEPENDFILE ?= yes 60.endif 61UPDATE_DEPENDFILE ?= NO 62 63# prog.mk will do the rest 64.else 65all: ${PROGS} 66 67# We cannot capture dependencies for meta mode here 68UPDATE_DEPENDFILE = NO 69.endif 70.endif # PROGS || PROGS_CXX 71 72# These are handled by the main make process. 73.ifdef _RECURSING_PROGS 74_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS FILESGROUPS SCRIPTS CONFGROUPS 75.for v in ${_PROGS_GLOBAL_VARS} 76$v = 77.endfor 78.endif 79 80# handle being called [bsd.]progs.mk 81.include <bsd.prog.mk> 82 83.if !empty(PROGS) && !defined(_RECURSING_PROGS) 84# tell progs.mk we might want to install things 85PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install 86 87.for p in ${PROGS} 88.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 89# bsd.prog.mk may need to know this 90x.$p= PROG_CXX=$p 91.endif 92 93# Main PROG target 94$p ${p}_p: .PHONY .MAKE 95 (cd ${.CURDIR} && \ 96 DEPENDFILE=.depend.$p \ 97 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 98 SUBDIR= PROG=$p ${x.$p}) 99 100# Pseudo targets for PROG, such as 'install'. 101.for t in ${PROGS_TARGETS:O:u} 102$p.$t: .PHONY .MAKE 103 (cd ${.CURDIR} && \ 104 DEPENDFILE=.depend.$p \ 105 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 106 SUBDIR= PROG=$p ${x.$p} ${@:E}) 107.endfor 108.endfor 109 110# Depend main pseudo targets on all PROG.pseudo targets too. 111.for t in ${PROGS_TARGETS:O:u} 112$t: ${PROGS:%=%.$t} 113.endfor 114.endif 115