about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Config/defs.mk.in4
-rw-r--r--Src/Modules/curses.c22
-rw-r--r--Src/Modules/termcap.c8
-rw-r--r--Src/Modules/terminfo.c28
-rw-r--r--Src/zsh.mdd19
-rw-r--r--configure.ac212
7 files changed, 171 insertions, 130 deletions
diff --git a/ChangeLog b/ChangeLog
index cb323769d..49c76fe05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-13  Peter Stephenson  <pws@csr.com>
+
+	* 24705: configure.ac, Config/defs.mk.in, Src/zsh.mdd,
+	Src/Modules/curses.c, Src/Modules/termcap.c,
+	Src/Modules/terminfo.c: rationalise curses and term headers
+	some more and add intermediate generated <build>/Src/zshcurses.h
+	and <build>/Src/zshterm.h to include the right ones.
+
 2008-03-12  Clint Adams  <clint@zsh.org>
 
 	* 24704: Completion/Unix/Command/_calendar: completion for BSD
diff --git a/Config/defs.mk.in b/Config/defs.mk.in
index bfa96edf7..5195bf8e0 100644
--- a/Config/defs.mk.in
+++ b/Config/defs.mk.in
@@ -29,6 +29,10 @@ SHELL = /bin/sh
 @SET_MAKE@
 EXEEXT = @EXEEXT@
 
+# headers
+ZSH_CURSES_H = @ZSH_CURSES_H@
+ZSH_TERM_H = @ZSH_TERM_H@
+
 # install basename
 tzsh            = @tzsh@
 
diff --git a/Src/Modules/curses.c b/Src/Modules/curses.c
index 0649f5750..df8a9cdc6 100644
--- a/Src/Modules/curses.c
+++ b/Src/Modules/curses.c
@@ -41,26 +41,8 @@
 # undef HAVE_NCURSESW_NCURSES_H
 #endif
 
-#ifdef ZSH_IGNORE_NCURSES
-# ifdef HAVE_CURSES_H
-#  include <curses.h>
-# endif
-#else
-# ifdef HAVE_NCURSESW_NCURSES_H
-#  include <ncursesw/ncurses.h>
-# else
-#  ifdef HAVE_NCURSES_NCURSES_H
-#   include <ncurses/ncurses.h>
-#  else
-#   ifdef HAVE_NCURSES_H
-#    include <ncurses.h>
-#   else
-#    ifdef HAVE_CURSES_H
-#     include <curses.h>
-#    endif
-#   endif
-#  endif
-# endif
+#ifdef ZSH_HAVE_CURSES_H
+# include "../zshcurses.h"
 #endif
 
 #ifdef HAVE_SETCCHAR
diff --git a/Src/Modules/termcap.c b/Src/Modules/termcap.c
index 351324a68..776351cf6 100644
--- a/Src/Modules/termcap.c
+++ b/Src/Modules/termcap.c
@@ -36,7 +36,7 @@
 #include "../../config.h"
 
 #ifdef HAVE_TGETENT
-# if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
+# if defined(ZSH_HAVE_CURSES_H) && defined(ZSH_HAVE_TERM_H)
 #  define USES_TERM_H 1
 # else
 #  ifdef HAVE_TERMCAP_H
@@ -54,10 +54,10 @@
 #  ifdef HAVE_TERMIO_H
 #   include <termio.h>
 #  endif
-#  ifdef TERM_H_NEEDS_CURSES_H
-#   include <curses.h>
+#  ifdef ZSH_HAVE_CURSES_H
+#   include "../zshcurses.h"
 #  endif
-#  include <term.h>
+#  include "../zshterm.h"
 # else
 #  ifdef USES_TERMCAP_H
 #   include <termcap.h>
diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c
index 1038c243e..db9a6c053 100644
--- a/Src/Modules/terminfo.c
+++ b/Src/Modules/terminfo.c
@@ -30,7 +30,7 @@
 #define USES_TERM_H 1
 #include "terminfo.mdh"
 
-#if defined(HAVE_TIGETFLAG) && (defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H) || defined(HAVE_NCURSES_NCURSES_H) || defined(HAVE_NCURSESW_NCURSES_H))
+#if defined(HAVE_TIGETFLAG) && defined(ZSH_HAVE_CURSES_H)
 # define USE_TERMINFO_MODULE 1
 #else
 # undef USE_TERMINFO_MODULE
@@ -49,30 +49,12 @@
 #  undef offsetof
 # endif
 
