From: Sami Kerola Date: Thu, 18 Aug 2016 20:52:39 +0000 (+0100) Subject: build-sys: use pkg-config to find ncurses X-Git-Tag: v0.88~30^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e2a948a167d9b8a0a63b46a423d4ae1519ad759;p=thirdparty%2Fmtr.git build-sys: use pkg-config to find ncurses The curses function attron() has been part of posix since 1997. There is no need to go-around for it. Reference: http://pubs.opengroup.org/onlinepubs/7908799/xcurses/attron.html --- diff --git a/Makefile.am b/Makefile.am index 0e740a9..5ee48c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,14 +23,14 @@ if IPINFO mtr_SOURCES += asn.c asn.h endif -EXTRA_mtr_SOURCES = curses.c +if WITH_NCURSES +mtr_SOURCES += curses.c +endif if WITH_GTK mtr_SOURCES += gtk.c endif -mtr_DEPENDENCIES = $(CURSES_OBJ) -mtr_LDFLAGS = $(CURSES_OBJ) mtr_INCLUDES = $(GLIB_CFLAGS) -I$(top_builddir) -I$(top_srcdir) mtr_CFLAGS = $(GTK_CFLAGS) $(NCURSES_CFLAGS) -mtr_LDADD = $(GTK_LIBS) $(NCURSES_LDADD) $(RESOLV_LIBS) +mtr_LDADD = $(GTK_LIBS) $(NCURSES_LIBS) $(RESOLV_LIBS) diff --git a/configure.ac b/configure.ac index 92e2cef..5b73470 100644 --- a/configure.ac +++ b/configure.ac @@ -15,9 +15,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])]) -AC_SUBST([CURSES_OBJ]) -CURSES_OBJ=curses.o - AC_PROG_CC # Check pkg-config availability. @@ -50,24 +47,8 @@ AC_CHECK_HEADERS([ \ sys/xti.h \ ]) -# Find ncursses. -AC_SEARCH_LIBS([initscr], - [ncurses curses cursesX], - [], - [AC_MSG_WARN([Building without curses display support]) - AC_DEFINE([NO_CURSES], [1], [Define if you don't have the curses libraries available.]) - CURSES_OBJ=]) - -AC_CHECK_LIB([ncurses], - [use_default_colors], - [AC_DEFINE([HAVE_USE_DEFAULT_COLORS], - [1], - [Define this if your curses library has the use_default_colors() command.]) - ]) - # Check functions. AC_CHECK_FUNCS([ \ - attron \ fcntl \ ]) @@ -84,6 +65,24 @@ AS_IF([test "x$with_gtk" = "xyes"], ]) AM_CONDITIONAL([WITH_GTK], [test "x$with_gtk" = xyes]) +# Find ncurses +AC_ARG_WITH([ncurses], + [AS_HELP_STRING([--without-ncurses], [Build without the ncurses interface])], + [], [with_ncurses=yes]) +AS_IF([test "x$with_ncurses" = "xyes"], + [PKG_CHECK_MODULES([NCURSES], [ncurses], [ + AC_DEFINE([HAVE_NCURSES], [1], [Define if ncurses library available]) + AC_CHECK_LIB([ncurses], + [use_default_colors], + [AC_DEFINE([HAVE_USE_DEFAULT_COLORS], [1], + [Define this if your curses library has the use_default_colors() command.] + ) + ]) + ], + [with_ncurses=no]) +]) +AM_CONDITIONAL([WITH_NCURSES], [test "x$with_ncurses" = xyes]) + # Enable ipinfo AC_ARG_WITH([ipinfo], [AS_HELP_STRING([--without-ipinfo], [Do not try to use ipinfo lookup at all])], diff --git a/curses.c b/curses.c index 4850589..4d8f436 100644 --- a/curses.c +++ b/curses.c @@ -21,7 +21,7 @@ #include #include -#ifndef NO_CURSES +#ifdef HAVE_NCURSES #include #include #include @@ -50,11 +50,6 @@ # error No curses header file available #endif -#ifndef HAVE_ATTRON -#define attron(x) -#define attroff(x) -#endif - #ifndef getmaxyx # define getmaxyx(win,y,x) ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1) #endif diff --git a/display.c b/display.c index 0c5b0e9..1f0d294 100644 --- a/display.c +++ b/display.c @@ -34,15 +34,15 @@ extern int DisplayMode; -#ifdef NO_CURSES +#ifdef HAVE_NCURSES +#include "mtr-curses.h" +#else // No support for curses mode, allow the calls to remain in the code. #define mtr_curses_open() #define mtr_curses_close() #define mtr_curses_redraw() #define mtr_curses_keyaction() 0 #define mtr_curses_clear() -#else -#include "mtr-curses.h" #endif #ifdef HAVE_GTK @@ -72,10 +72,10 @@ extern int DisplayMode; #define asn_close() #endif -#ifdef NO_CURSES -#define DEFAULT_DISPLAY DisplayReport -#else +#ifdef HAVE_NCURSES #define DEFAULT_DISPLAY DisplayCurses +#else +#define DEFAULT_DISPLAY DisplayReport #endif #ifdef HAVE_GTK diff --git a/split.c b/split.c index 5ead235..937ab9d 100644 --- a/split.c +++ b/split.c @@ -35,23 +35,20 @@ #include "net.h" #include "split.h" -#ifdef NO_CURSES -#include -#include -#include -#else -/* Use the curses variant */ - -#if defined(HAVE_NCURSES_H) +#ifdef HAVE_NCURSES +# if defined(HAVE_NCURSES_H) # include -#elif defined(HAVE_NCURSES_CURSES_H) +# elif defined(HAVE_NCURSES_CURSES_H) # include -#elif defined(HAVE_CURSES_H) +# elif defined(HAVE_CURSES_H) # include -#else +# else # error No curses header file available -#endif - +# endif +#else +# include +# include +# include #endif @@ -155,7 +152,9 @@ void split_close(void) int split_keyaction(void) { -#ifdef NO_CURSES +#ifdef HAVE_NCURSES + char c = getch(); +#else fd_set readfds; struct timeval tv; char c; @@ -169,8 +168,6 @@ int split_keyaction(void) read (0, &c, 1); } else return 0; -#else - char c = getch(); #endif #if DEBUG