From 0c0f7c2421aa650b11ae3914200c4be153718ca8 Mon Sep 17 00:00:00 2001
From: Bananymous <bananymousosq@gmail.com>
Date: Sun, 29 Oct 2023 17:39:44 +0200
Subject: [PATCH] Add target banan_os for i386 and x86_64

---
 bfd/config.bfd    | 10 ++++++++++
 config.sub        |  2 +-
 gas/configure.tgt |  1 +
 ld/configure.tgt  |  6 ++++++
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/bfd/config.bfd b/bfd/config.bfd
index a4c6c8e885..1f083e596f 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -602,6 +602,11 @@ case "${targ}" in
     targ_defvec=i386_elf32_vec
     targ_selvecs=iamcu_elf32_vec
     ;;
+  i[3-7]86-*-banan_os*)
+    targ_defvec=i386_elf32_vec
+    targ_selvecs=
+    targ64_selvecs=x86_64_elf64_vec
+    ;;
   i[3-7]86-*-dicos*)
     targ_defvec=i386_elf32_vec
     targ_selvecs=iamcu_elf32_vec
@@ -656,6 +661,11 @@ case "${targ}" in
     targ64_selvecs=x86_64_elf64_vec
     ;;
 #ifdef BFD64
+  x86_64-*-banan_os*)
+    targ_defvec=x86_64_elf64_vec
+    targ_selvecs=i386_elf32_vec
+    want64=true
+    ;;
   x86_64-*-cloudabi*)
     targ_defvec=x86_64_elf64_cloudabi_vec
     want64=true
diff --git a/config.sub b/config.sub
index dba16e84c7..9a37bb30fd 100755
--- a/config.sub
+++ b/config.sub
@@ -1754,7 +1754,7 @@ case $os in
 	     | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
 	     | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
 	     | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
-	     | fiwix* )
+	     | fiwix* | banan_os* )
 		;;
 	# This one is extra strict with allowed versions
 	sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 62f806bdfe..e05db38382 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -221,6 +221,7 @@ case ${generic_target} in
   h8300-*-elf)				fmt=elf ;;
   h8300-*-linux*)			fmt=elf em=linux ;;

+  i386-*-banan_os*)			fmt=elf em=gnu ;;
   i386-*-beospe*)			fmt=coff em=pe ;;
   i386-*-beos*)				fmt=elf ;;
   i386-*-elfiamcu)			fmt=elf arch=iamcu ;;
diff --git a/ld/configure.tgt b/ld/configure.tgt
index 2bae9099b6..640426e81f 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -352,6 +352,9 @@ i[3-7]86-*-aros*)	targ_emul=elf_i386
 i[3-7]86-*-rdos*)	targ_emul=elf_i386
 			targ_extra_emuls=elf_iamcu
 			;;
+i[3-7]86-*-banan_os*)	targ_emul=elf_i386
+			targ64_extra_emuls=elf_x86_64
+			;;
 i[3-7]86-*-bsd)		targ_emul=i386bsd
 			targ_extra_ofiles=
 			;;
@@ -988,6 +991,9 @@ visium-*-elf)		targ_emul=elf32visium
 			;;
 x86_64-*-rdos*)		targ_emul=elf64rdos
 			;;
+x86_64-*-banan_os*)	targ_emul=elf_x86_64
+			targ_extra_emuls=elf_i386
+			;;
 x86_64-*-cloudabi*)	targ_emul=elf_x86_64_cloudabi
 			;;
 x86_64-*-haiku*)	targ_emul=elf_x86_64_haiku
-- 
2.42.0

