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:M*.[dhly]} 106.if !empty(_PROGS_COMMON_SRCS:N*.[dhly]) 107_PROGS_COMMON_OBJS+= ${_PROGS_COMMON_SRCS:N*.[dhly]:R:S/$/.o/g} 108.endif 109${PROGS}: ${_PROGS_COMMON_OBJS} 110.endif 111 112.for p in ${PROGS} 113.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 114# bsd.prog.mk may need to know this 115x.$p= PROG_CXX=$p 116.endif 117 118# Main PROG target 119$p ${p}_p: .PHONY .MAKE 120 (cd ${.CURDIR} && \ 121 DEPENDFILE=.depend.$p \ 122 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 123 PROG=$p ${x.$p}) 124 125# Pseudo targets for PROG, such as 'install'. 126.for t in ${PROGS_TARGETS:O:u} 127$p.$t: .PHONY .MAKE 128 (cd ${.CURDIR} && \ 129 DEPENDFILE=.depend.$p \ 130 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 131 PROG=$p ${x.$p} ${@:E}) 132.endfor 133.endfor 134 135# Depend main pseudo targets on all PROG.pseudo targets too. 136.for t in ${PROGS_TARGETS:O:u} 137$t: ${PROGS:%=%.$t} 138.endfor 139.endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 140