From f1b9067e57387e4c84bed0de8bdf5d19a5b49b46 Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Sun, 3 Nov 2019 15:49:16 +0100 Subject: [PATCH] Allow compiling and linking poke with an older version of textstyle This commit is a hack. It abuses AC_CHECK_LIB to check if the libtextstyle library supports a specific function. It currently doesn't work correctly when a second textstyle.so is available in /usr/local/lib due to issues with GCC's search path. This will be fixed with an updated version of this macro once relevant fixes are pushed to gnulib. Until then, this version will at least allow people with an older version of libtextstyle to compile poke. * m4/libtextstyle-hyperlink.m4: New file with autoconf macro to test for hyperlink support in libtextstyle * configure.ac: Invoke new macro AX_LIBTEXTSTYLE_HYPERLINK * src/pk-term.c (pk_term_hyperlink): Conditionally invoke the function styled_ostream_set_hyperlink based on whether libtextstyle supports it (pk_term_end_hyperlink): Same --- configure.ac | 1 + m4/libtextstyle-hyperlink.m4 | 32 ++++++++++++++++++++++++++++++++ src/pk-term.c | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 m4/libtextstyle-hyperlink.m4 diff --git a/configure.ac b/configure.ac index d3a0b37..15d5a09 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,7 @@ dnl Use libtextstyle if available. Otherwise, use the dummy header dnl file provided by gnulib's libtextstyle-optional module. gl_LIBTEXTSTYLE_OPTIONAL +AX_LIBTEXTSTYLE_HYPERLINK dnl Generate output files AC_CONFIG_FILES(Makefile diff --git a/m4/libtextstyle-hyperlink.m4 b/m4/libtextstyle-hyperlink.m4 new file mode 100644 index 0000000..ae830dd --- /dev/null +++ b/m4/libtextstyle-hyperlink.m4 @@ -0,0 +1,32 @@ +# libtextstyle-hyperlink.m4 serial 1 +dnl Copyright (C) 2019 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Darshit Shah + +dnl AX_LIBTEXTSTYLE_HYPERLINK +dnl Checks if the version of libtextstyle available in the system is recent +dnl enough to support hyperlinks. +dnl It AC_DEFINEs HAVE_TEXTSTYLE_HYPERLINK_SUPPORT based on the result of the +dnl test. + +AC_DEFUN([AX_LIBTEXTSTYLE_HYPERLINK], +[ + AC_REQUIRE([gl_LIBTEXTSTYLE_OPTIONAL]) + if test $HAVE_LIBTEXTSTYLE = yes; then + AC_CHECK_LIB([textstyle], [styled_ostream_set_hyperlink]) + has_hyper_support=${ac_cv_lib_textstyle_styled_ostream_set_hyperlink} + else + dnl If HAVE_LIBTEXTSTYLE is no, then we assume that the gnulib stubs of + dnl textstyle are available. Those stubs implement the dummy functions + dnl required and hence we can assume that hyperlink support is available + has_hyper_support=yes + fi + + if test $has_hyper_support = yes; then + AC_DEFINE([HAVE_TEXTSTYLE_HYPERLINK_SUPPORT], 1, + [Defined if libtextstyle has support for terminal hyperlinks]) + fi +]) diff --git a/src/pk-term.c b/src/pk-term.c index fddeda3..df9ced1 100644 --- a/src/pk-term.c +++ b/src/pk-term.c @@ -133,11 +133,15 @@ pk_term_end_class (const char *class) void pk_term_hyperlink (const char *url, const char *id) { +#ifdef HAVE_LIBTEXT_HYPERLINK_SUPPORT styled_ostream_set_hyperlink (poke_ostream, url, id); +#endif } void pk_term_end_hyperlink (void) { +#ifdef HAVE_LIBTEXT_HYPERLINK_SUPPORT styled_ostream_set_hyperlink (poke_ostream, NULL, NULL); +#endif } -- 2.23.0