Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "stdscr" configure failure & ncursest support #1558

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pixmap_DATA = htop.png
appicondir = $(datadir)/icons/hicolor/scalable/apps
appicon_DATA = htop.svg

AM_CFLAGS += -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR="\"$(sysconfdir)\"" -I"$(top_srcdir)/$(my_htop_platform)"
AM_CFLAGS += -DSYSCONFDIR="\"$(sysconfdir)\"" -I"$(top_srcdir)/$(my_htop_platform)"
AM_LDFLAGS =

myhtopsources = \
Expand Down Expand Up @@ -508,11 +508,11 @@ cppcheck:
cppcheck -q -v . --enable=all -DHAVE_OPENVZ

dist-hook: $(top_distdir)/configure
@if test "x$$FORCE_MAKE_DIST" = x && \
grep 'pkg_m4_absent' '$(top_distdir)/configure' >/dev/null; then \
echo 'ERROR: This distribution would have incomplete pkg-config support. Rebuilding the configure script is advised. Set FORCE_MAKE_DIST=1 to ignore this warning.'>&2; \
@if test "x$$FORCE_MAKE_DIST" != x || \
grep 'pkg_m4_included' '$(top_distdir)/configure' >/dev/null; then :; \
else \
echo 'ERROR: The configure script has incomplete pkg-config support and regenerating it is advised. Set FORCE_MAKE_DIST=1 to ignore this warning.'>&2; \
(exit 1); \
else :; \
fi
@if grep 'PACKAGE_VERSION.*-g' '$(top_distdir)/configure'; then \
echo 'WARNING: You are building a dist from a git version. Better run make dist outside of a .git repo on a tagged release.'>&2; \
Expand Down
4 changes: 4 additions & 0 deletions ProvideCurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ in the source distribution for its full text.
*/


// This header is also used in tests by configure, thus conditionally
// including "config.h".
#if defined(HAVE_CONFIG_H)
#include "config.h" // IWYU pragma: keep
#endif

// IWYU pragma: begin_exports

Expand Down
76 changes: 64 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ esac
# Enable extensions, required by hwloc scripts
AC_USE_SYSTEM_EXTENSIONS

# The header of ncurses exposes wide-character interfaces only if
# _XOPEN_SOURCE_EXTENDED is defined or _XOPEN_SOURCE defined to be
# >= 500. In DragonFly BSD, FreeBSD and OpenBSD, defining
# _XOPEN_SOURCE to any value *hides* interfaces that would be useful
# for htop.
dnl
dnl Note: The "#undef" in AH_VERBATIM will be replaced with "#define"
dnl when config.h is generated.
AH_VERBATIM([_XOPEN_SOURCE_EXTENDED],
[/* Enables XPG4v2 (SUSv1) interfaces if they are not enabled already with _XOPEN_SOURCE */
#ifndef _XOPEN_SOURCE_EXTENDED
#undef _XOPEN_SOURCE_EXTENDED
#endif
Comment on lines +81 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you got the check inverted by accident …

Suggested change
#ifndef _XOPEN_SOURCE_EXTENDED
#undef _XOPEN_SOURCE_EXTENDED
#endif
#ifdef _XOPEN_SOURCE_EXTENDED
#undef _XOPEN_SOURCE_EXTENDED
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It is not an error. It's the peculiarity of the config.h.in format. The #undef is technically the placeholder that would be replaced by #define during configure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. Please add a small note about this to document this somewhat. TIA.

])
AC_DEFINE([_XOPEN_SOURCE_EXTENDED], 1)

# Activate some more of the missing global defines
AC_SYS_LARGEFILE

