]> xenbits.xensource.com Git - xen.git/commitdiff
autoconf: add check for curses library
authorRoger Pau Monne <roger.pau@entel.upc.edu>
Tue, 13 Mar 2012 15:23:35 +0000 (15:23 +0000)
committerRoger Pau Monne <roger.pau@entel.upc.edu>
Tue, 13 Mar 2012 15:23:35 +0000 (15:23 +0000)
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)

Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 files changed:
config/NetBSD.mk
config/StdGNU.mk
config/SunOS.mk
config/Tools.mk.in
tools/config.h.in
tools/configure
tools/configure.ac
tools/m4/curses.m4 [new file with mode: 0644]
tools/misc/Makefile
tools/misc/gtraceview.c
tools/xenstat/xentop/Makefile
tools/xenstat/xentop/xentop.c

index 7aed0e7440e046cebf6bc3e40f9aeca9b7d3bee3..274bfb010726bcaa475a15a692c4ee6e7d1481ab 100644 (file)
@@ -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)
index 2af2841ccc558252bb7be58dd65b35bb160bfdb6..e2c9335db457388901052ca753705645988338db 100644 (file)
@@ -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
index 6fa0e817dda8a5c23a6ae1b0dc8272a29489d2a2..ba809f5f5b9160c45ecd5a9006d401b4ecb12047 100644 (file)
@@ -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
index 881bb05f038494d56c539094f0fab0c30fb2d549..68de1e4cf0facffa3b631aaea0d4efece0b609cf 100644 (file)
@@ -43,3 +43,4 @@ CONFIG_SYSTEM_LIBAIO:= @system_aio@
 CONFIG_LIBICONV     := @libiconv@
 CONFIG_GCRYPT       := @libgcrypt@
 CONFIG_EXT2FS       := @libext2fs@
+CURSES_LIBS         := @CURSES_LIBS@
index 3d701f47b6e96f6b6069b28377d3bd98b9426f40..f8f96dc3dfd14cc612c1417094fb35ca06026c66 100644 (file)
@@ -14,3 +14,6 @@
 
 /* Define to 1 if you have the <yajl/yajl_version.h> header file. */
 #undef HAVE_YAJL_YAJL_VERSION_H
+
+/* Define curses header to include. */
+#undef INCLUDE_CURSES_H
index cd4a93de9a8d41a347459390b7d934f05fbe73ea..57fdf86ea18af015c1a3e62f2c80b5cc9e0e9523 100755 (executable)
@@ -611,6 +611,7 @@ glib_CFLAGS
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+CURSES_LIBS
 PYTHONPATH
 OCAMLBUILD
 OCAMLDOC
@@ -3904,6 +3905,8 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
 # PKG_CHECK_MODULES
 
 
+
+
 # Enable/disable options
 # Check whether --enable-githttp was given.
 if test "${enable_githttp+set}" = set; then :
@@ -6227,6 +6230,132 @@ fi
 fi
 
 
+ac_fn_c_check_header_mongrel "$LINENO" "curses.h" "ac_cv_header_curses_h" "$ac_includes_default"
+if test "x$ac_cv_header_curses_h" = x""yes; then :
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clear in -lcurses" >&5
+$as_echo_n "checking for clear in -lcurses... " >&6; }
+if test "${ac_cv_lib_curses_clear+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcurses  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clear ();
+int
+main ()
+{
+return clear ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_curses_clear=yes
+else
+  ac_cv_lib_curses_clear=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curses_clear" >&5
+$as_echo "$ac_cv_lib_curses_clear" >&6; }
+if test "x$ac_cv_lib_curses_clear" = x""yes; then :
+  curses="y"
+else
+  curses="n"
+fi
+
+
+else
+  curses="n"
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "ncurses.h" "ac_cv_header_ncurses_h" "$ac_includes_default"
+if test "x$ac_cv_header_ncurses_h" = x""yes; then :
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clear in -lncurses" >&5
+$as_echo_n "checking for clear in -lncurses... " >&6; }
+if test "${ac_cv_lib_ncurses_clear+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lncurses  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clear ();
+int
+main ()
+{
+return clear ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ncurses_clear=yes
+else
+  ac_cv_lib_ncurses_clear=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncurses_clear" >&5
+$as_echo "$ac_cv_lib_ncurses_clear" >&6; }
+if test "x$ac_cv_lib_ncurses_clear" = x""yes; then :
+  ncurses="y"
+else
+  ncurses="n"
+fi
+
+
+else
+  ncurses="n"
+fi
+
+
+if test "$curses" = "n" && test "$ncurses" = "n"; then :
+
+    as_fn_error $? "Unable to find a suitable curses library" "$LINENO" 5
+
+fi
+# Prefer ncurses over curses if both are present
+if test "$ncurses" = "y"; then :
+
+    CURSES_LIBS="-lncurses"
+
+$as_echo "#define INCLUDE_CURSES_H <ncurses.h>" >>confdefs.h
+
+
+else
+
+    CURSES_LIBS="-lcurses"
+
+$as_echo "#define INCLUDE_CURSES_H <curses.h>" >>confdefs.h
+
+
+fi
+
+
+
 
 
 
index c4afe1cf773fc5321a2df675b9b462dcc32e8016..cf376bf05fa81efd95374316f8cc4686adc725ce 100644 (file)
@@ -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([githttp], [Download GIT repositories via HTTP])
@@ -98,6 +99,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
diff --git a/tools/m4/curses.m4 b/tools/m4/curses.m4
new file mode 100644 (file)
index 0000000..c1e483f
--- /dev/null
@@ -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([INCLUDE_CURSES_H], [<ncurses.h>], [Define curses header to use])
+], [
+    CURSES_LIBS="-lcurses"
+    AC_DEFINE([INCLUDE_CURSES_H], [<curses.h>], [Define curses header to use])
+])
+AC_SUBST(CURSES_LIBS)
+])
index af380b0a65c884de683af084b16ea3d2eb5d410e..834ffe7f80e629cae2e36b0f2c423b1881308586 100644 (file)
@@ -27,6 +27,9 @@ INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvmcrash
 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
 
index 3bfedad6542d39e8d2f88bd7353587e2d61b6ae1..d8b458996f923dd2e8ade58fb8556443285a9790 100644 (file)
@@ -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>
 #include <xenctrl.h>
 #include <xen/trace.h>
 
-#ifdef __linux__
-#include <ncurses.h>
-#endif
-#ifdef __NetBSD__
-#include <curses.h>
-#endif
+/* get curses header from configure */
+#include INCLUDE_CURSES_H
 
 /********** MACROS **********/
 #define MAX_CPU_NR  32
index fb025d4106ba0f257dd4dd5b3a002bbac1ea4c30..afed0d190de3634eea825c4d8de3cf25c62336d4 100644 (file)
@@ -22,6 +22,9 @@ CFLAGS += -DGCC_PRINTF -Wall -Werror $(CFLAGS_libxenstat)
 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
 
index b89082945957cf161297dff6f534b9dfa5942a47..60cf607794b75f377ba16fcb0b6ec268fc97258f 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <curses.h>
+
+/* Include output from configure */
+#include <config.h>
+
+/* get curses header from configure */
+#include INCLUDE_CURSES_H
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>