@@ -3013,45 +3013,127 @@ then
30133013 esac
30143014 done
30153015fi
3016+
3017+
30163018# Microchip/Atmel CryptoAuthLib
30173019ENABLED_CRYPTOAUTHLIB="no"
3018- trylibatcadir=""
30193020AC_ARG_WITH ( [ cryptoauthlib] ,
3020- [ AS_HELP_STRING ( [ --with-cryptoauthlib=PATH] ,[ PATH to CryptoAuthLib install (default /usr)] ) ] ,
3021- [
3022- AC_MSG_CHECKING ( [ for cryptoauthlib] )
3023- LIBS="$LIBS -lcryptoauth -lwolfssl -lpthread -lrt"
3024-
3025- AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [ #include <cryptoauthlib.h>] ] , [ [ atcab_init(0); ] ] ) ] ,[ libatca_linked=yes ] ,[ libatca_linked=no ] )
3021+ [ AS_HELP_STRING ( [ --with-cryptoauthlib=PATH] ,
3022+ [ PATH to CryptoAuthLib install (default: system paths)] ) ] ,
3023+ [ with_cryptoauthlib=$withval] ,
3024+ [ with_cryptoauthlib=no] )
3025+
3026+ AS_IF ( [ test "x$with_cryptoauthlib" != "xno"] , [
3027+ AC_MSG_CHECKING ( [ for CryptoAuthLib] )
3028+
3029+ libdir=""
3030+ incdir=""
3031+ cryptoauthlib_found="no"
3032+
3033+ saved_LIBS="$LIBS"
3034+ saved_LDFLAGS="$LDFLAGS"
3035+ saved_CPPFLAGS="$CPPFLAGS"
3036+ saved_CFLAGS="$CFLAGS"
3037+
3038+ # Method 1: Try pkg-config first (most reliable)
3039+ PKG_CHECK_MODULES([ CRYPTOAUTHLIB] , [ cryptoauthlib] , [
3040+ CPPFLAGS="$CRYPTOAUTHLIB_CFLAGS $CPPFLAGS"
3041+ CFLAGS="$CRYPTOAUTHLIB_CFLAGS $CFLAGS"
3042+ LDFLAGS="$CRYPTOAUTHLIB_LIBS $LDFLAGS"
3043+ LIBS="$CRYPTOAUTHLIB_LIBS $LIBS"
3044+ cryptoauthlib_found="pkg-config"
3045+ ] , [
3046+ # Method 2: Manual search
3047+ AS_IF ( [ test "x$with_cryptoauthlib" = "xyes"] , [
3048+ search_dirs="/usr /usr/local"
3049+ ] , [
3050+ search_dirs="$with_cryptoauthlib"
3051+ ] )
30263052
3027- if test "x$libatca_linked" = "xno" ; then
3028- if test "x$withval" != "xno" ; then
3029- trylibatcadir=$withval
3030- fi
3031- if test "x$withval" = "xyes" ; then
3032- trylibatcadir="/usr"
3053+ for trylibatcadir in $search_dirs; do
3054+ for try_libdir in "$trylibatcadir/lib" "$trylibatcadir/lib64"; do
3055+ if test -f "$try_libdir/libcryptoauth.so" || test -f "$try_libdir/libcryptoauth.a"; then
3056+ libdir="$try_libdir"
3057+ break
3058+ fi
3059+ done
3060+
3061+ if test -z "$libdir"; then
3062+ if test -x /usr/bin/dpkg-architecture; then
3063+ DEB_HOST_MULTIARCH=`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`
3064+ if test -n "$DEB_HOST_MULTIARCH"; then
3065+ try_libdir="$trylibatcadir/lib/$DEB_HOST_MULTIARCH"
3066+ if test -f "$try_libdir/libcryptoauth.so" || test -f "$try_libdir/libcryptoauth.a"; then
3067+ libdir="$try_libdir"
3068+ fi
3069+ fi
3070+ fi
30333071 fi
30343072
3035- if test "$host_cpu" = "aarch64" ; then
3036- LIB_SUFFIX="/aarch64-linux-gnu"
3037- else
3038- LIB_SUFFIX=""
3039- fi
3073+ for try_incdir in "$trylibatcadir/include/cryptoauthlib" "$trylibatcadir/include"; do
3074+ if test -f "$try_incdir/cryptoauthlib.h"; then
3075+ incdir="$try_incdir"
3076+ break
3077+ fi
3078+ done
30403079
3041- LDFLAGS="$LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3042- CPPFLAGS="$CPPFLAGS -I$trylibatcadir/include/cryptoauthlib"
3043- AM_LDFLAGS="$AM_LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3044- AM_CFLAGS="$AM_CFLAGS -I$trylibatcadir/include/cryptoauthlib"
3080+ if test -n "$libdir" && test -n "$incdir"; then
3081+ break
3082+ fi
3083+ libdir=""
3084+ incdir=""
3085+ done
30453086
3046- AC_MSG_RESULT ( [ yes] )
3047- else
3048- AC_MSG_RESULT ( [ yes] )
3087+ if test -n "$libdir" && test -n "$incdir"; then
3088+ CPPFLAGS="-I$incdir $CPPFLAGS"
3089+ CFLAGS="-I$incdir $CFLAGS"
3090+ LDFLAGS="-L$libdir $LDFLAGS"
3091+ LIBS="-lcryptoauth $LIBS"
3092+ cryptoauthlib_found="$libdir"
30493093 fi
3094+ ] )
30503095
3051- ENABLED_CRYPTOAUTHLIB="yes"
3052- ]
3053- )
3096+ AS_IF ( [ test "x$cryptoauthlib_found" != "xno"] , [
3097+ wolfssl_include=""
3098+ AS_IF ( [ test -f "${srcdir}/wolfssl/wolfcrypt/types.h"] , [
3099+ wolfssl_include="-I${srcdir}"
3100+ ] , [ test -f "${srcdir}/wolfssl.h"] , [
3101+ wolfssl_include="-I${srcdir}"
3102+ ] )
3103+
3104+ test_CPPFLAGS="$wolfssl_include $CPPFLAGS"
3105+ test_CFLAGS="$wolfssl_include $CFLAGS"
3106+
3107+ saved_test_CPPFLAGS="$CPPFLAGS"
3108+ saved_test_CFLAGS="$CFLAGS"
3109+ CPPFLAGS="$test_CPPFLAGS"
3110+ CFLAGS="$test_CFLAGS"
3111+
3112+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM (
3113+ [ [ #include <cryptoauthlib.h>] ] ,
3114+ [ [ atcab_init(0); return 0;] ] ) ] ,
3115+ [
3116+ ENABLED_CRYPTOAUTHLIB="yes"
3117+ AC_MSG_RESULT ( [ yes ($cryptoauthlib_found)] )
3118+ AC_DEFINE ( [ HAVE_CRYPTOAUTHLIB] , [ 1] , [ CryptoAuthLib support] )
3119+ CPPFLAGS="$saved_test_CPPFLAGS"
3120+ CFLAGS="$saved_test_CFLAGS"
3121+ ] ,
3122+ [
3123+ LIBS="$saved_LIBS"
3124+ LDFLAGS="$saved_LDFLAGS"
3125+ CPPFLAGS="$saved_CPPFLAGS"
3126+ CFLAGS="$saved_CFLAGS"
3127+ AC_MSG_RESULT ( [ no - compilation failed] )
3128+ AC_MSG_ERROR ( [ CryptoAuthLib found but test compilation failed. Check config.log for details.] )
3129+ ] )
3130+ ] , [
3131+ AC_MSG_RESULT ( [ no - library not found] )
3132+ AC_MSG_ERROR ( [ CryptoAuthLib not found. Install it or specify path with --with-cryptoauthlib=/path] )
3133+ ] )
3134+ ] )
30543135
3136+ AM_CONDITIONAL([ BUILD_CRYPTOAUTHLIB] , [ test "x$ENABLED_CRYPTOAUTHLIB" = "xyes"] )
30553137
30563138# TropicSquare TROPIC01
30573139# Example: "./configure --with-tropic01=/home/pi/libtropic"
0 commit comments