Source: ghdl
Followup-For: Bug #916475

Hello.
A rebased and extended list of suggestions is attached.
Debdiff reports no change in the binary packages.
>From 734fee62a113b8c36c929f8ee739243d67d64a34 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Wed, 14 Dec 2022 13:48:00 +0100
Subject: [PATCH 01/14] Install the usr/bin/ghdl wrapper with dh_install
 directly

---
 debian/{ghdl.wrapper => bin/ghdl} | 0
 debian/ghdl-common.install        | 3 ++-
 debian/rules                      | 1 -
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename debian/{ghdl.wrapper => bin/ghdl} (100%)
 mode change 100644 => 100755

diff --git a/debian/ghdl.wrapper b/debian/bin/ghdl
old mode 100644
new mode 100755
similarity index 100%
rename from debian/ghdl.wrapper
rename to debian/bin/ghdl
diff --git a/debian/ghdl-common.install b/debian/ghdl-common.install
index 1d4197f0..5ff3ad65 100644
--- a/debian/ghdl-common.install
+++ b/debian/ghdl-common.install
@@ -1,4 +1,5 @@
-usr/bin/ghdl
+debian/bin/ghdl                         usr/bin/
+
 usr/lib/ghdl/src
 usr/lib/ghdl/include/ghdl/vpi_user.h
 usr/lib/ghdl/include/ghdl/vhpi_user.h
diff --git a/debian/rules b/debian/rules
index dcece304..217fd601 100755
--- a/debian/rules
+++ b/debian/rules
@@ -91,7 +91,6 @@ override_dh_auto_install: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/install-$(b
 	@echo ------------------------------------------------------------
 	@echo Common install final steps
 	@echo ------------------------------------------------------------
-	install -pD debian/ghdl.wrapper $(CURDIR)/debian/tmp/usr/bin/ghdl
 	cd debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) && ln -s libghdl-*.so libghdl.so
 	$(RM) debian/tmp/usr/lib/ghdl/src/ieee2008/LICENSE
 
-- 
2.39.2

>From af3bf32c7959c411658b9a0adc94024d16bb1bed Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 13:43:54 +0200
Subject: [PATCH 02/14] Install sources into usr/lib/ghdl with dh_install
 directly

---
 debian/ghdl-common.install | 8 +++++++-
 debian/not-installed       | 3 +++
 debian/rules               | 7 -------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/debian/ghdl-common.install b/debian/ghdl-common.install
index 5ff3ad65..36ec5acf 100644
--- a/debian/ghdl-common.install
+++ b/debian/ghdl-common.install
@@ -1,5 +1,11 @@
 debian/bin/ghdl                         usr/bin/
 
-usr/lib/ghdl/src
+# The wildcard matches backend(s).
+usr/lib/ghdl/*/vhdl/src/ieee/           usr/lib/ghdl/src/
+usr/lib/ghdl/*/vhdl/src/ieee2008/*.vhdl usr/lib/ghdl/src/ieee2008/
+usr/lib/ghdl/*/vhdl/src/std/            usr/lib/ghdl/src/
+usr/lib/ghdl/*/vhdl/src/synopsys/       usr/lib/ghdl/src/
+usr/lib/ghdl/*/vhdl/src/upf/            usr/lib/ghdl/src/
+
 usr/lib/ghdl/include/ghdl/vpi_user.h
 usr/lib/ghdl/include/ghdl/vhpi_user.h
diff --git a/debian/not-installed b/debian/not-installed
index 97006213..1f68b482 100644
--- a/debian/not-installed
+++ b/debian/not-installed
@@ -3,10 +3,13 @@
 # file from its original location directly to debian/PACKAGE/usr/bin.
 usr/bin/ghdl-gcc
 
+# The wildcard matches backend(s).
 usr/lib/ghdl/*/vhdl/ansi_color.sh
+usr/lib/ghdl/*/vhdl/src/ieee2008/LICENSE
 usr/lib/ghdl/*/vhdl/vendors
 usr/lib/ghdl/*/libghw.so
 usr/lib/ghdl/*/libghdl.link
+
 usr/lib/ghdl/include/ghdl/libghw.h
 
 usr/lib/ghdl/gcc/libexec
diff --git a/debian/rules b/debian/rules
index 217fd601..346ea20f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -92,7 +92,6 @@ override_dh_auto_install: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/install-$(b
 	@echo Common install final steps
 	@echo ------------------------------------------------------------
 	cd debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) && ln -s libghdl-*.so libghdl.so
-	$(RM) debian/tmp/usr/lib/ghdl/src/ieee2008/LICENSE
 
 override_dh_dwz:
 	# dwz currently has problems with some debug sections created by the
@@ -151,8 +150,6 @@ $(STAMPSDIR)/install-mcode: $(STAMPSDIR)/build-mcode
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	$(RM) -r debian/tmp/usr/lib/ghdl/src
-	mv debian/tmp/usr/lib/ghdl/mcode/vhdl/src debian/tmp/usr/lib/ghdl
 	ln -s ../../src debian/tmp/usr/lib/ghdl/mcode/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/mcode/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/mcode/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
@@ -207,8 +204,6 @@ $(STAMPSDIR)/install-llvm: $(STAMPSDIR)/build-llvm
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	$(RM) -r debian/tmp/usr/lib/ghdl/src
-	mv debian/tmp/usr/lib/ghdl/llvm/vhdl/src debian/tmp/usr/lib/ghdl
 	ln -s ../../src debian/tmp/usr/lib/ghdl/llvm/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/llvm/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/llvm/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
@@ -297,8 +292,6 @@ $(STAMPSDIR)/install-gcc: $(STAMPSDIR)/build-gcc
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	$(RM) -r debian/tmp/usr/lib/ghdl/src
-	mv debian/tmp/usr/lib/ghdl/gcc/vhdl/src debian/tmp/usr/lib/ghdl
 	ln -s ../../src debian/tmp/usr/lib/ghdl/gcc/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/gcc/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/gcc/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
-- 
2.39.2

>From 21d319a63ea31d83bd2cad3346c4b4b739cebbf5 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 13:46:40 +0200
Subject: [PATCH 03/14] Install development symbolic link to shared library
 with dh_link directly

---
 debian/libghdl-dev.install |  1 -
 debian/libghdl-dev.links   | 11 +++++++++++
 debian/rules               |  5 -----
 3 files changed, 11 insertions(+), 6 deletions(-)
 create mode 100755 debian/libghdl-dev.links

diff --git a/debian/libghdl-dev.install b/debian/libghdl-dev.install
index cbcf11a7..ea834081 100644
--- a/debian/libghdl-dev.install
+++ b/debian/libghdl-dev.install
@@ -1,3 +1,2 @@
 usr/lib/*/libghdl.a
