From b1e26d51fa1ddb68757c940d713b6d8e089b0b24 Mon Sep 17 00:00:00 2001
From: Ben Avison <bavison@riscosopen.org>
Date: Thu, 8 Oct 2020 12:00:06 +0100
Subject: [PATCH] Always implicitly include StdTools when cross-compiling

`AAsmModule`, `CApp`, `CLibrary` and `CModule` implicitly include various
other shared makefile fragments to permit simpler master makefiles. However,
when cross-compiling, they were only included when invoked from within the
`objs` subdirectory, which in particular meant you couldn't rely on any of
the definitions from `StdTools` when extending the `clean` rule unless you
explicitly included it from the master makefile, thereby defeating the
purpose of the implicit inclusion. Change them so that `StdTools` is included
for all rules.
---
 GNUmakefiles/AAsmModule |  8 ++++----
 GNUmakefiles/CApp       | 12 ++++++------
 GNUmakefiles/CLibrary   |  8 ++++----
 GNUmakefiles/CModule    |  7 ++++---
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/GNUmakefiles/AAsmModule b/GNUmakefiles/AAsmModule
index ccf9383..4f554f1 100644
--- a/GNUmakefiles/AAsmModule
+++ b/GNUmakefiles/AAsmModule
@@ -127,6 +127,10 @@ endif
 
 SOURCES_TO_SYMLINK += $(wildcard h/*) $(wildcard hdr/*) $(wildcard s/*) Resources VersionNum VersionASM
 
+ifeq ("${INCLUDED_STDTOOLS}","")
+include StdTools
+endif
+
 ifneq (objs,$(notdir ${CURDIR}))
 
 # Makefile invoked from same directory
@@ -172,10 +176,6 @@ else
 
 # Makefile invoked from objs subdirectory
 
-ifeq ("${INCLUDED_STDTOOLS}","")
-include StdTools
-endif
-
 all: rom debug standalone
 
 # GNU make seems to treat any double-colon rule with no dependencies as
diff --git a/GNUmakefiles/CApp b/GNUmakefiles/CApp
index 863b329..acc6d5a 100644
--- a/GNUmakefiles/CApp
+++ b/GNUmakefiles/CApp
@@ -111,6 +111,12 @@ ROM_OBJS_     = $(addsuffix .oz,${ROM_OBJS})
 
 SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard c++/*) $(wildcard h/*) $(wildcard s/*) VersionNum VersionASM
 
+ifeq ("${INCLUDED_STDTOOLS}","")
+ifeq ("${INCLUDED_HOSTTOOLS}","")
+include StdTools
+endif
+endif
+
 ifneq (objs,$(notdir ${CURDIR}))
 
 # Makefile invoked from same directory
@@ -151,12 +157,6 @@ else
 
 # Makefile invoked from objs subdirectory
 
-ifeq ("${INCLUDED_STDTOOLS}","")
-ifeq ("${INCLUDED_HOSTTOOLS}","")
-include StdTools
-endif
-endif
-
 ifeq ($(filter rom%,${MAKECMDGOALS}),)
 ifeq ("${INCLUDED_APPLIBS}","")
 include AppLibs
diff --git a/GNUmakefiles/CLibrary b/GNUmakefiles/CLibrary
index 534bc5b..a980b9c 100644
--- a/GNUmakefiles/CLibrary
+++ b/GNUmakefiles/CLibrary
@@ -109,6 +109,10 @@ endif
 
 SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard h/*) $(wildcard s/*)
 
+ifeq ("${INCLUDED_STDTOOLS}","")
+include StdTools
+endif
+
 ifneq (objs,$(notdir ${CURDIR}))
 
 # Makefile invoked from same directory
@@ -148,10 +152,6 @@ else
 
 # Makefile invoked from objs subdirectory
 
-ifeq ("${INCLUDED_STDTOOLS}","")
-include StdTools
-endif
-
 ifeq ("${INCLUDED_STDRULES}","")
 include StdRules
 endif
diff --git a/GNUmakefiles/CModule b/GNUmakefiles/CModule
index faae272..e1852a4 100644
--- a/GNUmakefiles/CModule
+++ b/GNUmakefiles/CModule
@@ -208,6 +208,10 @@ TOKENSOURCE  := TokHelpSrc.s
 
 SOURCES_TO_SYMLINK += $(wildcard c/*) $(wildcard c++/*) $(wildcard cmhg/*) $(wildcard h/*) $(wildcard hdr/*) $(wildcard s/*) VersionNum VersionASM
 
+ifeq ("${INCLUDED_STDTOOLS}","")
+include StdTools
+endif
+
 ifneq (objs,$(notdir ${CURDIR}))
 
 # Makefile invoked from same directory
@@ -254,9 +258,6 @@ ifneq ("${ASM2TXT_EXT}","")
 ASM2TXT_EXT  := .${ASM2TXT_EXT}
 endif
 
-ifeq ("${INCLUDED_STDTOOLS}","")
-include StdTools
-endif
 ifeq ("${INCLUDED_MODULELIBS}","")
 include ModuleLibs
 endif
-- 
GitLab