-#ifdef ZSH_IGNORE_NCURSES
-# ifdef HAVE_CURSES_H
-#  include <curses.h>
-# endif
-#else
-# ifdef HAVE_NCURSESW_NCURSES_H
-#  include <ncursesw/ncurses.h>
-# else
-#  ifdef HAVE_NCURSES_NCURSES_H
-#   include <ncurses/ncurses.h>
-#  else
-#   ifdef HAVE_NCURSES_H
-#    include <ncurses.h>
-#   else
-#    ifdef HAVE_CURSES_H
-#     include <curses.h>
-#    endif
-#   endif
-#  endif
-# endif
+#ifdef ZSH_HAVE_CURSES_H
+# include "../zshcurses.h"
 #endif
 
-# ifdef HAVE_TERM_H
-#  include <term.h>
+# ifdef ZSH_HAVE_TERM_H
+#  include "../zshterm.h"
 # endif
 
 /* echoti: output a terminfo capability */
diff --git a/Src/zsh.mdd b/Src/zsh.mdd
index 8aef628c5..ab36ec8d7 100644
--- a/Src/zsh.mdd
+++ b/Src/zsh.mdd
@@ -33,9 +33,26 @@ init.o: bltinmods.list zshpaths.h zshxmods.h
 
 init.o params.o parse.o: version.h
 
-version.h: $(sdir_top)/Config/version.mk
+# The main shell doesn't currently need zshcurses.h and zshterm.h,
+# but make sure these are built with the headers.
+# If it did need need them they would be in headers at the top instead.
+version.h: $(sdir_top)/Config/version.mk zshcurses.h zshterm.h
 	echo '#define ZSH_VERSION "'$(VERSION)'"' > $@
 
+zshcurses.h: ../config.h
+	@if test x$(ZSH_CURSES_H) != x; then \
+	  echo "#include <$(ZSH_CURSES_H)>" >zshcurses.h; \
+	else \
+	  echo >zshcurses.h; \
+	fi
+
+zshterm.h: ../config.h
+	@if test x$(ZSH_TERM_H) != x; then \
+	  echo "#include <$(ZSH_TERM_H)>" >zshterm.h; \
+	else \
+	  echo >zshterm.h; \
+	fi
+
 zshpaths.h: Makemod $(CONFIG_INCS)
 	@echo '#define MODULE_DIR "'$(MODDIR)'"' > zshpaths.h.tmp
 	@if test x$(sitescriptdir) != xno; then \
diff --git a/configure.ac b/configure.ac
index ea0b51583..88a7d836d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -685,20 +685,6 @@ if test x$zsh_cv_curses_needs_xopen = xyes; then
   AC_DEFINE(ZSH_CURSES_NEEDS_XOPEN)
 fi
 
-AH_TEMPLATE([HAVE_BOOLCODES],
-[Define if you have the termcap boolcodes symbol.])
-AH_TEMPLATE([HAVE_NUMCODES],
-[Define if you have the termcap numcodes symbol.])
-AH_TEMPLATE([HAVE_STRCODES],
-[Define if you have the termcap strcodes symbol.])
-AH_TEMPLATE([HAVE_BOOLNAMES],
-[Define if you have the terminfo boolnames symbol.])
-AH_TEMPLATE([HAVE_NUMNAMES],
-[Define if you have the terminfo numnames symbol.])
-AH_TEMPLATE([HAVE_STRNAMES],
-[Define if you have the terminfo strnames symbol.])
-AH_TEMPLATE([TERM_H_NEEDS_CURSES_H],
-[Define if term.h chokes without curses.h.])
 dnl Check for tigetflag (terminfo) before tgetent (termcap).
 dnl That's so that on systems where termcap and [n]curses are
 dnl both available and both contain termcap functions, while
@@ -721,69 +707,18 @@ ac_cv_header_curses_solaris=no))
 if test x$ac_cv_header_curses_solaris = xyes; then
 AC_DEFINE(HAVE_CURSES_H)
 fi])