-usr/lib/*/libghdl.so
 usr/lib/ghdl/include/ghdl/synth*.h usr/include/ghdl
diff --git a/debian/libghdl-dev.links b/debian/libghdl-dev.links
new file mode 100755
index 00000000..d49c2d8b
--- /dev/null
+++ b/debian/libghdl-dev.links
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -C -e -u
+
+# 1 to 3 copies of the same base name exist in debian/tmp, but only
+# one is actually installed by debian/libghdl-3.0.0.install.
+duplicates=$(basename debian/tmp/usr/lib/ghdl/*/libghdl-*.so)
+
+# Select the first word.
+shared_object_name=${duplicates%% *}
+
+echo "usr/lib/\${DEB_HOST_MULTIARCH}/$shared_object_name usr/lib/\${DEB_HOST_MULTIARCH}/libghdl.so"
diff --git a/debian/rules b/debian/rules
index 346ea20f..9eeff819 100755
--- a/debian/rules
+++ b/debian/rules
@@ -87,11 +87,6 @@ override_dh_auto_configure: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/configure
 override_dh_auto_build: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/build-$(backend))
 
 override_dh_auto_install: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/install-$(backend))
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Common install final steps
-	@echo ------------------------------------------------------------
-	cd debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) && ln -s libghdl-*.so libghdl.so
 
 override_dh_dwz:
 	# dwz currently has problems with some debug sections created by the
-- 
2.39.2

>From 7f641e67c4dd6bb34b42272c550b202d5243bc9a Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Wed, 14 Dec 2022 14:02:42 +0100
Subject: [PATCH 04/14] Install usr/lib/ghdl/backend/vhdl/src with dh_link
 directly

---
 debian/ghdl-gcc.install   | 1 -
 debian/ghdl-gcc.links     | 3 +++
 debian/ghdl-llvm.install  | 1 -
 debian/ghdl-llvm.links    | 3 +++
 debian/ghdl-mcode.install | 1 -
 debian/ghdl-mcode.links   | 3 +++
 debian/rules              | 3 ---
 7 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/debian/ghdl-gcc.install b/debian/ghdl-gcc.install
index e2383ee6..a76c8645 100644
--- a/debian/ghdl-gcc.install
+++ b/debian/ghdl-gcc.install
@@ -7,6 +7,5 @@ usr/lib/ghdl/gcc/vhdl/*.a
 usr/lib/ghdl/gcc/vhdl/grt.*
 usr/lib/ghdl/gcc/vhdl/grt-*.*
 
-usr/lib/ghdl/gcc/vhdl/src
 usr/lib/ghdl/gcc/vhdl/std
 usr/lib/ghdl/gcc/vhdl/ieee
diff --git a/debian/ghdl-gcc.links b/debian/ghdl-gcc.links
index 6ba63a7b..605c1aca 100644
--- a/debian/ghdl-gcc.links
+++ b/debian/ghdl-gcc.links
@@ -1 +1,4 @@
+# The actual files are provided by the ghdl-common package.
+usr/lib/ghdl/src/                       usr/lib/ghdl/gcc/vhdl/src
+
 usr/share/man/man1/ghdl.1.gz usr/share/man/man1/ghdl-gcc.1.gz
diff --git a/debian/ghdl-llvm.install b/debian/ghdl-llvm.install
index b9abd68e..d2236f97 100644
--- a/debian/ghdl-llvm.install
+++ b/debian/ghdl-llvm.install
@@ -6,6 +6,5 @@ usr/lib/ghdl/llvm/vhdl/*.a
 usr/lib/ghdl/llvm/vhdl/grt.*
 usr/lib/ghdl/llvm/vhdl/grt-*.*
 
-usr/lib/ghdl/llvm/vhdl/src
 usr/lib/ghdl/llvm/vhdl/std
 usr/lib/ghdl/llvm/vhdl/ieee
diff --git a/debian/ghdl-llvm.links b/debian/ghdl-llvm.links
index 52b5924a..00bf63ae 100644
--- a/debian/ghdl-llvm.links
+++ b/debian/ghdl-llvm.links
@@ -1 +1,4 @@
+# The actual files are provided by the ghdl-common package.
+usr/lib/ghdl/src/                       usr/lib/ghdl/llvm/vhdl/src
+
 usr/share/man/man1/ghdl.1.gz usr/share/man/man1/ghdl-llvm.1.gz
diff --git a/debian/ghdl-mcode.install b/debian/ghdl-mcode.install
index 84e7ea12..176179f6 100644
--- a/debian/ghdl-mcode.install
+++ b/debian/ghdl-mcode.install
@@ -1,5 +1,4 @@
 usr/bin/ghdl-mcode
 usr/lib/ghdl/mcode/libghdlvpi.so
-usr/lib/ghdl/mcode/vhdl/src
 usr/lib/ghdl/mcode/vhdl/std
 usr/lib/ghdl/mcode/vhdl/ieee
diff --git a/debian/ghdl-mcode.links b/debian/ghdl-mcode.links
index de694b94..72153f5f 100644
--- a/debian/ghdl-mcode.links
+++ b/debian/ghdl-mcode.links
@@ -1 +1,4 @@
+# The actual files are provided by the ghdl-common package.
+usr/lib/ghdl/src/                       usr/lib/ghdl/mcode/vhdl/src
+
 usr/share/man/man1/ghdl.1.gz usr/share/man/man1/ghdl-mcode.1.gz
diff --git a/debian/rules b/debian/rules
index 9eeff819..62293134 100755
--- a/debian/rules
+++ b/debian/rules
@@ -145,7 +145,6 @@ $(STAMPSDIR)/install-mcode: $(STAMPSDIR)/build-mcode
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	ln -s ../../src debian/tmp/usr/lib/ghdl/mcode/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/mcode/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/mcode/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
@@ -199,7 +198,6 @@ $(STAMPSDIR)/install-llvm: $(STAMPSDIR)/build-llvm
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	ln -s ../../src debian/tmp/usr/lib/ghdl/llvm/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/llvm/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/llvm/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
@@ -287,7 +285,6 @@ $(STAMPSDIR)/install-gcc: $(STAMPSDIR)/build-gcc
 	@echo Moving parts to required locations
 	@echo ------------------------------------------------------------
 	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	ln -s ../../src debian/tmp/usr/lib/ghdl/gcc/vhdl/src
 	mv debian/tmp/usr/lib/ghdl/gcc/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 	mv debian/tmp/usr/lib/ghdl/gcc/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
-- 
2.39.2

>From f369c491b24a22a0e8b832e1c8fb037f745dea11 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 15:53:20 +0200
Subject: [PATCH 05/14] Install shared and static libraries with dh_install
 directly

Refine pattern in ghdl-gcc.install because libghdl-*.so now matches
during the dh_install step.
---
 debian/ghdl-gcc.install      |  3 ++-
 debian/libghdl-3-0-0.install |  3 ++-
 debian/libghdl-dev.install   |  4 +++-
 debian/rules                 | 21 ---------------------
 4 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/debian/ghdl-gcc.install b/debian/ghdl-gcc.install
index a76c8645..77b43184 100644
--- a/debian/ghdl-gcc.install
+++ b/debian/ghdl-gcc.install
@@ -1,6 +1,7 @@
 usr/lib/ghdl/gcc/bin/ghdl-gcc           usr/bin
 usr/lib/ghdl/gcc/lib/gcc/*/*/ghdl1
