# Both json-c.pc (libjson-c-dev on Debian Testing) and json.pc
# (legacy, libjson0-dev on Debian Wheezy and Testing) are okay.
PKG_CHECK_MODULES(JSON, [json], HAVE_JSON=yes,
                  [PKG_CHECK_MODULES(JSON, [json-c], HAVE_JSON=yes, HAVE_JSON=no)])

def_oauth2="no"

if test "$ENABLE_LIBSOUP" = "yes" && test "$HAVE_JSON" = "yes"; then
   def_oauth2="yes"
fi

AC_ARG_ENABLE(oauth2,
              AS_HELP_STRING([--enable-oauth2],
                             [enables or disables support for refresh token single-sign-on system without HMI; default is on if development files are available]),
              [enable_oauth2="$enableval"
               test "$enable_oauth2" = "yes" || test "$enable_oauth2" = "no" || AC_MSG_ERROR([invalid value for --enable-oauth2: $enable_oauth2])
               test "$enable_oauth2" = "no" || test "$HAVE_JSON" = "yes" || test "$ENABLE_LIBSOUP" = "yes"|| AC_MSG_ERROR([required pkg(s) not found that are needed for --enable-oauth2])],
              enable_oauth2="$def_oauth2")
if test "$enable_oauth2" = "yes"; then
    # link into static executables, similar to a SyncSource
    SYNCSOURCES="$SYNCSOURCES src/backends/oauth2/provideroauth2.la"
    if test "$enable_static" = "yes"; then
       AC_DEFINE(STATIC_OAUTH2, 1, [activate OAuth2 based on refresh token])
    fi
fi

# conditional compilation in make
AM_CONDITIONAL([USE_OAUTH2], [test "$enable_oauth2" = "yes"])
