Skip to content

Commit

Permalink
Build: configure: Rework curses detection.
Browse files Browse the repository at this point in the history
* Get rid of the large block in configure.ac in favor of using
  AC_SEARCH_LIBS.

* Rename CURSES_ENABLED to PCMK__ENABLE_CURSES.

* Simplify the block in crm_mon.h to only check for the right header to
  include.  Whether or not to build with curses is entirely handled by
  configure.ac now.

* Rename CURSESLIBS to CURSES_LIBS for consistency.

* Get rid of PC_NAME_CURSES and PC_LIBS_CURSES, which aren't used
  anywhere.

* Get rid of HAVE_INCOMPATIBLE_PRINTW.  Instead of having this duplicate
  flag, we can just set PCMK__ENABLE_CURSES based on this test.

Related T876
  • Loading branch information
clumens committed Oct 17, 2024
1 parent 0f75163 commit c4a7eb6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 76 deletions.
66 changes: 22 additions & 44 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1255,45 +1255,20 @@ dnl ncurses takes precedence.
dnl
AC_CHECK_HEADERS([curses.h curses/curses.h ncurses.h ncurses/ncurses.h])

dnl Although n-library is preferred, only look for it if the n-header was found.
CURSESLIBS=''
PC_NAME_CURSES=""
PC_LIBS_CURSES=""
AS_IF([test x"$ac_cv_header_ncurses_h" = x"yes"], [
AC_CHECK_LIB(ncurses, printw,
[AC_DEFINE(HAVE_LIBNCURSES,1, have ncurses library)])
CURSESLIBS=`$PKG_CONFIG --libs ncurses` || CURSESLIBS='-lncurses'
PC_NAME_CURSES="ncurses"
])

AS_IF([test x"$ac_cv_header_ncurses_ncurses_h" = x"yes"], [
AC_CHECK_LIB(ncurses, printw,
[AC_DEFINE(HAVE_LIBNCURSES,1, have ncurses library)])
CURSESLIBS=`$PKG_CONFIG --libs ncurses` || CURSESLIBS='-lncurses'
PC_NAME_CURSES="ncurses"
])

dnl Only look for non-n-library if there was no n-library.
AS_IF([test x"$CURSESLIBS" = x"" && test x"$ac_cv_header_curses_h" = x"yes"], [
AC_CHECK_LIB(curses, printw,
[CURSESLIBS='-lcurses'; AC_DEFINE(HAVE_LIBCURSES,1, have curses library)])
PC_LIBS_CURSES="$CURSESLIBS"
])

dnl Only look for non-n-library if there was no n-library.
AS_IF([test x"$CURSESLIBS" = x"" && test x"$ac_cv_header_curses_curses_h" = x"yes"], [
AC_CHECK_LIB(curses, printw,
[CURSESLIBS='-lcurses'; AC_DEFINE(HAVE_LIBCURSES,1, have curses library)])
PC_LIBS_CURSES="$CURSESLIBS"
])

AS_IF([test x"$CURSESLIBS" != x""],
[PCMK_FEATURES="$PCMK_FEATURES ncurses"])
save_LIBS="$LIBS"
found_curses=0
CURSES_LIBS=""
LIBS=""
AC_SEARCH_LIBS([printw], [ncurses curses],
[test "$ac_cv_search_printw" = "none required" || CURSES_LIBS="$LIBS"
found_curses=1],
[found_curses=0])
LIBS="$save_LIBS"