-usr/lib/ghdl/gcc/*.so
+usr/lib/ghdl/gcc/libghdlvpi.so
+usr/lib/ghdl/gcc/libghw.so
 
 usr/lib/ghdl/gcc/lib/ghdl/libbacktrace.a usr/lib/ghdl/gcc/vhdl
 usr/lib/ghdl/gcc/vhdl/*.a
diff --git a/debian/libghdl-3-0-0.install b/debian/libghdl-3-0-0.install
index 4d03fcb0..022eec3c 100644
--- a/debian/libghdl-3-0-0.install
+++ b/debian/libghdl-3-0-0.install
@@ -1 +1,2 @@
-usr/lib/*/libghdl-*.so
+# The wildcard matches backend(s).
+usr/lib/ghdl/*/libghdl-*.so             usr/lib/${DEB_HOST_MULTIARCH}/
diff --git a/debian/libghdl-dev.install b/debian/libghdl-dev.install
index ea834081..5054a492 100644
--- a/debian/libghdl-dev.install
+++ b/debian/libghdl-dev.install
@@ -1,2 +1,4 @@
-usr/lib/*/libghdl.a
+# The wildcard matches backend(s).
+usr/lib/ghdl/*/libghdl.a                usr/lib/${DEB_HOST_MULTIARCH}/
+
 usr/lib/ghdl/include/ghdl/synth*.h usr/include/ghdl
diff --git a/debian/rules b/debian/rules
index 62293134..d22c4b5d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -140,13 +140,6 @@ $(STAMPSDIR)/install-mcode: $(STAMPSDIR)/build-mcode
 	@echo Installing with mcode backend
 	@echo ------------------------------------------------------------
 	$(MAKE) -C $(BUILDDIR)/mcode install DESTDIR=../../debian/tmp
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Moving parts to required locations
-	@echo ------------------------------------------------------------
-	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	mv debian/tmp/usr/lib/ghdl/mcode/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
-	mv debian/tmp/usr/lib/ghdl/mcode/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
 $(STAMPSDIR)/test-mcode: $(STAMPSDIR)/build-mcode
 	dh_testdir
@@ -193,13 +186,6 @@ $(STAMPSDIR)/install-llvm: $(STAMPSDIR)/build-llvm
 	@echo Installing with llvm backend
 	@echo ------------------------------------------------------------
 	$(MAKE) -C $(BUILDDIR)/llvm install DESTDIR=../../debian/tmp
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Moving parts to required locations
-	@echo ------------------------------------------------------------
-	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	mv debian/tmp/usr/lib/ghdl/llvm/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
-	mv debian/tmp/usr/lib/ghdl/llvm/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
 $(STAMPSDIR)/test-llvm: $(STAMPSDIR)/build-llvm
 	dh_testdir
@@ -280,13 +266,6 @@ $(STAMPSDIR)/install-gcc: $(STAMPSDIR)/build-gcc
 	ln -sf ../lib/ghdl/gcc/bin/ghdl-gcc $(CURDIR)/debian/tmp/usr/bin/ghdl-gcc
 	$(MAKE) -C $(BUILDDIR)/gcc/build install DESTDIR=$(CURDIR)/debian/tmp
 	$(MAKE) -C $(BUILDDIR)/gcc install DESTDIR=$(CURDIR)/debian/tmp
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Moving parts to required locations
-	@echo ------------------------------------------------------------
-	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	mv debian/tmp/usr/lib/ghdl/gcc/libghdl-*.so debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
-	mv debian/tmp/usr/lib/ghdl/gcc/libghdl.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
 
 $(STAMPSDIR)/test-gcc: $(STAMPSDIR)/build-gcc
 	dh_testdir
-- 
2.39.2

>From e083dd106fa7acc8ef54ead386cd83857e72e86b Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 14:41:22 +0200
Subject: [PATCH 06/14] debian/rules: replace shell constructs with Make
 equivalents

Prefer Make variables and conditionals to shell constructs so that the
log explicitly shows what is executed.

Prefer a separate recipe line for each command, so that each exit
status is checked, and comments can be inserted.
---
 debian/rules | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/debian/rules b/debian/rules
index d22c4b5d..3ae0ffaa 100755
--- a/debian/rules
+++ b/debian/rules
@@ -205,6 +205,10 @@ $(STAMPSDIR)/test-llvm: $(STAMPSDIR)/build-llvm
 	touch $@
 
 
+gcc_local_patches_dir := debian/gcc-patches/gcc-$(DEB_GNAT_VERSION)
+# Ignore comment lines, extensions like .diff and options like -p0.
+gcc_local_patches != sed '/^\#/d; s/\..*//' $(gcc_local_patches_dir)/series
+
 $(STAMPSDIR)/configure-gcc:
 	dh_testdir
 	mkdir -p $(BUILDDIR)/gcc $(STAMPSDIR)
@@ -216,23 +220,24 @@ $(STAMPSDIR)/configure-gcc:
 	# We have to disable the gcc-verbose-lto-link patch since it replaces
 	# the LLINKER value with one that runs the linker under /usr/bin/time
 	# and the spaces are not escaped properly somewhere on the ghdl side.
