tools: kwboot: use pkg-config to get -ltinfo

Instead of hardcoding -ltinfo as the flags needed to build
kwboot, use pkg-config when available.

We gracefully fallback on the previous behavior of hardcoding -ltinfo
if pkg-config is not available or fails with an error.

Reviewed-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
diff --git a/tools/Makefile b/tools/Makefile
index aab06ae..005e736 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -198,7 +198,9 @@
 HOSTCFLAGS_mkexynosspl.o := -pedantic
 
 HOSTCFLAGS_kwboot.o += -pthread
-HOSTLDLIBS_kwboot += -pthread -ltinfo
+HOSTLDLIBS_kwboot += -pthread
+HOSTLDLIBS_kwboot += \
+	$(shell pkg-config --libs tinfo 2> /dev/null || echo "-ltinfo")
 
 ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
 hostprogs-$(CONFIG_X86) += ifdtool