xref: /freebsd/contrib/bmake/mk/sys.dirdeps.mk (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1# $Id: sys.dirdeps.mk,v 1.9 2023/05/11 20:05:42 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
22MK_DIRDEPS_BUILD ?= yes
23# these are all implied
24MK_AUTO_OBJ ?= yes
25MK_META_MODE ?= yes
26MK_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
34dirdeps:
35# first .MAIN is what counts
36.MAIN: dirdeps
37.NOPATH: dirdeps
38all: dirdeps .WAIT
39.endif
40
41.if empty(SRCTOP)
42# fallback assumes share/mk!
43SRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}}
44.export SRCTOP
45.endif
46
47# fake SB if not using mk wrapper
48.if !defined(SB)
49SB := ${SRCTOP:H}
50.export SB
51.endif
52
53.if empty(OBJROOT)
54OBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/}
55.export OBJROOT
56.endif
57
58.if empty(STAGE_ROOT)
59STAGE_ROOT ?= ${OBJROOT}stage
60.export STAGE_ROOT
61.endif
62
63# We should be included before meta.sys.mk
64# If TARGET_SPEC_VARS is other than just MACHINE
65# it should be set by now.
66# TARGET_SPEC must not contain any '.'s.
67TARGET_SPEC_VARS ?= MACHINE
68
69.if !target(_tspec_env_done_)
70_tspec_env_done_: .NOTMAIN
71
72.if ${TARGET_SPEC:Uno:M*,*} != ""
73# deal with TARGET_SPEC from env
74_tspec := ${TARGET_SPEC:S/,/ /g}
75.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}}
76${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]}
77.endfor
78# We need to stop that TARGET_SPEC affecting any submakes
79TARGET_SPEC=
80# so export but do not track
81.export-env TARGET_SPEC
82.export ${TARGET_SPEC_VARS}
83.for v in ${TARGET_SPEC_VARS:O:u}
84.if empty($v)
85.undef $v
86.endif
87.endfor
88.endif
89.endif
90
91# Now make sure we know what TARGET_SPEC is
92# as we may need it to find Makefile.depend*
93.if ${MACHINE:Mhost*} != ""
94# host is special
95TARGET_SPEC = ${MACHINE}
96.else
97TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,}
98.endif
99
100.if ${TARGET_SPEC_VARS:[#]} > 1
101TARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.}
102.else
103TARGET_OBJ_SPEC ?= ${MACHINE}
104.endif
105
106MAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS}
107
108.if !defined(MACHINE0)
109# it can be handy to know which MACHINE kicked off the build
110# for example, if using Makefild.depend for multiple machines,
111# allowing only MACHINE0 to update can keep things simple.
112MACHINE0 := ${MACHINE}
113.export MACHINE0
114.endif
115
116.if ${MACHINE} == "host"
117OBJTOP = ${HOST_OBJTOP}
118.elif ${MACHINE} == "host32"
119OBJTOP = ${HOST_OBJTOP32}
120.endif
121
122MACHINE_OBJ.host = ${HOST_TARGET}
123MACHINE_OBJ.host32 = ${HOST_TARGET32}
124MACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC}
125MACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}}
126OBJTOP ?= ${OBJROOT}/${MACHINE_OBJDIR}
127
128# we do not use MAKEOBJDIRPREFIX
129.undef MAKEOBJDIRPREFIX
130# we use this
131MAKEOBJDIR ?= ${.CURDIR:S,${SRCTOP},${OBJTOP},}
132
133STAGE_MACHINE ?= ${MACHINE_OBJDIR}
134STAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE}
135STAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common
136STAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET}
137STAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32}
138
139STAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include}
140STAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib}
141
142TIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U}
143DATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'`
144TIME_STAMP ?= ${TIME_STAMP_FMT:localtime}
145
146.if ${MK_TIME_STAMPS:Uyes} == "yes"
147TRACER = ${TIME_STAMP}
148ECHO_DIR = echo ${TIME_STAMP}
149ECHO_TRACE = echo ${TIME_STAMP}
150.endif
151
152.if ${.CURDIR} == ${SRCTOP}
153RELDIR= .
154RELTOP= .
155.elif ${.CURDIR:M${SRCTOP}/*}
156RELDIR:= ${.CURDIR:S,${SRCTOP}/,,}
157.else
158RELDIR:= ${.OBJDIR:S,${OBJTOP}/,,}
159.endif
160RELTOP?= ${RELDIR:C,[^/]+,..,g}
161RELOBJTOP?= ${RELTOP}
162RELSRCTOP?= ${RELTOP}
163
164# this does all the smarts of setting .MAKE.DEPENDFILE
165.-include <sys.dependfile.mk>
166
167.-include <local.sys.dirdeps.mk>
168
169# check if we got anything sane
170.if ${.MAKE.DEPENDFILE} == ".depend"
171.undef .MAKE.DEPENDFILE
172.endif
173# just in case
174.MAKE.DEPENDFILE ?= Makefile.depend
175
176.if ${.MAKE.LEVEL} > 0
177# Makefile.depend* also get read at level 1+
178# and often refer to DEP_MACHINE etc,
179# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set
180.for V in ${TARGET_SPEC_VARS}
181DEP_$V = ${$V}
182.endfor
183.endif
184