-	set -e && \
+	ln -fs ${GCC_DIR}/gcc-*.tar.* $(BUILDDIR)/gcc
+	cp -a ${GCC_DIR}/debian/ $(BUILDDIR)/gcc
+  ifneq (,$(gcc_local_patches))
+	cp -n $(gcc_local_patches_dir)/*.diff $(BUILDDIR)/gcc/debian/patches/
+	cat $(gcc_local_patches_dir)/series >> $(BUILDDIR)/gcc/debian/patches/series
+	sed -i \
+	  "s/\(^series_stamp.*\)/debian_patches += $(gcc_local_patches)\n\n\1/" \
+	  $(BUILDDIR)/gcc/debian/rules.patch
+  endif
+	echo -n > $(BUILDDIR)/gcc/debian/patches/gcc-verbose-lto-link.diff
+	$(MAKE) -C$(BUILDDIR)/gcc -fdebian/rules patch
 	cd $(BUILDDIR)/gcc && \
-	ln -sf ${GCC_DIR}/gcc-*.tar.* && \
-	cp -a  ${GCC_DIR}/debian/ . && \
-	if [ -n "$$(grep -v '^\#' ${CURDIR}/debian/gcc-patches/gcc-${DEB_GNAT_VERSION}/series)" ]; then \
-		cp -n ${CURDIR}/debian/gcc-patches/gcc-${DEB_GNAT_VERSION}/*.diff debian/patches/  && \
-		cat ${CURDIR}/debian/gcc-patches/gcc-${DEB_GNAT_VERSION}/series >> debian/patches/series  && \
-		sed -i "s/\(^series_stamp.*\)/debian_patches += $$(grep -v '^#' ${CURDIR}/debian/gcc-patches/gcc-$(DEB_GNAT_VERSION)/series|sed 's/\..*//'|tr '\n' ' ')\n\n\1/" debian/rules.patch ; \
-	fi && \
-	echo -n > $(BUILDDIR)/gcc/debian/patches/gcc-verbose-lto-link.diff && \
-	debian/rules patch && \
 	../../configure --srcdir=../.. $(common_configure_arguments) \
 		--libdir=lib/ghdl/gcc \
 		--libghdldir=lib/ghdl/gcc/vhdl \
-		--with-gcc=src && \
-	make copy-sources && \
-	$(MAKE) -f debian/rules2 configure PF=usr/lib/ghdl/gcc with_bootstrap=off \
+		--with-gcc=src
+	make -C$(BUILDDIR)/gcc copy-sources
+	$(MAKE) -C$(BUILDDIR)/gcc -f debian/rules2 configure PF=usr/lib/ghdl/gcc with_bootstrap=off \
 		with_cc1=no with_dev=no separate_lang=yes enabled_languages=vhdl \
 		with_common_libs=no with_common_pkgs=no \
 		with_check="skipped for GHDL build"
-- 
2.39.2

>From 09e40665f28cd433365f6b1f10e6670d1d4a4559 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Sun, 1 Oct 2023 01:14:25 +0200
Subject: [PATCH 07/14] Delegate computation of Built-Using to dh-builtusing

---
 debian/control | 7 ++++---
 debian/rules   | 9 ---------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/debian/control b/debian/control
index 0e19560e..a354cf0d 100644
--- a/debian/control
+++ b/debian/control
@@ -5,6 +5,7 @@ Maintainer: Debian Electronics Team <pkg-electronics-devel@lists.alioth.debian.o
 Uploaders: Andreas Bombe <a...@debian.org>
 Build-Depends: debhelper-compat (= 13),
                dh-ada-library (>= 8.1),
+               dh-sequence-builtusing,
                gnat-12, gcc-12, g++-12,
                gcc-12-source <!pkg.ghdl.nogcc>,
                libisl-dev (>= 0.14) <!pkg.ghdl.nogcc>,
@@ -80,7 +81,7 @@ Description: VHDL compiler/simulator (mcode backend)
 Package: ghdl-gcc
 Architecture: any
 Build-Profiles: <!pkg.ghdl.nogcc>
-Built-Using: ${Built-Using-GCC}
+Built-Using: ${dh-builtusing:gcc-S-source}
 Depends: ghdl-common (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends},
 	gcc, zlib1g-dev
 Description: VHDL compiler/simulator (GCC backend)
@@ -122,7 +123,7 @@ Description: VHDL compiler/simulator (tools)
 
 Package: libghdl-3-0-0
 Architecture: any
-Built-Using: ${Built-Using-GCC}
+Built-Using: ${dh-builtusing:gcc-S-source} <!pkg.ghdl.nogcc>
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Multi-Arch: same
 Description: VHDL compiler/simulator (shared library)
@@ -135,7 +136,7 @@ Description: VHDL compiler/simulator (shared library)
 
 Package: libghdl-dev
 Architecture: any
-Built-Using: ${Built-Using-GCC}
+Built-Using: ${dh-builtusing:gcc-S-source} <!pkg.ghdl.nogcc>
 Depends: libghdl-3-0-0 (= ${binary:Version}), ${misc:Depends}
 Multi-Arch: same
 Description: VHDL compiler/simulator (library development files)
diff --git a/debian/rules b/debian/rules
index 3ae0ffaa..91b50e6a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -102,15 +102,6 @@ override_dh_strip:
 	dh_strip -N libghdl-3-0-0
 	dh_strip -p libghdl-3-0-0 --dbgsym-migration='libghdl-2-0-0'
 
-override_dh_gencontrol:
-ifneq ($(filter gcc,$(BACKENDS)),)
-	dh_gencontrol -- -VBuilt-Using-GCC="$(shell dpkg-query -f '$${Source} (= $${Version})' -W gcc-$(DEB_GNAT_VERSION)-source)"
-else
-	dh_gencontrol
-endif
-
-
-
 $(STAMPSDIR)/configure-mcode:
 	dh_testdir
 	mkdir -p $(BUILDDIR)/mcode $(STAMPSDIR)
-- 
2.39.2

>From 4ed89022672a4b225b695a02550c64ca25548253 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Sat, 31 Dec 2022 13:26:58 +0100
Subject: [PATCH 08/14] Drop obsolete gcc-10 patch

---
 debian/gcc-patches/gcc-10/fix_ghdl_ppc64.diff | 42 -------------------
 debian/gcc-patches/gcc-10/series              |  1 -
 2 files changed, 43 deletions(-)
 delete mode 100644 debian/gcc-patches/gcc-10/fix_ghdl_ppc64.diff
 delete mode 100644 debian/gcc-patches/gcc-10/series