-AC_CHECK_HEADERS(term.h,
-[AC_MSG_CHECKING(if term.h needs curses.h)
-AC_TRY_COMPILE([#include <term.h>], [char **test = boolcodes;], boolcodes_with_only_term_h=yes,
-boolcodes_with_only_term_h=no)
-AC_TRY_COMPILE([#include <curses.h>
-#include <term.h>], [char **test = boolcodes;], boolcodes_with_curses_h_and_term_h=yes,
-boolcodes_with_curses_h_and_term_h=no)
-if test "x$boolcodes_with_curses_h_and_term_h" = xyes && test "x$boolcodes_with_only_term_h" = xno;
-then
-AC_DEFINE(TERM_H_NEEDS_CURSES_H)
-AC_MSG_RESULT(yes)
-else
-AC_MSG_RESULT(no)
-fi
-
-AC_MSG_CHECKING(if boolcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = boolcodes; printf(*test);],
-AC_DEFINE(HAVE_BOOLCODES) boolcodes=yes, boolcodes=no)
-AC_MSG_RESULT($boolcodes)
-AC_MSG_CHECKING(if numcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = numcodes; printf(*test);],
-AC_DEFINE(HAVE_NUMCODES) numcodes=yes, numcodes=no)
-AC_MSG_RESULT($numcodes)
-AC_MSG_CHECKING(if strcodes is available)
-AC_TRY_LINK([#ifdef TERM_H_NEEDS_CURSES_H
-#include <curses.h>
-#endif
-#include <term.h>], [char **test = strcodes; printf(*test);],
-AC_DEFINE(HAVE_STRCODES) strcodes=yes, strcodes=no)
-AC_MSG_RESULT($strcodes)
-AC_MSG_CHECKING(if boolnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = boolnames; printf(*test);],
-AC_DEFINE(HAVE_BOOLNAMES) boolnames=yes, boolnames=no)
-AC_MSG_RESULT($boolnames)
-AC_MSG_CHECKING(if numnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = numnames; printf(*test);],
-AC_DEFINE(HAVE_NUMNAMES) numnames=yes, numnames=no)
-AC_MSG_RESULT($numnames)
-AC_MSG_CHECKING(if strnames is available)
-AC_TRY_LINK([#include <curses.h>
-#include <term.h>], [char **test = strnames; printf(*test);],
-AC_DEFINE(HAVE_STRNAMES) strnames=yes, strnames=no)
-AC_MSG_RESULT($strnames)
-])
-
 
 dnl If our terminal library is not ncurses, don't try including
 dnl any ncurses headers.
-AH_TEMPLATE([ZSH_IGNORE_NCURSES],
-[Define to 1 to ignore any ncurses library headers found on the system.])
-case $LIBS in
-  *-lncurses*) ;;
+AC_CACHE_CHECK(if we need to ignore ncurses, zsh_cv_ignore_ncurses,
+[case $LIBS in
+  *-lncurses*)
+  zsh_cv_ignore_ncurses=no
+  ;;
   *)
-  AC_DEFINE(ZSH_IGNORE_NCURSES) ;;
-esac
+  zsh_cv_ignore_ncurses=yes
+  ;;
+esac])
 
 AC_SEARCH_LIBS(getpwnam, nsl)
 
@@ -1407,20 +1342,42 @@ zsh_cv_path_errno_h="$ERRNO_H"
 ERRNO_H="$zsh_cv_path_errno_h"
 AC_SUBST(ERRNO_H)dnl
 
