]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/sys.dirdeps.mk
bsddialog: import version 1.0
[FreeBSD/FreeBSD.git] / share / mk / sys.dirdeps.mk
1 # $Id: sys.dirdeps.mk,v 1.12 2023/05/14 16:16:03 sjg Exp $
2 #
3 #       @(#) Copyright (c) 2012-2023, Simon J. Gerraty
4 #
5 #       This file is provided in the hope that it will
6 #       be of use.  There is absolutely NO WARRANTY.
7 #       Permission to copy, redistribute or otherwise
8 #       use this file is hereby granted provided that
9 #       the above copyright notice and this notice are
10 #       left intact.
11 #
12 #       Please send copies of changes and bug-fixes to:
13 #       sjg@crufty.net
14 #
15
16 # Originally DIRDEPS_BUILD and META_MODE were the same thing.
17 # So, much of this was done in *meta.sys.mk and local*mk
18 # but properly belongs here.
19
20 # Include from [local.]sys.mk - if doing DIRDEPS_BUILD
21 # we should not be here otherwise
22 MK_DIRDEPS_BUILD ?= yes
23 # these are all implied
24 MK_AUTO_OBJ ?= yes
25 MK_META_MODE ?= yes
26 MK_STAGING ?= yes
27
28 _PARSEDIR ?= ${.PARSEDIR:tA}
29
30 .-include <local.sys.dirdeps.env.mk>
31
32 .if ${.MAKE.LEVEL} == 0
33 # make sure dirdeps target exists and do it first
34 dirdeps:
35 # first .MAIN is what counts
36 .MAIN: dirdeps
37 .NOPATH: dirdeps
38 all: dirdeps .WAIT
39 .endif
40
41 .if empty(SRCTOP)
42 # fallback assumes share/mk!
43 SRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}}
44 .export SRCTOP
45 .endif
46
47 # fake SB if not using mk wrapper
48 # SB documented at http://www.crufty.net/sjg/docs/sb-tools.htm
49 .if !defined(SB)
50 SB := ${SRCTOP:H}
51 .export SB
52 .endif
53
54 .if empty(OBJROOT)
55 OBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/}
56 .export OBJROOT
57 .endif
58 # we expect OBJROOT to end with / (- can work too)
59 .if ${OBJROOT:M*[/-]} == ""
60 OBJROOT := ${OBJROOT}/
61 .endif
62
63 .if empty(STAGE_ROOT)
64 STAGE_ROOT ?= ${OBJROOT}stage
65 .export STAGE_ROOT
66 .endif
67
68 # We should be included before meta.sys.mk
69 # If TARGET_SPEC_VARS is other than just MACHINE
70 # it should be set by now.
71 # TARGET_SPEC must not contain any '.'s.
72 TARGET_SPEC_VARS ?= MACHINE
73
74 .if ${TARGET_SPEC:Uno:M*,*} != ""
75 # deal with TARGET_SPEC from env
76 _tspec := ${TARGET_SPEC:S/,/ /g}
77 .for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}}
78 ${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]}
79 .endfor
80 # We need to stop that TARGET_SPEC affecting any submakes
81 TARGET_SPEC=
82 # so export but do not track
83 .export-env TARGET_SPEC
84 .export ${TARGET_SPEC_VARS}
85 .for v in ${TARGET_SPEC_VARS:O:u}
86 .if empty($v)
87 .undef $v
88 .endif
89 .endfor
90 .endif
91
92 # Now make sure we know what TARGET_SPEC is
93 # as we may need it to find Makefile.depend*
94 .if ${MACHINE:Mhost*} != ""
95 # host is special
96 TARGET_SPEC = ${MACHINE}
97 .else
98 TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
99 .endif
100
101 .if ${TARGET_SPEC_VARS:[#]} > 1
102 TARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]}
103 # alternatives might be
104 # TARGET_OBJ_SPEC = ${TARGET_SPEC_VARSr:@v@${$v:U}@:ts/}
105 # TARGET_OBJ_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts/}
106 TARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.}
107 .else
108 TARGET_OBJ_SPEC ?= ${MACHINE}
109 .endif
110
111 MAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS}
112
113 .if !defined(MACHINE0)
114 # it can be handy to know which MACHINE kicked off the build
115 # for example, if using Makefild.depend for multiple machines,
116 # allowing only MACHINE0 to update can keep things simple.
117 MACHINE0 := ${MACHINE}
118 .export MACHINE0
119 .endif
120
121 MACHINE_OBJ.host = ${HOST_TARGET}
122 MACHINE_OBJ.host32 = ${HOST_TARGET32}
123 MACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC}
124 MACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}}
125
126 # we likely want to override env for OBJTOP
127 .if ${MACHINE} == "host"
128 OBJTOP = ${HOST_OBJTOP}
129 .elif ${MACHINE} == "host32"
130 OBJTOP = ${HOST_OBJTOP32}
131 .else
132 OBJTOP = ${OBJROOT}${MACHINE_OBJDIR}
133 .endif
134 .if ${.MAKE.LEVEL} > 0
135 # should not change from level 1 onwards
136 # this only matters for cases like bmake/unit-tests
137 # where we do ${MAKE} -r
138 .export OBJTOP
139 .endif
140
141 .if ${MAKEOBJDIR:U:M*/*} == ""
142 # we do not use MAKEOBJDIRPREFIX
143 # though we may have used it above to initialize OBJROOT
144 .undef MAKEOBJDIRPREFIX
145 # this is what we expected in env
146 MAKEOBJDIR = $${.CURDIR:S,^$${SRCTOP},$${OBJTOP},}
147 # export that but do not track
148 .export-env MAKEOBJDIR
149 # this what we need here
150 MAKEOBJDIR = ${.CURDIR:S,${SRCTOP},${OBJTOP},}
151 .endif
152
153 STAGE_MACHINE ?= ${MACHINE_OBJDIR}
154 STAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE}
155 STAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common
156 STAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET}
157 STAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32}
158
159 STAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include}
160 STAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib}
161
162 TIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U}
163 DATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'`
164 TIME_STAMP ?= ${TIME_STAMP_FMT:localtime}
165
166 .if ${MK_TIME_STAMPS:Uyes} == "yes"
167 TRACER = ${TIME_STAMP}
168 ECHO_DIR = echo ${TIME_STAMP}
169 ECHO_TRACE = echo ${TIME_STAMP}
170 .endif
171
172 .if ${.CURDIR} == ${SRCTOP}
173 RELDIR= .
174 RELTOP= .
175 .elif ${.CURDIR:M${SRCTOP}/*}
176 RELDIR:= ${.CURDIR:S,${SRCTOP}/,,}
177 .else
178 RELDIR:= ${.OBJDIR:S,${OBJTOP}/,,}
179 .endif
180 RELTOP?= ${RELDIR:C,[^/]+,..,g}
181 RELOBJTOP?= ${RELTOP}
182 RELSRCTOP?= ${RELTOP}
183
184 # this does all the smarts of setting .MAKE.DEPENDFILE
185 .-include <sys.dependfile.mk>
186
187 .-include <local.sys.dirdeps.mk>
188
189 # check if we got anything sane
190 .if ${.MAKE.DEPENDFILE} == ".depend"
191 .undef .MAKE.DEPENDFILE
192 .endif
193 # just in case
194 .MAKE.DEPENDFILE ?= Makefile.depend
195
196 .if ${.MAKE.LEVEL} > 0
197 # Makefile.depend* also get read at level 1+
198 # and often refer to DEP_MACHINE etc,
199 # so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set
200 .for V in ${TARGET_SPEC_VARS}
201 DEP_$V = ${$V}
202 .endfor
203 .endif