diff --git a/debian/gcc-patches/gcc-10/fix_ghdl_ppc64.diff b/debian/gcc-patches/gcc-10/fix_ghdl_ppc64.diff
deleted file mode 100644
index 45e9c845..00000000
--- a/debian/gcc-patches/gcc-10/fix_ghdl_ppc64.diff
+++ /dev/null
@@ -1,42 +0,0 @@
-Description: Fix ppc64* FTBFS of ghdl's gcc backend
- On Power, ghdl fails to build from source with the following error :
-
-/<<BUILDDIR>>/ghdl-0.35+git20180503+dfsg/builddir/gcc/gccbuild/gcc/ghdl -a --GHDL1=/<<BUILDDIR>>/ghdl-0.35+git20180503+dfsg/builddir/gcc/gccbuild/gcc/ghdl1 --std=87 --bootstrap --work=std ../../src/std/textio.v87
-/<<BUILDDIR>>/ghdl-0.35+git20180503+dfsg/builddir/gcc/lib/ghdl/gcc/std/v87/../../src/std/textio.v87: In function 'std__textio__ELAB_SPEC':
-/<<BUILDDIR>>/ghdl-0.35+git20180503+dfsg/builddir/gcc/lib/ghdl/gcc/std/v87/../../src/std/textio.v87:1:0: internal compiler error: in rs6000_output_function_epilogue, at config/rs6000/rs6000.c:31660
- --  Std.Textio package declaration.  This file is part of GHDL.
- 
-0x10a330ef rs6000_output_function_epilogue
-	../../src/gcc/config/rs6000/rs6000.c:31660
-0x103723c7 final_end_function()
-	../../src/gcc/final.c:1919
-0x10377777 rest_of_handle_final
-	../../src/gcc/final.c:4492
-0x10377777 execute
-	../../src/gcc/final.c:4562
-Please submit a full bug report,
-with preprocessed source if appropriate.
-Please include the complete backtrace with any bug report.
-See <https://gcc.gnu.org/bugs/> for instructions.
-/<<BUILDDIR>>/ghdl-0.35+git20180503+dfsg/builddir/gcc/gccbuild/gcc/ghdl: exec error
-
- It seems that Power specific code rs6000.c has no knowledge of the language_string/lang_hooks.name
- which is defined in ortho-lang-7.c:#define LANG_HOOKS_NAME "vhdl"
- So adding vhdl in the language type searching. Not sure though if 0 is correct.
-Author: Frédéric Bonnard <fre...@debian.org>
----
-This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
-Index: gcc/src/gcc/config/rs6000/rs6000.c
-===================================================================
---- gcc.orig/src/gcc/config/rs6000/rs6000-logue.c	2020-12-05 11:27:23.979679736 +0000
-+++ gcc/src/gcc/config/rs6000/rs6000-logue.c	2020-12-05 11:28:09.323595170 +0000
-@@ -5268,7 +5268,8 @@ rs6000_output_function_epilogue (FILE *f
- 	  || ! strcmp (language_string, "GNU GIMPLE")
- 	  || ! strcmp (language_string, "GNU Go")
- 	  || ! strcmp (language_string, "GNU D")
--	  || ! strcmp (language_string, "libgccjit"))
-+	  || ! strcmp (language_string, "libgccjit")
-+	  || ! strcmp (language_string, "vhdl"))
- 	i = 0;
-       else if (! strcmp (language_string, "GNU F77")
- 	       || lang_GNU_Fortran ())
diff --git a/debian/gcc-patches/gcc-10/series b/debian/gcc-patches/gcc-10/series
deleted file mode 100644
index c3182338..00000000
--- a/debian/gcc-patches/gcc-10/series
+++ /dev/null
@@ -1 +0,0 @@
-fix_ghdl_ppc64.diff -p3
-- 
2.39.2

>From abfc77826c0a3cc8b91e7151bf3ec9928b793112 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 15:18:07 +0200
Subject: [PATCH 09/14] Store stamp files in the current directory

Dh_clean removes them by default, and they are convenient to directly
run a target during development.

The new targets have a sensible length, there is no need for a
shortcut anymore.

Adapt the name of the install target.
---
 debian/rules | 62 ++++++++++++++++------------------------------------
 1 file changed, 19 insertions(+), 43 deletions(-)

diff --git a/debian/rules b/debian/rules
index 91b50e6a..9ce5a768 100755
--- a/debian/rules
+++ b/debian/rules
@@ -40,7 +40,6 @@ endif
 
 BUILDDIR := $(CURDIR)/builddir
 TESTRUNDIR := $(CURDIR)/testrundir
-STAMPSDIR := $(BUILDDIR)/stamps
 
 # Common arguments for all calls to ./configure.
 # The order is the same than there.
@@ -82,11 +81,10 @@ override_dh_installdocs:
 	dh_installdocs -pghdl -pghdl-mcode -pghdl-llvm -pghdl-gcc --link-doc=ghdl-common
 	dh_installdocs --remaining-packages
 
-override_dh_auto_configure: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/configure-$(backend))
-
-override_dh_auto_build: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/build-$(backend))
-
-override_dh_auto_install: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/install-$(backend))
+override_dh_auto_configure: $(BACKENDS:%=configure-%-stamp)
+override_dh_auto_build    : $(BACKENDS:%=build-%-stamp)
+override_dh_auto_install  : $(BACKENDS:%=install-%)
+override_dh_auto_test     : $(BACKENDS:%=test-%-stamp)
 
 override_dh_dwz:
 	# dwz currently has problems with some debug sections created by the
@@ -96,15 +94,13 @@ override_dh_dwz:
 	# libghdlvpi.so and runs into assertions, so disable it altogether for
 	# now.
 
-override_dh_auto_test: $(foreach backend,$(BACKENDS),$(STAMPSDIR)/test-$(backend))
-
 override_dh_strip:
 	dh_strip -N libghdl-3-0-0
 	dh_strip -p libghdl-3-0-0 --dbgsym-migration='libghdl-2-0-0'
 
-$(STAMPSDIR)/configure-mcode:
+configure-mcode-stamp:
 	dh_testdir
-	mkdir -p $(BUILDDIR)/mcode $(STAMPSDIR)
+	mkdir -p $(BUILDDIR)/mcode
 	@echo
 	@echo ------------------------------------------------------------
 	@echo Configuring with mcode backend
@@ -115,7 +111,7 @@ $(STAMPSDIR)/configure-mcode:
 		--libghdldir=lib/ghdl/mcode/vhdl
 	touch $@
 
-$(STAMPSDIR)/build-mcode: $(STAMPSDIR)/configure-mcode
+build-mcode-stamp: configure-mcode-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -124,7 +120,7 @@ $(STAMPSDIR)/build-mcode: $(STAMPSDIR)/configure-mcode
 	$(MAKE) -C $(BUILDDIR)/mcode
 	touch $@
 
-$(STAMPSDIR)/install-mcode: $(STAMPSDIR)/build-mcode
+install-mcode: build-mcode-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -132,7 +128,7 @@ $(STAMPSDIR)/install-mcode: $(STAMPSDIR)/build-mcode
 	@echo ------------------------------------------------------------
 	$(MAKE) -C $(BUILDDIR)/mcode install DESTDIR=../../debian/tmp
 
-$(STAMPSDIR)/test-mcode: $(STAMPSDIR)/build-mcode
+test-mcode-stamp: build-mcode-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -147,9 +143,9 @@ $(STAMPSDIR)/test-mcode: $(STAMPSDIR)/build-mcode
 	touch $@
 
 
-$(STAMPSDIR)/configure-llvm:
+configure-llvm-stamp:
 	dh_testdir
-	mkdir -p $(BUILDDIR)/llvm $(STAMPSDIR)
+	mkdir -p $(BUILDDIR)/llvm
 	@echo
 	@echo ------------------------------------------------------------
 	@echo Configuring with llvm backend
