1# $FreeBSD$ 2# RCSid: 3# $Id: dirdeps-targets.mk,v 1.9 2019/10/06 20:07:50 sjg Exp $ 4# 5# @(#) Copyright (c) 2019 Simon J. Gerraty 6# 7# This file is provided in the hope that it will 8# be of use. There is absolutely NO WARRANTY. 9# Permission to copy, redistribute or otherwise 10# use this file is hereby granted provided that 11# the above copyright notice and this notice are 12# left intact. 13# 14# Please send copies of changes and bug-fixes to: 15# sjg@crufty.net 16# 17 18## 19# This makefile is used to set initial DIRDEPS for top-level build 20# targets. 21# 22# The basic idea is that we have a list of directories in 23# DIRDEPS_TARGETS_DIRS which are relative to SRCTOP. 24# When asked to make 'foo' we look for any directory named 'foo' 25# under DIRDEPS_TARGETS_DIRS. 26# We then search those dirs for any Makefile.depend* 27# Finally we select any that match conditions like REQUESTED_MACHINE 28# or TARGET_SPEC and initialize DIRDEPS accordingly. 29# 30 31.if ${.MAKE.LEVEL} == 0 32# pickup customizations 33.-include <local.dirdeps-targets.mk> 34 35# for DIRDEPS_BUILD this is how we prime the pump 36DIRDEPS_TARGETS_DIRS ?= targets targets/pseudo 37# these prefixes can modify how we behave 38# they need to be stripped when looking for target dirs 39DIRDEPS_TARGETS_PREFIX_LIST ?= pkg- build- 40 41# matching target dirs if any 42tdirs := ${.TARGETS:Nall:${DIRDEPS_TARGETS_PREFIX_LIST:@p@S,^$p,,@:ts:}:@t@${DIRDEPS_TARGETS_DIRS:@d@$d/$t@}@:@d@${exists(${SRCTOP}/$d):?$d:}@} 43 44.if !empty(DEBUG_DIRDEPS_TARGETS) 45.info tdirs=${tdirs} 46.endif 47 48.if !empty(tdirs) 49# some things we know we want to ignore 50DIRDEPS_TARGETS_SKIP_LIST += \ 51 *~ \ 52 *.bak \ 53 *.inc \ 54 *.old \ 55 *.options \ 56 *.orig \ 57 *.rej \ 58 59# the list of MACHINEs we consider 60DIRDEPS_TARGETS_MACHINE_LIST += \ 61 ${ALL_MACHINE_LIST:U} \ 62 ${PSEUDO_MACHINE_LIST:Ucommon host host32} \ 63 ${TARGET_MACHINE_LIST} 64 65DIRDEPS_TARGETS_MACHINE_LIST := ${DIRDEPS_TARGETS_MACHINE_LIST:O:u} 66 67# raw Makefile.depend* list 68tdeps != 'cd' ${SRCTOP} && 'ls' -1 ${tdirs:O:u:@d@$d/${.MAKE.DEPENDFILE_PREFIX}*@} 2> /dev/null; echo 69.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" 70.info tdeps=${tdeps} 71.endif 72# remove things we know we don't want 73tdeps := ${tdeps:${DIRDEPS_TARGETS_SKIP_LIST:${M_ListToSkip}}} 74.if ${DEBUG_DIRDEPS_TARGETS:U:Mdep*} != "" 75.info tdeps=${tdeps} 76.endif 77 78# plain entries (no qualifiers) these apply to any TARGET_SPEC 79ptdeps := ${tdeps:M*${.MAKE.DEPENDFILE_PREFIX}:S,/${.MAKE.DEPENDFILE_PREFIX},,} 80 81# MACHINE qualified entries 82mqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} 83 84tqtdeps = 85.if ${TARGET_SPEC_VARS:[#]} > 1 86# TARGET_SPEC qualified entries 87.if !empty(TARGET_SPEC_LIST) 88# we have a list of valid TARGET_SPECS; use it 89tqtdeps := ${TARGET_SPEC_LIST:U:O:u:@t@${tdeps:M*.$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} 90.else 91# do we have a list of valid tuple members for at least 92# the last tupple element? if so match on that 93TARGET_SPEC_LAST_LIST ?= ${${TARGET_SPEC_VARS:[-1]}_LIST} 94.if !empty(TARGET_SPEC_LAST_LIST) 95tqtdeps := ${TARGET_SPEC_LAST_LIST:U:O:u:@t@${tdeps:M*,$t}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} 96.else 97# this is sub-optimal match MACHINE, 98tqtdeps := ${DIRDEPS_TARGETS_MACHINE_LIST:@m@${tdeps:M*.$m,*}@:S,/${.MAKE.DEPENDFILE_PREFIX},,} 99.endif 100.endif 101.endif 102 103# now work out what we want in DIRDEPS 104.if empty(REQUESTED_MACHINE) 105# we want them all just as found 106DIRDEPS = ${ptdeps} ${mqtdeps} ${tqtdeps} 107.else 108# we only want those that match REQUESTED_MACHINE/REQUESTED_TARGET_SPEC 109# or REQUESTED_TARGET_SPEC (TARGET_SPEC) 110DIRDEPS = \ 111 ${ptdeps:@d@$d.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC:U${REQUESTED_MACHINE}}}@} \ 112 ${mqtdeps:M*.${REQUESTED_MACHINE}} \ 113 ${tqtdeps:M*.${REQUESTED_TARGET_SPEC:U${TARGET_SPEC}}} 114.endif 115# clean up 116DIRDEPS := ${DIRDEPS:O:u} 117 118.if !empty(DEBUG_DIRDEPS_TARGETS) 119.for x in tdeps ptdeps mqtdeps tqtdeps DIRDEPS 120.info $x=${$x} 121.endfor 122.endif 123.endif 124# if we got DIRDEPS get to work 125.if !empty(DIRDEPS) 126.include <dirdeps.mk> 127 128DIRDEPS_TARGETS_SKIP += all clean* destroy* 129 130.for t in ${.TARGETS:${DIRDEPS_TARGETS_SKIP:${M_ListToSkip}}} 131$t: dirdeps 132.endfor 133.endif 134.endif 135