xref: /PHP-7.2/ext/sodium/config.m4 (revision 401188cb)
1dnl $Id$
2dnl config.m4 for extension sodium
3
4PHP_ARG_WITH(sodium, for sodium support,
5[  --with-sodium[=DIR]     Include sodium support])
6
7if test "$PHP_SODIUM" != "no"; then
8  SEARCH_PATH="/usr/local /usr"     # you might want to change this
9  SEARCH_FOR="/include/sodium.h"  # you most likely want to change this
10
11  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
12  AC_MSG_CHECKING([for libsodium])
13
14  dnl user provided location
15  if test -r $PHP_SODIUM/$SEARCH_FOR; then # path given as parameter
16    LIBSODIUM_DIR=$PHP_SODIUM
17    AC_MSG_RESULT([found in $PHP_SODIUM])
18
19  dnl pkg-config output
20  elif test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libsodium; then
21    LIBSODIUM_VERSION=`$PKG_CONFIG libsodium --modversion`
22    if $PKG_CONFIG libsodium --atleast-version=1.0.8; then
23      LIBSODIUM_CFLAGS=`$PKG_CONFIG libsodium --cflags`
24      LIBSODIUM_LIBS=`$PKG_CONFIG libsodium --libs`
25      AC_MSG_RESULT(version $LIBSODIUM_VERSION found using pkg-config)
26      PHP_EVAL_LIBLINE($LIBSODIUM_LIBS, SODIUM_SHARED_LIBADD)
27      PHP_EVAL_INCLINE($LIBSODIUM_CFLAGS)
28    else
29      AC_MSG_ERROR([Libsodium $LIBSODIUM_VERSION is too old, version >= 1.0.8 required])
30    fi
31
32  dnl search default path list
33  else
34    for i in $SEARCH_PATH ; do
35      if test -r $i/$SEARCH_FOR; then
36        LIBSODIUM_DIR=$i
37        AC_MSG_RESULT(found in $i)
38      fi
39    done
40    if test -z "$LIBSODIUM_DIR"; then
41      AC_MSG_ERROR([Please install libsodium - See https://github.com/jedisct1/libsodium])
42    fi
43  fi
44
45  LIBNAME=sodium
46  LIBSYMBOL=sodium_add
47
48  if test -n "$LIBSODIUM_DIR"; then
49    PHP_ADD_INCLUDE($LIBSODIUM_DIR/include)
50    PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBSODIUM_DIR/$PHP_LIBDIR, SODIUM_SHARED_LIBADD)
51  fi
52
53  PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
54  [
55    AC_DEFINE(HAVE_LIBSODIUMLIB,1,[ ])
56  ],[
57    AC_MSG_ERROR([wrong libsodium lib version (< 1.0.8) or lib not found])
58  ],[
59  ])
60
61  PHP_SUBST(SODIUM_SHARED_LIBADD)
62
63  PHP_NEW_EXTENSION(sodium, libsodium.c, $ext_shared)
64fi
65