1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 2c59c3bf3SSimon J. Gerraty# 3*548bfc56SSimon J. Gerraty# $Id: sys.dirdeps.mk,v 1.15 2024/04/18 17:18:31 sjg Exp $ 4c1d01b5fSSimon J. Gerraty# 5c1d01b5fSSimon J. Gerraty# @(#) Copyright (c) 2012-2023, Simon J. Gerraty 6c1d01b5fSSimon J. Gerraty# 7c1d01b5fSSimon J. Gerraty# This file is provided in the hope that it will 8c1d01b5fSSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 9c1d01b5fSSimon J. Gerraty# Permission to copy, redistribute or otherwise 10c1d01b5fSSimon J. Gerraty# use this file is hereby granted provided that 11c1d01b5fSSimon J. Gerraty# the above copyright notice and this notice are 12c1d01b5fSSimon J. Gerraty# left intact. 13c1d01b5fSSimon J. Gerraty# 14c1d01b5fSSimon J. Gerraty# Please send copies of changes and bug-fixes to: 15c1d01b5fSSimon J. Gerraty# sjg@crufty.net 16c1d01b5fSSimon J. Gerraty# 17c1d01b5fSSimon J. Gerraty 18c1d01b5fSSimon J. Gerraty# Originally DIRDEPS_BUILD and META_MODE were the same thing. 19c1d01b5fSSimon J. Gerraty# So, much of this was done in *meta.sys.mk and local*mk 20c1d01b5fSSimon J. Gerraty# but properly belongs here. 21c1d01b5fSSimon J. Gerraty 22c1d01b5fSSimon J. Gerraty# Include from [local.]sys.mk - if doing DIRDEPS_BUILD 23c1d01b5fSSimon J. Gerraty# we should not be here otherwise 24c1d01b5fSSimon J. GerratyMK_DIRDEPS_BUILD ?= yes 25c1d01b5fSSimon J. Gerraty# these are all implied 26c1d01b5fSSimon J. GerratyMK_AUTO_OBJ ?= yes 27c1d01b5fSSimon J. GerratyMK_META_MODE ?= yes 28c1d01b5fSSimon J. GerratyMK_STAGING ?= yes 29c1d01b5fSSimon J. Gerraty 30c1d01b5fSSimon J. Gerraty_PARSEDIR ?= ${.PARSEDIR:tA} 31c1d01b5fSSimon J. Gerraty 32c1d01b5fSSimon J. Gerraty.-include <local.sys.dirdeps.env.mk> 33c1d01b5fSSimon J. Gerraty 34c1d01b5fSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0 35c1d01b5fSSimon J. Gerraty# make sure dirdeps target exists and do it first 36c59c3bf3SSimon J. Gerraty# init.mk will set .MAIN to 'dirdeps' if appropriate 37c59c3bf3SSimon J. Gerraty# as will dirdeps-targets.mk for top-level builds. 38c59c3bf3SSimon J. Gerraty# This allows a Makefile to have more control. 39c1d01b5fSSimon J. Gerratydirdeps: 40c1d01b5fSSimon J. Gerraty.NOPATH: dirdeps 41c1d01b5fSSimon J. Gerratyall: dirdeps .WAIT 42c1d01b5fSSimon J. Gerraty.endif 43c1d01b5fSSimon J. Gerraty 44c1d01b5fSSimon J. Gerraty.if empty(SRCTOP) 45c1d01b5fSSimon J. Gerraty# fallback assumes share/mk! 46c1d01b5fSSimon J. GerratySRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}} 47c1d01b5fSSimon J. Gerraty.export SRCTOP 48c1d01b5fSSimon J. Gerraty.endif 49c1d01b5fSSimon J. Gerraty 50c1d01b5fSSimon J. Gerraty# fake SB if not using mk wrapper 51148ee845SSimon J. Gerraty# SB documented at http://www.crufty.net/sjg/docs/sb-tools.htm 52c1d01b5fSSimon J. Gerraty.if !defined(SB) 53c1d01b5fSSimon J. GerratySB := ${SRCTOP:H} 54c1d01b5fSSimon J. Gerraty.export SB 55c1d01b5fSSimon J. Gerraty.endif 56c1d01b5fSSimon J. Gerraty 57c1d01b5fSSimon J. Gerraty.if empty(OBJROOT) 58c1d01b5fSSimon J. GerratyOBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/} 59c1d01b5fSSimon J. Gerraty.export OBJROOT 60c1d01b5fSSimon J. Gerraty.endif 61148ee845SSimon J. Gerraty# we expect OBJROOT to end with / (- can work too) 62148ee845SSimon J. Gerraty.if ${OBJROOT:M*[/-]} == "" 63148ee845SSimon J. GerratyOBJROOT := ${OBJROOT}/ 64148ee845SSimon J. Gerraty.endif 65c1d01b5fSSimon J. Gerraty 66c1d01b5fSSimon J. Gerraty.if empty(STAGE_ROOT) 67c1d01b5fSSimon J. GerratySTAGE_ROOT ?= ${OBJROOT}stage 68c1d01b5fSSimon J. Gerraty.export STAGE_ROOT 69c1d01b5fSSimon J. Gerraty.endif 70c1d01b5fSSimon J. Gerraty 71c1d01b5fSSimon J. Gerraty# We should be included before meta.sys.mk 72c1d01b5fSSimon J. Gerraty# If TARGET_SPEC_VARS is other than just MACHINE 73c1d01b5fSSimon J. Gerraty# it should be set by now. 74c1d01b5fSSimon J. Gerraty# TARGET_SPEC must not contain any '.'s. 75c1d01b5fSSimon J. GerratyTARGET_SPEC_VARS ?= MACHINE 76c1d01b5fSSimon J. Gerraty 77c1d01b5fSSimon J. Gerraty.if ${TARGET_SPEC:Uno:M*,*} != "" 78c1d01b5fSSimon J. Gerraty# deal with TARGET_SPEC from env 79c1d01b5fSSimon J. Gerraty_tspec := ${TARGET_SPEC:S/,/ /g} 80c1d01b5fSSimon J. Gerraty.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} 81c1d01b5fSSimon J. Gerraty${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} 82c1d01b5fSSimon J. Gerraty.endfor 83c1d01b5fSSimon J. Gerraty# We need to stop that TARGET_SPEC affecting any submakes 84c1d01b5fSSimon J. GerratyTARGET_SPEC= 85c1d01b5fSSimon J. Gerraty# so export but do not track 86c1d01b5fSSimon J. Gerraty.export-env TARGET_SPEC 87c1d01b5fSSimon J. Gerraty.export ${TARGET_SPEC_VARS} 88c1d01b5fSSimon J. Gerraty.for v in ${TARGET_SPEC_VARS:O:u} 89c1d01b5fSSimon J. Gerraty.if empty($v) 90c1d01b5fSSimon J. Gerraty.undef $v 91c1d01b5fSSimon J. Gerraty.endif 92c1d01b5fSSimon J. Gerraty.endfor 93c1d01b5fSSimon J. Gerraty.endif 94c1d01b5fSSimon J. Gerraty 95c1d01b5fSSimon J. Gerraty# Now make sure we know what TARGET_SPEC is 96c1d01b5fSSimon J. Gerraty# as we may need it to find Makefile.depend* 97c1d01b5fSSimon J. Gerraty.if ${MACHINE:Mhost*} != "" 98c1d01b5fSSimon J. Gerraty# host is special 99c1d01b5fSSimon J. GerratyTARGET_SPEC = ${MACHINE} 100c1d01b5fSSimon J. Gerraty.else 101c1d01b5fSSimon J. GerratyTARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 102c1d01b5fSSimon J. Gerraty.endif 103c1d01b5fSSimon J. Gerraty 104c1d01b5fSSimon J. Gerraty.if ${TARGET_SPEC_VARS:[#]} > 1 105148ee845SSimon J. GerratyTARGET_SPEC_VARSr := ${TARGET_SPEC_VARS:[-1..1]} 106148ee845SSimon J. Gerraty# alternatives might be 107148ee845SSimon J. Gerraty# TARGET_OBJ_SPEC = ${TARGET_SPEC_VARSr:@v@${$v:U}@:ts/} 108148ee845SSimon J. Gerraty# TARGET_OBJ_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts/} 109c1d01b5fSSimon J. GerratyTARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.} 110c1d01b5fSSimon J. Gerraty.else 111c1d01b5fSSimon J. GerratyTARGET_OBJ_SPEC ?= ${MACHINE} 112c1d01b5fSSimon J. Gerraty.endif 113c1d01b5fSSimon J. Gerraty 114c1d01b5fSSimon J. GerratyMAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS} 115c1d01b5fSSimon J. Gerraty 116c1d01b5fSSimon J. Gerraty.if !defined(MACHINE0) 117c1d01b5fSSimon J. Gerraty# it can be handy to know which MACHINE kicked off the build 118c1d01b5fSSimon J. Gerraty# for example, if using Makefild.depend for multiple machines, 119c1d01b5fSSimon J. Gerraty# allowing only MACHINE0 to update can keep things simple. 120c1d01b5fSSimon J. GerratyMACHINE0 := ${MACHINE} 121c1d01b5fSSimon J. Gerraty.export MACHINE0 122c1d01b5fSSimon J. Gerraty.endif 123c1d01b5fSSimon J. Gerraty 124c1d01b5fSSimon J. GerratyMACHINE_OBJ.host = ${HOST_TARGET} 125c1d01b5fSSimon J. GerratyMACHINE_OBJ.host32 = ${HOST_TARGET32} 126c1d01b5fSSimon J. GerratyMACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC} 127c1d01b5fSSimon J. GerratyMACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}} 128c1d01b5fSSimon J. Gerraty 129148ee845SSimon J. Gerraty# we likely want to override env for OBJTOP 130148ee845SSimon J. Gerraty.if ${MACHINE} == "host" 131148ee845SSimon J. GerratyOBJTOP = ${HOST_OBJTOP} 132148ee845SSimon J. Gerraty.elif ${MACHINE} == "host32" 133148ee845SSimon J. GerratyOBJTOP = ${HOST_OBJTOP32} 134148ee845SSimon J. Gerraty.else 135148ee845SSimon J. GerratyOBJTOP = ${OBJROOT}${MACHINE_OBJDIR} 136148ee845SSimon J. Gerraty.endif 137148ee845SSimon J. Gerraty.if ${.MAKE.LEVEL} > 0 138148ee845SSimon J. Gerraty# should not change from level 1 onwards 139148ee845SSimon J. Gerraty# this only matters for cases like bmake/unit-tests 140148ee845SSimon J. Gerraty# where we do ${MAKE} -r 141148ee845SSimon J. Gerraty.export OBJTOP 142148ee845SSimon J. Gerraty.endif 143148ee845SSimon J. Gerraty 144148ee845SSimon J. Gerraty.if ${MAKEOBJDIR:U:M*/*} == "" 145c1d01b5fSSimon J. Gerraty# we do not use MAKEOBJDIRPREFIX 146148ee845SSimon J. Gerraty# though we may have used it above to initialize OBJROOT 147c1d01b5fSSimon J. Gerraty.undef MAKEOBJDIRPREFIX 148148ee845SSimon J. Gerraty# this is what we expected in env 149148ee845SSimon J. GerratyMAKEOBJDIR = $${.CURDIR:S,^$${SRCTOP},$${OBJTOP},} 150148ee845SSimon J. Gerraty# export that but do not track 151148ee845SSimon J. Gerraty.export-env MAKEOBJDIR 152148ee845SSimon J. Gerraty# this what we need here 153148ee845SSimon J. GerratyMAKEOBJDIR = ${.CURDIR:S,${SRCTOP},${OBJTOP},} 154148ee845SSimon J. Gerraty.endif 155c1d01b5fSSimon J. Gerraty 156c1d01b5fSSimon J. GerratySTAGE_MACHINE ?= ${MACHINE_OBJDIR} 157c1d01b5fSSimon J. GerratySTAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE} 158c1d01b5fSSimon J. GerratySTAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common 159c1d01b5fSSimon J. GerratySTAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET} 160c1d01b5fSSimon J. GerratySTAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32} 161c1d01b5fSSimon J. Gerraty 162c1d01b5fSSimon J. GerratySTAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include} 163c1d01b5fSSimon J. GerratySTAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib} 164c1d01b5fSSimon J. Gerraty 165c1d01b5fSSimon J. GerratyTIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U} 166c1d01b5fSSimon J. GerratyDATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'` 167c1d01b5fSSimon J. GerratyTIME_STAMP ?= ${TIME_STAMP_FMT:localtime} 168c1d01b5fSSimon J. Gerraty 169c1d01b5fSSimon J. Gerraty.if ${MK_TIME_STAMPS:Uyes} == "yes" 170c1d01b5fSSimon J. GerratyTRACER = ${TIME_STAMP} 171c1d01b5fSSimon J. GerratyECHO_DIR = echo ${TIME_STAMP} 172c1d01b5fSSimon J. GerratyECHO_TRACE = echo ${TIME_STAMP} 173c1d01b5fSSimon J. Gerraty.endif 174c1d01b5fSSimon J. Gerraty 175c1d01b5fSSimon J. Gerraty.if ${.CURDIR} == ${SRCTOP} 176c1d01b5fSSimon J. GerratyRELDIR= . 177c1d01b5fSSimon J. GerratyRELTOP= . 178c1d01b5fSSimon J. Gerraty.elif ${.CURDIR:M${SRCTOP}/*} 179c1d01b5fSSimon J. GerratyRELDIR:= ${.CURDIR:S,${SRCTOP}/,,} 180c1d01b5fSSimon J. Gerraty.else 181c1d01b5fSSimon J. GerratyRELDIR:= ${.OBJDIR:S,${OBJTOP}/,,} 182c1d01b5fSSimon J. Gerraty.endif 183c1d01b5fSSimon J. GerratyRELTOP?= ${RELDIR:C,[^/]+,..,g} 184c1d01b5fSSimon J. GerratyRELOBJTOP?= ${RELTOP} 185c1d01b5fSSimon J. GerratyRELSRCTOP?= ${RELTOP} 186c1d01b5fSSimon J. Gerraty 187c1d01b5fSSimon J. Gerraty# this does all the smarts of setting .MAKE.DEPENDFILE 188c1d01b5fSSimon J. Gerraty.-include <sys.dependfile.mk> 189c1d01b5fSSimon J. Gerraty 190c1d01b5fSSimon J. Gerraty.-include <local.sys.dirdeps.mk> 191c1d01b5fSSimon J. Gerraty 192c1d01b5fSSimon J. Gerraty# check if we got anything sane 193c1d01b5fSSimon J. Gerraty.if ${.MAKE.DEPENDFILE} == ".depend" 194c1d01b5fSSimon J. Gerraty.undef .MAKE.DEPENDFILE 195c1d01b5fSSimon J. Gerraty.endif 196c1d01b5fSSimon J. Gerraty# just in case 197c1d01b5fSSimon J. Gerraty.MAKE.DEPENDFILE ?= Makefile.depend 198c1d01b5fSSimon J. Gerraty 199*548bfc56SSimon J. Gerraty# Makefile.depend* often refer to DEP_MACHINE etc, 200*548bfc56SSimon J. Gerraty# we need defaults for both first include in a leaf dir 201*548bfc56SSimon J. Gerraty# and when level > 0 202*548bfc56SSimon J. Gerraty# so ensure DEP_* for TARGET_SPEC_VARS and RELDIR are set 203*548bfc56SSimon J. Gerraty.for V in ${TARGET_SPEC_VARS} RELDIR 204*548bfc56SSimon J. GerratyDEP_$V ?= ${$V} 205c1d01b5fSSimon J. Gerraty.endfor 206