1# $Id: meta.sys.mk,v 1.48 2023/05/04 16:41:10 sjg Exp $ 2 3# 4# @(#) Copyright (c) 2010-2021, Simon J. Gerraty 5# 6# This file is provided in the hope that it will 7# be of use. There is absolutely NO WARRANTY. 8# Permission to copy, redistribute or otherwise 9# use this file is hereby granted provided that 10# the above copyright notice and this notice are 11# left intact. 12# 13# Please send copies of changes and bug-fixes to: 14# sjg@crufty.net 15# 16 17# include this if you want to enable meta mode 18# for maximum benefit, requires filemon(4) driver. 19 20.if ${MAKE_VERSION:U0} > 20100901 21.if !target(.ERROR) 22 23.-include <local.meta.sys.env.mk> 24 25# If TARGET_SPEC_VARS is other than just MACHINE 26# it should be set by now. 27# TARGET_SPEC must not contain any '.'s. 28TARGET_SPEC_VARS ?= MACHINE 29 30.if !target(_meta_tspec_env_done_) 31_meta_tspec_env_done_: .NOTMAIN 32# Allow for local.meta.sys.env.mk to have done this 33 34.if ${TARGET_SPEC:Uno:M*,*} != "" 35# deal with TARGET_SPEC from env 36_tspec := ${TARGET_SPEC:S/,/ /g} 37.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} 38${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} 39.endfor 40# We need to stop that TARGET_SPEC affecting any submakes 41TARGET_SPEC= 42# so export but do not track 43.export-env TARGET_SPEC 44.export ${TARGET_SPEC_VARS} 45.for v in ${TARGET_SPEC_VARS:O:u} 46.if empty($v) 47.undef $v 48.endif 49.endfor 50.endif 51.endif 52 53# Now make sure we know what TARGET_SPEC is 54# as we may need it to find Makefile.depend* 55.if ${MACHINE:Mhost*} != "" 56# host is special 57TARGET_SPEC = ${MACHINE} 58.else 59TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} 60.endif 61 62# absolute path to what we are reading. 63_PARSEDIR = ${.PARSEDIR:tA} 64 65.if !defined(SYS_MK_DIR) 66SYS_MK_DIR := ${_PARSEDIR} 67.endif 68 69META_MODE += meta verbose 70.if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON) 71# we do not support filemon 72META_MODE += nofilemon 73MKDEP_MK ?= auto.dep.mk 74.endif 75 76.MAKE.MODE ?= ${META_MODE} 77 78_filemon := ${.MAKE.PATH_FILEMON:U/dev/filemon} 79 80.if empty(UPDATE_DEPENDFILE) 81_make_mode := ${.MAKE.MODE} ${META_MODE} 82.if ${_make_mode:M*read*} != "" || ${_make_mode:M*nofilemon*} != "" 83# tell everyone we are not updating Makefile.depend* 84UPDATE_DEPENDFILE = NO 85.export UPDATE_DEPENDFILE 86.endif 87.if ${_filemon:T:Mfilemon} == "filemon" 88.if ${UPDATE_DEPENDFILE:Uyes:tl} == "no" && !exists(${_filemon}) 89# we should not get upset 90META_MODE += nofilemon 91.export META_MODE 92.endif 93.endif 94.endif 95 96.if !defined(NO_SILENT) 97.if ${MAKE_VERSION} > 20110818 98# only be silent when we have a .meta file 99META_MODE += silent=yes 100.else 101.SILENT: 102.endif 103.endif 104 105# we use the pseudo machine "host" for the build host. 106# this should be taken care of before we get here 107.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} 108MACHINE = host 109.endif 110 111.if !defined(MACHINE0) 112# it can be handy to know which MACHINE kicked off the build 113# for example, if using Makefild.depend for multiple machines, 114# allowing only MACHINE0 to update can keep things simple. 115MACHINE0 := ${MACHINE} 116.export MACHINE0 117.endif 118 119.if !defined(META2DEPS) 120.if defined(PYTHON) && exists(${PYTHON}) 121# we prefer the python version of this - it is much faster 122META2DEPS ?= ${.PARSEDIR}/meta2deps.py 123.else 124META2DEPS ?= ${.PARSEDIR}/meta2deps.sh 125.endif 126META2DEPS := ${META2DEPS} 127.export META2DEPS 128.endif 129 130MAKE_PRINT_VAR_ON_ERROR += \ 131 .ERROR_TARGET \ 132 .ERROR_META_FILE \ 133 .MAKE.LEVEL \ 134 MAKEFILE \ 135 .MAKE.MODE 136 137.if !defined(SB) && defined(SRCTOP) 138SB = ${SRCTOP:H} 139.endif 140ERROR_LOGDIR ?= ${SB}/error 141meta_error_log = ${ERROR_LOGDIR}/meta-${.MAKE.PID}.log 142 143# we are not interested in make telling us a failure happened elsewhere 144.ERROR: _metaError 145_metaError: .NOMETA .NOTMAIN 146 -@[ "${.ERROR_META_FILE}" ] && { \ 147 grep -q 'failure has been detected in another branch' ${.ERROR_META_FILE} && exit 0; \ 148 mkdir -p ${meta_error_log:H}; \ 149 cp ${.ERROR_META_FILE} ${meta_error_log}; \ 150 echo "ERROR: log ${meta_error_log}" >&2; }; : 151 152.endif 153 154# Are we, after all, in meta mode? 155.if ${.MAKE.MODE:Uno:Mmeta*} != "" 156MKDEP_MK ?= meta.autodep.mk 157 158.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == "" 159# this does all the smarts of setting .MAKE.DEPENDFILE 160.-include <sys.dependfile.mk> 161# check if we got anything sane 162.if ${.MAKE.DEPENDFILE} == ".depend" 163.undef .MAKE.DEPENDFILE 164.endif 165.MAKE.DEPENDFILE ?= Makefile.depend 166.endif 167 168# we can afford to use cookies to prevent some targets 169# re-running needlessly 170META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} 171META_NOPHONY= 172META_NOECHO= : 173 174# some targets involve old pre-built targets 175# ignore mtime of shell 176# and mtime of makefiles does not matter in meta mode 177.MAKE.META.IGNORE_PATHS += \ 178 ${MAKEFILE} \ 179 ${MAKE_SHELL} \ 180 ${SHELL} \ 181 ${SYS_MK_DIR} \ 182 183 184.if ${UPDATE_DEPENDFILE:Uyes:tl} != "no" 185.if ${.MAKEFLAGS:Uno:M-k} != "" 186# make this more obvious 187.warning Setting UPDATE_DEPENDFILE=NO due to -k 188UPDATE_DEPENDFILE= NO 189.export UPDATE_DEPENDFILE 190.elif ${_filemon:T} == "filemon" && !exists(${_filemon}) 191.error ${.newline}ERROR: The filemon module (${_filemon}) is not loaded. 192.endif 193.endif 194 195.if ${.MAKE.LEVEL} == 0 196.if ${MK_DIRDEPS_BUILD:Uyes} == "yes" 197# make sure dirdeps target exists and do it first 198all: dirdeps .WAIT 199dirdeps: 200.NOPATH: dirdeps 201 202.if defined(ALL_MACHINES) 203# the first .MAIN: is what counts 204# by default dirdeps is all we want at level0 205.MAIN: dirdeps 206.endif 207.endif 208 209.else # level > 0 210 211# Makefile.depend* get read at level 1+ 212# and often refer to DEP_MACHINE etc, 213# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set 214.for V in ${TARGET_SPEC_VARS} 215DEP_$V = ${$V} 216.endfor 217 218.endif 219.else 220META_COOKIE_TOUCH= 221# some targets need to be .PHONY in non-meta mode 222META_NOPHONY= .PHONY 223META_NOECHO= echo 224.endif 225.endif 226 227.-include <local.meta.sys.mk> 228