@@ -161,7 +157,7 @@ $(STAMPSDIR)/configure-llvm:
 		--with-llvm-config
 	touch $@
 
-$(STAMPSDIR)/build-llvm: $(STAMPSDIR)/configure-llvm
+build-llvm-stamp: configure-llvm-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -170,7 +166,7 @@ $(STAMPSDIR)/build-llvm: $(STAMPSDIR)/configure-llvm
 	$(MAKE) -C $(BUILDDIR)/llvm
 	touch $@
 
-$(STAMPSDIR)/install-llvm: $(STAMPSDIR)/build-llvm
+install-llvm: build-llvm-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -178,7 +174,7 @@ $(STAMPSDIR)/install-llvm: $(STAMPSDIR)/build-llvm
 	@echo ------------------------------------------------------------
 	$(MAKE) -C $(BUILDDIR)/llvm install DESTDIR=../../debian/tmp
 
-$(STAMPSDIR)/test-llvm: $(STAMPSDIR)/build-llvm
+test-llvm-stamp: build-llvm-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -200,9 +196,9 @@ gcc_local_patches_dir := debian/gcc-patches/gcc-$(DEB_GNAT_VERSION)
 # Ignore comment lines, extensions like .diff and options like -p0.
 gcc_local_patches != sed '/^\#/d; s/\..*//' $(gcc_local_patches_dir)/series
 
-$(STAMPSDIR)/configure-gcc:
+configure-gcc-stamp:
 	dh_testdir
-	mkdir -p $(BUILDDIR)/gcc $(STAMPSDIR)
+	mkdir -p $(BUILDDIR)/gcc
 	@echo
 	@echo ------------------------------------------------------------
 	@echo Configuring with gcc backend
@@ -234,7 +230,7 @@ $(STAMPSDIR)/configure-gcc:
 		with_check="skipped for GHDL build"
 	touch $@
 
-$(STAMPSDIR)/build-gcc: $(STAMPSDIR)/configure-gcc
+build-gcc-stamp: configure-gcc-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -249,7 +245,7 @@ $(STAMPSDIR)/build-gcc: $(STAMPSDIR)/configure-gcc
 		GHDL1_GCC_BIN="--GHDL1=$(BUILDDIR)/gcc/build/gcc/ghdl1"
 	touch $@
 
-$(STAMPSDIR)/install-gcc: $(STAMPSDIR)/build-gcc
+install-gcc: build-gcc-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -263,7 +259,7 @@ $(STAMPSDIR)/install-gcc: $(STAMPSDIR)/build-gcc
 	$(MAKE) -C $(BUILDDIR)/gcc/build install DESTDIR=$(CURDIR)/debian/tmp
 	$(MAKE) -C $(BUILDDIR)/gcc install DESTDIR=$(CURDIR)/debian/tmp
 
-$(STAMPSDIR)/test-gcc: $(STAMPSDIR)/build-gcc
+test-gcc-stamp: build-gcc-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
@@ -288,23 +284,3 @@ $(STAMPSDIR)/test-gcc: $(STAMPSDIR)/build-gcc
 	ln -sf ghdl/gcc/lib/gcc $(TESTRUNDIR)/gcc/usr/lib/gcc
 	debian/tests/ghdl-tests buildtest gcc
 	touch $@
-
-
-# convenience targets for development
-configure-mcode: $(STAMPSDIR)/configure-mcode
-build-mcode: $(STAMPSDIR)/build-mcode
-install-mcode: $(STAMPSDIR)/install-mcode
-test-mcode: $(STAMPSDIR)/test-mcode
-.PHONY: configure-mcode build-mcode install-mcode test-mcode
-
-configure-llvm: $(STAMPSDIR)/configure-llvm
-build-llvm: $(STAMPSDIR)/build-llvm
-install-llvm: $(STAMPSDIR)/install-llvm
-test-llvm: $(STAMPSDIR)/test-llvm
-.PHONY: configure-llvm build-llvm install-llvm test-llvm
-
-configure-gcc: $(STAMPSDIR)/configure-gcc
-build-gcc: $(STAMPSDIR)/build-gcc
-install-gcc: $(STAMPSDIR)/install-gcc
-test-gcc: $(STAMPSDIR)/test-gcc
-.PHONY: configure-gcc build-gcc install-gcc test-gcc
-- 
2.39.2

>From 2439a62ec2d43a7b2df39a40ca0c8c8d9d375bf0 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Mon, 2 Oct 2023 16:26:05 +0200
Subject: [PATCH 10/14] Slightly simplify the backend selection with build
 profiles

---
 debian/rules | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/debian/rules b/debian/rules
index 9ce5a768..d15f38c8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -19,24 +19,14 @@ export GHDL_VER_DESC := $(DEB_VENDOR) $(DEB_VERSION)
 # are already parallelized by code included from debian_packaging-*.mk above).
 MAKEPARALLEL = $(DEB_BUILD_OPTION_PARALLEL:%=-j%)
 
-# List of the ghdl backends to build
-BACKENDS := mcode llvm gcc
+# Mcode is only supported on x86 architectures.
+all_backends := gcc llvm $(and $(filter amd64 i386,$(DEB_HOST_ARCH_CPU)),mcode)
 
 # build profile control over what backends get built
-ifneq ($(filter pkg.ghdl.nomcode,$(DEB_BUILD_PROFILES)),)
-    BACKENDS := $(filter-out mcode,$(BACKENDS))
-endif
-ifneq ($(filter pkg.ghdl.nollvm,$(DEB_BUILD_PROFILES)),)
-    BACKENDS := $(filter-out llvm,$(BACKENDS))
-endif
-ifneq ($(filter pkg.ghdl.nogcc,$(DEB_BUILD_PROFILES)),)
-    BACKENDS := $(filter-out gcc,$(BACKENDS))
-endif
+pkg.ghdl.no_profiles := $(filter pkg.ghdl.no%,$(DEB_BUILD_PROFILES))
 
-# force disable mcode build on non-x86 architectures where it isn't supported
-ifeq ($(filter amd64 i386,$(DEB_HOST_ARCH_CPU)),)
-    BACKENDS := $(filter-out mcode,$(BACKENDS))
-endif
+# Built backends.
+BACKENDS := $(filter-out $(pkg.ghdl.no_profiles:pkg.ghdl.no%=%),$(all_backends))
 
 BUILDDIR := $(CURDIR)/builddir
 TESTRUNDIR := $(CURDIR)/testrundir
-- 
2.39.2

>From cfccfea4fadedf7d85f9ef3a89b1bf7c4743fc29 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Thu, 5 Oct 2023 16:30:47 +0200
Subject: [PATCH 11/14] Merge recipes for llvm and mcode, inhibit llvm tests in
 test script

