
define([PACKAGE_VERSION_MAJOR], [#CFGMAJOR#])
define([PACKAGE_VERSION_MINOR], [#CFGMINOR#])
define([PACKAGE_VERSION_FIX], [#CFGFIX#])

AC_INIT([libpkcs11-#CFGDIST#],[PACKAGE_VERSION_MAJOR.PACKAGE_VERSION_MINOR.PACKAGE_VERSION_FIX])
AC_CONFIG_AUX_DIR([auxdir])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([${PACKAGE_NAME}], [${PACKAGE_VERSION}])

LT_INIT
 
AC_PROG_CC
AC_PROG_CXX
 
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile CryptoPP/Makefile skeletons/Makefile ASN1/Makefile Sources/Makefile test_DIST/Makefile test_P11/Makefile])

#AM_GNU_GETTEXT([external])

PKG_CHECK_EXISTS([libpcsclite],
	[PKG_CHECK_MODULES([PCSC], [libpcsclite])]	#this line, generate PCSC_CFLAGS and PCSC_LIBS of package libpcsclite
)


dnl Check and set PINENTRY path
case "${host}" in
        *-*-solaris*)
		AC_ARG_WITH(
        		[pinentry],
		        [AS_HELP_STRING([--with-pinentry=PROG],[run PROG as PIN-entry for OpenSC Signer @<:/usr/bin/pinentry:>@])],
        		,
		        [with_pinentry="/opt/csw/bin/pinentry"]
		)
		PIN_ENTRY="/opt/csw/bin/pinentry"
		AC_DEFINE_UNQUOTED(PIN_ENTRY, "$PIN_ENTRY", [PIN-entry program for popup])
	;;
        *)
		AC_ARG_WITH(
	        	[pinentry],
		        [AS_HELP_STRING([--with-pinentry=PROG],[run PROG as PIN-entry for OpenSC Signer @<:/usr/bin/pinentry:>@])],
	        	,
		        [with_pinentry="/usr/bin/pinentry"]
		)
		PIN_ENTRY="/usr/bin/pinentry"
		AC_DEFINE_UNQUOTED(PIN_ENTRY, "$PIN_ENTRY", [PIN-entry program for popup])
	;;
esac

case "${host}" in
        *-*-darwin*)
		LIBS="${LIBS} -Wl,-framework,CoreFoundation -Wl,/System/Library/Frameworks/PCSC.framework/PCSC"
		if test "${GCC}" = "yes"; then
                        CFLAGS="${CFLAGS} -no-cpp-precomp"
                fi

		PCSC_CFLAGS="-I/System/Library/Frameworks/PCSC.framework/Headers"
		saved_CFLAGS="${CFLAGS}"
        	CFLAGS="${CFLAGS} ${PCSC_CFLAGS}"
        	# We must cope with mingw32 that does not have winscard.h mingw64 has it.
        	AC_CHECK_HEADERS([winscard.h],,[test "${WIN32}" != "yes" && AC_MSG_ERROR([winscard.h is required for pcsc])])
        	CFLAGS="${saved_CFLAGS}"

		CRYPTOPP_CFLAGS="-DCRYPTOPP_DISABLE_ASM"
	        CPPFLAGS="${CPPFLAGS} ${CRYPTOPP_CFLAGS}"
        ;;
esac


if test "x$prefix" = xNONE; then
  prefix=$ac_default_prefix
fi
if test "x$exec_prefix" = xNONE; then
  exec_prefix='${prefix}'
fi

case "${host}" in
    *-*-darwin*)
    ;;
    *)
	dnl AM_PATH_LIBASSUAN([MINIMUM-VERSION,
	dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
	dnl Test for libassuan and define LIBASSUAN_CFLAGS and LIBASSUAN_LIBS
	AM_PATH_LIBASSUAN(
	        2.0.0,
	        [have_assuan="yes"],
	        [have_assuan="no"]
	)
    ;;
esac


#AC_SUBST extract MACRO to posterior uses
AC_SUBST([PCSC_CFLAGS])
AC_SUBST([PCSC_LIBS])


test "${with_pinentry}" != "no" && AC_DEFINE_UNQUOTED([PIN_ENTRY], ["${with_pinentry}"], [PIN-entry program for OpenSC Signer])


AC_OUTPUT


cat <<EOF

Application has been configured with the following options:


Version:                 ${PACKAGE_VERSION}
User binaries:           $(eval eval eval echo "${bindir}")
Configuration files:     $(eval eval eval echo "${sysconfdir}")
XSL stylesheets:         ${xslstylesheetsdir}

pinentry:                ${PIN_ENTRY}

Host:                    ${host}
C Compiler:              ${CC}
Compiler flags:          ${CFLAGS}
C++  flags:              ${CPPFLAGS}
Linker flags:            ${LDFLAGS}
Libraries:               ${LIBS}

PCSC_CFLAGS:             ${PCSC_CFLAGS}
PCSC_LIBS:		 ${PCSC_LIBS}
LIBASSUAN_CFLAGS:        ${LIBASSUAN_CFLAGS}
LIBASSUAN_LIBS:          ${LIBASSUAN_LIBS}


EOF

