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.if defined(PROG) 24# just one of many 25PROG_OVERRIDE_VARS += BINDIR BINGRP BINOWN BINMODE DPSRCS MAN NO_WERROR \ 26 PROGNAME SRCS STRIP WARNS 27PROG_VARS += CFLAGS CXXFLAGS DEBUG_FLAGS DPADD INTERNALPROG LDADD LIBADD \ 28 LINKS LDFLAGS MLINKS ${PROG_OVERRIDE_VARS} 29.for v in ${PROG_VARS:O:u} 30.if empty(${PROG_OVERRIDE_VARS:M$v}) 31.if defined(${v}.${PROG}) 32$v += ${${v}.${PROG}} 33.elif defined(${v}_${PROG}) 34$v += ${${v}_${PROG}} 35.endif 36.else 37$v ?= 38.endif 39.endfor 40 41.if ${MK_DIRDEPS_BUILD} == "yes" 42# Leave updating the Makefile.depend to the parent. 43UPDATE_DEPENDFILE = NO 44 45# Record our meta files for the parent to use. 46CLEANFILES+= ${PROG}.meta_files 47${PROG}.meta_files: .NOMETA $${.MAKE.META.CREATED} ${_this} 48 @echo "Updating ${.TARGET}: ${.OODATE:T:[1..8]}" 49 @echo ${.MAKE.META.FILES} > ${.TARGET} 50 51.if !defined(_SKIP_BUILD) 52.END: ${PROG}.meta_files 53.endif 54.endif # ${MK_DIRDEPS_BUILD} == "yes" 55 56# prog.mk will do the rest 57.else # !defined(PROG) 58.if !defined(_SKIP_BUILD) 59all: ${PROGS} 60.endif 61 62META_XTRAS+= ${cat ${PROGS:S/$/*.meta_files/} 2>/dev/null || true:L:sh} 63 64.if ${MK_STAGING} != "no" && !empty(PROGS) 65# Stage from parent while respecting PROGNAME and BINDIR overrides. 66.for _prog in ${PROGS} 67STAGE_DIR.prog.${_prog}= ${STAGE_OBJTOP}${BINDIR.${_prog}:UBINDIR_${_prog}:U${BINDIR}} 68STAGE_AS_SETS+= prog.${_prog} 69STAGE_AS_prog.${_prog}= ${PROGNAME.${_prog}:UPROGNAME_${_prog}:U${_prog}} 70stage_as.prog.${_prog}: ${_prog} 71.endfor 72.endif # ${MK_STAGING} != "no" && !empty(PROGS) 73.endif 74.endif # PROGS || PROGS_CXX 75 76# These are handled by the main make process. 77.ifdef _RECURSING_PROGS 78MK_STAGING= no 79 80_PROGS_GLOBAL_VARS= CLEANFILES CLEANDIRS CONFGROUPS FILESGROUPS INCSGROUPS \ 81 SCRIPTS 82.for v in ${_PROGS_GLOBAL_VARS} 83$v = 84.endfor 85.endif 86 87# handle being called [bsd.]progs.mk 88.include <bsd.prog.mk> 89 90# Find common sources among the PROGS to 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.endif 110 111# When recursing, ensure common sources are not rebuilt in META_MODE. 112.if defined(_RECURSING_PROGS) && !empty(_PROGS_COMMON_OBJS) && \ 113 !empty(.MAKE.MODE:Mmeta) 114${_PROGS_COMMON_OBJS}: .NOMETA 115.endif 116 117.if !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 118# tell progs.mk we might want to install things 119PROGS_TARGETS+= checkdpadd clean cleandepend cleandir depend install 120 121# Ensure common objects are built before recursing. 122.if !empty(_PROGS_COMMON_OBJS) 123${PROGS}: ${_PROGS_COMMON_OBJS} 124.endif 125 126.for p in ${PROGS} 127.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 128# bsd.prog.mk may need to know this 129x.$p= PROG_CXX=$p 130.endif 131 132# Main PROG target 133$p ${p}_p: .PHONY .MAKE 134 (cd ${.CURDIR} && \ 135 DEPENDFILE=.depend.$p \ 136 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 137 PROG=$p ${x.$p}) 138 139# Pseudo targets for PROG, such as 'install'. 140.for t in ${PROGS_TARGETS:O:u} 141$p.$t: .PHONY .MAKE 142 (cd ${.CURDIR} && \ 143 DEPENDFILE=.depend.$p \ 144 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 145 PROG=$p ${x.$p} ${@:E}) 146.endfor 147.endfor 148 149# Depend main pseudo targets on all PROG.pseudo targets too. 150.for t in ${PROGS_TARGETS:O:u} 151.if make(${t}) 152$t: ${PROGS:%=%.$t} 153.endif 154.endfor 155.endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 156