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 DIRS 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]:${OBJS_SRCS_FILTER:ts:}: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 depend install 120# Only handle removing depend files from the main process. 121_PROG_MK.cleandir= CLEANDEPENDFILES= CLEANDEPENDDIRS= 122_PROG_MK.cleanobj= CLEANDEPENDFILES= CLEANDEPENDDIRS= 123# Only recurse on these if there is no objdir, meaning a normal 124# 'clean' gets ran via the target defined in bsd.obj.mk. 125# Same check from cleanobj: in bsd.obj.mk 126.if ${CANONICALOBJDIR} == ${.CURDIR} || !exists(${CANONICALOBJDIR}/) 127PROGS_TARGETS+= cleandir cleanobj 128.endif 129 130# Ensure common objects are built before recursing. 131.if !empty(_PROGS_COMMON_OBJS) 132${PROGS}: ${_PROGS_COMMON_OBJS} 133.endif 134 135.for p in ${PROGS} 136.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p) 137# bsd.prog.mk may need to know this 138x.$p= PROG_CXX=$p 139.endif 140 141# Main PROG target 142$p ${p}_p: .PHONY .MAKE 143 (cd ${.CURDIR} && \ 144 DEPENDFILE=.depend.$p \ 145 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 146 PROG=$p ${x.$p}) 147 148# Pseudo targets for PROG, such as 'install'. 149.for t in ${PROGS_TARGETS:O:u} 150$p.$t: .PHONY .MAKE 151 (cd ${.CURDIR} && \ 152 DEPENDFILE=.depend.$p \ 153 NO_SUBDIR=1 ${MAKE} -f ${MAKEFILE} _RECURSING_PROGS=t \ 154 ${_PROG_MK.${t}} PROG=$p ${x.$p} ${@:E}) 155.endfor 156.endfor 157 158# Depend main pseudo targets on all PROG.pseudo targets too. 159.for t in ${PROGS_TARGETS:O:u} 160.if make(${t}) 161$t: ${PROGS:%=%.$t} 162.endif 163.endfor 164.endif # !empty(PROGS) && !defined(_RECURSING_PROGS) && !defined(PROG) 165