Use pkg-config to get ncurses(w) flags, falling back to static strings
authorJames Le Cuirot <chewi@gentoo.org>
Mon, 2 Sep 2019 21:39:03 +0000 (22:39 +0100)
committerJames Le Cuirot <chewi@gentoo.org>
Mon, 2 Sep 2019 22:04:42 +0000 (23:04 +0100)
Using pkg-config ensures that -I/usr/include/ncursesw is added when
necessary. This picks up the correct ncurses.h when both the wide and
non-wide versions are installed.

It also ensures that -ltinfo(w) is added when necessary. Some
distributions such as Gentoo build it as a separate library.

Makefile

index 5a8457d8462a8584de169a2281b33a4713bc3c51..b7bb68036164e8887ab7e3ca874c5f20649cf57e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -169,14 +169,9 @@ export CFLAGS
 ifeq ($(CURSES), curses)
   CURSES_LDFLAGS += -lcurses
   CURSES_DEFINE = USE_CURSES_H
-endif
-ifeq ($(CURSES), ncurses)
-  CURSES_LDFLAGS += -lncurses
-  CURSES_DEFINE = USE_NCURSES_H
-endif
-ifeq ($(CURSES), ncursesw)
-  CURSES_LDFLAGS += -lncursesw
-  CURSES_CFLAGS += -D_XOPEN_SOURCE_EXTENDED
+else ifneq ($(findstring ncurses,$(CURSES)),)
+  CURSES_LDFLAGS += $(or $(shell $(PKG_CONFIG) $(CURSES) --libs 2>/dev/null),-l$(CURSES))
+  CURSES_CFLAGS += $(or $(shell $(PKG_CONFIG) $(CURSES) --cflags 2>/dev/null),-D_XOPEN_SOURCE_EXTENDED)
   CURSES_DEFINE = USE_NCURSES_H
 endif