summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2021-07-14 11:03:19 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2021-07-14 11:03:19 +0100
commitd723466df2adaec4bb655094a942a427633aacff (patch)
tree01ab9819a3d1104160229dd688eec4c8bd4b4c9c
parentbb4bc8caf4a7fa1680333a42679ca72390b60001 (diff)
Pick default-terminal from the first of tmux-256color, tmux, screen-256color,
screen that is available on the build system.
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac94
2 files changed, 90 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index 9bb5b89e..dadf13a0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,8 @@ dist_EXTRA_tmux_SOURCES = compat/*.[ch]
# Preprocessor flags.
AM_CPPFLAGS += @XOPEN_DEFINES@ \
-DTMUX_VERSION='"@VERSION@"' \
- -DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"'
+ -DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"' \
+ -DTMUX_TERM='"@DEFAULT_TERM@"'
# Additional object files.
LDADD = $(LIBOBJS)
diff --git a/configure.ac b/configure.ac
index 30b4d370..2a9907ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,21 @@ if test "x$enable_static" = xyes; then
LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
fi
+# Allow default TERM to be set.
+AC_ARG_WITH(
+ TERM,
+ AC_HELP_STRING(--with-TERM, set default TERM),
+ [DEFAULT_TERM=$withval],
+ [DEFAULT_TERM=]
+)
+case "x$DEFAULT_TERM" in
+ xscreen*|xtmux*|x)
+ ;;
+ *)
+ AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
+ ;;
+esac
+
# Do we need fuzzers?
AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
@@ -156,12 +171,12 @@ AC_FUNC_STRNLEN
# Check if strtonum works.
AC_MSG_CHECKING([for working strtonum])
AC_RUN_IFELSE([AC_LANG_PROGRAM(
- [#include <stdlib.h>],
- [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
- )],
- [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
- [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
- [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
+ [#include <stdlib.h>],
+ [return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
+ )],
+ [AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
+ [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
+ [AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
)
# Clang sanitizers wrap reallocarray even if it isn't available on the target
@@ -299,6 +314,7 @@ if test "x$found_ncurses" = xno; then
fi
fi
if test "x$found_ncurses" = xyes; then
+ CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
AC_DEFINE(HAVE_NCURSES_H)
else
AC_CHECK_LIB(
@@ -314,6 +330,7 @@ else
)
if test "x$found_curses" = xyes; then
LIBS="$LIBS -lcurses"
+ CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
AC_DEFINE(HAVE_CURSES_H)
else
AC_MSG_ERROR("curses not found")
@@ -673,6 +690,71 @@ else
AC_MSG_RESULT(no)
fi
+# Try to figure out what the best value for TERM might be.
+if test "x$DEFAULT_TERM" = x; then
+ DEFAULT_TERM=screen
+ AC_MSG_CHECKING(TERM)
+ AC_RUN_IFELSE([AC_LANG_SOURCE(
+ [
+ #include <stdio.h>
+ #include <stdlib.h>
+ #if defined(HAVE_CURSES_H)
+ #include <curses.h>
+ #elif defined(HAVE_NCURSES_H)
+ #include <ncurses.h>
+ #endif
+ #include <term.h>
+ int main(void) {
+ if (setupterm("screen-256color", -1, NULL) != OK)
+ exit(1);
+ exit(0);
+ }
+ ])],
+ [DEFAULT_TERM=screen-256color],
+ ,
+ )
+ AC_RUN_IFELSE([AC_LANG_SOURCE(
+ [
+ #include <stdio.h>
+ #include <stdlib.h>
+ #if defined(HAVE_CURSES_H)
+ #include <curses.h>
+ #elif defined(HAVE_NCURSES_H)
+ #include <ncurses.h>
+ #endif
+ #include <term.h>
+ int main(void) {
+ if (setupterm("tmux", -1, NULL) != OK)
+ exit(1);
+ exit(0);
+ }
+ ])],
+ [DEFAULT_TERM=tmux],
+ ,
+ )
+ AC_RUN_IFELSE([AC_LANG_SOURCE(
+ [
+ #include <stdio.h>
+ #include <stdlib.h>
+ #if defined(HAVE_CURSES_H)
+ #include <curses.h>
+ #elif defined(HAVE_NCURSES_H)
+ #include <ncurses.h>
+ #endif
+ #include <term.h>
+ int main(void) {
+ if (setupterm("tmux-256color", -1, NULL) != OK)
+ exit(1);
+ exit(0);
+ }
+ ])],
+ [DEFAULT_TERM=tmux-256color],
+ ,
+ )
+ AC_MSG_RESULT($DEFAULT_TERM)
+fi
+AC_SUBST(DEFAULT_TERM)
+
# Man page defaults to mdoc.
MANFORMAT=mdoc
AC_SUBST(MANFORMAT)