Skip to contentSkip to conversation

autoconf: add check for curses library

PATCH Superseded Roger Pau Monne 1 participant 1 message Feb 23, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 autoconf: add check for curses library

# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1329958678 -3600
# Node ID 8c83cbb30fe84a2ff7c9f9bb1ab73b30eeee244c # Parent caf03354472676522f7407a80ad5bec3963a90a9
autoconf: add check for curses library

Check for a curses compatible library (curses or ncurses basically). One of those is needed to compile Xen tools (gtraceview and xentop).

Modify Makefiles/sources to use configure output (fetch CURSES_LIBS from tools/Tools.mk and header to include from tools/config.h)

Changes since v2:

* Fixed ncursesh/cursesh variable mess in curses.m4.

Changes since v1:

* Added better ncurses/curses detection.

* Modify Makefiles/sources to use configure output.

config/NetBSD.mk +0 -2
diff -r caf033544726 -r 8c83cbb30fe8 config/NetBSD.mk
@@ -1,8 +1,6 @@
 include $(XEN_ROOT)/config/StdGNU.mk
 
 # Override settings for this OS
-CURSES_LIBS = -lcurses
-
 LIBLEAFDIR_x86_64 = lib
 LIBEXEC = $(PREFIX)/libexec
 PRIVATE_BINDIR = $(BINDIR)
config/StdGNU.mk +0 -1
diff -r caf033544726 -r 8c83cbb30fe8 config/StdGNU.mk
@@ -67,7 +67,6 @@ XEN_CONFIG_DIR = $(CONFIG_DIR)/xen
 XEN_SCRIPT_DIR = $(XEN_CONFIG_DIR)/scripts
 
 SOCKET_LIBS =
-CURSES_LIBS = -lncurses
 PTHREAD_LIBS = -lpthread
 UTIL_LIBS = -lutil
 DLOPEN_LIBS = -ldl
config/SunOS.mk +0 -1
diff -r caf033544726 -r 8c83cbb30fe8 config/SunOS.mk
@@ -47,7 +47,6 @@ SunOS_LIBDIR = /usr/sfw/lib
 SunOS_LIBDIR_x86_64 = /usr/sfw/lib/amd64
 
 SOCKET_LIBS = -lsocket
-CURSES_LIBS = -lcurses
 PTHREAD_LIBS = -lpthread
 UTIL_LIBS =
 DLOPEN_LIBS = -ldl
config/Tools.mk.in +1 -0
diff -r caf033544726 -r 8c83cbb30fe8 config/Tools.mk.in
@@ -46,3 +46,4 @@ CONFIG_SYSTEM_LIBAIO:= @system_aio@
 CONFIG_LIBICONV     := @libiconv@
 CONFIG_GCRYPT       := @libgcrypt@
 CONFIG_EXT2FS       := @libext2fs@
+CURSES_LIBS         := @CURSES_LIBS@
tools/config.h.in +6 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/config.h.in
@@ -14,3 +14,9 @@
 
 /* Define to 1 if you have the <yajl/yajl_version.h> header file. */
 #undef HAVE_YAJL_YAJL_VERSION_H
+
+/* Define to 1 if you have the <curses.h> header file. */
+#undef HAVE_CURSES_H
+
+/* Define to 1 if you have the <ncurses.h> header file. */
+#undef HAVE_NCURSES_H
tools/configure +134 -0

152 lines not on this page · raw message

tools/configure.ac +2 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/configure.ac
@@ -33,6 +33,7 @@ m4_include([m4/default_lib.m4])
 m4_include([m4/set_cflags_ldflags.m4])
 m4_include([m4/uuid.m4])
 m4_include([m4/pkg.m4])
+m4_include([m4/curses.m4])
 
 # Enable/disable options
 AX_ARG_ENABLE_AND_EXPORT([xsm],
@@ -102,6 +103,7 @@ AS_IF([test "x$pythontools" = "xy"], [
 ])
 AX_PATH_PROG_OR_FAIL([XGETTEXT], [xgettext])
 AX_CHECK_UUID
+AX_CHECK_CURSES
 PKG_CHECK_MODULES(glib, glib-2.0)
 
 # Check library path
tools/m4/curses.m4 new file +20 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/m4/curses.m4
@@ -0,0 +1,20 @@
+AC_DEFUN([AX_CHECK_CURSES], [
+AC_CHECK_HEADER([curses.h], [
+    AC_CHECK_LIB([curses], [clear], [curses="y"], [curses="n"])
+], [curses="n"])
+AC_CHECK_HEADER([ncurses.h], [
+    AC_CHECK_LIB([ncurses], [clear], [ncurses="y"], [ncurses="n"])
+], [ncurses="n"])
+AS_IF([test "$curses" = "n" && test "$ncurses" = "n"], [
+    AC_MSG_ERROR([Unable to find a suitable curses library])
+])
+# Prefer ncurses over curses if both are present
+AS_IF([test "$ncurses" = "y"], [
+    CURSES_LIBS="-lncurses"
+    AC_DEFINE([HAVE_NCURSES_H], [1], [Define if ncurses.h should be used])
+], [
+    CURSES_LIBS="-lcurses"
+    AC_DEFINE([HAVE_CURSES_H], [1], [Define if curses.h should be used])
+])
+AC_SUBST(CURSES_LIBS)
+])
tools/misc/Makefile +3 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/misc/Makefile
@@ -26,6 +26,9 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx
 INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool
 INSTALL_SBIN := $(INSTALL_SBIN-y)
 
+# Include configure output (config.h) to headers search path
+CFLAGS += -I$(XEN_ROOT)/tools
+
 .PHONY: all
 all: build
 
tools/misc/gtraceview.c +5 -3
diff -r caf033544726 -r 8c83cbb30fe8 tools/misc/gtraceview.c
@@ -16,6 +16,9 @@
  * Place - Suite 330, Boston, MA 02111-1307 USA.
  */
 
+/* Include output from configure */
+#include <config.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -30,10 +33,9 @@
 #include <xenctrl.h>
 #include <xen/trace.h>
 
-#ifdef __linux__
+#if defined(HAVE_NCURSES_H)
 #include <ncurses.h>
-#endif
-#ifdef __NetBSD__
+#elif defined(HAVE_CURSES_H)
 #include <curses.h>
 #endif
 
tools/xenstat/xentop/Makefile +3 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/xenstat/xentop/Makefile
@@ -22,6 +22,9 @@ CFLAGS += -DGCC_PRINTF -Wall -Werror $(C
 LDLIBS += $(LDLIBS_libxenstat) $(CURSES_LIBS) $(SOCKET_LIBS)
 CFLAGS += -DHOST_$(XEN_OS)
 
+# Include configure output (config.h) to headers search path
+CFLAGS += -I$(XEN_ROOT)/tools
+
 .PHONY: all
 all: xentop
 
tools/xenstat/xentop/xentop.c +9 -0
diff -r caf033544726 -r 8c83cbb30fe8 tools/xenstat/xentop/xentop.c
@@ -18,7 +18,16 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+/* Include output from configure */
+#include <config.h>
+
+#if defined(HAVE_NCURSES_H)
+#include <ncurses.h>
+#elif defined(HAVE_CURSES_H)
 #include <curses.h>
+#endif
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>