1*bee3d4bfSSimon J. Gerraty# $Id: sys.dirdeps.mk,v 1.9 2023/05/11 20:05:42 sjg Exp $ 2*bee3d4bfSSimon J. Gerraty# 3*bee3d4bfSSimon J. Gerraty# @(#) Copyright (c) 2012-2023, Simon J. Gerraty 4*bee3d4bfSSimon J. Gerraty# 5*bee3d4bfSSimon J. Gerraty# This file is provided in the hope that it will 6*bee3d4bfSSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 7*bee3d4bfSSimon J. Gerraty# Permission to copy, redistribute or otherwise 8*bee3d4bfSSimon J. Gerraty# use this file is hereby granted provided that 9*bee3d4bfSSimon J. Gerraty# the above copyright notice and this notice are 10*bee3d4bfSSimon J. Gerraty# left intact. 11*bee3d4bfSSimon J. Gerraty# 12*bee3d4bfSSimon J. Gerraty# Please send copies of changes and bug-fixes to: 13*bee3d4bfSSimon J. Gerraty# sjg@crufty.net 14*bee3d4bfSSimon J. Gerraty# 15*bee3d4bfSSimon J. Gerraty 16*bee3d4bfSSimon J. Gerraty# Originally DIRDEPS_BUILD and META_MODE were the same thing. 17*bee3d4bfSSimon J. Gerraty# So, much of this was done in *meta.sys.mk and local*mk 18*bee3d4bfSSimon J. Gerraty# but properly belongs here. 19*bee3d4bfSSimon J. Gerraty 20*bee3d4bfSSimon J. Gerraty# Include from [local.]sys.mk - if doing DIRDEPS_BUILD 21*bee3d4bfSSimon J. Gerraty# we should not be here otherwise 22*bee3d4bfSSimon J. GerratyMK_DIRDEPS_BUILD ?= yes 23*bee3d4bfSSimon J. Gerraty# these are all implied 24*bee3d4bfSSimon J. GerratyMK_AUTO_OBJ ?= yes 25*bee3d4bfSSimon J. GerratyMK_META_MODE ?= yes 26*bee3d4bfSSimon J. GerratyMK_STAGING ?= yes 27*bee3d4bfSSimon J. Gerraty 28*bee3d4bfSSimon J. Gerraty_PARSEDIR ?= ${.PARSEDIR:tA} 29*bee3d4bfSSimon J. Gerraty 30*bee3d4bfSSimon J. Gerraty.-include <local.sys.dirdeps.env.mk> 31*bee3d4bfSSimon J. Gerraty 32*bee3d4bfSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0 33*bee3d4bfSSimon J. Gerraty# make sure dirdeps target exists and do it first 34*bee3d4bfSSimon J. Gerratydirdeps: 35*bee3d4bfSSimon J. Gerraty# first .MAIN is what counts 36*bee3d4bfSSimon J. Gerraty.MAIN: dirdeps 37*bee3d4bfSSimon J. Gerraty.NOPATH: dirdeps 38*bee3d4bfSSimon J. Gerratyall: dirdeps .WAIT 39*bee3d4bfSSimon J. Gerraty.endif 40*bee3d4bfSSimon J. Gerraty 41*bee3d4bfSSimon J. Gerraty.if empty(SRCTOP) 42*bee3d4bfSSimon J. Gerraty# fallback assumes share/mk! 43*bee3d4bfSSimon J. GerratySRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}} 44*bee3d4bfSSimon J. Gerraty.export SRCTOP 45*bee3d4bfSSimon J. Gerraty.endif 46*bee3d4bfSSimon J. Gerraty 47*bee3d4bfSSimon J. Gerraty# fake SB if not using mk wrapper 48*bee3d4bfSSimon J. Gerraty.if !defined(SB) 49*bee3d4bfSSimon J. GerratySB := ${SRCTOP:H} 50*bee3d4bfSSimon J. Gerraty.export SB 51*bee3d4bfSSimon J. Gerraty.endif 52*bee3d4bfSSimon J. Gerraty 53*bee3d4bfSSimon J. Gerraty.if empty(OBJROOT) 54*bee3d4bfSSimon J. GerratyOBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/} 55*bee3d4bfSSimon J. Gerraty.export OBJROOT 56*bee3d4bfSSimon J. Gerraty.endif 57*bee3d4bfSSimon J. Gerraty 58*bee3d4bfSSimon J. Gerraty.if empty(STAGE_ROOT) 59*bee3d4bfSSimon J. GerratySTAGE_ROOT ?= ${OBJROOT}stage 60*bee3d4bfSSimon J. Gerraty.export STAGE_ROOT 61*bee3d4bfSSimon J. Gerraty.endif 62*bee3d4bfSSimon J. Gerraty 63*bee3d4bfSSimon J. Gerraty# We should be included before meta.sys.mk 64*bee3d4bfSSimon J. Gerraty# If TARGET_SPEC_VARS is other than just MACHINE 65*bee3d4bfSSimon J. Gerraty# it should be set by now. 66*bee3d4bfSSimon J. Gerraty# TARGET_SPEC must not contain any '.'s. 67*bee3d4bfSSimon J. GerratyTARGET_SPEC_VARS ?= MACHINE 68*bee3d4bfSSimon J. Gerraty 69*bee3d4bfSSimon J. Gerraty.if !target(_tspec_env_done_) 70*bee3d4bfSSimon J. Gerraty_tspec_env_done_: .NOTMAIN 71*bee3d4bfSSimon J. Gerraty 72*bee3d4bfSSimon J. Gerraty.if ${TARGET_SPEC:Uno:M*,*} != "" 73*bee3d4bfSSimon J. Gerraty# deal with TARGET_SPEC from env 74*bee3d4bfSSimon J. Gerraty_tspec := ${TARGET_SPEC:S/,/ /g} 75*bee3d4bfSSimon J. Gerraty.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} 76*bee3d4bfSSimon J. Gerraty${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} 77*bee3d4bfSSimon J. Gerraty.endfor 78*bee3d4bfSSimon J. Gerraty# We need to stop that TARGET_SPEC affecting any submakes 79*bee3d4bfSSimon J. GerratyTARGET_SPEC= 80*bee3d4bfSSimon J. Gerraty# so export but do not track 81*bee3d4bfSSimon J. Gerraty.export-env TARGET_SPEC 82*bee3d4bfSSimon J. Gerraty.export ${TARGET_SPEC_VARS} 83*bee3d4bfSSimon J. Gerraty.for v in ${TARGET_SPEC_VARS:O:u} 84*bee3d4bfSSimon J. Gerraty.if empty($v) 85*bee3d4bfSSimon J. Gerraty.undef $v 86*bee3d4bfSSimon J. Gerraty.endif 87*bee3d4bfSSimon J. Gerraty.endfor 88*bee3d4bfSSimon J. Gerraty.endif 89*bee3d4bfSSimon J. Gerraty.endif 90*bee3d4bfSSimon J. Gerraty 91*bee3d4bfSSimon J. Gerraty# Now make sure we know what TARGET_SPEC is 92*bee3d4bfSSimon J. Gerraty# as we may need it to find Makefile.depend* 93*bee3d4bfSSimon J. Gerraty.if ${MACHINE:Mhost*} != "" 94*bee3d4bfSSimon J. Gerraty# host is special 95*bee3d4bfSSimon J. GerratyTARGET_SPEC = ${MACHINE} 96*bee3d4bfSSimon J. Gerraty.else 97*bee3d4bfSSimon J. GerratyTARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 98*bee3d4bfSSimon J. Gerraty.endif 99*bee3d4bfSSimon J. Gerraty 100*bee3d4bfSSimon J. Gerraty.if ${TARGET_SPEC_VARS:[#]} > 1 101*bee3d4bfSSimon J. GerratyTARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.} 102*bee3d4bfSSimon J. Gerraty.else 103*bee3d4bfSSimon J. GerratyTARGET_OBJ_SPEC ?= ${MACHINE} 104*bee3d4bfSSimon J. Gerraty.endif 105*bee3d4bfSSimon J. Gerraty 106*bee3d4bfSSimon J. GerratyMAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS} 107*bee3d4bfSSimon J. Gerraty 108*bee3d4bfSSimon J. Gerraty.if !defined(MACHINE0) 109*bee3d4bfSSimon J. Gerraty# it can be handy to know which MACHINE kicked off the build 110*bee3d4bfSSimon J. Gerraty# for example, if using Makefild.depend for multiple machines, 111*bee3d4bfSSimon J. Gerraty# allowing only MACHINE0 to update can keep things simple. 112*bee3d4bfSSimon J. GerratyMACHINE0 := ${MACHINE} 113*bee3d4bfSSimon J. Gerraty.export MACHINE0 114*bee3d4bfSSimon J. Gerraty.endif 115*bee3d4bfSSimon J. Gerraty 116*bee3d4bfSSimon J. Gerraty.if ${MACHINE} == "host" 117*bee3d4bfSSimon J. GerratyOBJTOP = ${HOST_OBJTOP} 118*bee3d4bfSSimon J. Gerraty.elif ${MACHINE} == "host32" 119*bee3d4bfSSimon J. GerratyOBJTOP = ${HOST_OBJTOP32} 120*bee3d4bfSSimon J. Gerraty.endif 121*bee3d4bfSSimon J. Gerraty 122*bee3d4bfSSimon J. GerratyMACHINE_OBJ.host = ${HOST_TARGET} 123*bee3d4bfSSimon J. GerratyMACHINE_OBJ.host32 = ${HOST_TARGET32} 124*bee3d4bfSSimon J. GerratyMACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC} 125*bee3d4bfSSimon J. GerratyMACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}} 126*bee3d4bfSSimon J. GerratyOBJTOP = ${OBJROOT}/${MACHINE_OBJDIR} 127*bee3d4bfSSimon J. Gerraty 128*bee3d4bfSSimon J. Gerraty# we do not use MAKEOBJDIRPREFIX 129*bee3d4bfSSimon J. Gerraty.undef MAKEOBJDIRPREFIX 130*bee3d4bfSSimon J. Gerraty# we use this 131*bee3d4bfSSimon J. GerratyMAKEOBJDIR ?= ${.CURDIR:S,${SRCTOP},${OBJTOP},} 132*bee3d4bfSSimon J. Gerraty 133*bee3d4bfSSimon J. GerratySTAGE_MACHINE ?= ${MACHINE_OBJDIR} 134*bee3d4bfSSimon J. GerratySTAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE} 135*bee3d4bfSSimon J. GerratySTAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common 136*bee3d4bfSSimon J. GerratySTAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET} 137*bee3d4bfSSimon J. GerratySTAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32} 138*bee3d4bfSSimon J. Gerraty 139*bee3d4bfSSimon J. GerratySTAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include} 140*bee3d4bfSSimon J. GerratySTAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib} 141*bee3d4bfSSimon J. Gerraty 142*bee3d4bfSSimon J. GerratyTIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U} 143*bee3d4bfSSimon J. GerratyDATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'` 144*bee3d4bfSSimon J. GerratyTIME_STAMP ?= ${TIME_STAMP_FMT:localtime} 145*bee3d4bfSSimon J. Gerraty 146*bee3d4bfSSimon J. Gerraty.if ${MK_TIME_STAMPS:Uyes} == "yes" 147*bee3d4bfSSimon J. GerratyTRACER = ${TIME_STAMP} 148*bee3d4bfSSimon J. GerratyECHO_DIR = echo ${TIME_STAMP} 149*bee3d4bfSSimon J. GerratyECHO_TRACE = echo ${TIME_STAMP} 150*bee3d4bfSSimon J. Gerraty.endif 151*bee3d4bfSSimon J. Gerraty 152*bee3d4bfSSimon J. Gerraty.if ${.CURDIR} == ${SRCTOP} 153*bee3d4bfSSimon J. GerratyRELDIR= . 154*bee3d4bfSSimon J. GerratyRELTOP= . 155*bee3d4bfSSimon J. Gerraty.elif ${.CURDIR:M${SRCTOP}/*} 156*bee3d4bfSSimon J. GerratyRELDIR:= ${.CURDIR:S,${SRCTOP}/,,} 157*bee3d4bfSSimon J. Gerraty.else 158*bee3d4bfSSimon J. GerratyRELDIR:= ${.OBJDIR:S,${OBJTOP}/,,} 159*bee3d4bfSSimon J. Gerraty.endif 160*bee3d4bfSSimon J. GerratyRELTOP?= ${RELDIR:C,[^/]+,..,g} 161*bee3d4bfSSimon J. GerratyRELOBJTOP?= ${RELTOP} 162*bee3d4bfSSimon J. GerratyRELSRCTOP?= ${RELTOP} 163*bee3d4bfSSimon J. Gerraty 164*bee3d4bfSSimon J. Gerraty# this does all the smarts of setting .MAKE.DEPENDFILE 165*bee3d4bfSSimon J. Gerraty.-include <sys.dependfile.mk> 166*bee3d4bfSSimon J. Gerraty 167*bee3d4bfSSimon J. Gerraty.-include <local.sys.dirdeps.mk> 168*bee3d4bfSSimon J. Gerraty 169*bee3d4bfSSimon J. Gerraty# check if we got anything sane 170*bee3d4bfSSimon J. Gerraty.if ${.MAKE.DEPENDFILE} == ".depend" 171*bee3d4bfSSimon J. Gerraty.undef .MAKE.DEPENDFILE 172*bee3d4bfSSimon J. Gerraty.endif 173*bee3d4bfSSimon J. Gerraty# just in case 174*bee3d4bfSSimon J. Gerraty.MAKE.DEPENDFILE ?= Makefile.depend 175*bee3d4bfSSimon J. Gerraty 176*bee3d4bfSSimon J. Gerraty.if ${.MAKE.LEVEL} > 0 177*bee3d4bfSSimon J. Gerraty# Makefile.depend* also get read at level 1+ 178*bee3d4bfSSimon J. Gerraty# and often refer to DEP_MACHINE etc, 179*bee3d4bfSSimon J. Gerraty# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set 180*bee3d4bfSSimon J. Gerraty.for V in ${TARGET_SPEC_VARS} 181*bee3d4bfSSimon J. GerratyDEP_$V = ${$V} 182*bee3d4bfSSimon J. Gerraty.endfor 183*bee3d4bfSSimon J. Gerraty.endif 184