Subject: [PATCH] gnu: patches: Add qbe-makefile-add-target.patch.

From: "(unmatched-parenthesis" <[email-masked]>
Date: Sat, 7 May 2022 18:11:04 +0100

* gnu/packages/patches/qbe-makefile-add-target.patch: New variable.

Signed-off-by: (unmatched-parenthesis <[email-masked]>
---
 .../patches/qbe-makefile-add-target.patch     | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 gnu/packages/patches/qbe-makefile-add-target.patch

diff --git a/gnu/packages/patches/qbe-makefile-add-target.patch b/gnu/packages/patches/qbe-makefile-add-target.patch
new file mode 100644
index 0000000000..e87559c3fa
--- /dev/null
+++ b/gnu/packages/patches/qbe-makefile-add-target.patch
@@ -0,0 +1,56 @@
+This patch modifies the QBE makefile to add a TARGET variable that allows us to support
+cross-compiling it. We modify the case...esac in the config.h target to use this variable
+instead of TARGET.
+--- a/Makefile
++++ b/Makefile
+@@ -17,6 +17,8 @@ OBJ      = $(SRC:%.c=$(OBJDIR)/%.o) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ)
+ 
+ CFLAGS += -Wall -Wextra -std=c99 -g -pedantic
+ 
++TARGET = unknown
++
+ $(OBJDIR)/$(BIN): $(OBJ) $(OBJDIR)/timestamp
+ 	@test -z "$(V)" || echo "ld $@"
+ 	$(V)$(CC) $(LDFLAGS) $(OBJ) -o $@
+@@ -39,26 +41,21 @@ $(RV64OBJ): rv64/all.h
+ $(OBJDIR)/main.o: config.h
+ 
+ config.h:
+-	@case `uname` in                               \
+-	*Darwin*)                                      \
+-		echo "#define Defasm Gasmacho";        \
+-		echo "#define Deftgt T_amd64_sysv";    \
+-		;;                                     \
+-	*)                                             \
+-		echo "#define Defasm Gaself";          \
+-		case `uname -m` in                     \
+-		*aarch64*)                             \
+-			echo "#define Deftgt T_arm64"; \
+-			;;                             \
+-		*riscv64*)                             \
+-			echo "#define Deftgt T_rv64";  \
+-			;;                             \
+-		*)                                     \
+-			echo "#define Deftgt T_amd64_sysv";\
+-			;;                             \
+-		esac                                   \
+-		;;                                     \
+-	esac > $@
++	@echo "#define Defasm Gaself" >> $@
++	@case $(TARGET) in \
++	*x86_64*) \
++		echo "#define Deftgt T_amd64_sysv"; \
++		;; \
++	*aarch64*) \
++		echo "#define Deftgt T_arm64"; \
++		;; \
++	*riscv64*) \
++		echo "#define Deftgt T_rv64"; \
++		;; \
++	*) \
++		echo "#error target not set to x86_64, aarch64, or riscv64 in makefile"; \
++		;; \
++	esac >> $@
+ 
+ install: $(OBJDIR)/$(BIN)
+ 	mkdir -p "$(DESTDIR)/$(PREFIX)/bin/"
-- 
2.36.0