Expand Down Expand Up @@ -384,8 +400,8 @@ dnl If the macro is not called, some pkg-config checks might be skipped
dnl and $PKG_CONFIG might be unset.
m4_ifdef([PKG_PROG_PKG_CONFIG], [
PKG_PROG_PKG_CONFIG()
pkg_m4_included=1 # Makefile might grep this keyword. Don't remove.
], [
pkg_m4_absent=1 # Makefile might grep this keyword. Don't remove.
m4_warn(
[syntax],
[pkg.m4 is absent or older than version 0.16; this 'configure' would have incomplete pkg-config support])
Expand All @@ -412,10 +428,10 @@ AC_ARG_WITH([curses],
[],
[with_curses=check])
case $with_curses in
check)
check|yes)
: # No-op. Use default list.
;;
yes|no)
no)
AC_MSG_ERROR([bad value '$with_curses' for --with-curses option])
;;
*)
Expand Down Expand Up @@ -450,18 +466,17 @@ htop_check_curses_capability () {
# At this point we have not checked the name of curses header, so
# use forward declaration for the linking tests below.

# htop uses keypad() and "stdscr", but for ncurses implementation,
# the symbols are in "-ltinfo" and not "-lncurses".
# htop uses keypad(), but for ncurses implementation, the symbol is
# in "-ltinfo" and not "-lncurses".
# Check "-ltinfo" symbols first, as libncurses might require
# explicit "-ltinfo" to link (for internal dependency).
AC_MSG_CHECKING([for keypad in $htop_msg_linker_flags])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
/* extern WINDOW* stdscr; */
/* int keypad(WINDOW* win, bool enable); */
extern void* stdscr;
int keypad(void* win, int enable);
]], [[
keypad(stdscr, 0);
static char dummy;
keypad((void*)&dummy, 0);
]])],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
Expand All @@ -483,13 +498,17 @@ doupdate();
htop_curses_status=1])
fi

# htop calls mvadd_wchnstr(), which might be implemented as a macro.
# It is more reliable to test linking with wadd_wchnstr().
if test "x$htop_curses_status$enable_unicode" = x0yes; then
AC_MSG_CHECKING([for mvadd_wchnstr in $htop_msg_linker_flags])
AC_MSG_CHECKING([for wadd_wchnstr in $htop_msg_linker_flags])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
/* int mvadd_wchnstr(int y, int x, const cchar_t* wchstr, int n); */
int mvadd_wchnstr(int y, int x, const void* wchstr, int n);
/* int wadd_wchnstr(WINDOW* win, const cchar_t* wchstr, int n); */
int wadd_wchnstr(void* win, const void* wchstr, int n);
]], [[
mvadd_wchnstr(0, 0, (void*)0, 0);
static char dummy1;
static char dummy2;
wadd_wchnstr((void*)&dummy1, (void*)&dummy2, 0);
]])],
[AC_MSG_RESULT(yes)
htop_curses_capability=wide],
Expand Down Expand Up @@ -607,7 +626,11 @@ none-*|nonwide-yes)
for d in $list; do
result=`find "$d" -name '*curses*.pc' 2>/dev/null | sed '1 q'`
if test "x$result" != x; then
echo detected a .pc file: "$result" >&AS_MESSAGE_LOG_FD
AC_MSG_WARN([your system supports pkg-config; installing pkg-config is recommended before configuring htop])
m4_ifdef([PKG_PROG_PKG_CONFIG], [], [
AC_MSG_WARN([this configure script would also need to be regenerated])
])
break
fi
done
Expand Down Expand Up @@ -643,6 +666,7 @@ esac

htop_save_CFLAGS=$CFLAGS
CFLAGS="$AM_CFLAGS $CFLAGS"

if test "x$enable_unicode" = xyes; then
AC_CHECK_HEADERS([ncursesw/curses.h], [],
[AC_CHECK_HEADERS([ncurses/ncurses.h], [],
Expand All @@ -665,6 +689,34 @@ else
[AC_CHECK_HEADERS([term.h], [],
[AC_MSG_ERROR([can not find required term header file])])])
fi

CFLAGS="-I$srcdir $CFLAGS"

# Check for things that might be macros.
# "stdscr" is a macro in ncursest (reentrant version of ncurses).
AC_MSG_CHECKING([whether the curses header works])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
/* Checks if the "bool" definition in curses is ISO C compatible */
#include <stdbool.h>

#include "ProvideCurses.h"
]], [[
keypad(stdscr, false);

refresh();

#if defined(HAVE_LIBNCURSESW)
{
static cchar_t dummy;
mvadd_wchnstr(0, 0, &dummy, 0);
}
#endif
]])],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
AC_MSG_FAILURE([there are problems with the curses header])]
)

CFLAGS=$htop_save_CFLAGS

if test "$enable_static" = yes; then
Expand Down
Loading