---
 debian/rules            | 83 +++++++++--------------------------------
 debian/tests/ghdl-tests | 15 +++++++-
 2 files changed, 31 insertions(+), 67 deletions(-)

diff --git a/debian/rules b/debian/rules
index d15f38c8..37bae8cb 100755
--- a/debian/rules
+++ b/debian/rules
@@ -88,100 +88,51 @@ override_dh_strip:
 	dh_strip -N libghdl-3-0-0
 	dh_strip -p libghdl-3-0-0 --dbgsym-migration='libghdl-2-0-0'
 
-configure-mcode-stamp:
+configure-llvm-stamp configure-mcode-stamp: configure-%-stamp:
 	dh_testdir
-	mkdir -p $(BUILDDIR)/mcode
+	mkdir -p $(BUILDDIR)/$*
 	@echo
 	@echo ------------------------------------------------------------
-	@echo Configuring with mcode backend
+	@echo Configuring with $* backend
 	@echo ------------------------------------------------------------
-	cd $(BUILDDIR)/mcode && \
+	cd $(BUILDDIR)/$* && \
 	../../configure --srcdir=../.. $(common_configure_arguments) \
-		--libdir=lib/ghdl/mcode \
-		--libghdldir=lib/ghdl/mcode/vhdl
+		--libdir=lib/ghdl/$* \
+		--libghdldir=lib/ghdl/$*/vhdl
 	touch $@
+configure-llvm-stamp: common_configure_arguments += --with-llvm-config
 
-build-mcode-stamp: configure-mcode-stamp
+build-llvm-stamp build-mcode-stamp: build-%-stamp: configure-%-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
-	@echo Building with mcode backend
+	@echo Building with $* backend
 	@echo ------------------------------------------------------------
-	$(MAKE) -C $(BUILDDIR)/mcode
+	$(MAKE) -C $(BUILDDIR)/$*
 	touch $@
 
-install-mcode: build-mcode-stamp
+install-llvm install-mcode: install-%: build-%-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
-	@echo Installing with mcode backend
+	@echo Installing with $* backend
 	@echo ------------------------------------------------------------
-	$(MAKE) -C $(BUILDDIR)/mcode install DESTDIR=../../debian/tmp
+	$(MAKE) -C $(BUILDDIR)/$* install DESTDIR=../../debian/tmp
 
-test-mcode-stamp: build-mcode-stamp
+test-llvm-stamp test-mcode-stamp: test-%-stamp: build-%-stamp
 	dh_testdir
 	@echo
 	@echo ------------------------------------------------------------
-	@echo Run testsuite for mcode backend
+	@echo Run testsuite for $* backend
 	@echo ------------------------------------------------------------
 	# With some paths patched for the Debian packaging, the tests will not
 	# work right when run from the build directory. To keep it simple
 	# install into a temporary location and tell the testsuite to find ghdl
 	# there.
-	$(MAKE) -C $(BUILDDIR)/mcode install DESTDIR=$(TESTRUNDIR)/mcode
-	debian/tests/ghdl-tests buildtest mcode
+	$(MAKE) -C $(BUILDDIR)/$* install DESTDIR=$(TESTRUNDIR)/$*
+	debian/tests/ghdl-tests buildtest $*
 	touch $@
 
-
-configure-llvm-stamp:
-	dh_testdir
-	mkdir -p $(BUILDDIR)/llvm
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Configuring with llvm backend
-	@echo ------------------------------------------------------------
-	cd $(BUILDDIR)/llvm && \
-	../../configure --srcdir=../.. $(common_configure_arguments) \
-		--libdir=lib/ghdl/llvm \
-		--libghdldir=lib/ghdl/llvm/vhdl \
-		--with-llvm-config
-	touch $@
-
-build-llvm-stamp: configure-llvm-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Building with llvm backend
-	@echo ------------------------------------------------------------
-	$(MAKE) -C $(BUILDDIR)/llvm
-	touch $@
-
-install-llvm: build-llvm-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Installing with llvm backend
-	@echo ------------------------------------------------------------
-	$(MAKE) -C $(BUILDDIR)/llvm install DESTDIR=../../debian/tmp
-
-test-llvm-stamp: build-llvm-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Run testsuite for llvm backend
-	@echo ------------------------------------------------------------
-	# With some paths patched for the Debian packaging, the tests will not
-	# work right when run from the build directory. To keep it simple
-	# install into a temporary location and tell the testsuite to find ghdl
-	# there.
-	$(MAKE) -C $(BUILDDIR)/llvm install DESTDIR=$(TESTRUNDIR)/llvm
-	# Temporarily make LLVM backend testsuite failure non-fatal to more
-	# easily collect data for investigating the PSL testsuite failures on
-	# some architectures
-	-debian/tests/ghdl-tests buildtest llvm
-	touch $@
-
-
 gcc_local_patches_dir := debian/gcc-patches/gcc-$(DEB_GNAT_VERSION)
 # Ignore comment lines, extensions like .diff and options like -p0.
 gcc_local_patches != sed '/^\#/d; s/\..*//' $(gcc_local_patches_dir)/series
diff --git a/debian/tests/ghdl-tests b/debian/tests/ghdl-tests
index df1881f6..5868e16c 100755
--- a/debian/tests/ghdl-tests
+++ b/debian/tests/ghdl-tests
@@ -43,4 +43,17 @@ mkdir -p "$RUNDIR/src"
 cp -r src/grt "$RUNDIR/src"
 
 export GHDL
-(cd "$RUNDIR/testsuite"; ./testsuite.sh $TESTS -- --keep-going)
+
+cd "$RUNDIR/testsuite"
+
+# Temporarily make LLVM backend testsuite failure non-fatal to more
+# easily collect data for investigating the PSL testsuite failures on
+# some architectures
+if ./testsuite.sh $TESTS -- --keep-going; then
+    echo "Tests for backend $BACKEND passed."
+elif test $BACKEND = llvm; then
+    echo "Tests for backend llvm failed (but ignored for now)."
+else
+    echo >&2 "Tests for backend $BACKEND failed."
+    exit 1
+fi
-- 
2.39.2

>From 6b909b937eb31e6e0bc7069ebc2548448143ebbb Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Thu, 5 Oct 2023 14:39:35 +0200
Subject: [PATCH 12/14] Various minor improvements in the test driver

Enable more alerts by the shell.

Check the argument count.

Replace test cascades with 'case' constructs.

There is no need to create RUNDIR because the script is called after a
'make install'.

There is no need to check that the RUNDIR variable is not empty, it is
set in all branches of the previous construct.
---
 debian/tests/ghdl-tests | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/debian/tests/ghdl-tests b/debian/tests/ghdl-tests
index 5868e16c..871d594b 100755
--- a/debian/tests/ghdl-tests
+++ b/debian/tests/ghdl-tests
@@ -1,39 +1,35 @@
 #!/bin/sh
 
