https://github.com/LibtraceTeam/libtrace/pull/201

From dde6c39e5808f06f1450b03e7c682edb0f1290cf Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Tue, 8 Feb 2022 05:30:32 +0000
Subject: [PATCH 1/3] build: fix bashism in configure

configures have a shebang of #!/bin/sh so need to work with a POSIX-compliant
shell; let's use = instead of == which will have the same effect on both Bash
and said shells (like dash).

Signed-off-by: Sam James <sam@gentoo.org>
---
 configure.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 95d63fdc..dbbaabb7 100644
--- a/configure.in
+++ b/configure.in
@@ -305,7 +305,7 @@ AC_ARG_WITH(xdp, AS_HELP_STRING(--with-xdp, include XDP capture support),
 
 if test "$want_xdp" != no; then
     AC_CHECK_LIB(elf, elf_begin, elffound=1, elffound=0)
-    if test "$elffound" == 1; then
+    if test "$elffound" = 1; then
         # check for libbpf
         AC_CHECK_LIB(bpf, xsk_socket__create, bpffound=1, bpffound=0, -lelf)
 

From 1525a42b386da02bda3982cf6e8b472f57f8ac34 Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Tue, 8 Feb 2022 05:32:59 +0000
Subject: [PATCH 2/3] build: make NUMA support optional

This avoids an 'automagic dependency' [0] on NUMA. This is helpful for
downstreams to ensure we don't miss dependencies or when we may not
want to enable support for a feature even though a dependency is enabled.

Gentoo has shipped this patch for quite some time.

[0] https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Automagic_dependencies

Signed-off-by: Sam James <sam@gentoo.org>
---
 configure.in | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index dbbaabb7..6fbff150 100644
--- a/configure.in
+++ b/configure.in
@@ -518,7 +518,23 @@ AC_CHECK_DECL([PACKET_FANOUT],
         [[#include <linux/if_packet.h>]])
 
 # If we use DPDK we might be able to use libnuma
-AC_CHECK_LIB(numa, numa_node_to_cpus, have_numa=1, have_numa=0)
+AC_ARG_WITH(numa,
+	AS_HELP_STRING(--with-numa,include NUMA support),
+[
+	if test "$withval" = no
+	then
+		want_numa=no
+	else
+		want_numa=yes
+	fi
+],[
+	# Default to building without NUMA
+	want_numa=yes
+])
+
+if test "$want_numa" != no; then
+	AC_CHECK_LIB(numa, numa_node_to_cpus, have_numa=1, have_numa=0)
+fi
 
 # Need libwandder for ETSI live decoding
 AC_CHECK_LIB(wandder, init_wandder_decoder, have_wandder=1, have_wandder=0)

From 153254413ae3cd6a62ee7d8b5eae189e84ebc066 Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Tue, 8 Feb 2022 05:34:05 +0000
Subject: [PATCH 3/3] build: use pkg-config to find ncurses

ncurses can be built in a variety of configurations, but the motivating case
for Gentoo was "split tinfo" where libtinfo is no longer included within
libncurses.

Use pkg-config to find where ncurses is installed and the required libraries
needed to link against it (which will include -ltinfo if required).

We've been shipping this patch in Gentoo for quite some time.

Signed-off-by: Sam James <sam@gentoo.org>
---
 configure.in               | 4 ++++
 tools/tracetop/Makefile.am | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 6fbff150..cbb94d55 100644
--- a/configure.in
+++ b/configure.in
@@ -79,6 +79,8 @@ AC_PROG_INSTALL
 AC_CHECK_PROGS(YACC, 'bison -y' byacc yacc) 
 AM_PROG_LEX
 
+PKG_PROG_PKG_CONFIG
+
 # All our source files for function replacements are in lib/
 AC_CONFIG_LIBOBJ_DIR(lib)
 
@@ -916,6 +918,8 @@ if (test "$use_llvm" != "no"); then
 	fi
 fi
 
+PKG_CHECK_MODULES(ncurses,ncurses,have_ncurses=yes,have_ncurses=no)
+
 AC_ARG_WITH([ncurses],
 	AC_HELP_STRING([--with-ncurses], [build tracetop (requires ncurses)]))
 
diff --git a/tools/tracetop/Makefile.am b/tools/tracetop/Makefile.am
index 2ebbc3a7..a2eb2797 100644
--- a/tools/tracetop/Makefile.am
+++ b/tools/tracetop/Makefile.am
@@ -6,6 +6,6 @@ bin_PROGRAMS = tracetop
 include ../Makefile.tools
 
 tracetop_SOURCES = tracetop.cc
-tracetop_LDADD = -lncurses 
+tracetop_LDADD = @ncurses_LIBS@
 tracetop_CPPFLAGS = -fno-strict-aliasing $(AM_CFLAGS)
 endif

