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) 34.if ${PROGS_CXX:U:M${t}} 35PROG_CXX ?= $t 36.endif 37PROG ?= $t 38.endif 39.endfor 40.endif 41 42.if defined(PROG) 43# just one of many 44PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \ 45 PROGNAME SRCS WARNS 46PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD LIBADD LINKS \ 47 LDFLAGS MLINKS ${PROG_OVERRIDE_VARS} 48.for v in ${PROG_VARS:O:u} 49.if empty(${PROG_OVERRIDE_VARS:M$v}) 50.if defined(${v}.${PROG}) 51$v += ${${v}.${PROG}} 52.elif defined(${v}_${PROG}) 53$v += ${${v}_${PROG}} 54.endif 55.else 56$v ?= 57.endif 58.endfor 59 60# for meta mode, there can be only one! 61.if ${PROG} == ${UPDATE_DEPENDFILE_PROG} 62UPDATE_DEPENDFILE ?= yes 63.endif 64UPDATE_DEPENDFILE ?= NO 65 66# prog.mk will do the rest 67.else # !defined(PROG) 68all: ${PROGS} 69 70# We cannot capture dependencies for meta mode here 71UPDATE_DEPENDFILE = NO 72.endif 73.endif # PROGS || PROGS_CXX 74 75# These are handled by the main make process. 76.ifdef _RECURSING_PROGS 77_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS FILESGROUPS SCRIPTS CONFGROUPS 78.for v in ${_PROGS_GLOBAL_VARS} 79$v = 80.endfor 81.endif 82 83# handle being called [bsd.]progs.mk 84.include <bsd.prog.mk> 85 86.if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 87# tell progs.mk we might want to install things 88PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install 89 90# Find common sources among the PROGS and depend on them before building 91# anything. This allows parallelization without them each fighting over 92# the same objects. 93_PROGS_COMMON_SRCS= 94_PROGS_ALL_SRCS= 95.for p in ${PROGS} 96.for s in ${SRCS.${p}} 97.if ${_PROGS_ALL_SRCS:M${s}} && !${_PROGS_COMMON_SRCS:M${s}} 98_PROGS_COMMON_SRCS+= ${s} 99.else 100_PROGS_ALL_SRCS+= ${s} 101.endif 102.endfor 103.endfor 104.if !empty(_PROGS_COMMON_SRCS) 105_PROGS_COMMON_OBJS= ${_PROGS_COMMON_SRCS:N*.h:R:S/$/.o/g} 106${PROGS}: ${_PROGS_COMMON_OBJS} 107.endif 108 109.for p in ${PROGS} 110.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 111# bsd.prog.mk may need to know this 112x.$p= PROG_CXX=$p 113.endif 114 115# Main PROG target 116$p ${p}_p: .PHONY .MAKE 117 (cd ${.CURDIR} && \ 118 DEPENDFILE=.depend.$p \ 119 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 120 PROG=$p ${x.$p}) 121 122# Pseudo targets for PROG, such as 'install'. 123.for t in ${PROGS_TARGETS:O:u} 124$p.$t: .PHONY .MAKE 125 (cd ${.CURDIR} && \ 126 DEPENDFILE=.depend.$p \ 127 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS= \ 128 PROG=$p ${x.$p} ${@:E}) 129.endfor 130.endfor 131 132# Depend main pseudo targets on all PROG.pseudo targets too. 133.for t in ${PROGS_TARGETS:O:u} 134$t: ${PROGS:%=%.$t} 135.endfor 136.endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 137