diff --git a/configure.ac b/configure.ac index b2eaa7e1e..9d33b9474 100644 --- a/configure.ac +++ b/configure.ac @@ -259,6 +259,40 @@ fi # # libsecp256k1 # +AC_ARG_WITH([system-secp256k1], + [AS_HELP_STRING([[--with-system-secp256k1[=PKG]]], + [build using system-installed libsecp256k1 instead of bundled, passing PKG (default: libsecp256k1 or libsecp256k1_zkp, depending on --enable-standard-secp) to pkg-config (default: no)])], + [AS_IF([test "x$withval" = xyes], + [AM_COND_IF([BUILD_STANDARD_SECP], [with_system_secp256k1=libsecp256k1], [with_system_secp256k1=libsecp256k1_zkp])])], + [with_system_secp256k1=no]) +AM_CONDITIONAL([LINK_SYSTEM_SECP256K1], [test "x$with_system_secp256k1" != xno]) +AM_COND_IF([LINK_SYSTEM_SECP256K1], [ + saved_LIBS=$LIBS + PKG_CHECK_MODULES([libsecp256k1], [$with_system_secp256k1]) + LIBS="$libsecp256k1_LIBS $LIBS" + missing_modules= + AC_DEFUN([CHECK_MODULE], [ + AC_CHECK_FUNCS([$2], [], [missing_modules="${missing_modules} $1"]) + ]) + CHECK_MODULE([ecdh], [secp256k1_ecdh]) + CHECK_MODULE([extrakeys], [secp256k1_xonly_pubkey_parse]) + CHECK_MODULE([recovery], [secp256k1_ecdsa_recover]) + CHECK_MODULE([schnorrsig], [secp256k1_schnorrsig_verify]) + AM_COND_IF([BUILD_STANDARD_SECP], [], [ + CHECK_MODULE([ecdsa-s2c], [secp256k1_ecdsa_s2c_sign]) + ]) + AM_COND_IF([BUILD_ELEMENTS], [ + CHECK_MODULE([generator], [secp256k1_generator_parse]) + CHECK_MODULE([rangeproof], [secp256k1_rangeproof_verify]) + CHECK_MODULE([surjectionproof], [secp256k1_surjectionproof_initialize]) + CHECK_MODULE([whitelist], [secp256k1_whitelist_sign]) + ]) + AS_IF([test -n "${missing_modules}"], [ + AC_MSG_ERROR([system-installed $with_system_secp256k1 does not support these required modules:${missing_modules}]) + ]) + LIBS=$saved_LIBS +], [ + libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include' # FIXME: This is needed to force libtool to use all object files from secp. # We can only build secp properly by recursively invoking # configure/make, and can't include it as a noinst_ library. Libtool @@ -277,8 +311,10 @@ fi # Because libtool both intercepts -Wl and arbitrarily re-orders its # command line inputs, we have to concoct a single expression to # enforce linking that cannot be split, hence the below expression. -LIBADD_SECP256K1="-Wl,secp256k1/src/libsecp256k1_la-secp256k1.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult_gen.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult.${OBJEXT}" -AC_SUBST([LIBADD_SECP256K1]) + libsecp256k1_LIBS="-Wl,secp256k1/src/libsecp256k1_la-secp256k1.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult_gen.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult.${OBJEXT}" +]) +AC_SUBST([libsecp256k1_CFLAGS]) +AC_SUBST([libsecp256k1_LIBS]) # # Python facilities @@ -410,8 +446,11 @@ export ARFLAGS export AR_FLAGS export LD export LDFLAGS -ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" -AC_CONFIG_SUBDIRS([src/secp256k1]) + +AM_COND_IF([LINK_SYSTEM_SECP256K1], [], [ + ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" + AC_CONFIG_SUBDIRS([src/secp256k1]) +]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index b8f62ed75..73bb3c8e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,7 @@ if USE_SWIG_PYTHON noinst_LTLIBRARIES += libswig_python.la libswig_python_la_SOURCES = swig_python/swig_python_wrap.c -libswig_python_la_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) $(SWIG_PYTHON_CPPFLAGS) $(SWIG_WARN_CFLAGS) $(NOALIAS_CFLAGS) +libswig_python_la_CFLAGS = -I$(top_srcdir) $(libsecp256k1_CFLAGS) $(AM_CFLAGS) $(SWIG_PYTHON_CPPFLAGS) $(SWIG_WARN_CFLAGS) $(NOALIAS_CFLAGS) if PYTHON_MANYLINUX else libswig_python_la_LIBADD = $(PYTHON_LIBS) @@ -83,7 +83,7 @@ noinst_LTLIBRARIES += libswig_java.la libswig_java_la_SOURCES = \ swig_java/swig_java_wrap.c -libswig_java_la_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) $(SWIG_JAVA_CPPFLAGS) $(SWIG_WARN_CFLAGS) +libswig_java_la_CFLAGS = -I$(top_srcdir) $(libsecp256k1_CFLAGS) $(AM_CFLAGS) $(SWIG_JAVA_CPPFLAGS) $(SWIG_WARN_CFLAGS) SWIG_JOPT = $(SWIG_JAVA_OPT) -outdir swig_java -noproxy -package com.blockstream.libwally @@ -205,10 +205,12 @@ libwallycore_la_LDFLAGS += -no-undefined endif endif # SHARED_BUILD_ENABLED -libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan -DWALLY_CORE_BUILD=1 $(AM_CFLAGS) -libwallycore_la_LIBADD = $(LIBADD_SECP256K1) $(noinst_LTLIBRARIES) +libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan $(libsecp256k1_CFLAGS) -DWALLY_CORE_BUILD=1 $(AM_CFLAGS) +libwallycore_la_LIBADD = $(libsecp256k1_LIBS) $(noinst_LTLIBRARIES) +if !LINK_SYSTEM_SECP256K1 SUBDIRS = secp256k1 +endif TESTS = noinst_PROGRAMS = diff --git a/src/ecdh.c b/src/ecdh.c index f81e76c74..0130de427 100644 --- a/src/ecdh.c +++ b/src/ecdh.c @@ -1,7 +1,7 @@ #include "internal.h" #include -#include "secp256k1/include/secp256k1.h" -#include "secp256k1/include/secp256k1_ecdh.h" +#include +#include int wally_ecdh(const unsigned char *pub_key, size_t pub_key_len, const unsigned char *priv_key, size_t priv_key_len, diff --git a/src/elements.c b/src/elements.c index 9edb58ca8..cbe39ba1b 100644 --- a/src/elements.c +++ b/src/elements.c @@ -7,10 +7,10 @@ #include #include #include -#include "secp256k1/include/secp256k1_generator.h" -#include "secp256k1/include/secp256k1_rangeproof.h" -#include "src/secp256k1/include/secp256k1_surjectionproof.h" -#include "src/secp256k1/include/secp256k1_whitelist.h" +#include +#include +#include +#include static const unsigned char LABEL_STR[] = { diff --git a/src/internal.h b/src/internal.h index f99087b31..a60307afc 100644 --- a/src/internal.h +++ b/src/internal.h @@ -13,11 +13,11 @@ #pragma GCC diagnostic ignored "-Wunused-parameter" #endif /* BUILD_ELEMENTS */ #endif /* WALLY_ABI_NO_ELEMENTS */ -#include "secp256k1/include/secp256k1.h" -#include "secp256k1/include/secp256k1_recovery.h" -#include "secp256k1/include/secp256k1_extrakeys.h" +#include +#include +#include #ifndef BUILD_STANDARD_SECP -#include "secp256k1/include/secp256k1_ecdsa_s2c.h" +#include #endif #include #if defined(HAVE_MEMSET_S) diff --git a/src/sign.c b/src/sign.c index c76ab4474..f5b929fee 100644 --- a/src/sign.c +++ b/src/sign.c @@ -1,7 +1,7 @@ #include "internal.h" #include #include "script_int.h" -#include "secp256k1/include/secp256k1_schnorrsig.h" +#include #include "ccan/ccan/build_assert/build_assert.h" #define EC_FLAGS_TYPES (EC_FLAG_ECDSA | EC_FLAG_SCHNORR)