|
| 1 | +dnl Check for PCRE2 Libraries |
| 2 | +dnl CHECK_PCRE2(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) |
| 3 | + |
| 4 | +AC_DEFUN([PROG_PCRE2], [ |
| 5 | +
|
| 6 | +# Possible names for the pcre2 library/package (pkg-config) |
| 7 | +PCRE2_POSSIBLE_LIB_NAMES="pcre2 pcre2-8" |
| 8 | +
|
| 9 | +# Possible extensions for the library |
| 10 | +PCRE2_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0" |
| 11 | +
|
| 12 | +# Possible paths (if pkg-config was not found, proceed with the file lookup) |
| 13 | +PCRE2_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/libpcre2-8 /usr/local/pcre2 /usr/local /opt/libpcre2-8 /opt/pcre2 /opt /usr /usr/lib64 /opt/local" |
| 14 | +
|
| 15 | +# Variables to be set by this very own script. |
| 16 | +PCRE2_VERSION="" |
| 17 | +PCRE2_CFLAGS="" |
| 18 | +PCRE2_CPPFLAGS="" |
| 19 | +PCRE2_LDADD="" |
| 20 | +PCRE2_LDFLAGS="" |
| 21 | +
|
| 22 | +AC_ARG_WITH( |
| 23 | + pcre2, |
| 24 | + AC_HELP_STRING( |
| 25 | + [--with-pcre2=PATH], |
| 26 | + [Path to pcre2 prefix or config script] |
| 27 | + ) |
| 28 | +) |
| 29 | +
|
| 30 | +if test "x${with_pcre2}" == "xno"; then |
| 31 | + AC_DEFINE(HAVE_PCRE2, 0, [Support for PCRE2 was disabled by the utilization of --without-pcre2 or --with-pcre2=no]) |
| 32 | + AC_MSG_NOTICE([Support for PCRE2 was disabled by the utilization of --without-pcre2 or --with-pcre2=no]) |
| 33 | + PCRE2_DISABLED=yes |
| 34 | +else |
| 35 | + if test "x${with_pcre2}" == "xyes"; then |
| 36 | + PCRE2_MANDATORY=yes |
| 37 | + AC_MSG_NOTICE([PCRE2 support was marked as mandatory by the utilization of --with-pcre2=yes]) |
| 38 | + fi |
| 39 | +# for x in ${PCRE2_POSSIBLE_LIB_NAMES}; do |
| 40 | +# CHECK_FOR_PCRE2_AT(${x}) |
| 41 | +# if test -n "${PCRE2_VERSION}"; then |
| 42 | +# break |
| 43 | +# fi |
| 44 | +# done |
| 45 | +
|
| 46 | +# if test "x${with_pcre2}" != "xyes" or test "x${with_pcre2}" == "xyes"; then |
| 47 | + if test "x${with_pcre2}" == "x" || test "x${with_pcre2}" == "xyes"; then |
| 48 | + # Nothing about PCRE2 was informed, using the pkg-config to figure things out. |
| 49 | + if test -n "${PKG_CONFIG}"; then |
| 50 | + PCRE2_PKG_NAME="" |
| 51 | + for x in ${PCRE2_POSSIBLE_LIB_NAMES}; do |
| 52 | + if ${PKG_CONFIG} --exists ${x}; then |
| 53 | + PCRE2_PKG_NAME="$x" |
| 54 | + break |
| 55 | + fi |
| 56 | + done |
| 57 | + fi |
| 58 | + AC_MSG_NOTICE([Nothing about PCRE2 was informed during the configure phase. Trying to detect it on the platform...]) |
| 59 | + if test -n "${PCRE2_PKG_NAME}"; then |
| 60 | + # Package was found using the pkg-config scripts |
| 61 | + PCRE2_VERSION="`${PKG_CONFIG} ${PCRE2_PKG_NAME} --modversion`" |
| 62 | + PCRE2_CFLAGS="`${PKG_CONFIG} ${PCRE2_PKG_NAME} --cflags`" |
| 63 | + PCRE2_LDADD="`${PKG_CONFIG} ${PCRE2_PKG_NAME} --libs-only-l`" |
| 64 | + PCRE2_LDFLAGS="`${PKG_CONFIG} ${PCRE2_PKG_NAME} --libs-only-L --libs-only-other`" |
| 65 | + PCRE2_DISPLAY="${PCRE2_LDADD}, ${PCRE2_CFLAGS}" |
| 66 | + else |
| 67 | + # If pkg-config did not find anything useful, go over file lookup. |
| 68 | + for x in ${PCRE2_POSSIBLE_PATHS}; do |
| 69 | + CHECK_FOR_PCRE2_AT(${x}) |
| 70 | + if test -n "${PCRE2_VERSION}"; then |
| 71 | + break |
| 72 | + fi |
| 73 | + done |
| 74 | + fi |
| 75 | + fi |
| 76 | + if test "x${with_pcre2}" != "x"; then |
| 77 | + # An specific path was informed, lets check. |
| 78 | + PCRE2_MANDATORY=yes |
| 79 | + CHECK_FOR_PCRE2_AT(${with_pcre2}) |
| 80 | + fi |
| 81 | +# fi |
| 82 | +fi |
| 83 | +
|
| 84 | +if test -z "${PCRE2_LDADD}"; then |
| 85 | + if test -z "${PCRE2_MANDATORY}"; then |
| 86 | + if test -z "${PCRE2_DISABLED}"; then |
| 87 | + AC_MSG_NOTICE([PCRE2 library was not found]) |
| 88 | + PCRE2_FOUND=0 |
| 89 | + else |
| 90 | + PCRE2_FOUND=2 |
| 91 | + fi |
| 92 | + else |
| 93 | + AC_MSG_ERROR([PCRE2 was explicitly referenced but it was not found]) |
| 94 | + PCRE2_FOUND=-1 |
| 95 | + fi |
| 96 | +else |
| 97 | + if test -z "${PCRE2_MANDATORY}"; then |
| 98 | + PCRE2_FOUND=2 |
| 99 | + AC_MSG_NOTICE([PCRE2 is disabled by default.]) |
| 100 | + else |
| 101 | + PCRE2_FOUND=1 |
| 102 | + AC_MSG_NOTICE([using PCRE2 v${PCRE2_VERSION}]) |
| 103 | + PCRE2_CFLAGS="-DWITH_PCRE2 ${PCRE2_CFLAGS}" |
| 104 | + PCRE2_DISPLAY="${PCRE2_LDADD}, ${PCRE2_CFLAGS}" |
| 105 | + AC_SUBST(PCRE2_VERSION) |
| 106 | + AC_SUBST(PCRE2_LDADD) |
| 107 | + AC_SUBST(PCRE2_LIBS) |
| 108 | + AC_SUBST(PCRE2_LDFLAGS) |
| 109 | + AC_SUBST(PCRE2_CFLAGS) |
| 110 | + AC_SUBST(PCRE2_DISPLAY) |
| 111 | + fi |
| 112 | +fi |
| 113 | +
|
| 114 | +
|
| 115 | +AC_SUBST(PCRE2_FOUND) |
| 116 | +
|
| 117 | +]) # AC_DEFUN [PROG_PCRE2] |
| 118 | + |
| 119 | + |
| 120 | +AC_DEFUN([CHECK_FOR_PCRE2_AT], [ |
| 121 | + path=$1 |
| 122 | + echo "*** LOOKING AT PATH: " ${path} |
| 123 | + for y in ${PCRE2_POSSIBLE_EXTENSIONS}; do |
| 124 | + for z in ${PCRE2_POSSIBLE_LIB_NAMES}; do |
| 125 | + if test -e "${path}/${z}.${y}"; then |
| 126 | + pcre2_lib_path="${path}/" |
| 127 | + pcre2_lib_name="${z}" |
| 128 | + pcre2_lib_file="${pcre2_lib_path}/${z}.${y}" |
| 129 | + break |
| 130 | + fi |
| 131 | + if test -e "${path}/lib${z}.${y}"; then |
| 132 | + pcre2_lib_path="${path}/" |
| 133 | + pcre2_lib_name="${z}" |
| 134 | + pcre2_lib_file="${pcre2_lib_path}/lib${z}.${y}" |
| 135 | + break |
| 136 | + fi |
| 137 | + if test -e "${path}/lib/lib${z}.${y}"; then |
| 138 | + pcre2_lib_path="${path}/lib/" |
| 139 | + pcre2_lib_name="${z}" |
| 140 | + pcre2_lib_file="${pcre2_lib_path}/lib${z}.${y}" |
| 141 | + break |
| 142 | + fi |
| 143 | + if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then |
| 144 | + pcre2_lib_path="${path}/lib/x86_64-linux-gnu/" |
| 145 | + pcre2_lib_name="${z}" |
| 146 | + pcre2_lib_file="${pcre2_lib_path}/lib${z}.${y}" |
| 147 | + break |
| 148 | + fi |
| 149 | + if test -e "${path}/lib/i386-linux-gnu/lib${z}.${y}"; then |
| 150 | + pcre2_lib_path="${path}/lib/i386-linux-gnu/" |
| 151 | + pcre2_lib_name="${z}" |
| 152 | + pcre2_lib_file="${pcre2_lib_path}/lib${z}.${y}" |
| 153 | + break |
| 154 | + fi |
| 155 | + done |
| 156 | + if test -n "$pcre2_lib_path"; then |
| 157 | + break |
| 158 | + fi |
| 159 | + done |
| 160 | + if test -e "${path}/include/pcre2.h"; then |
| 161 | + pcre2_inc_path="${path}/include" |
| 162 | + elif test -e "${path}/pcre2.h"; then |
| 163 | + pcre2_inc_path="${path}" |
| 164 | + elif test -e "${path}/include/pcre2/pcre2.h"; then |
| 165 | + pcre2_inc_path="${path}/include" |
| 166 | + fi |
| 167 | +
|
| 168 | + if test -n "${pcre2_lib_path}"; then |
| 169 | + AC_MSG_NOTICE([PCRE2 library found at: ${pcre2_lib_file}]) |
| 170 | + fi |
| 171 | +
|
| 172 | + if test -n "${pcre2_inc_path}"; then |
| 173 | + AC_MSG_NOTICE([PCRE2 headers found at: ${pcre2_inc_path}]) |
| 174 | + fi |
| 175 | +
|
| 176 | + if test -n "${pcre2_lib_path}" -a -n "${pcre2_inc_path}"; then |
| 177 | + # TODO: Compile a piece of code to check the version. |
| 178 | + PCRE2_CFLAGS="-I${pcre2_inc_path}" |
| 179 | + PCRE2_LDADD="-l${pcre2_lib_name}" |
| 180 | + PCRE2_LDFLAGS="-L${pcre2_lib_path}" |
| 181 | + PCRE2_DISPLAY="${pcre2_lib_file}, ${pcre2_inc_path}" |
| 182 | + fi |
| 183 | +]) # AC_DEFUN [CHECK_FOR_PCRE2_AT] |
0 commit comments