-set -e
+set -C -e -f -u
 
 # The pyunit tests are not run here. These parts are not activated in
 # Debian yet.
 TESTS="sanity gna vests synth vpi vhpi"
 
+test $# = 2
 
-if [ "$2" = mcode ]; then
-	BACKEND=mcode
-elif [ "$2" = llvm ]; then
-	BACKEND=llvm
-elif [ "$2" = gcc ]; then
-	BACKEND=gcc
-else
+case "$2" in
+    gcc|llvm|mcode)
+	BACKEND=$2
+	;;
+    *)
 	echo >&2 "Invalid backend specification"
 	exit 1
-fi
+esac
 
-if [ "$1" = buildtest ]; then
+case "$1" in
+    buildtest)
 	RUNDIR=testrundir/$BACKEND
-	mkdir -p "$RUNDIR"
 	GHDL="$PWD/$RUNDIR/usr/bin/ghdl-$BACKEND"
-elif [ "$1" = autopkgtest ]; then
+	;;
+    autopkgtest)
 	RUNDIR="$AUTOPKGTEST_TMP"
 	GHDL=/usr/bin/ghdl-$BACKEND
-else
+	;;
+    *)
 	echo >&2 "Invalid test environment specification"
 	exit 1
-fi
-
-if [ -z "$RUNDIR" ]; then
-	echo >&2 "RUNDIR is empty string"
-	exit 1
-fi
+esac
 
 # Copy testsuite into $RUNDIR to execute there, so that no cleanup is necessary
 # (entire $RUNDIR will be deleted later). Also copy src/grt as at least one test
-- 
2.39.2

>From cd3d7967d64f89440eec90e270af116a830792e9 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Thu, 5 Oct 2023 17:47:14 +0200
Subject: [PATCH 13/14] Share the debian/rules snippet announcing the current
 Make target

---
 debian/rules | 55 ++++++++++++++--------------------------------------
 1 file changed, 15 insertions(+), 40 deletions(-)

diff --git a/debian/rules b/debian/rules
index 37bae8cb..138b8581 100755
--- a/debian/rules
+++ b/debian/rules
@@ -50,6 +50,13 @@ common_configure_arguments := \
   --enable-gplcompat \
  # EOL
 
+define announce
+	dh_testdir
+	@echo
+	@echo '------------------------------------------------------------'
+	@echo 'About to run Make target: $@'
+	@echo '------------------------------------------------------------'
+endef
 
 %:
 ifneq (,$(findstring $(shell dpkg-architecture -qDEB_HOST_ARCH), s390x))
@@ -89,12 +96,8 @@ override_dh_strip:
 	dh_strip -p libghdl-3-0-0 --dbgsym-migration='libghdl-2-0-0'
 
 configure-llvm-stamp configure-mcode-stamp: configure-%-stamp:
-	dh_testdir
+	$(announce)
 	mkdir -p $(BUILDDIR)/$*
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Configuring with $* backend
-	@echo ------------------------------------------------------------
 	cd $(BUILDDIR)/$* && \
 	../../configure --srcdir=../.. $(common_configure_arguments) \
 		--libdir=lib/ghdl/$* \
@@ -103,28 +106,16 @@ configure-llvm-stamp configure-mcode-stamp: configure-%-stamp:
 configure-llvm-stamp: common_configure_arguments += --with-llvm-config
 
 build-llvm-stamp build-mcode-stamp: build-%-stamp: configure-%-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Building with $* backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	$(MAKE) -C $(BUILDDIR)/$*
 	touch $@
 
 install-llvm install-mcode: install-%: build-%-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Installing with $* backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	$(MAKE) -C $(BUILDDIR)/$* install DESTDIR=../../debian/tmp
 
 test-llvm-stamp test-mcode-stamp: test-%-stamp: build-%-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Run testsuite for $* backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	# With some paths patched for the Debian packaging, the tests will not
 	# work right when run from the build directory. To keep it simple
 	# install into a temporary location and tell the testsuite to find ghdl
@@ -138,12 +129,8 @@ gcc_local_patches_dir := debian/gcc-patches/gcc-$(DEB_GNAT_VERSION)
 gcc_local_patches != sed '/^\#/d; s/\..*//' $(gcc_local_patches_dir)/series
 
 configure-gcc-stamp:
-	dh_testdir
+	$(announce)
 	mkdir -p $(BUILDDIR)/gcc
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Configuring with gcc backend
-	@echo ------------------------------------------------------------
 	# gcc unpack sequence cribbed from gcc-7-cross debian/rules
 	# We have to disable the gcc-verbose-lto-link patch since it replaces
 	# the LLINKER value with one that runs the linker under /usr/bin/time
@@ -172,11 +159,7 @@ configure-gcc-stamp:
 	touch $@
 
 build-gcc-stamp: configure-gcc-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Building with gcc backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	$(MAKE) $(MAKEPARALLEL) -C $(BUILDDIR)/gcc/build
 	# For some reason, on the i386 architecture only, it decides to delete
 	# one important build result. Just rerun make as a workaround.
@@ -187,11 +170,7 @@ build-gcc-stamp: configure-gcc-stamp
 	touch $@
 
 install-gcc: build-gcc-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Installing with gcc backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	# Place a symlink for the binary ahead of time so that the compilation
 	# of the VHDL standard libraries works during the gcc install step. The
 	# binary is properly moved afterwards.
@@ -201,11 +180,7 @@ install-gcc: build-gcc-stamp
 	$(MAKE) -C $(BUILDDIR)/gcc install DESTDIR=$(CURDIR)/debian/tmp
 
 test-gcc-stamp: build-gcc-stamp
-	dh_testdir
-	@echo
-	@echo ------------------------------------------------------------
-	@echo Run testsuite for gcc backend
-	@echo ------------------------------------------------------------
+	$(announce)
 	# With some paths patched for the Debian packaging, the tests will not
 	# work right when run from the build directory. To keep it simple
 	# install into a temporary location and tell the testsuite to find ghdl
-- 
2.39.2

>From 1ade1b2c5e3e8e5a64782ef13347c4bd854615b4 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nico...@debian.org>
Date: Wed, 11 Oct 2023 08:36:22 +0200
Subject: [PATCH 14/14] debian/control: remove unused shlibs:Depends
 substitution variable

---
 debian/control | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index a354cf0d..545c44b4 100644
--- a/debian/control
+++ b/debian/control
@@ -55,7 +55,7 @@ Description: VHDL compiler/simulator
 
 Package: ghdl-common
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${misc:Depends}
 Breaks: ghdl (<< 0.37+dfsg2)
 Replaces: ghdl (<< 0.37+dfsg2)
 Description: VHDL compiler/simulator (common files)
-- 
2.39.2

Reply via email to