From ee11fbe173c4e79a6f129f8eb50ae47a0a8d81ad Mon Sep 17 00:00:00 2001
From: Joel Holdsworth <jholdsworth@nvidia.com>
Date: Tue, 2 Dec 2025 14:13:06 -0800
Subject: [PATCH 3/4] Assemble without copying input sources

When doing parallel out-of-tree builds, race conditions can occur between
multiple threads assembling the same files several times in different
configurations.
---
 device/lib/ez80_z80/Makefile.in           | 5 +----
 device/lib/f8/Makefile.in                 | 5 +----
 device/lib/mcs51/Makefile.in              | 5 +----
 device/lib/mos6502-stack-auto/Makefile.in | 5 +----
 device/lib/mos6502/Makefile.in            | 5 +----
 device/lib/mos65c02/Makefile.in           | 5 +----
 device/lib/pdk13/Makefile.in              | 5 +----
 device/lib/pdk14/Makefile.in              | 5 +----
 device/lib/pdk15-stack-auto/Makefile.in   | 5 +----
 device/lib/pdk15/Makefile.in              | 5 +----
 device/lib/r2k/Makefile.in                | 5 +----
 device/lib/r2ka/Makefile.in               | 5 +----
 device/lib/r3ka/Makefile.in               | 5 +----
 device/lib/r800/Makefile.in               | 5 +----
 device/lib/sm83/Makefile.in               | 5 +----
 device/lib/stm8-large/Makefile.in         | 5 +----
 device/lib/stm8/Makefile.in               | 5 +----
 device/lib/tlcs90/Makefile.in             | 5 +----
 device/lib/z180/Makefile.in               | 5 +----
 device/lib/z80/Makefile.in                | 5 +----
 device/lib/z80n/Makefile.in               | 5 +----
 21 files changed, 21 insertions(+), 84 deletions(-)

diff --git a/device/lib/ez80_z80/Makefile.in b/device/lib/ez80_z80/Makefile.in
index d19f9d685..436d957f4 100644
--- a/device/lib/ez80_z80/Makefile.in
+++ b/device/lib/ez80_z80/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasz80
 override PORTDIR = ../build/ez80_z80
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/f8/Makefile.in b/device/lib/f8/Makefile.in
index a5df8408b..1dad2378d 100644
--- a/device/lib/f8/Makefile.in
+++ b/device/lib/f8/Makefile.in
@@ -89,10 +89,7 @@ endif
 	$(CC) $(CFLAGS) -c $<
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 %.rel: ../%.c
 	$(CC) $(CFLAGS) -c $<
diff --git a/device/lib/mcs51/Makefile.in b/device/lib/mcs51/Makefile.in
index 85866712c..df9b0c54a 100644
--- a/device/lib/mcs51/Makefile.in
+++ b/device/lib/mcs51/Makefile.in
@@ -52,10 +52,7 @@ endif
 	$(CC) $(CFLAGS) -c $<
 
 %.rel: %.asm
-	@# TODO: asx8051 should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 clean:
 	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.lib
diff --git a/device/lib/mos6502-stack-auto/Makefile.in b/device/lib/mos6502-stack-auto/Makefile.in
index d49056cef..929855d1a 100644
--- a/device/lib/mos6502-stack-auto/Makefile.in
+++ b/device/lib/mos6502-stack-auto/Makefile.in
@@ -99,10 +99,7 @@ else
 endif
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 clean:
 	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib
diff --git a/device/lib/mos6502/Makefile.in b/device/lib/mos6502/Makefile.in
index 5734a71f7..6e56f16c5 100644
--- a/device/lib/mos6502/Makefile.in
+++ b/device/lib/mos6502/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdas6500
 override PORTDIR = ../build/mos6502
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/mos65c02/Makefile.in b/device/lib/mos65c02/Makefile.in
index 4aea09f4c..1dff9fe89 100644
--- a/device/lib/mos65c02/Makefile.in
+++ b/device/lib/mos65c02/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdas6500
 override PORTDIR = ../build/mos65c02
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/pdk13/Makefile.in b/device/lib/pdk13/Makefile.in
index df0fa6f68..cf7d09b1b 100644
--- a/device/lib/pdk13/Makefile.in
+++ b/device/lib/pdk13/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdaspdk13
 override PORTDIR = ../build/pdk13
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/pdk14/Makefile.in b/device/lib/pdk14/Makefile.in
index 26b9b7880..5d1fbe05a 100644
--- a/device/lib/pdk14/Makefile.in
+++ b/device/lib/pdk14/Makefile.in
@@ -92,10 +92,7 @@ else
 endif
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 clean:
 	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib
