[Asterisk-code-review] BuildSystem: Enable ncurses for menuselect in Solaris 11. (asterisk[master])

Alexander Traud asteriskteam at digium.com
Sat Jul 28 11:49:10 CDT 2018


Alexander Traud has uploaded this change for review. ( https://gerrit.asterisk.org/9770


Change subject: BuildSystem: Enable ncurses for menuselect in Solaris 11.
......................................................................

BuildSystem: Enable ncurses for menuselect in Solaris 11.

The check for the library ncurses should use not use the header <curses.h> but
<ncurses.h>, because on some platforms <curses.h> is not a drop-in replacement
for <ncurses.h>: For example in Solaris, the symbol initscr is a typedef in
<curses.h> to a symbol which does not exist in the library ncurses (initscr32).
Simply use <ncurses.h> when you link to ncurses.

Furthermore in Solaris, the header <ncurses.h> is in a subdirectory
/usr/include/ncurses and not available via pkg-config.

ASTERISK-15331
ASTERISK-14935
ASTERISK-9107

Change-Id: Ife367776b0ccf17d3fefed868245376bfb93745d
---
M menuselect/Makefile
M menuselect/configure
M menuselect/configure.ac
M menuselect/makeopts.in
M menuselect/menuselect_curses.c
5 files changed, 442 insertions(+), 297 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/9770/1

diff --git a/menuselect/Makefile b/menuselect/Makefile
index d949efd..da4a6c0 100644
--- a/menuselect/Makefile
+++ b/menuselect/Makefile
@@ -41,6 +41,10 @@
   C_LIBS +=$(NCURSES_LIB)
   C_INCLUDE += $(NCURSES_INCLUDE)
   ALL_TGTS += cmenuselect
+  CFLAGS += -DHAVE_NCURSES
+  ifeq ($(HAVE_NCURSES_SUBDIR),yes)
+    CFLAGS += -DHAVE_NCURSES_SUBDIR
+  endif
 else
   ifdef CURSES_LIB
     C_OBJS += menuselect_curses.o
diff --git a/menuselect/configure b/menuselect/configure
index 7cbe477..dae9d2e 100755
--- a/menuselect/configure
+++ b/menuselect/configure
@@ -632,6 +632,7 @@
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+HAVE_NCURSES_SUBDIR
 CONFIG_LIBXML2
 SED
 PBX_LIBXML2
@@ -3784,8 +3785,6 @@
 done
 
 
-# The frontend can use curses, ncurses, newt or GTK2 so check for all of them
-
 
     NEWT_DESCRIP="newt"
     NEWT_OPTION="newt"
@@ -3915,294 +3914,7 @@
 
 
 
-
-if test "x${PBX_NEWT}" != "x1" -a "${USE_NEWT}" != "no"; then
-   pbxlibdir=""
-   # if --with-NEWT=DIR has been specified, use it.
-   if test "x${NEWT_DIR}" != "x"; then
-      if test -d ${NEWT_DIR}/lib; then
-         pbxlibdir="-L${NEWT_DIR}/lib"
-      else
-         pbxlibdir="-L${NEWT_DIR}"
-      fi
-   fi
-
-      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
-      CFLAGS="${CFLAGS} "
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for newtBell in -lnewt" >&5
-$as_echo_n "checking for newtBell in -lnewt... " >&6; }
-if ${ac_cv_lib_newt_newtBell+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lnewt ${pbxlibdir}  $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 newtBell ();
-int
-main ()
-{
-return newtBell ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_newt_newtBell=yes
-else
-  ac_cv_lib_newt_newtBell=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_newt_newtBell" >&5
-$as_echo "$ac_cv_lib_newt_newtBell" >&6; }
-if test "x$ac_cv_lib_newt_newtBell" = xyes; then :
-  AST_NEWT_FOUND=yes
-else
-  AST_NEWT_FOUND=no
-fi
-
-      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
-
-
-   # now check for the header.
-   if test "${AST_NEWT_FOUND}" = "yes"; then
-      NEWT_LIB="${pbxlibdir} -lnewt "
-      # if --with-NEWT=DIR has been specified, use it.
-      if test "x${NEWT_DIR}" != "x"; then
-         NEWT_INCLUDE="-I${NEWT_DIR}/include"
-      fi
-      NEWT_INCLUDE="${NEWT_INCLUDE} "
-
-         # check for the header
-         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
-         CPPFLAGS="${CPPFLAGS} ${NEWT_INCLUDE}"
-         ac_fn_c_check_header_mongrel "$LINENO" "newt.h" "ac_cv_header_newt_h" "$ac_includes_default"
-if test "x$ac_cv_header_newt_h" = xyes; then :
-  NEWT_HEADER_FOUND=1
-else
-  NEWT_HEADER_FOUND=0
-fi
-
-
-         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
-
-      if test "x${NEWT_HEADER_FOUND}" = "x0" ; then
-         NEWT_LIB=""
-         NEWT_INCLUDE=""
-      else
-
-         PBX_NEWT=1
-         cat >>confdefs.h <<_ACEOF
-#define HAVE_NEWT 1
-_ACEOF
-
-      fi
-   fi
-fi
-
-
-
-if test "x${PBX_CURSES}" != "x1" -a "${USE_CURSES}" != "no"; then
-   pbxlibdir=""
-   # if --with-CURSES=DIR has been specified, use it.
-   if test "x${CURSES_DIR}" != "x"; then
-      if test -d ${CURSES_DIR}/lib; then
-         pbxlibdir="-L${CURSES_DIR}/lib"
-      else
-         pbxlibdir="-L${CURSES_DIR}"
-      fi
-   fi
-
-      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
-      CFLAGS="${CFLAGS} "
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lcurses" >&5
-$as_echo_n "checking for initscr in -lcurses... " >&6; }
-if ${ac_cv_lib_curses_initscr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lcurses ${pbxlibdir}  $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 initscr ();
-int
-main ()
-{
-return initscr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_curses_initscr=yes
-else
-  ac_cv_lib_curses_initscr=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_initscr" >&5
-$as_echo "$ac_cv_lib_curses_initscr" >&6; }
-if test "x$ac_cv_lib_curses_initscr" = xyes; then :
-  AST_CURSES_FOUND=yes
-else
-  AST_CURSES_FOUND=no
-fi
-
-      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
-
-
-   # now check for the header.
-   if test "${AST_CURSES_FOUND}" = "yes"; then
-      CURSES_LIB="${pbxlibdir} -lcurses "
-      # if --with-CURSES=DIR has been specified, use it.
-      if test "x${CURSES_DIR}" != "x"; then
-         CURSES_INCLUDE="-I${CURSES_DIR}/include"
-      fi
-      CURSES_INCLUDE="${CURSES_INCLUDE} "
-
-         # check for the header
-         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
-         CPPFLAGS="${CPPFLAGS} ${CURSES_INCLUDE}"
-         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" = xyes; then :
-  CURSES_HEADER_FOUND=1
-else
-  CURSES_HEADER_FOUND=0
-fi
-
-
-         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
-
-      if test "x${CURSES_HEADER_FOUND}" = "x0" ; then
-         CURSES_LIB=""
-         CURSES_INCLUDE=""
-      else
-
-         PBX_CURSES=1
-         cat >>confdefs.h <<_ACEOF
-#define HAVE_CURSES 1
-_ACEOF
-
-      fi
-   fi
-fi
-
-
-
-if test "x${PBX_NCURSES}" != "x1" -a "${USE_NCURSES}" != "no"; then
-   pbxlibdir=""
-   # if --with-NCURSES=DIR has been specified, use it.
-   if test "x${NCURSES_DIR}" != "x"; then
-      if test -d ${NCURSES_DIR}/lib; then
-         pbxlibdir="-L${NCURSES_DIR}/lib"
-      else
-         pbxlibdir="-L${NCURSES_DIR}"
-      fi
-   fi
-
-      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
-      CFLAGS="${CFLAGS} "
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lncurses" >&5
-$as_echo_n "checking for initscr in -lncurses... " >&6; }
-if ${ac_cv_lib_ncurses_initscr+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lncurses ${pbxlibdir}  $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 initscr ();
-int
-main ()
-{
-return initscr ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_ncurses_initscr=yes
-else
-  ac_cv_lib_ncurses_initscr=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_initscr" >&5
-$as_echo "$ac_cv_lib_ncurses_initscr" >&6; }
-if test "x$ac_cv_lib_ncurses_initscr" = xyes; then :
-  AST_NCURSES_FOUND=yes
-else
-  AST_NCURSES_FOUND=no
-fi
-
-      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
-
-
-   # now check for the header.
-   if test "${AST_NCURSES_FOUND}" = "yes"; then
-      NCURSES_LIB="${pbxlibdir} -lncurses "
-      # if --with-NCURSES=DIR has been specified, use it.
-      if test "x${NCURSES_DIR}" != "x"; then
-         NCURSES_INCLUDE="-I${NCURSES_DIR}/include"
-      fi
-      NCURSES_INCLUDE="${NCURSES_INCLUDE} "
-
-         # check for the header
-         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
-         CPPFLAGS="${CPPFLAGS} ${NCURSES_INCLUDE}"
-         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" = xyes; then :
-  NCURSES_HEADER_FOUND=1
-else
-  NCURSES_HEADER_FOUND=0
-fi
-
-
-         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
-
-      if test "x${NCURSES_HEADER_FOUND}" = "x0" ; then
-         NCURSES_LIB=""
-         NCURSES_INCLUDE=""
-      else
-
-         PBX_NCURSES=1
-         cat >>confdefs.h <<_ACEOF
-#define HAVE_NCURSES 1
-_ACEOF
-
-      fi
-   fi
-fi
-
-
+# Find required XML library (libxml).
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
 $as_echo_n "checking for a sed that does not truncate output... " >&6; }
 if ${ac_cv_path_SED+:} false; then :
