@@ -3108,45 +3108,127 @@ then
31083108 esac
31093109 done
31103110fi
3111+
3112+
31113113# Microchip/Atmel CryptoAuthLib
31123114ENABLED_CRYPTOAUTHLIB="no"
3113- trylibatcadir=""
31143115AC_ARG_WITH ( [ cryptoauthlib] ,
3115- [ AS_HELP_STRING ( [ --with-cryptoauthlib=PATH] ,[ PATH to CryptoAuthLib install (default /usr)] ) ] ,
3116- [
3117- AC_MSG_CHECKING ( [ for cryptoauthlib] )
3118- LIBS="$LIBS -lcryptoauth -lwolfssl -lpthread -lrt"
3119-
3120- AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [ #include <cryptoauthlib.h>] ] , [ [ atcab_init(0); ] ] ) ] ,[ libatca_linked=yes ] ,[ libatca_linked=no ] )
3116+ [ AS_HELP_STRING ( [ --with-cryptoauthlib=PATH] ,
3117+ [ PATH to CryptoAuthLib install (default: system paths)] ) ] ,
3118+ [ with_cryptoauthlib=$withval] ,
3119+ [ with_cryptoauthlib=no] )
3120+
3121+ AS_IF ( [ test "x$with_cryptoauthlib" != "xno"] , [
3122+ AC_MSG_CHECKING ( [ for CryptoAuthLib] )
3123+
3124+ libdir=""
3125+ incdir=""
3126+ cryptoauthlib_found="no"
3127+
3128+ saved_LIBS="$LIBS"
3129+ saved_LDFLAGS="$LDFLAGS"
3130+ saved_CPPFLAGS="$CPPFLAGS"
3131+ saved_CFLAGS="$CFLAGS"
3132+
3133+ # Method 1: Try pkg-config first (most reliable)
3134+ PKG_CHECK_MODULES([ CRYPTOAUTHLIB] , [ cryptoauthlib] , [
3135+ CPPFLAGS="$CRYPTOAUTHLIB_CFLAGS $CPPFLAGS"
3136+ CFLAGS="$CRYPTOAUTHLIB_CFLAGS $CFLAGS"
3137+ LDFLAGS="$CRYPTOAUTHLIB_LIBS $LDFLAGS"
3138+ LIBS="$CRYPTOAUTHLIB_LIBS $LIBS"
3139+ cryptoauthlib_found="pkg-config"
3140+ ] , [
3141+ # Method 2: Manual search
3142+ AS_IF ( [ test "x$with_cryptoauthlib" = "xyes"] , [
3143+ search_dirs="/usr /usr/local"
3144+ ] , [
3145+ search_dirs="$with_cryptoauthlib"
3146+ ] )
31213147
3122- if test "x$libatca_linked" = "xno" ; then
3123- if test "x$withval" != "xno" ; then
3124- trylibatcadir=$withval
3125- fi
3126- if test "x$withval" = "xyes" ; then
3127- trylibatcadir="/usr"
3148+ for trylibatcadir in $search_dirs; do
3149+ for try_libdir in "$trylibatcadir/lib" "$trylibatcadir/lib64"; do
3150+ if test -f "$try_libdir/libcryptoauth.so" || test -f "$try_libdir/libcryptoauth.a"; then
3151+ libdir="$try_libdir"
3152+ break
3153+ fi
3154+ done
3155+
3156+ if test -z "$libdir"; then
3157+ if test -x /usr/bin/dpkg-architecture; then
3158+ DEB_HOST_MULTIARCH=`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`
3159+ if test -n "$DEB_HOST_MULTIARCH"; then
3160+ try_libdir="$trylibatcadir/lib/$DEB_HOST_MULTIARCH"
3161+ if test -f "$try_libdir/libcryptoauth.so" || test -f "$try_libdir/libcryptoauth.a"; then
3162+ libdir="$try_libdir"
3163+ fi
3164+ fi
3165+ fi
31283166 fi
31293167
3130- if test "$host_cpu" = "aarch64" ; then
3131- LIB_SUFFIX="/aarch64-linux-gnu"
3132- else
3133- LIB_SUFFIX=""
3134- fi
3168+ for try_incdir in "$trylibatcadir/include/cryptoauthlib" "$trylibatcadir/include"; do
3169+ if test -f "$try_incdir/cryptoauthlib.h"; then
3170+ incdir="$try_incdir"
3171+ break
3172+ fi
3173+ done
31353174
3136- LDFLAGS="$LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3137- CPPFLAGS="$CPPFLAGS -I$trylibatcadir/include/cryptoauthlib"
3138- AM_LDFLAGS="$AM_LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3139- AM_CFLAGS="$AM_CFLAGS -I$trylibatcadir/include/cryptoauthlib"
3175+ if test -n "$libdir" && test -n "$incdir"; then
3176+ break
3177+ fi
3178+ libdir=""
3179+ incdir=""
3180+ done
31403181
3141- AC_MSG_RESULT ( [ yes] )
3142- else
3143- AC_MSG_RESULT ( [ yes] )
3182+ if test -n "$libdir" && test -n "$incdir"; then
3183+ CPPFLAGS="-I$incdir $CPPFLAGS"
3184+ CFLAGS="-I$incdir $CFLAGS"
3185+ LDFLAGS="-L$libdir $LDFLAGS"
3186+ LIBS="-lcryptoauth $LIBS"
3187+ cryptoauthlib_found="$libdir"
31443188 fi
3189+ ] )
31453190
3146- ENABLED_CRYPTOAUTHLIB="yes"
3147- ]
3148- )
3191+ AS_IF ( [ test "x$cryptoauthlib_found" != "xno"] , [
3192+ wolfssl_include=""
3193+ AS_IF ( [ test -f "${srcdir}/wolfssl/wolfcrypt/types.h"] , [
3194+ wolfssl_include="-I${srcdir}"
3195+ ] , [ test -f "${srcdir}/wolfssl.h"] , [
3196+ wolfssl_include="-I${srcdir}"
3197+ ] )
3198+
3199+ test_CPPFLAGS="$wolfssl_include $CPPFLAGS"
3200+ test_CFLAGS="$wolfssl_include $CFLAGS"
3201+
3202+ saved_test_CPPFLAGS="$CPPFLAGS"
3203+ saved_test_CFLAGS="$CFLAGS"
3204+ CPPFLAGS="$test_CPPFLAGS"
3205+ CFLAGS="$test_CFLAGS"
3206+
3207+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM (
3208+ [ [ #include <cryptoauthlib.h>] ] ,
3209+ [ [ atcab_init(0); return 0;] ] ) ] ,
3210+ [
3211+ ENABLED_CRYPTOAUTHLIB="yes"
3212+ AC_MSG_RESULT ( [ yes ($cryptoauthlib_found)] )
3213+ AC_DEFINE ( [ HAVE_CRYPTOAUTHLIB] , [ 1] , [ CryptoAuthLib support] )
3214+ CPPFLAGS="$saved_test_CPPFLAGS"
3215+ CFLAGS="$saved_test_CFLAGS"
3216+ ] ,
3217+ [
3218+ LIBS="$saved_LIBS"
3219+ LDFLAGS="$saved_LDFLAGS"
3220+ CPPFLAGS="$saved_CPPFLAGS"
3221+ CFLAGS="$saved_CFLAGS"
3222+ AC_MSG_RESULT ( [ no - compilation failed] )
3223+ AC_MSG_ERROR ( [ CryptoAuthLib found but test compilation failed. Check config.log for details.] )
3224+ ] )
3225+ ] , [
3226+ AC_MSG_RESULT ( [ no - library not found] )
3227+ AC_MSG_ERROR ( [ CryptoAuthLib not found. Install it or specify path with --with-cryptoauthlib=/path] )
3228+ ] )
3229+ ] )
31493230
3231+ AM_CONDITIONAL([ BUILD_CRYPTOAUTHLIB] , [ test "x$ENABLED_CRYPTOAUTHLIB" = "xyes"] )
31503232
31513233# TropicSquare TROPIC01
31523234# Example: "./configure --with-tropic01=/home/pi/libtropic"
0 commit comments