From 04011f284dcf23f1ac8e2adc13ddd4f58adf3f47 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sun, 11 Sep 2022 01:06:16 +0200
Subject: [PATCH] testing/libabigail: new aport

---
 .../0001-Find-fts-standalone-on-musl.patch    | 107 ++++++++++++++++++
 testing/libabigail/APKBUILD                   | 107 ++++++++++++++++++
 testing/libabigail/apk.patch                  |  16 +++
 testing/libabigail/musl-compat.patch          |  10 ++
 testing/libabigail/musl-fts.patch             |  11 ++
 5 files changed, 251 insertions(+)
 create mode 100644 testing/libabigail/0001-Find-fts-standalone-on-musl.patch
 create mode 100644 testing/libabigail/APKBUILD
 create mode 100644 testing/libabigail/apk.patch
 create mode 100644 testing/libabigail/musl-compat.patch
 create mode 100644 testing/libabigail/musl-fts.patch

diff --git a/testing/libabigail/0001-Find-fts-standalone-on-musl.patch b/testing/libabigail/0001-Find-fts-standalone-on-musl.patch
new file mode 100644
index 000000000000..9423601626e8
--- /dev/null
+++ b/testing/libabigail/0001-Find-fts-standalone-on-musl.patch
@@ -0,0 +1,107 @@
+Patch-Source: https://sourceware.org/git/?p=libabigail.git;a=commit;h=11987989859520541d785c0b3129b562b6672d4c
+--
+From 11987989859520541d785c0b3129b562b6672d4c Mon Sep 17 00:00:00 2001
+From: David Seifert <soap@gentoo.org>
+Date: Sat, 29 Jan 2022 20:31:07 +0100
+Subject: [PATCH] Find fts-standalone on musl
+
+When using the musl C library fts is optional.  So we need to detect
+its presence by looking at the fts-standalone pkgconfig module.
+
+This patch does that.
+
+This comes from Gentoo bug https://bugs.gentoo.org/831571
+
+	* configure.ac: Invoke AC_CANONICAL_HOST to compute the host_cpu,
+	host_vendor, host_os parts of the 'host" variable.  Then if the
+	host_os ends up with "musl" then, check for the fts-standalone
+	pkgconfig module and record the fts library into
+	FTS_{LIBS,CFLAGS}.
+	* src/Makefile.am: Link to $FTS_LIBS and use $FTS_CFLAGS for
+	compilation.
+	* tools/Makefile.am: Likewise.
+	* tools/abisym.cc: Include libgen.h
+	* tools/kmidiff.cc: Remove useless fts.h header file.
+
+Signed-off-by: David Seifert <soap@gentoo.org>
+Signed-off-by: Dodji Seketeli <dodji@redhat.com>
+---
+ configure.ac      | 7 +++++++
+ src/Makefile.am   | 4 ++--
+ tools/Makefile.am | 3 ++-
+ tools/kmidiff.cc  | 1 -
+ 4 files changed, 11 insertions(+), 4 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 29130175..019bdbac 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -161,6 +161,7 @@ dnl check for dependencies
+ dnl *************************************************
+ 
+ AC_PROG_CXX
++AC_CANONICAL_HOST
+ AC_USE_SYSTEM_EXTENSIONS
+ AC_PROG_INSTALL
+ 
+@@ -219,6 +220,12 @@ AS_IF([test "x$ac_cv_bad_fts" = "xyes"],
+       [CFLAGS="$CFLAGS -DBAD_FTS=1",
+        CXXFLAGS="$CXXFLAGS -DBAD_FTS=1"])
+ 
++dnl On musl, we need to find fts-standalone
++AS_CASE(
++  [${host_os}], [*-musl*], [
++    PKG_CHECK_MODULES([FTS], [fts-standalone])
++])
++
+ dnl Check for dependency: libelf, libdw, libebl (elfutils)
+ dnl Note that we need to use at least elfutils 0.159 but
+ dnl at that time elfutils didnt have pkgconfig capabilities
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 29da1ecf..1591224f 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -46,12 +46,12 @@ if CTF_READER
+ libabigail_la_SOURCES += abg-ctf-reader.cc
+ endif
+ 
+-libabigail_la_LIBADD = $(DEPS_LIBS)
++libabigail_la_LIBADD = $(DEPS_LIBS) $(FTS_LIBS)
+ libabigail_la_LDFLAGS = -lpthread -Wl,--as-needed -no-undefined
+ 
+ CUSTOM_MACROS = -DABIGAIL_ROOT_SYSTEM_LIBDIR=\"${libdir}\"
+ 
+ AM_CPPFLAGS=\
+-$(CUSTOM_MACROS) $(DEPS_CPPFLAGS) \
++$(CUSTOM_MACROS) $(DEPS_CPPFLAGS) $(FTS_CFLAGS) \
+ -Wall -I$(abs_top_srcdir) -I$(abs_top_srcdir)/include \
+ -I$(abs_top_builddir)/include -I$(abs_top_builddir)
+diff --git a/tools/Makefile.am b/tools/Makefile.am
+index 648a71b5..f7592b60 100644
+--- a/tools/Makefile.am
++++ b/tools/Makefile.am
+@@ -37,7 +37,8 @@ abicompat_LDADD = $(abs_top_builddir)/src/libabigail.la
+ 
+ abipkgdiff_SOURCES = abipkgdiff.cc
+ abipkgdiffdir = $(bindir)
+-abipkgdiff_LDADD = $(abs_top_builddir)/src/libabigail.la
++abipkgdiff_CPPFLAGS = $(FTS_CFLAGS)
++abipkgdiff_LDADD = $(abs_top_builddir)/src/libabigail.la $(FTS_LIBS)
+ abipkgdiff_LDFLAGS = -pthread
+ 
+ kmidiff_SOURCES = kmidiff.cc
+diff --git a/tools/kmidiff.cc b/tools/kmidiff.cc
+index b802348f..2e88baa7 100644
+--- a/tools/kmidiff.cc
++++ b/tools/kmidiff.cc
+@@ -11,7 +11,6 @@
+ 
+ #include <sys/types.h>
+ #include <dirent.h>
+-#include <fts.h>
+ #include <cstring>
+ #include <string>
+ #include <vector>
+-- 
+2.37.1
+
diff --git a/testing/libabigail/APKBUILD b/testing/libabigail/APKBUILD
new file mode 100644
index 000000000000..079619f9858a
--- /dev/null
+++ b/testing/libabigail/APKBUILD
@@ -0,0 +1,107 @@
+# Contributor: Jakub Jirutka <jakub@jirutka.cz>
+# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
+pkgname=libabigail
+pkgver=2.0
+pkgrel=0
+pkgdesc="The ABI Generic Analysis and Instrumentation Library"
+url="https://sourceware.org/libabigail/"
+arch="all"
+license="Apache-2.0 WITH LLVM-exception"
+makedepends="
+	autoconf
+	automake
+	elfutils-dev
+	libtool
+	libxml2-dev
+	musl-fts-dev
+	py3-sphinx
+	"
+checkdepends="
+	bash
+	python3
+	"
+subpackages="
+	$pkgname-dev
+	$pkgname-tools
+	$pkgname-doc
+	$pkgname-bash-completion
+	"
+source="http://mirrors.kernel.org/sourceware/libabigail/libabigail-$pkgver.tar.gz
+	0001-Find-fts-standalone-on-musl.patch
+	musl-fts.patch
+	musl-compat.patch
+	apk.patch
+	"
+
+prepare() {
+	default_prepare
+
+	# FIXME: This test segfaults, dunno why.
+	sed -i '/\bruntestreaddwarf\b/d' \
+		tests/Makefile.am
+
+	# FIXME
+	case "$CARCH" in aarch64 | armhf | armv7 | s390x)
+		sed -i '/\bruntestdiffpkg\b/d' tests/Makefile.am
+	esac
+
+	autoreconf -fi
+}
+
+build() {
+	./configure \
+		--build=$CBUILD \
+		--host=$CHOST \
+		--prefix=/usr \
+		--sysconfdir=/etc \
+		--mandir=/usr/share/man \
+		--localstatedir=/var \
+		--enable-rpm=no \
+		--enable-rpm415=no \
+		--enable-debug-self-comparison=no \
+		--enable-deb=no \
+		--enable-tar=yes \
+		--enable-apidoc=no \
+		--enable-manual=yes \
+		--enable-bash-completion=yes \
+		--enable-fedabipkgdiff=no \
+		--enable-python3=yes
+	make
+	make -C doc/manuals man
+}
+
+check() {
+	make check check-self-compare || {
+		cat tests/test-suite.log
+		return 1
+	}
+}
+
+package() {
+	make DESTDIR="$pkgdir" install
+	make -C doc/manuals DESTDIR="$pkgdir" install-man-and-info-doc
+
+	cd bash-completion
+	install -D -m644 -t "$pkgdir"/usr/share/bash-completion/completions/ \
+		abicompat \
+		abidiff \
+		abidw \
+		abilint \
+		abipkgdiff
+
+}
+
+tools() {
+	pkgdesc="$pkgdesc (CLI tools)"
+	depends="$pkgname=$pkgver-r$pkgrel"
+
+	amove usr/bin
+}
+
+sha512sums="
+288f63f3495f0cd38258c50b78f30a573e43ab60494fefa22c8cba6d6776c5f94742ffea26297a232b78d25f6804f1b3f51febd59ec487733e6ef683cef2c180  libabigail-2.0.tar.gz
+6273c995bafd6ca0a5d732b55978cd3fa92cd4a483df4c04f1523ffc80240417dc3136e0717239e6b90a76dd64211fef3b57278ff0c75da78e004662d11c7c66  0001-Find-fts-standalone-on-musl.patch
+d789a76dfedf9e74c13906aa72da4f9f4113484a98326f662ed9a2badbd29d7fb5e402272bfe24dbdfaf44992ba6a9be3d8ecbdda275910e00cf4f0abaac96e2  musl-fts.patch
+0f22568359bedfd5b469b0b74319e2f72b39f06da8396d31e94bbd7fff383fb440f4662d4f45875054c1d481881924c0283657baabe3abf1c3998f45f750c968  musl-compat.patch
+78bdbb2fd285b5dd2ceaac8a3631e433d4f154b6882c09be7117ef4ead35f872a19b33ca21e1c8d738baa78e3784aebd2d25c731b50a8c3c3c47d616dc33b5fd  apk.patch
+"
diff --git a/testing/libabigail/apk.patch b/testing/libabigail/apk.patch
new file mode 100644
index 000000000000..cf2a92368ede
--- /dev/null
+++ b/testing/libabigail/apk.patch
@@ -0,0 +1,16 @@
+Detect .apk as tarballs.
+
+This is based on https://github.com/void-linux/void-packages/blob/c4880df0bb88e6e9ba08bd22f2ada592a6e60fc7/srcpkgs/libabigail/patches/xbps.patch.
+
+--- a/src/abg-tools-utils.cc
++++ b/src/abg-tools-utils.cc
+@@ -690,7 +690,8 @@
+       || string_ends_with(file_path, ".tlz")
+       || string_ends_with(file_path, ".tar.Z")
+       || string_ends_with(file_path, ".taz")
+-      || string_ends_with(file_path, ".tz"))
++      || string_ends_with(file_path, ".tz")
++      || string_ends_with(file_path, ".apk"))
+     return FILE_TYPE_TAR;
+ 
+   ifstream in(file_path.c_str(), ifstream::binary);
diff --git a/testing/libabigail/musl-compat.patch b/testing/libabigail/musl-compat.patch
new file mode 100644
index 000000000000..d96ac225da77
--- /dev/null
+++ b/testing/libabigail/musl-compat.patch
@@ -0,0 +1,10 @@
+--- a/tools/abisym.cc.orig
++++ b/tools/abisym.cc
+@@ -14,6 +14,7 @@
+ #include <cstring>
+ #include <iostream>
+ #include <sstream>
++#include <libgen.h>  // basename()
+ #include "abg-config.h"
+ #include "abg-dwarf-reader.h"
+ #include "abg-ir.h"
diff --git a/testing/libabigail/musl-fts.patch b/testing/libabigail/musl-fts.patch
new file mode 100644
index 000000000000..917ee64c3881
--- /dev/null
+++ b/testing/libabigail/musl-fts.patch
@@ -0,0 +1,11 @@
+--- a/configure.ac
++++ b/configure.ac
+@@ -261,6 +261,6 @@
+ 
+-dnl On musl, we need to find fts-standalone
++dnl On musl, we need to find musl-fts
+ AS_CASE(
+   [${host_os}], [*-musl*], [
+-    PKG_CHECK_MODULES([FTS], [fts-standalone])
++    PKG_CHECK_MODULES([FTS], [musl-fts])
+ ])
-- 
GitLab