git: da1ef2d61930 - main - Move MACHINE/MACHINE_ARCH handling to sys.machine.mk

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Sat, 13 May 2023 15:17:16 UTC
The branch main has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=da1ef2d6193036518d483a608f4b6ac753b78b96

commit da1ef2d6193036518d483a608f4b6ac753b78b96
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2023-05-13 15:15:49 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2023-05-13 15:15:49 +0000

    Move MACHINE/MACHINE_ARCH handling to sys.machine.mk
    
    Rather than define the TARGETS and TARGET_ARCHES in src/Makefile
    put them in sys.machine.mk so they can also be leveraged by
    non-top-level builds.
    
    We have TARGET_MACHINE_LIST as the list of MACHINES we build for.
    
    For each MACHINE we have a MACHINE_ARCH_LIST_${MACHINE}
    and the first entry of each list is used as default for
    MACHINE_ARCH_${MACHINE}
    
    We can now remove a bunch of MACHINE_ARCH.* handling from
    local.sys.dirdeps*mk
    
    Reviewed by:    imp
    Sponsored by:   Juniper Networks, Inc.
    Differential Revision:  https://reviews.freebsd.org/D40083
---
 Makefile                          |  8 ++------
 share/mk/local.sys.dirdeps.env.mk | 30 +++---------------------------
 share/mk/local.sys.env.mk         |  2 ++
 share/mk/sys.machine.mk           | 23 +++++++++++++++++++++++
 4 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/Makefile b/Makefile
index 0b2438a0cfc0..4658a75986f9 100644
--- a/Makefile
+++ b/Makefile
@@ -530,14 +530,10 @@ worlds: .PHONY
 # powerpcspe excluded from main list until clang fixed
 EXTRA_ARCHES_powerpc=	powerpcspe
 .endif
-TARGETS?=amd64 arm arm64 i386 powerpc riscv
+TARGETS?= ${TARGET_MACHINE_LIST}
 _UNIVERSE_TARGETS=	${TARGETS}
-TARGET_ARCHES_arm?=	armv6 armv7
-TARGET_ARCHES_arm64?=	aarch64
-TARGET_ARCHES_powerpc?=	powerpc powerpc64 powerpc64le ${EXTRA_ARCHES_powerpc}
-TARGET_ARCHES_riscv?=	riscv64
 .for target in ${TARGETS}
-TARGET_ARCHES_${target}?= ${target}
+TARGET_ARCHES_${target}= ${MACHINE_ARCH_LIST_${target}}
 .endfor
 
 .if defined(USE_GCC_TOOLCHAINS)
diff --git a/share/mk/local.sys.dirdeps.env.mk b/share/mk/local.sys.dirdeps.env.mk
index 3d45719ff292..fdc03cae29eb 100644
--- a/share/mk/local.sys.dirdeps.env.mk
+++ b/share/mk/local.sys.dirdeps.env.mk
@@ -12,41 +12,17 @@ TARGET_SPEC_VARS?= MACHINE MACHINE_ARCH
 	${.MAKE.DEPENDFILE_PREFIX}.${MACHINE} \
 	${.MAKE.DEPENDFILE_PREFIX}
 
-# before we process TARGET_SPEC
-# we assume that MK_DIRDEPS_BUILD=yes
-
-# from src/Makefile (for universe)
-# would be nice to have this sort of info in sys.machine.mk
-TARGET_ARCHES_arm?=     armv6 armv7
-TARGET_ARCHES_arm64?=   aarch64
-TARGET_ARCHES_powerpc?= powerpc powerpc64 powerpc64le powerpcspe
-TARGET_ARCHES_riscv?=   riscv64
-
 # some corner cases
 BOOT_MACHINE_DIR.amd64 = boot/i386
-MACHINE_ARCH.host = ${_HOST_ARCH}
-
-# the list of machines we support
-ALL_MACHINE_LIST?= amd64 arm arm64 i386 powerpc riscv
 
 .-include <site.sys.dirdeps.env.mk>
 
+ALL_MACHINE_LIST?= ${TARGET_MACHINE_LIST}
+
 .for m in ${ALL_MACHINE_LIST:O:u}
-MACHINE_ARCH_LIST.$m?= ${TARGET_ARCHES_${m}:U$m}
-MACHINE_ARCH.$m?= ${MACHINE_ARCH_LIST.$m:[1]}
 BOOT_MACHINE_DIR.$m ?= boot/$m
 .endfor
 
-.if empty(MACHINE_ARCH)
-.if !empty(TARGET_ARCH)
-MACHINE_ARCH= ${TARGET_ARCH}
-.else
-MACHINE_ARCH= ${MACHINE_ARCH.${MACHINE}}
-.endif
-.endif
-MACHINE_ARCH?= ${MACHINE_ARCH.${MACHINE}}
-MACHINE_ARCH:= ${MACHINE_ARCH}
-
 HOST_OBJTOP ?= ${OBJROOT}${HOST_TARGET}
 
 .if ${REQUESTED_MACHINE:U${MACHINE}} == "host"
@@ -58,7 +34,7 @@ TARGET_MACHINE= host
 .endif
 .if ${MACHINE} == "host"
 OBJTOP := ${HOST_OBJTOP}
-MACHINE_ARCH= ${MACHINE_ARCH.${MACHINE}}
+MACHINE_ARCH= ${MACHINE_ARCH_${MACHINE}}
 .endif
 
 
diff --git a/share/mk/local.sys.env.mk b/share/mk/local.sys.env.mk
index e10bf58e14e8..5444fd77652f 100644
--- a/share/mk/local.sys.env.mk
+++ b/share/mk/local.sys.env.mk
@@ -56,3 +56,5 @@ ECHO_TRACE?=	true
 .include <host-target.mk>
 .export HOST_TARGET
 .endif
+
+.include <sys.machine.mk>
diff --git a/share/mk/sys.machine.mk b/share/mk/sys.machine.mk
new file mode 100644
index 000000000000..445aaa4b62fd
--- /dev/null
+++ b/share/mk/sys.machine.mk
@@ -0,0 +1,23 @@
+
+.-include <local.sys.machine.mk>
+
+PSEUDO_MACHINE_LIST?= common host
+TARGET_MACHINE_LIST?= amd64 arm arm64 i386 powerpc riscv
+
+MACHINE_ARCH_host?= ${_HOST_ARCH}
+
+MACHINE_ARCH_LIST_arm?= armv6 armv7
+MACHINE_ARCH_LIST_arm64?= aarch64
+MACHINE_ARCH_LIST_powerpc?= powerpc powerpc64 powerpc64le ${EXTRA_ARCHES_powerpc}
+MACHINE_ARCH_LIST_riscv?= riscv64
+
+.for m in ${TARGET_MACHINE_LIST}
+MACHINE_ARCH_LIST_$m?= $m
+MACHINE_ARCH_$m?= ${MACHINE_ARCH_LIST_$m:[1]}
+# for backwards comatability
+MACHINE_ARCH.$m?= ${MACHINE_ARCH_$m}
+.endfor
+
+.if empty(MACHINE_ARCH)
+MACHINE_ARCH:= ${MACHINE_ARCH_${MACHINE}}
+.endif