kamcmd: use pkg-config to get compile flags for lib readline
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 18 Mar 2020 16:39:18 +0000 (17:39 +0100)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 18 Mar 2020 16:39:49 +0000 (17:39 +0100)
utils/kamcmd/Makefile

index aae4f13..c8a7e68 100644 (file)
@@ -18,6 +18,17 @@ readline_localpath=$(LOCALBASE)/include/readline/readline.h
 readline_locations= /usr/include/readline/readline.h \
                                        $(readline_localpath)
 
 readline_locations= /usr/include/readline/readline.h \
                                        $(readline_localpath)
 
+ifeq ($(CROSS_COMPILE),)
+       BUILDER = $(shell which pkg-config)
+ifneq ($(BUILDER),)
+       PKGREADLINE = $(shell $(BUILDER) --exists readline > /dev/null 2>&1 ; echo $$? )
+ifneq ($(PKGREADLINE),0)
+       BUILDER =
+endif
+endif
+endif
+
+
 use_readline ?=
 ifneq (,$(MAKECMDGOALS))
 ifeq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
 use_readline ?=
 ifneq (,$(MAKECMDGOALS))
 ifeq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
@@ -66,6 +77,12 @@ ifneq (,$(findstring cygwin, $(OS)))
        LIBS:= -lresolv
 endif
 
        LIBS:= -lresolv
 endif
 
+# detect libreadline
+ifneq ($(BUILDER),)
+       DEFS += $(shell $(BUILDER) --cflags readline)
+       LIBS += $(shell $(BUILDER) --libs readline)
+       use_readline := 1
+else
 ifeq ($(use_readline),)
 readline_path := $(shell  \
                                                for r in $(readline_locations) ""; do \
 ifeq ($(use_readline),)
 readline_path := $(shell  \
                                                for r in $(readline_locations) ""; do \
@@ -93,14 +110,20 @@ endif
        LIBS+=-lreadline -lncurses
 endif
 
        LIBS+=-lreadline -lncurses
 endif
 
-endif
+endif  # ifeq ($(use_readline),1)
+
+endif  # ifneq ($(BUILDER),)
 
 
 include $(COREPATH)/Makefile.utils
 
 ifeq (,$(quiet))
 ifeq ($(use_readline),1)
 
 
 include $(COREPATH)/Makefile.utils
 
 ifeq (,$(quiet))
 ifeq ($(use_readline),1)
+ifneq ($(BUILDER),)
+$(info readline detected via pkg-config)
+else
 $(info readline detected ($(readline_path)) )
 $(info readline detected ($(readline_path)) )
+endif
 $(info command completion enabled)
 else
 $(info "no readline include files detected, disabling readline support")
 $(info command completion enabled)
 else
 $(info "no readline include files detected, disabling readline support")