diff --git a/device/lib/pdk15-stack-auto/Makefile.in b/device/lib/pdk15-stack-auto/Makefile.in
index 559635533..68feaa2ce 100644
--- a/device/lib/pdk15-stack-auto/Makefile.in
+++ b/device/lib/pdk15-stack-auto/Makefile.in
@@ -96,10 +96,7 @@ endif
 	$(CC) $(CFLAGS) ${EXTRA_CFLAGS} -c $<
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 %.rel: ../%.c
 	$(CC) $(CFLAGS) ${EXTRA_CFLAGS} -c $<
diff --git a/device/lib/pdk15/Makefile.in b/device/lib/pdk15/Makefile.in
index 454e66ef2..28f834ff3 100644
--- a/device/lib/pdk15/Makefile.in
+++ b/device/lib/pdk15/Makefile.in
@@ -92,10 +92,7 @@ else
 endif
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 clean:
 	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib
diff --git a/device/lib/r2k/Makefile.in b/device/lib/r2k/Makefile.in
index a6a19b727..c4c6de812 100644
--- a/device/lib/r2k/Makefile.in
+++ b/device/lib/r2k/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasrab
 override PORTDIR = ../build/r2k
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/r2ka/Makefile.in b/device/lib/r2ka/Makefile.in
index 9f9b2cd93..e67f1e06c 100644
--- a/device/lib/r2ka/Makefile.in
+++ b/device/lib/r2ka/Makefile.in
@@ -15,10 +15,7 @@ override PORTDIR = ../build/r2ka
 
 # BUG?
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/r3ka/Makefile.in b/device/lib/r3ka/Makefile.in
index 87a2eac58..86b816f56 100644
--- a/device/lib/r3ka/Makefile.in
+++ b/device/lib/r3ka/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasrab
 override PORTDIR = ../build/r3ka
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/r800/Makefile.in b/device/lib/r800/Makefile.in
index fb0e9bd63..1b3e27225 100644
--- a/device/lib/r800/Makefile.in
+++ b/device/lib/r800/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasz80
 override PORTDIR = ../build/r800
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/sm83/Makefile.in b/device/lib/sm83/Makefile.in
index 72e43979d..ed80bb3ba 100644
--- a/device/lib/sm83/Makefile.in
+++ b/device/lib/sm83/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasgb
 override PORTDIR = ../build/sm83
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/stm8-large/Makefile.in b/device/lib/stm8-large/Makefile.in
index 8ce32964d..51fc718f2 100644
--- a/device/lib/stm8-large/Makefile.in
+++ b/device/lib/stm8-large/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasstm8
 override PORTDIR = ../build/stm8-large
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/stm8/Makefile.in b/device/lib/stm8/Makefile.in
index 3aa887db7..bada111d6 100644
--- a/device/lib/stm8/Makefile.in
+++ b/device/lib/stm8/Makefile.in
@@ -15,10 +15,7 @@ SAS = $(top_builddir)/bin/sdasstm8
 override PORTDIR = ../build/stm8
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/tlcs90/Makefile.in b/device/lib/tlcs90/Makefile.in
index 01509d87c..a5aa7a762 100644
--- a/device/lib/tlcs90/Makefile.in
+++ b/device/lib/tlcs90/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdastlcs90
 override PORTDIR = ../build/tlcs90
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) -I$(dir $<) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -I$(dir $<) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/z180/Makefile.in b/device/lib/z180/Makefile.in
index 44b6f4ca6..cdbe77841 100644
--- a/device/lib/z180/Makefile.in
+++ b/device/lib/z180/Makefile.in
@@ -15,10 +15,7 @@ override PORTDIR = ../build/z180
 
 # BUG: before incl.mk
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/z80/Makefile.in b/device/lib/z80/Makefile.in
index 3bad46ceb..765c40c9e 100644
--- a/device/lib/z80/Makefile.in
+++ b/device/lib/z80/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasz80
 override PORTDIR = ../build/z80
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
diff --git a/device/lib/z80n/Makefile.in b/device/lib/z80n/Makefile.in
index b8a9cd50d..e85211489 100644
--- a/device/lib/z80n/Makefile.in
+++ b/device/lib/z80n/Makefile.in
@@ -14,10 +14,7 @@ SAS = $(top_builddir)/bin/sdasz80
 override PORTDIR = ../build/z80n
 
 %.rel: %.s
-	@# TODO: sdas should place it\'s output in the current dir
-	test $(srcdir) = . || cp $< .
-	-$(AS) $(ASFLAGS) $(notdir $<)
-	test $(srcdir) = . || rm $(notdir $<)
+	$(AS) $(ASFLAGS) -o $@ $<
 
 include $(srcdir)/../incl.mk
 
-- 
2.52.0