@@ -4414,11 +4126,412 @@
 		fi
 	fi
 
-
 if test "${PBX_LIBXML2}" != 1; then
   as_fn_error $? "Could not find required 'Libxml2' development package" "$LINENO" 5
 fi
 
+# Find libraries for the optional graphical frontend:
+# 1) newt,
+# 2) {n}curses, or
+# 3) GTK+ 2
+# If ncurses is available, it takes precedence over the older curses.
+# You are able to select a specific frontend via
+# A) make nmenuselect
+# B) make cmenuselect
+# C) make gmenuselect
+# Therefore, this script checks all of the optional libraries:
+
+if test "x${PBX_NEWT}" != "x1" -a "${USE_NEWT}" != "no"; then
+   pbxlibdir=""
+   # if --with-NEWT=DIR has been specified, use it.
+   if test "x${NEWT_DIR}" != "x"; then
+      if test -d ${NEWT_DIR}/lib; then
+         pbxlibdir="-L${NEWT_DIR}/lib"
+      else
+         pbxlibdir="-L${NEWT_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for newtBell in -lnewt" >&5
+$as_echo_n "checking for newtBell in -lnewt... " >&6; }
+if ${ac_cv_lib_newt_newtBell+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnewt ${pbxlibdir}  $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 newtBell ();
+int
+main ()
+{
+return newtBell ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_newt_newtBell=yes
+else
+  ac_cv_lib_newt_newtBell=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_newt_newtBell" >&5
+$as_echo "$ac_cv_lib_newt_newtBell" >&6; }
+if test "x$ac_cv_lib_newt_newtBell" = xyes; then :
+  AST_NEWT_FOUND=yes
+else
+  AST_NEWT_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_NEWT_FOUND}" = "yes"; then
+      NEWT_LIB="${pbxlibdir} -lnewt "
+      # if --with-NEWT=DIR has been specified, use it.
+      if test "x${NEWT_DIR}" != "x"; then
+         NEWT_INCLUDE="-I${NEWT_DIR}/include"
+      fi
+      NEWT_INCLUDE="${NEWT_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${NEWT_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "newt.h" "ac_cv_header_newt_h" "$ac_includes_default"
+if test "x$ac_cv_header_newt_h" = xyes; then :
+  NEWT_HEADER_FOUND=1
+else
+  NEWT_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${NEWT_HEADER_FOUND}" = "x0" ; then
+         NEWT_LIB=""
+         NEWT_INCLUDE=""
+      else
+
+         PBX_NEWT=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_NEWT 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
+if test "x${PBX_NCURSES}" != "x1" -a "${USE_NCURSES}" != "no"; then
+   pbxlibdir=""
+   # if --with-NCURSES=DIR has been specified, use it.
+   if test "x${NCURSES_DIR}" != "x"; then
+      if test -d ${NCURSES_DIR}/lib; then
+         pbxlibdir="-L${NCURSES_DIR}/lib"
+      else
+         pbxlibdir="-L${NCURSES_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lncurses" >&5
+$as_echo_n "checking for initscr in -lncurses... " >&6; }
+if ${ac_cv_lib_ncurses_initscr+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lncurses ${pbxlibdir}  $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 initscr ();
+int
+main ()
+{
+return initscr ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ncurses_initscr=yes
+else
+  ac_cv_lib_ncurses_initscr=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_initscr" >&5
+$as_echo "$ac_cv_lib_ncurses_initscr" >&6; }
+if test "x$ac_cv_lib_ncurses_initscr" = xyes; then :
+  AST_NCURSES_FOUND=yes
+else
+  AST_NCURSES_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_NCURSES_FOUND}" = "yes"; then
+      NCURSES_LIB="${pbxlibdir} -lncurses "
+      # if --with-NCURSES=DIR has been specified, use it.
+      if test "x${NCURSES_DIR}" != "x"; then
+         NCURSES_INCLUDE="-I${NCURSES_DIR}/include"
+      fi
+      NCURSES_INCLUDE="${NCURSES_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${NCURSES_INCLUDE}"
+         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" = xyes; then :
+  NCURSES_HEADER_FOUND=1
+else
+  NCURSES_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${NCURSES_HEADER_FOUND}" = "x0" ; then
+         NCURSES_LIB=""
+         NCURSES_INCLUDE=""
+      else
+
+         PBX_NCURSES=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_NCURSES 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+if test "${PBX_NCURSES}" != 1; then
+  # some platforms have the header in a sub-directory, for example Solaris
+
+if test "x${PBX_NCURSES}" != "x1" -a "${USE_NCURSES}" != "no"; then
+   pbxlibdir=""
+   # if --with-NCURSES=DIR has been specified, use it.
+   if test "x${NCURSES_DIR}" != "x"; then
+      if test -d ${NCURSES_DIR}/lib; then
+         pbxlibdir="-L${NCURSES_DIR}/lib"
+      else
+         pbxlibdir="-L${NCURSES_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lncurses" >&5
+$as_echo_n "checking for initscr in -lncurses... " >&6; }
+if ${ac_cv_lib_ncurses_initscr+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lncurses ${pbxlibdir}  $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 initscr ();
+int
+main ()
+{
+return initscr ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_ncurses_initscr=yes
+else
+  ac_cv_lib_ncurses_initscr=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_initscr" >&5
+$as_echo "$ac_cv_lib_ncurses_initscr" >&6; }
+if test "x$ac_cv_lib_ncurses_initscr" = xyes; then :
+  AST_NCURSES_FOUND=yes
+else
+  AST_NCURSES_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_NCURSES_FOUND}" = "yes"; then
+      NCURSES_LIB="${pbxlibdir} -lncurses "
+      # if --with-NCURSES=DIR has been specified, use it.
+      if test "x${NCURSES_DIR}" != "x"; then
+         NCURSES_INCLUDE="-I${NCURSES_DIR}/include"
+      fi
+      NCURSES_INCLUDE="${NCURSES_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${NCURSES_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "ncurses/ncurses.h" "ac_cv_header_ncurses_ncurses_h" "$ac_includes_default"
+if test "x$ac_cv_header_ncurses_ncurses_h" = xyes; then :
+  NCURSES_HEADER_FOUND=1
+else
+  NCURSES_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${NCURSES_HEADER_FOUND}" = "x0" ; then
+         NCURSES_LIB=""
+         NCURSES_INCLUDE=""
+      else
+
+         PBX_NCURSES=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_NCURSES 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+  if test "${PBX_NCURSES}" != 1; then
+
+if test "x${PBX_CURSES}" != "x1" -a "${USE_CURSES}" != "no"; then
+   pbxlibdir=""
+   # if --with-CURSES=DIR has been specified, use it.
+   if test "x${CURSES_DIR}" != "x"; then
+      if test -d ${CURSES_DIR}/lib; then
+         pbxlibdir="-L${CURSES_DIR}/lib"
+      else
+         pbxlibdir="-L${CURSES_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for initscr in -lcurses" >&5
+$as_echo_n "checking for initscr in -lcurses... " >&6; }
+if ${ac_cv_lib_curses_initscr+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcurses ${pbxlibdir}  $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 initscr ();
+int
+main ()
+{
+return initscr ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_curses_initscr=yes
+else
+  ac_cv_lib_curses_initscr=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_initscr" >&5
+$as_echo "$ac_cv_lib_curses_initscr" >&6; }
+if test "x$ac_cv_lib_curses_initscr" = xyes; then :
+  AST_CURSES_FOUND=yes
+else
+  AST_CURSES_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_CURSES_FOUND}" = "yes"; then
+      CURSES_LIB="${pbxlibdir} -lcurses "
+      # if --with-CURSES=DIR has been specified, use it.
+      if test "x${CURSES_DIR}" != "x"; then
+         CURSES_INCLUDE="-I${CURSES_DIR}/include"
+      fi
+      CURSES_INCLUDE="${CURSES_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${CURSES_INCLUDE}"
+         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" = xyes; then :
+  CURSES_HEADER_FOUND=1
+else
+  CURSES_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${CURSES_HEADER_FOUND}" = "x0" ; then
+         CURSES_LIB=""
+         CURSES_INCLUDE=""
+      else
+
+         PBX_CURSES=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_CURSES 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+  else
+    HAVE_NCURSES_SUBDIR=yes
+  fi
+fi
+
 
 
 
