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