From 9c8abddc52c58cd115372daf010166b2fbedbe63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Fri, 8 Apr 2022 09:07:30 -0700 Subject: [PATCH] pcre2test: really allow using libedit when enabled (#96) * pcre2test: use the right header for libedit in FreeBSD with autoconf When `./configure --enable-pcre2test-libedit` is used in FreeBSD, the resulting test will succeed but won't set the necessary flag to distinguish between libedit and readline header files, therefore using readline's at built time (if installed) Consolidate all header tests into one and use instead the corresponding autogenerated defines to check for each possibility. * pcre2test: really allow libedit with cmake Using cmake to configure and enable linking pcre2test with libedit, could result in a broken build, because the header used was instead pointing to readline. In cases were the build will succeed (because both libraries were available), it would likely show warnings, because several history functions were being used without declarations, since readline requires including "history.h" for those. Additionally, since PCRE2_SUPPORT_READLINE is ON by default (unlike configure), turning PCRE2_SUPPORT_LIBEDIT=ON, would require setting that other option to OFF explicitly (even if readline wasn't available) or the setup would abort. Lastly, in systems with no default sysroot (ex: macOS), the use of absolute paths for searching for libedit's readline.h could fail so use instead relative PATH_SUFFIXES. * pcre2test: avoid using readline headers with libedit When asked to enable libedit in a system that ALSO has readline, the headers of the former would be found and used by the earlier. While that would mostly work, some functions will be missing definitions (which is forbidden in C99), so instead abort the configuration and let the user provide for them. --- CMakeLists.txt | 19 +++++++++++++++---- cmake/FindEditline.cmake | 7 +++---- configure.ac | 13 ++++++------- src/pcre2test.c | 4 +++- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e3a8dd..31c0a70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,9 +306,15 @@ ENDIF(PCRE2_SUPPORT_LIBZ) IF(EDITLINE_FOUND) OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) ENDIF(EDITLINE_FOUND) -IF(PCRE2_SUPPORT_LIBEDIT) - INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) -ENDIF(PCRE2_SUPPORT_LIBEDIT) +IF(EDITLINE_FOUND) + IF(PCRE2_SUPPORT_LIBEDIT) + INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) + ENDIF(PCRE2_SUPPORT_LIBEDIT) +ELSE(EDITLINE_FOUND) + IF(PCRE2_SUPPORT_LIBEDIT) + MESSAGE(FATAL_ERROR "libedit not found, set Editline_ROOT if needed") + ENDIF(PCRE2_SUPPORT_LIBEDIT) +ENDIF(EDITLINE_FOUND) # readline lib IF(READLINE_FOUND) @@ -346,7 +352,12 @@ IF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) ENDIF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) IF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) - MESSAGE(FATAL_ERROR "Only one of libreadline or libeditline can be specified") + IF(READLINE_FOUND) + MESSAGE(FATAL_ERROR + " Only one of the readline compatible libraries can be enabled.\n" + " Disable libreadline with -DPCRE2_SUPPORT_LIBREADLINE=OFF" + ) + ENDIF(READLINE_FOUND) ENDIF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) IF(PCRE2_SUPPORT_BSR_ANYCRLF) diff --git a/cmake/FindEditline.cmake b/cmake/FindEditline.cmake index 2d0b7cc..37eeb3e 100644 --- a/cmake/FindEditline.cmake +++ b/cmake/FindEditline.cmake @@ -3,10 +3,9 @@ if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) set(EDITLINE_FOUND TRUE) else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) - FIND_PATH(EDITLINE_INCLUDE_DIR readline.h - /usr/include/editline - /usr/include/edit/readline - /usr/include/readline + FIND_PATH(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES + editline + edit/readline ) FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit) diff --git a/configure.ac b/configure.ac index caa4093..7f22640 100644 --- a/configure.ac +++ b/configure.ac @@ -597,14 +597,14 @@ if test "$enable_pcre2test_libreadline" = "yes"; then fi fi - # Check for the availability of libedit. Different distributions put its # headers in different places. Try to cover the most common ones. if test "$enable_pcre2test_libedit" = "yes"; then - AC_CHECK_HEADERS([editline/readline.h], [HAVE_EDITLINE_READLINE_H=1], - [AC_CHECK_HEADERS([edit/readline/readline.h], [HAVE_READLINE_READLINE_H=1], - [AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_READLINE_H=1])])]) + AC_CHECK_HEADERS([editline/readline.h edit/readline/readline.h], [ + HAVE_LIBEDIT_HEADER=1 + break + ]) AC_CHECK_LIB([edit], [readline], [LIBEDIT="-ledit"]) fi @@ -940,10 +940,9 @@ if test "$enable_pcre2test_libedit" = "yes"; then echo "** Cannot use both --enable-pcre2test-libedit and --enable-pcre2test-readline" exit 1 fi - if test "$HAVE_EDITLINE_READLINE_H" != "1" -a \ - "$HAVE_READLINE_READLINE_H" != "1"; then + if test -z "$HAVE_LIBEDIT_HEADER"; then echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h" - echo "** nor readline/readline.h was found." + echo "** nor edit/readline/readline.h was found." exit 1 fi if test -z "$LIBEDIT"; then diff --git a/src/pcre2test.c b/src/pcre2test.c index 8e712c3..3de92b4 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -94,8 +94,10 @@ that first, falling back to readline/readline.h. */ #else #if defined(HAVE_EDITLINE_READLINE_H) #include +#elif defined(HAVE_EDIT_READLINE_READLINE_H) +#include #else -#include +#include #endif #endif #endif