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