@@ -4630,6 +4743,7 @@
 
 
 
+# If no frontend was found, you still can use menuselect via the command line.
 
 test "$silent"=yes && ac_sub_configure_args="${ac_sub_configure_args} --silent"
 
diff --git a/menuselect/configure.ac b/menuselect/configure.ac
index 4a2d0ac..64af09c 100644
--- a/menuselect/configure.ac
+++ b/menuselect/configure.ac
@@ -59,29 +59,47 @@
 AC_FUNC_ALLOCA
 AC_CHECK_FUNCS([asprintf getloadavg setenv strcasestr strndup strnlen strsep unsetenv vasprintf])
 
-# The frontend can use curses, ncurses, newt or GTK2 so check for all of them
-
 AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
 AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
 
-AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
-AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
-AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
+# Find required XML library (libxml).
 AST_EXT_TOOL_CHECK([LIBXML2], [xml2-config], , ,
         [#include <libxml/tree.h>
         #include <libxml/parser.h>],
         [LIBXML_TEST_VERSION])
-
 if test "${PBX_LIBXML2}" != 1; then
   AC_MSG_ERROR([Could not find required 'Libxml2' development package])
 fi
 
+# Find libraries for the optional graphical frontend:
+# 1) newt,
+# 2) {n}curses, or
+# 3) GTK+ 2
+# If ncurses is available, it takes precedence over the older curses.
+# You are able to select a specific frontend via
+# A) make nmenuselect
+# B) make cmenuselect
+# C) make gmenuselect
+# Therefore, this script checks all of the optional libraries:
+AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
+AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [ncurses.h])
+if test "${PBX_NCURSES}" != 1; then
+  # some platforms have the header in a sub-directory, for example Solaris
+  AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [ncurses/ncurses.h])
+  if test "${PBX_NCURSES}" != 1; then
+    AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
+  else
+    HAVE_NCURSES_SUBDIR=yes
+  fi
+fi
+AC_SUBST(HAVE_NCURSES_SUBDIR)
 AST_PKG_CONFIG_CHECK([GTK2], [gtk+-2.0])
 AC_SUBST(PBX_GTK2)
 AC_SUBST(GTK2_INCLUDE)
 AC_SUBST(GTK2_LIB)