+AC_CACHE_CHECK(location of curses header, zsh_cv_path_curses_header,
+[if test x$zsh_cv_ignore_ncurses = xyes; then
+  if test x$ac_cv_header_curses_h = xyes; then
+    zsh_cv_path_curses_header=curses.h
+  else
+    zsh_cv_path_curses_header=none
+  fi
+elif test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncursesw/ncurses.h
+elif test x$ac_cv_header_ncurses_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncurses/ncurses.h
+elif test x$ac_cv_header_ncurses_h = xyes; then
+  zsh_cv_path_curses_header=ncurses.h
+elif test x$ac_cv_header_curses_h = xyes; then
+  zsh_cv_path_curses_header=curses.h
+else
+  zsh_cv_path_curses_header=none
+fi])
+AH_TEMPLATE([ZSH_HAVE_CURSES_H],
+[Define to 1 if some variant of a curses header can be included])
+if test x$zsh_cv_path_curses_header != xnone; then
+  AC_DEFINE(ZSH_HAVE_CURSES_H)
+  ZSH_CURSES_H=$zsh_cv_path_curses_header
+else
+  ZSH_CURSES_H=
+fi
+AC_SUBST(ZSH_CURSES_H)
+
 dnl Where are curses key definitions located?  Need for keypad() mode.
 AC_CACHE_CHECK(where curses key definitions are located, zsh_cv_path_curses_keys_h,
 [dnl This is an identical trick to errno.h, except we use ncurses.h
 dnl if we can.
-if test x$ac_cv_header_ncurses_h = xyes; then
-  echo "#include <ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_ncurses_ncurses_h = xyes; then
-  echo "#include <ncurses/ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
-  echo "#include <ncursesw/ncurses.h>" >nametmp.c
-elif test x$ac_cv_header_curses_h = xyes; then
-  echo "#include <curses.h>" >nametmp.c
-else
+if test x$zsh_cv_path_curses_header = xnone; then
   echo >nametmp.c
+else
+  echo "#include <$zsh_cv_path_curses_header>" >nametmp.c
 fi
 
 curses_list="`$CPP nametmp.c |
@@ -1446,6 +1403,97 @@ zsh_cv_path_curses_keys_h="$CURSES_KEYS_H"
 CURSES_KEYS_H="$zsh_cv_path_curses_keys_h"
 AC_SUBST(CURSES_KEYS_H)dnl
 
+dnl See if there are variants of term.h.  For testing each one
+dnl we include the most likely variant of the curses header.
+AC_CHECK_HEADERS(ncursesw/term.h,
+true, true,
+[#include <ncursesw/ncurses.h>])
+AC_CHECK_HEADERS(ncurses/term.h,
+true, true,
+[#include <ncurses/ncurses.h>])
+AC_CHECK_HEADERS(term.h,
+true, true,
+[#include <curses.h>])
+
+dnl See if term.h is bundled along with the curses library we
+dnl are using.  If this isn't the default system curses, compilation
+dnl could barf unless we include from the right subdirectory.
+AC_CACHE_CHECK(where term.h is located, zsh_cv_path_term_header,
+[case x$zsh_cv_path_curses_header in
+  xncursesw/*)
+  if test x$ac_cv_header_ncursesw_term_h = xyes; then
+    zsh_cv_path_term_header=ncursesw/term.h
+  fi
+  ;;
+  xncurses/*)
+  if test x$ac_cv_header_ncurses_term_h = xyes; then
+    zsh_cv_path_term_header=ncurses/term.h
+  fi
+  ;;
+esac
+if test x$zsh_cv_path_term_header = x; then
+  if test x$ac_cv_header_term_h = xyes; then
+    zsh_cv_path_term_header=term.h
+  else
+    zsh_cv_path_term_header=none
+  fi
+fi])
+
+AH_TEMPLATE([ZSH_HAVE_TERM_H],
+[Define to 1 if some variant of term.h can be included])
+AH_TEMPLATE([HAVE_BOOLCODES],
+[Define if you have the termcap boolcodes symbol.])
+AH_TEMPLATE([HAVE_NUMCODES],
+[Define if you have the termcap numcodes symbol.])
+AH_TEMPLATE([HAVE_STRCODES],
+[Define if you have the termcap strcodes symbol.])
+AH_TEMPLATE([HAVE_BOOLNAMES],
+[Define if you have the terminfo boolnames symbol.])
+AH_TEMPLATE([HAVE_NUMNAMES],
+[Define if you have the terminfo numnames symbol.])
+AH_TEMPLATE([HAVE_STRNAMES],
+[Define if you have the terminfo strnames symbol.])
+
+if test x$zsh_cv_path_term_header != xnone; then
+  AC_DEFINE(ZSH_HAVE_TERM_H)
+  ZSH_TERM_H=$zsh_cv_path_term_header
+  if test x$zsh_cv_path_curses_header != xnone; then
+    term_includes="#include <$zsh_cv_path_curses_header>
+#include <$zsh_cv_path_term_header>"
+  else
+    term_includes="#include <$zsh_cv_path_term_header>"
+  fi
+
+  AC_MSG_CHECKING(if boolcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = boolcodes; printf(*test);],
+  AC_DEFINE(HAVE_BOOLCODES) boolcodes=yes, boolcodes=no)
+  AC_MSG_RESULT($boolcodes)
+  AC_MSG_CHECKING(if numcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = numcodes; printf(*test);],
+  AC_DEFINE(HAVE_NUMCODES) numcodes=yes, numcodes=no)
+  AC_MSG_RESULT($numcodes)
+  AC_MSG_CHECKING(if strcodes is available)
+  AC_TRY_LINK($term_includes, [char **test = strcodes; printf(*test);],
+  AC_DEFINE(HAVE_STRCODES) strcodes=yes, strcodes=no)
+  AC_MSG_RESULT($strcodes)
+  AC_MSG_CHECKING(if boolnames is available)
+  AC_TRY_LINK($term_includes, [char **test = boolnames; printf(*test);],
+  AC_DEFINE(HAVE_BOOLNAMES) boolnames=yes, boolnames=no)
+  AC_MSG_RESULT($boolnames)
+  AC_MSG_CHECKING(if numnames is available)
+  AC_TRY_LINK($term_includes, [char **test = numnames; printf(*test);],
+  AC_DEFINE(HAVE_NUMNAMES) numnames=yes, numnames=no)
+  AC_MSG_RESULT($numnames)
+  AC_MSG_CHECKING(if strnames is available)
+  AC_TRY_LINK($term_includes, [char **test = strnames; printf(*test);],
+  AC_DEFINE(HAVE_STRNAMES) strnames=yes, strnames=no)
+  AC_MSG_RESULT($strnames)
+else
+  ZSH_TERM_H=
+fi
+AC_SUBST(ZSH_TERM_H)
+
+
 dnl -----------------------------------------------------
 dnl Look for the file containing the RLIMIT_* definitions
 dnl -----------------------------------------------------