From fad5c3eb74b143d5eb06be3e0efdc00b02fdcb97 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Wed, 17 Jul 2024 15:59:51 -0300 Subject: [PATCH] Move ext/tidy to pkg-config It seems most distributions i.e. Debian/Gentoo/Fedora have all moved over to html-tidy as the tidy library they ship. It ships a pkg-config file, so we can just simply check for that and omit the various alternatives to check for. I'm not sure if the checks for library functionality are needed anymore if we assume the html5 tidy fork either. --- ext/tidy/config.m4 | 82 +++++++++++----------------------------------- ext/tidy/tidy.c | 9 ----- 2 files changed, 20 insertions(+), 71 deletions(-) diff --git a/ext/tidy/config.m4 b/ext/tidy/config.m4 index 18fa9acb3d4b..2a2c3a51fd4d 100644 --- a/ext/tidy/config.m4 +++ b/ext/tidy/config.m4 @@ -1,69 +1,29 @@ PHP_ARG_WITH([tidy], [for TIDY support], - [AS_HELP_STRING([[--with-tidy[=DIR]]], + [AS_HELP_STRING([--with-tidy], [Include TIDY support])]) if test "$PHP_TIDY" != "no"; then - AS_VAR_IF([PHP_TIDY], [yes], - [TIDY_SEARCH_DIRS="/usr/local /usr"], - [TIDY_SEARCH_DIRS=$PHP_TIDY]) + PKG_CHECK_MODULES([TIDY], [tidy]) - for i in $TIDY_SEARCH_DIRS; do - for j in tidy tidyp; do - AS_IF([test -f $i/include/$j/$j.h], [ - TIDY_DIR=$i - TIDY_INCDIR=$i/include/$j - TIDY_LIB_NAME=$j - break 2 - ], - [test -f $i/include/$j.h], [ - TIDY_DIR=$i - TIDY_INCDIR=$i/include - TIDY_LIB_NAME=$j - break 2 - ]) - done - done + PHP_EVAL_LIBLINE([$TIDY_LIBS], [TIDY_SHARED_LIBADD]) + PHP_EVAL_INCLINE([$TIDY_CFLAGS]) - AS_VAR_IF([TIDY_DIR],, [AC_MSG_ERROR([Cannot find libtidy])]) + dnl We used to check for tidybuffio, but it seems almost everyone has moved + dnl to using the html5 tidy fork which uses that name. + dnl This also means the library name is 'tidy'. - dnl Check for tidybuffio.h (as opposed to simply buffio.h) which indicates - dnl that we are building against tidy-html5 and not the legacy htmltidy. The - dnl two are compatible, except for with regard to this header file. - AS_IF([test -f "$TIDY_INCDIR/tidybuffio.h"], - [AC_DEFINE([HAVE_TIDYBUFFIO_H], [1], - [Define to 1 if you have the header file.])]) + PHP_CHECK_LIBRARY(tidy,tidyOptGetDoc, + [ + AC_DEFINE(HAVE_TIDYOPTGETDOC,1,[ ]) + ], [], []) + PHP_CHECK_LIBRARY(tidy, tidyReleaseDate, + [ + AC_DEFINE(HAVE_TIDYRELEASEDATE,1,[ ]) + ], [], []) - TIDY_LIBDIR=$TIDY_DIR/$PHP_LIBDIR - AS_VAR_IF([TIDY_LIB_NAME], [tidyp], - [AC_DEFINE([HAVE_TIDYP_H], [1], - [Define to 1 if you have the header file.])], - [AC_DEFINE([HAVE_TIDY_H], [1], - [Define to 1 if you have the header file.])]) - - PHP_CHECK_LIBRARY([$TIDY_LIB_NAME], [tidyOptGetDoc], - [AC_DEFINE([HAVE_TIDYOPTGETDOC], [1], - [Define to 1 if Tidy library has the 'tidyOptGetDoc' function.])], - [PHP_CHECK_LIBRARY([tidy5], [tidyOptGetDoc], - [TIDY_LIB_NAME=tidy5 - AC_DEFINE([HAVE_TIDYOPTGETDOC], [1])], - [], - [-L$TIDY_LIBDIR])], - [-L$TIDY_LIBDIR]) - - PHP_CHECK_LIBRARY([$TIDY_LIB_NAME], [tidyReleaseDate], - [AC_DEFINE([HAVE_TIDYRELEASEDATE], [1], - [Define to 1 if Tidy library has the 'tidyReleaseDate' function.])], - [], - [-L$TIDY_LIBDIR]) - - PHP_ADD_LIBRARY_WITH_PATH([$TIDY_LIB_NAME], - [$TIDY_LIBDIR], - [TIDY_SHARED_LIBADD]) - PHP_ADD_INCLUDE([$TIDY_INCDIR]) - - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS=-I$TIDY_INCDIR + old_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="-I$TIDY_INCDIR" dnl The tidyOptGetCategory function (added in tidy-html5 5.4.0) is only dnl useable if TidyInternalCategory (added in tidy-html5 5.6.0) is also @@ -84,14 +44,12 @@ if test "$PHP_TIDY" != "no"; then [Define to 1 if Tidy library has the 'tidyOptGetCategory' function and supports the 'TidyInternalCategory' enumeration.])]) - CPPFLAGS=$old_CPPFLAGS + CPPFLAGS="$old_CPPFLAGS" dnl Add -Wno-ignored-qualifiers as this is an issue upstream. Fixed in dnl tidy-html5 5.7.20: https://github.com/htacg/tidy-html5/issues/866 - PHP_NEW_EXTENSION([tidy], - [tidy.c], - [$ext_shared],, - [-Wno-ignored-qualifiers -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + TIDY_COMPILER_FLAGS="$TIDY_CFLAGS -Wno-ignored-qualifiers -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1" + PHP_NEW_EXTENSION(tidy, tidy.c, $ext_shared,, $TIDY_COMPILER_FLAGS) PHP_SUBST([TIDY_SHARED_LIBADD]) AC_DEFINE([HAVE_TIDY], [1], [Define to 1 if the PHP extension 'tidy' is available.]) diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 496fb260976e..063d10da945c 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -26,17 +26,8 @@ #include "php_ini.h" #include "ext/standard/info.h" -#ifdef HAVE_TIDY_H #include "tidy.h" -#elif defined(HAVE_TIDYP_H) -#include "tidyp.h" -#endif - -#ifdef HAVE_TIDYBUFFIO_H #include "tidybuffio.h" -#else -#include "buffio.h" -#endif #include "tidy_arginfo.h"