@@ -56,20 +56,48 @@ dnl gnulib will handle getopt and error functions
5656dnl Check pcre2 availability
5757AC_MSG_CHECKING ( [ whether PCRE2 support is requested] )
5858AC_ARG_WITH ( [ pcre2] ,
59- [ AS_HELP_STRING ( [ --with-pcre2] ,
60- [ use pcre2 regex library @<:@ default=check@:>@ ] ) ] ,
59+ [ AS_HELP_STRING ( [ --with-pcre2@<:@ =PATH @:>@ ] ,
60+ [ use pcre2 regex library, optionally from PATH @<:@ default=check@:>@ ] ) ] ,
6161 [ ] , [ with_pcre2=check] )
6262LIBPCRE2=
6363AS_IF ( [ test "x$with_pcre2" != xno] ,
6464 [
6565 AC_MSG_RESULT ( $with_pcre2 )
66+ dnl Handle custom path for PCRE2
67+ AS_IF ( [ test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck] ,
68+ [
69+ dnl Custom path specified
70+ PCRE2_CPPFLAGS="-I$with_pcre2/include"
71+ PCRE2_LDFLAGS="-L$with_pcre2/lib"
72+ save_CPPFLAGS="$CPPFLAGS"
73+ save_LDFLAGS="$LDFLAGS"
74+ CPPFLAGS="$CPPFLAGS $PCRE2_CPPFLAGS"
75+ LDFLAGS="$LDFLAGS $PCRE2_LDFLAGS"
76+ ] )
6677 AC_CHECK_HEADERS ( [ pcre2posix.h] , [ ] , [ LIBPCRE2=_missing_header] )
6778 AC_CHECK_LIB ( [ pcre2-posix${LIBPCRE2}] , [ regexec] ,
68- [ ] ,
69- [ if test "x$with_pcre2" != xcheck; then
70- AC_MSG_FAILURE (
71- [ --with-pcre2 was given, but test for pcre2-posix failed] )
72- fi]
79+ [
80+ dnl Success - add the flags permanently if custom path was used
81+ AS_IF ( [ test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck] ,
82+ [
83+ CPPFLAGS="$save_CPPFLAGS $PCRE2_CPPFLAGS"
84+ LDFLAGS="$save_LDFLAGS $PCRE2_LDFLAGS"
85+ ] )
86+ dnl Add the library to LIBS
87+ LIBS="$LIBS -lpcre2-posix${LIBPCRE2}"
88+ ] ,
89+ [
90+ dnl Failure - restore original flags if custom path was used
91+ AS_IF ( [ test "x$with_pcre2" != xyes && test "x$with_pcre2" != xcheck] ,
92+ [
93+ CPPFLAGS="$save_CPPFLAGS"
94+ LDFLAGS="$save_LDFLAGS"
95+ ] )
96+ if test "x$with_pcre2" != xcheck; then
97+ AC_MSG_FAILURE (
98+ [ --with-pcre2 was given, but test for pcre2-posix failed] )
99+ fi
100+ ]
73101 )
74102 ] ,
75103 AC_MSG_RESULT ( no )
0 commit comments