diff --git a/share/mk/dirdeps.mk b/share/mk/dirdeps.mk --- a/share/mk/dirdeps.mk +++ b/share/mk/dirdeps.mk @@ -1,4 +1,4 @@ -# $Id: dirdeps.mk,v 1.158 2023/05/04 18:26:17 sjg Exp $ +# $Id: dirdeps.mk,v 1.160 2023/05/10 20:44:58 sjg Exp $ # SPDX-License-Identifier: BSD-2-Clause # @@ -273,6 +273,10 @@ .endif .endif +# turn a list into a set of :N modifiers +# NskipFoo = ${Foo:${M_ListToSkip}} +M_ListToSkip ?= O:u:S,^,N,:ts: + # this is how we identify non-machine specific dependfiles N_notmachine := ${.MAKE.DEPENDFILE_PREFERENCE:E:N*${MACHINE}*:${M_ListToSkip}} @@ -661,7 +665,7 @@ # reset each time through _build_dirs = -.if ${DEP_RELDIR} == ${_DEP_RELDIR} +.if ${DEP_RELDIR} == ${_DEP_RELDIR} && ${_CURDIR} != ${SRCTOP} # pickup other machines for this dir if necessary _build_dirs += ${_machines:@m@${_CURDIR}.$m@} .endif diff --git a/share/mk/local.meta.sys.env.mk b/share/mk/local.meta.sys.env.mk --- a/share/mk/local.meta.sys.env.mk +++ b/share/mk/local.meta.sys.env.mk @@ -4,12 +4,6 @@ # before we process TARGET_SPEC # we assume that MK_DIRDEPS_BUILD=yes -.if !defined(HOST_TARGET) || !defined(HOST_MACHINE) -# we need HOST_TARGET etc below. -.include -.export HOST_TARGET -.endif - # from src/Makefile (for universe) TARGET_ARCHES_arm?= arm armv6 armv7 TARGET_ARCHES_arm64?= aarch64 @@ -41,11 +35,6 @@ MACHINE_ARCH?= ${MACHINE_ARCH.${MACHINE}} MACHINE_ARCH:= ${MACHINE_ARCH} -# For universe we want to potentially -# build for multiple MACHINE_ARCH per MACHINE -# so we need more than MACHINE in TARGET_SPEC -TARGET_SPEC_VARS?= MACHINE MACHINE_ARCH - HOST_OBJTOP ?= ${OBJROOT}${HOST_TARGET} .if ${REQUESTED_MACHINE:U${MACHINE}} == "host" @@ -74,17 +63,13 @@ .endif .endif -# this is sufficient for most of the tree. -.MAKE.DEPENDFILE_DEFAULT = ${.MAKE.DEPENDFILE_PREFIX} - -# but if we have a machine qualified file it should be used in preference -.MAKE.DEPENDFILE_PREFERENCE = \ - ${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \ - ${.MAKE.DEPENDFILE_PREFIX} - -.undef .MAKE.DEPENDFILE - -META_MODE+= missing-meta=yes +.if !defined(NO_META_MISSING) +META_MODE+= missing-meta=yes +.endif +# silent will hide command output if a .meta file is created. +.if !defined(NO_SILENT) +META_MODE+= silent=yes +.endif .if empty(META_MODE:Mnofilemon) META_MODE+= missing-filemon=yes .endif diff --git a/share/mk/local.sys.dirdeps.env.mk b/share/mk/local.sys.dirdeps.env.mk new file mode 100644 --- /dev/null +++ b/share/mk/local.sys.dirdeps.env.mk @@ -0,0 +1,14 @@ + +# For universe we want to potentially +# build for multiple MACHINE_ARCH per MACHINE +# so we need more than MACHINE in TARGET_SPEC +TARGET_SPEC_VARS?= MACHINE MACHINE_ARCH + +# this is sufficient for most of the tree. +.MAKE.DEPENDFILE_DEFAULT = ${.MAKE.DEPENDFILE_PREFIX} + +# but if we have a machine qualified file it should be used in preference +.MAKE.DEPENDFILE_PREFERENCE = \ + ${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \ + ${.MAKE.DEPENDFILE_PREFIX} + diff --git a/share/mk/local.meta.sys.mk b/share/mk/local.sys.dirdeps.mk rename from share/mk/local.meta.sys.mk rename to share/mk/local.sys.dirdeps.mk --- a/share/mk/local.meta.sys.mk +++ b/share/mk/local.sys.dirdeps.mk @@ -6,39 +6,13 @@ # we need this until there is an alternative MK_INSTALL_AS_USER= yes +.-include +# previously only included for DIRDEPS_BUILD anyway .-include -# to be consistent with src/Makefile just concatenate with '.'s -TARGET_OBJ_SPEC:= ${TARGET_SPEC:S;,;.;g} -.if ${MACHINE} != "host" -OBJTOP:= ${OBJROOT}${TARGET_OBJ_SPEC} -.endif - -.if defined(MAKEOBJDIR) -.if ${MAKEOBJDIR:M/*} == "" -.error Cannot use MAKEOBJDIR=${MAKEOBJDIR}${.newline}Unset MAKEOBJDIR to get default: MAKEOBJDIR='${_default_makeobjdir}' -.endif -.endif - - -# we want to end up with a singe stage tree for all machines .if ${MK_STAGING} == "yes" -.if empty(STAGE_ROOT) -STAGE_ROOT?= ${OBJROOT}stage -.export STAGE_ROOT -.endif -.endif -.if ${MK_STAGING} == "yes" -.if ${MACHINE} == "host" -STAGE_MACHINE= ${HOST_TARGET} -.else -STAGE_MACHINE:= ${TARGET_OBJ_SPEC} -.endif -STAGE_OBJTOP:= ${STAGE_ROOT}/${STAGE_MACHINE} -STAGE_COMMON_OBJTOP:= ${STAGE_ROOT}/common STAGE_TARGET_OBJTOP:= ${STAGE_ROOT}/${TARGET_OBJ_SPEC} -STAGE_HOST_OBJTOP:= ${STAGE_ROOT}/${HOST_TARGET} # These are exported for hooking in out-of-tree builds. They will always # be overridden in sub-makes above when building in-tree. .if ${.MAKE.LEVEL} > 0 @@ -156,7 +130,6 @@ ACFLAGS+= ${CROSS_TARGET_FLAGS} .endif -.if ${MK_DIRDEPS_BUILD} == "yes" # we set these here, rather than local.gendirdeps.mk # so we can ensure any DEP_* values that might be used in # conditionals do not cause syntax errors when Makefile.depend @@ -185,5 +158,3 @@ # some makefiles expect this BOOTSTRAPPING= 0 .endif - -.endif diff --git a/share/mk/local.sys.env.mk b/share/mk/local.sys.env.mk --- a/share/mk/local.sys.env.mk +++ b/share/mk/local.sys.env.mk @@ -50,3 +50,9 @@ .include "src.sys.env.mk" .-include + +.if !defined(HOST_TARGET) || !defined(HOST_MACHINE) +# we need HOST_TARGET etc below. +.include +.export HOST_TARGET +.endif diff --git a/share/mk/meta.sys.mk b/share/mk/meta.sys.mk --- a/share/mk/meta.sys.mk +++ b/share/mk/meta.sys.mk @@ -1,7 +1,7 @@ -# $Id: meta.sys.mk,v 1.48 2023/05/04 16:41:10 sjg Exp $ +# $Id: meta.sys.mk,v 1.50 2023/05/10 20:20:41 sjg Exp $ # -# @(#) Copyright (c) 2010-2021, Simon J. Gerraty +# @(#) Copyright (c) 2010-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. @@ -17,48 +17,8 @@ # include this if you want to enable meta mode # for maximum benefit, requires filemon(4) driver. -.if ${MAKE_VERSION:U0} > 20100901 -.if !target(.ERROR) - .-include -# If TARGET_SPEC_VARS is other than just MACHINE -# it should be set by now. -# TARGET_SPEC must not contain any '.'s. -TARGET_SPEC_VARS ?= MACHINE - -.if !target(_meta_tspec_env_done_) -_meta_tspec_env_done_: .NOTMAIN -# Allow for local.meta.sys.env.mk to have done this - -.if ${TARGET_SPEC:Uno:M*,*} != "" -# deal with TARGET_SPEC from env -_tspec := ${TARGET_SPEC:S/,/ /g} -.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} -${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} -.endfor -# We need to stop that TARGET_SPEC affecting any submakes -TARGET_SPEC= -# so export but do not track -.export-env TARGET_SPEC -.export ${TARGET_SPEC_VARS} -.for v in ${TARGET_SPEC_VARS:O:u} -.if empty($v) -.undef $v -.endif -.endfor -.endif -.endif - -# Now make sure we know what TARGET_SPEC is -# as we may need it to find Makefile.depend* -.if ${MACHINE:Mhost*} != "" -# host is special -TARGET_SPEC = ${MACHINE} -.else -TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} -.endif - # absolute path to what we are reading. _PARSEDIR = ${.PARSEDIR:tA} @@ -66,7 +26,12 @@ SYS_MK_DIR := ${_PARSEDIR} .endif -META_MODE += meta verbose +.if !target(.ERROR) + +META_MODE += meta +.if empty(.MAKEFLAGS:M-s) +META_MODE += verbose +.endif .if ${MAKE_VERSION:U0} > 20130323 && empty(.MAKE.PATH_FILEMON) # we do not support filemon META_MODE += nofilemon @@ -102,19 +67,7 @@ .endif .endif -# we use the pseudo machine "host" for the build host. -# this should be taken care of before we get here -.if ${OBJTOP:Ua} == ${HOST_OBJTOP:Ub} -MACHINE = host -.endif - -.if !defined(MACHINE0) -# it can be handy to know which MACHINE kicked off the build -# for example, if using Makefild.depend for multiple machines, -# allowing only MACHINE0 to update can keep things simple. -MACHINE0 := ${MACHINE} -.export MACHINE0 -.endif +.if ${MK_DIRDEPS_BUILD:Uno} == "yes" .if !defined(META2DEPS) .if defined(PYTHON) && exists(${PYTHON}) @@ -134,6 +87,11 @@ MAKEFILE \ .MAKE.MODE +MK_META_ERROR_TARGET = yes +.endif + +.if ${MK_META_ERROR_TARGET:Uno} == "yes" + .if !defined(SB) && defined(SRCTOP) SB = ${SRCTOP:H} .endif @@ -150,21 +108,12 @@ echo "ERROR: log ${meta_error_log}" >&2; }; : .endif +.endif # Are we, after all, in meta mode? .if ${.MAKE.MODE:Uno:Mmeta*} != "" MKDEP_MK ?= meta.autodep.mk -.if ${.MAKE.MAKEFILES:M*sys.dependfile.mk} == "" -# this does all the smarts of setting .MAKE.DEPENDFILE -.-include -# check if we got anything sane -.if ${.MAKE.DEPENDFILE} == ".depend" -.undef .MAKE.DEPENDFILE -.endif -.MAKE.DEPENDFILE ?= Makefile.depend -.endif - # we can afford to use cookies to prevent some targets # re-running needlessly META_COOKIE_TOUCH?= touch ${COOKIE.${.TARGET}:U${.OBJDIR}/${.TARGET:T}} @@ -192,36 +141,13 @@ .endif .endif -.if ${.MAKE.LEVEL} == 0 -.if ${MK_DIRDEPS_BUILD:Uyes} == "yes" -# make sure dirdeps target exists and do it first -all: dirdeps .WAIT -dirdeps: -.NOPATH: dirdeps - -.if defined(ALL_MACHINES) -# the first .MAIN: is what counts -# by default dirdeps is all we want at level0 -.MAIN: dirdeps -.endif -.endif - -.else # level > 0 - -# Makefile.depend* get read at level 1+ -# and often refer to DEP_MACHINE etc, -# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set -.for V in ${TARGET_SPEC_VARS} -DEP_$V = ${$V} -.endfor +.else # in meta mode? -.endif -.else META_COOKIE_TOUCH= # some targets need to be .PHONY in non-meta mode META_NOPHONY= .PHONY META_NOECHO= echo -.endif -.endif + +.endif # in meta mode? .-include diff --git a/share/mk/src.sys.obj.mk b/share/mk/src.sys.obj.mk --- a/share/mk/src.sys.obj.mk +++ b/share/mk/src.sys.obj.mk @@ -220,11 +220,6 @@ .endif .endif # defined(NO_OBJ) -.if !defined(HOST_TARGET) -# we need HOST_TARGET etc below. -.include -.export HOST_TARGET -.endif HOST_OBJTOP?= ${OBJROOT}${HOST_TARGET} .endif # ${MK_DIRDEPS_BUILD} == "no" diff --git a/share/mk/sys.dependfile.mk b/share/mk/sys.dependfile.mk --- a/share/mk/sys.dependfile.mk +++ b/share/mk/sys.dependfile.mk @@ -1,20 +1,22 @@ -# $FreeBSD$ -# $Id: sys.dependfile.mk,v 1.7 2016/02/20 01:57:39 sjg Exp $ +# $Id: sys.dependfile.mk,v 1.10 2023/05/10 19:23:26 sjg Exp $ # -# @(#) Copyright (c) 2012, Simon J. Gerraty +# @(#) Copyright (c) 2012-2023, Simon J. Gerraty # # This file is provided in the hope that it will # be of use. There is absolutely NO WARRANTY. # Permission to copy, redistribute or otherwise -# use this file is hereby granted provided that +# use this file is hereby granted provided that # the above copyright notice and this notice are -# left intact. -# +# left intact. +# # Please send copies of changes and bug-fixes to: # sjg@crufty.net # -# This only makes sense in meta mode. +.if !target(__${.PARSEFILE}__) +__${.PARSEFILE}__: .NOTMAIN + +# This only makes sense for DIRDEPS_BUILD. # This allows a mixture of auto generated as well as manually edited # dependency files, which can be differentiated by their names. # As per dirdeps.mk we only require: @@ -58,3 +60,5 @@ .endif .endif .MAKE.DEPENDFILE ?= ${.MAKE.DEPENDFILE_DEFAULT} + +.endif diff --git a/share/mk/sys.dirdeps.mk b/share/mk/sys.dirdeps.mk new file mode 100644 --- /dev/null +++ b/share/mk/sys.dirdeps.mk @@ -0,0 +1,181 @@ +# $Id: sys.dirdeps.mk,v 1.8 2023/05/11 05:09:41 sjg Exp $ +# +# @(#) Copyright (c) 2012-2023, Simon J. Gerraty +# +# This file is provided in the hope that it will +# be of use. There is absolutely NO WARRANTY. +# Permission to copy, redistribute or otherwise +# use this file is hereby granted provided that +# the above copyright notice and this notice are +# left intact. +# +# Please send copies of changes and bug-fixes to: +# sjg@crufty.net +# + +# Originally DIRDEPS_BUILD and META_MODE were the same thing. +# So, much of this was done in *meta.sys.mk and local*mk +# but properly belongs here. + +# Include from [local.]sys.mk - if doing DIRDEPS_BUILD +# we should not be here otherwise +MK_DIRDEPS_BUILD ?= yes +# these are all implied +MK_AUTO_OBJ ?= yes +MK_META_MODE ?= yes +MK_STAGING ?= yes + +.-include + +.if ${.MAKE.LEVEL} == 0 +# make sure dirdeps target exists and do it first +dirdeps: +# first .MAIN is what counts +.MAIN: dirdeps +.NOPATH: dirdeps +all: dirdeps .WAIT +.endif + +.if empty(SRCTOP) +# fallback assumes share/mk! +SRCTOP := ${SB_SRC:U${.PARSEDIR:tA:H:H}} +.export SRCTOP +.endif + +# fake SB if not using mk wrapper +.if !defined(SB) +SB := ${SRCTOP:H} +.export SB +.endif + +.if empty(OBJROOT) +OBJROOT := ${SB_OBJROOT:U${MAKEOBJDIRPREFIX:U${SB}/obj}/} +.export OBJROOT +.endif + +.if empty(STAGE_ROOT) +STAGE_ROOT ?= ${OBJROOT}stage +.export STAGE_ROOT +.endif + +# We should be included before meta.sys.mk +# If TARGET_SPEC_VARS is other than just MACHINE +# it should be set by now. +# TARGET_SPEC must not contain any '.'s. +TARGET_SPEC_VARS ?= MACHINE + +.if !target(_tspec_env_done_) +_tspec_env_done_: .NOTMAIN + +.if ${TARGET_SPEC:Uno:M*,*} != "" +# deal with TARGET_SPEC from env +_tspec := ${TARGET_SPEC:S/,/ /g} +.for i in ${TARGET_SPEC_VARS:${M_RANGE:Urange}} +${TARGET_SPEC_VARS:[$i]} := ${_tspec:[$i]} +.endfor +# We need to stop that TARGET_SPEC affecting any submakes +TARGET_SPEC= +# so export but do not track +.export-env TARGET_SPEC +.export ${TARGET_SPEC_VARS} +.for v in ${TARGET_SPEC_VARS:O:u} +.if empty($v) +.undef $v +.endif +.endfor +.endif +.endif + +# Now make sure we know what TARGET_SPEC is +# as we may need it to find Makefile.depend* +.if ${MACHINE:Mhost*} != "" +# host is special +TARGET_SPEC = ${MACHINE} +.else +TARGET_SPEC = ${TARGET_SPEC_VARS:@v@${$v:U}@:ts,} +.endif + +.if ${TARGET_SPEC_VARS:[#]} > 1 +TARGET_OBJ_SPEC ?= ${TARGET_SPEC_VARS:@v@${$v:U}@:ts.} +.else +TARGET_OBJ_SPEC ?= ${MACHINE} +.endif + +MAKE_PRINT_VAR_ON_ERROR += ${TARGET_SPEC_VARS} + +.if !defined(MACHINE0) +# it can be handy to know which MACHINE kicked off the build +# for example, if using Makefild.depend for multiple machines, +# allowing only MACHINE0 to update can keep things simple. +MACHINE0 := ${MACHINE} +.export MACHINE0 +.endif + +.if ${MACHINE} == "host" +OBJTOP = ${HOST_OBJTOP} +.elif ${MACHINE} == "host32" +OBJTOP = ${HOST_OBJTOP32} +.endif + +MACHINE_OBJ.host = ${HOST_TARGET} +MACHINE_OBJ.host32 = ${HOST_TARGET32} +MACHINE_OBJ.${MACHINE} ?= ${TARGET_OBJ_SPEC} +MACHINE_OBJDIR = ${MACHINE_OBJ.${MACHINE}} +OBJTOP = ${OBJROOT}/${MACHINE_OBJDIR} + +# we do not use MAKEOBJDIRPREFIX +.undef MAKEOBJDIRPREFIX +# we use this +MAKEOBJDIR ?= ${.CURDIR:S,${SRCTOP},${OBJTOP},} + +STAGE_MACHINE ?= ${MACHINE_OBJDIR} +STAGE_OBJTOP ?= ${STAGE_ROOT}/${STAGE_MACHINE} +STAGE_COMMON_OBJTOP ?= ${STAGE_ROOT}/common +STAGE_HOST_OBJTOP ?= ${STAGE_ROOT}/${HOST_TARGET} +STAGE_HOST_OBJTOP32 ?= ${STAGE_ROOT}/${HOST_TARGET32} + +STAGE_INCLUDEDIR ?= ${STAGE_OBJTOP}${INCLUDEDIR:U/usr/include} +STAGE_LIBDIR ?= ${STAGE_OBJTOP}${LIBDIR:U/lib} + +TIME_STAMP_FMT ?= @ %s [%Y-%m-%d %T] ${:U} +DATE_TIME_STAMP ?= `date '+${TIME_STAMP_FMT}'` +TIME_STAMP ?= ${TIME_STAMP_FMT:localtime} + +.if ${MK_TIME_STAMPS:Uyes} == "yes" +TRACER = ${TIME_STAMP} +ECHO_DIR = echo ${TIME_STAMP} +ECHO_TRACE = echo ${TIME_STAMP} +.endif + +.if ${.CURDIR} == ${SRCTOP} +RELDIR= . +RELTOP= . +.elif ${.CURDIR:M${SRCTOP}/*} +RELDIR:= ${.CURDIR:S,${SRCTOP}/,,} +.else +RELDIR:= ${.OBJDIR:S,${OBJTOP}/,,} +.endif +RELTOP?= ${RELDIR:C,[^/]+,..,g} +RELOBJTOP?= ${RELTOP} +RELSRCTOP?= ${RELTOP} + +# this does all the smarts of setting .MAKE.DEPENDFILE +.-include + +.-include + +# check if we got anything sane +.if ${.MAKE.DEPENDFILE} == ".depend" +.undef .MAKE.DEPENDFILE +.endif +# just in case +.MAKE.DEPENDFILE ?= Makefile.depend + +.if ${.MAKE.LEVEL} > 0 +# Makefile.depend* also get read at level 1+ +# and often refer to DEP_MACHINE etc, +# so ensure DEP_* (for TARGET_SPEC_VARS anyway) are set +.for V in ${TARGET_SPEC_VARS} +DEP_$V = ${$V} +.endfor +.endif diff --git a/share/mk/sys.mk b/share/mk/sys.mk --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -33,6 +33,7 @@ __DEFAULT_DEPENDENT_OPTIONS= \ AUTO_OBJ/DIRDEPS_BUILD \ + META_ERROR_TARGET/DIRDEPS_BUILD \ META_MODE/DIRDEPS_BUILD \ STAGING/DIRDEPS_BUILD \ SYSROOT/DIRDEPS_BUILD @@ -57,27 +58,13 @@ .endif .if ${MK_DIRDEPS_BUILD} == "yes" -.sinclude -.elif ${MK_META_MODE} == "yes" -META_MODE+= meta -.if empty(.MAKEFLAGS:M-s) -# verbose will show .MAKE.META.PREFIX for each target. -META_MODE+= verbose -.endif -.if !defined(NO_META_MISSING) -META_MODE+= missing-meta=yes -.endif -# silent will hide command output if a .meta file is created. -.if !defined(NO_SILENT) -META_MODE+= silent=yes +.-include .endif +.if ${MK_META_MODE} == "yes" .if !exists(/dev/filemon) || defined(NO_FILEMON) META_MODE+= nofilemon .endif -# Require filemon data with bmake -.if empty(META_MODE:Mnofilemon) -META_MODE+= missing-filemon=yes -.endif +.-include .endif META_MODE?= normal .export META_MODE