dnl Check for printw() prototype compatibility
AS_IF([test x"$CURSESLIBS" != x"" && cc_supports_flag -Wcast-qual], [
ac_save_LIBS=$LIBS
LIBS="$CURSESLIBS"
AS_IF([test $found_curses -eq 1 && cc_supports_flag -Wcast-qual], [
ac_save_LIBS="$LIBS"
LIBS="$CURSES_LIBS"
# avoid broken test because of hardened build environment in Fedora 23+
# - https://fedoraproject.org/wiki/Changes/Harden_All_Packages
Expand All @@ -1311,12 +1286,18 @@ AS_IF([test x"$CURSESLIBS" != x"" && cc_supports_flag -Wcast-qual], [
# include <ncurses/ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
#elif defined(HAVE_CURSES_CURSES_H)
# include <curses/curses.h>
#endif
],
[printw((const char *)"Test");]
)],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([yes])
PCMK_FEATURES="$PCMK_FEATURES ncurses"
],
[
found_curses=0
CURSES_LIBS=""
AC_MSG_RESULT([no])
AC_MSG_WARN(m4_normalize([Disabling curses because the printw()
function of your (n)curses library is old.
Expand All @@ -1325,18 +1306,15 @@ AS_IF([test x"$CURSESLIBS" != x"" && cc_supports_flag -Wcast-qual], [
recommended, available from
https://invisible-island.net/ncurses/)
]))
AC_DEFINE([HAVE_INCOMPATIBLE_PRINTW], [1],
[Define to 1 if curses library has incompatible printw()])
]
)
LIBS=$ac_save_LIBS
LIBS="$ac_save_LIBS"
cc_restore_flags
])

AC_SUBST(CURSESLIBS)
AC_SUBST(PC_NAME_CURSES)
AC_SUBST(PC_LIBS_CURSES)
AC_DEFINE_UNQUOTED([PCMK__ENABLE_CURSES], [$found_curses], [have ncurses library])
AC_SUBST(CURSES_LIBS)

dnl ========================================================================
dnl Profiling and GProf
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ crm_mon_LDADD += $(top_builddir)/lib/pengine/libpe_status.la
crm_mon_LDADD += $(top_builddir)/lib/fencing/libstonithd.la
crm_mon_LDADD += $(top_builddir)/lib/cib/libcib.la
crm_mon_LDADD += $(top_builddir)/lib/common/libcrmcommon.la
crm_mon_LDADD += $(CURSESLIBS)
crm_mon_LDADD += $(CURSES_LIBS)

crm_verify_SOURCES = crm_verify.c
crm_verify_LDADD = $(top_builddir)/lib/pacemaker/libpacemaker.la
Expand Down
30 changes: 15 additions & 15 deletions tools/crm_mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static enum pcmk__fence_history fence_history = pcmk__fence_history_none;
int interactive_fence_level = 0;

static pcmk__supported_format_t formats[] = {
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
CRM_MON_SUPPORTED_FORMAT_CURSES,
#endif
PCMK__SUPPORTED_FORMAT_HTML,
Expand Down Expand Up @@ -743,7 +743,7 @@ static GOptionEntry deprecated_entries[] = {
static gboolean
reconnect_after_timeout(gpointer data)
{
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
if (output_format == mon_output_console) {
clear();
refresh();
Expand Down Expand Up @@ -818,7 +818,7 @@ mon_shutdown(int nsig)
clean_up(CRM_EX_OK);
}

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
static volatile sighandler_t ncurses_winch_handler;

/* Signal handler installed the regular way (not into the main loop) for when
Expand Down Expand Up @@ -1011,7 +1011,7 @@ setup_api_connections(void)
return rc;
}

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
static const char *
get_option_desc(char c)
{
Expand Down Expand Up @@ -1162,7 +1162,7 @@ detect_user_input(GIOChannel *channel, GIOCondition condition, gpointer user_dat

return rc;
}
#endif // CURSES_ENABLED
#endif // PCMK__ENABLE_CURSES

// Basically crm_signal_handler(SIGCHLD, SIG_IGN) plus the SA_NOCLDWAIT flag
static void
Expand Down Expand Up @@ -1194,11 +1194,11 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
{ NULL }
};

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
const char *fmts = "console (default), html, text, xml, none";
#else
const char *fmts = "text (default), html, xml, none";
#endif // CURSES_ENABLED
#endif // PCMK__ENABLE_CURSES
const char *desc = NULL;

desc = "Notes:\n\n"
Expand All @@ -1221,7 +1221,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
"list of valid sections, pass --include=list or --exclude=list.\n\n"

"Interactive Use:\n\n"
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
"When run interactively, crm_mon can be told to hide and show\n"
"various sections of output. To see a help screen explaining the\n"
"options, press '?'. Any key stroke aside from those listed will\n"
Expand All @@ -1230,14 +1230,14 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
"The local installation of Pacemaker was built without support for\n"
"interactive (console) mode. A curses library must be available at\n"
"build time to support interactive mode.\n\n"
#endif // CURSES_ENABLED
#endif // PCMK__ENABLE_CURSES

"Examples:\n\n"
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
"Display the cluster status on the console with updates as they\n"
"occur:\n\n"
"\tcrm_mon\n\n"
#endif // CURSES_ENABLED
#endif // PCMK__ENABLE_CURSES

"Display the cluster status once and exit:\n\n"
"\tcrm_mon -1\n\n"
Expand Down Expand Up @@ -1298,7 +1298,7 @@ reconcile_output_format(pcmk__common_args_t *args)
} else if (pcmk__str_eq(args->output_ty, "xml", pcmk__str_none)) {
output_format = mon_output_xml;

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
} else if (pcmk__str_eq(args->output_ty, "console",
pcmk__str_null_matches)) {
/* Console is the default format if no conflicting options are given.
Expand All @@ -1322,7 +1322,7 @@ reconcile_output_format(pcmk__common_args_t *args)
output_format = mon_output_console;
crm_enable_stderr(FALSE);
}
#endif // CURSES_ENABLED
#endif // PCMK__ENABLE_CURSES

} else if (pcmk__str_eq(args->output_ty, "text", pcmk__str_null_matches)) {
/* Text output was explicitly requested, or it's the default because
Expand Down Expand Up @@ -1621,7 +1621,7 @@ main(int argc, char **argv)

// Give some time to view all output even if we won't retry
pcmk__sleep_ms(options.reconnect_ms);
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
if (output_format == mon_output_console) {
clear();
refresh();
Expand All @@ -1641,7 +1641,7 @@ main(int argc, char **argv)

mainloop_add_signal(SIGTERM, mon_shutdown);
mainloop_add_signal(SIGINT, mon_shutdown);
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
if (output_format == mon_output_console) {
ncurses_winch_handler = crm_signal_handler(SIGWINCH, mon_winresize);
if (ncurses_winch_handler == SIG_DFL ||
Expand Down
20 changes: 6 additions & 14 deletions tools/crm_mon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@
* We believe the following to be acceptable and portable.
*/

# if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBCURSES)
# if defined(HAVE_NCURSES_H) && !defined(HAVE_INCOMPATIBLE_PRINTW)
# if PCMK__ENABLE_CURSES
# if defined(HAVE_NCURSES_H)
# include <ncurses.h>
# define CURSES_ENABLED 1
# elif defined(HAVE_NCURSES_NCURSES_H) && !defined(HAVE_INCOMPATIBLE_PRINTW)
# elif defined(HAVE_NCURSES_NCURSES_H)
# include <ncurses/ncurses.h>
# define CURSES_ENABLED 1
# elif defined(HAVE_CURSES_H) && !defined(HAVE_INCOMPATIBLE_PRINTW)
# elif defined(HAVE_CURSES_H)
# include <curses.h>
# define CURSES_ENABLED 1
# elif defined(HAVE_CURSES_CURSES_H) && !defined(HAVE_INCOMPATIBLE_PRINTW)
# elif defined(HAVE_CURSES_CURSES_H)
# include <curses/curses.h>
# define CURSES_ENABLED 1
# else
# define CURSES_ENABLED 0
# endif
# else
# define CURSES_ENABLED 0
# endif

typedef enum mon_output_format_e {
Expand All @@ -62,7 +54,7 @@ enum mon_exec_mode {

void crm_mon_register_messages(pcmk__output_t *out);

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
pcmk__output_t *crm_mon_mk_curses_output(char **argv);
void curses_formatted_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
void curses_formatted_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
Expand Down
4 changes: 2 additions & 2 deletions tools/crm_mon_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "crm_mon.h"

#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES

typedef struct curses_list_data_s {
unsigned int len;
Expand Down Expand Up @@ -488,7 +488,7 @@ static pcmk__message_entry_t fmt_functions[] = {

void
crm_mon_register_messages(pcmk__output_t *out) {
#if CURSES_ENABLED
#if PCMK__ENABLE_CURSES
pcmk__register_messages(out, fmt_functions);
#endif
}

0 comments on commit c4a7eb6

Please sign in to comment.