+# If no frontend was found, you still can use menuselect via the command line.
 
 test "$silent"=yes && ac_sub_configure_args="${ac_sub_configure_args} --silent"
 
diff --git a/menuselect/makeopts.in b/menuselect/makeopts.in
index 495555d..efafbab 100644
--- a/menuselect/makeopts.in
+++ b/menuselect/makeopts.in
@@ -17,6 +17,7 @@
 
 NCURSES_INCLUDE=@NCURSES_INCLUDE@
 NCURSES_LIB=@NCURSES_LIB@
+HAVE_NCURSES_SUBDIR=@HAVE_NCURSES_SUBDIR@
 
 NEWT_INCLUDE=@NEWT_INCLUDE@
 NEWT_LIB=@NEWT_LIB@
diff --git a/menuselect/menuselect_curses.c b/menuselect/menuselect_curses.c
index 0917eba..fe42119 100644
--- a/menuselect/menuselect_curses.c
+++ b/menuselect/menuselect_curses.c
@@ -31,7 +31,15 @@
 #include <string.h>
 #include <signal.h>
 #include <time.h>
+#ifdef HAVE_NCURSES
+#ifdef HAVE_NCURSES_SUBDIR
+#include <ncurses/ncurses.h>
+#else
+#include <ncurses.h>
+#endif
+#else
 #include <curses.h>
+#endif
 
 #include "menuselect.h"
 

-- 
To view, visit https://gerrit.asterisk.org/9770
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ife367776b0ccf17d3fefed868245376bfb93745d
Gerrit-Change-Number: 9770
Gerrit-PatchSet: 1
Gerrit-Owner: Alexander Traud <pabstraud at compuserve.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180728/8945d2e7/attachment-0001.html>


More information about the asterisk-code-review mailing list