Skip to content

Commit

Permalink
Remove dependency on src/libsecp256k1-config.h
Browse files Browse the repository at this point in the history
This change eases the use of alternate build systems by moving
the variables in src/libsecp256k1-config.h to compiler macros
for each invocation, preventing duplication of these variables
for each build system.
  • Loading branch information
ZenulAbidin committed Oct 4, 2022
1 parent 694ce8f commit b487615
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 80 deletions.
22 changes: 11 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ noinst_HEADERS += examples/random.h
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)

if USE_EXTERNAL_ASM
COMMON_LIB = libsecp256k1_common.la
Expand All @@ -86,7 +86,7 @@ endif
endif

libsecp256k1_la_SOURCES = src/secp256k1.c
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES)
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE)

Expand All @@ -101,17 +101,17 @@ bench_SOURCES = src/bench.c
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
bench_internal_SOURCES = src/bench_internal.c
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
bench_internal_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
bench_ecmult_SOURCES = src/bench_ecmult.c
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
endif

TESTS =
if USE_TESTS
noinst_PROGRAMS += tests
tests_SOURCES = src/tests.c
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES) $(DEFINE_FLAGS)
if VALGRIND_ENABLED
tests_CPPFLAGS += -DVALGRIND
noinst_PROGRAMS += valgrind_ctime_test
Expand All @@ -129,7 +129,7 @@ endif
if USE_EXHAUSTIVE_TESTS
noinst_PROGRAMS += exhaustive_tests
exhaustive_tests_SOURCES = src/tests_exhaustive.c
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
if !ENABLE_COVERAGE
exhaustive_tests_CPPFLAGS += -DVERIFY
endif
Expand All @@ -142,7 +142,7 @@ endif
if USE_EXAMPLES
noinst_PROGRAMS += ecdsa_example
ecdsa_example_SOURCES = examples/ecdsa.c
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include $(DEFINE_FLAGS)
ecdsa_example_LDADD = libsecp256k1.la
ecdsa_example_LDFLAGS = -static
if BUILD_WINDOWS
Expand All @@ -152,7 +152,7 @@ TESTS += ecdsa_example
if ENABLE_MODULE_ECDH
noinst_PROGRAMS += ecdh_example
ecdh_example_SOURCES = examples/ecdh.c
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include $(DEFINE_FLAGS)
ecdh_example_LDADD = libsecp256k1.la
ecdh_example_LDFLAGS = -static
if BUILD_WINDOWS
Expand All @@ -163,7 +163,7 @@ endif
if ENABLE_MODULE_SCHNORRSIG
noinst_PROGRAMS += schnorr_example
schnorr_example_SOURCES = examples/schnorr.c
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include $(DEFINE_FLAGS)
schnorr_example_LDADD = libsecp256k1.la
schnorr_example_LDFLAGS = -static
if BUILD_WINDOWS
Expand All @@ -178,11 +178,11 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen
CLEANFILES = $(EXTRA_PROGRAMS)

precompute_ecmult_SOURCES = src/precompute_ecmult.c
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES)
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
precompute_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)

precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES)
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES) $(DEFINE_FLAGS)
precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)

# See Automake manual, Section "Errors with distclean".
Expand Down
26 changes: 13 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ fi
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])

if test x"$enable_coverage" = x"yes"; then
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
DEFINE_FLAGS="$DEFINE_FLAGS -DCOVERAGE=1"
SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS"
LDFLAGS="--coverage $LDFLAGS"
else
Expand Down Expand Up @@ -266,7 +266,7 @@ enable_external_asm=no

case $set_asm in
x86_64)
AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
DEFINE_FLAGS="$DEFINE_FLAGS -DUSE_ASM_X86_64=1"
;;
arm)
enable_external_asm=yes
Expand All @@ -279,17 +279,17 @@ no)
esac

if test x"$enable_external_asm" = x"yes"; then
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
DEFINE_FLAGS="$DEFINE_FLAGS -DUSE_EXTERNAL_ASM=1"
fi


# Select wide multiplication implementation
case $set_widemul in
int128)
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
DEFINE_FLAGS="$DEFINE_FLAGS -DUSE_FORCE_WIDEMUL_INT128=1"
;;
int64)
AC_DEFINE(USE_FORCE_WIDEMUL_INT64, 1, [Define this symbol to force the use of the (u)int64_t based wide multiplication implementation])
DEFINE_FLAGS="$DEFINE_FLAGS -DUSE_FORCE_WIDEMUL_INT64=1"
;;
auto)
;;
Expand All @@ -316,7 +316,7 @@ case $set_ecmult_window in
# not in range
AC_MSG_ERROR($error_window_size)
fi
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
DEFINE_FLAGS="$DEFINE_FLAGS -DECMULT_WINDOW_SIZE=$set_ecmult_window"
;;
esac

Expand All @@ -329,7 +329,7 @@ fi

case $set_ecmult_gen_precision in
2|4|8)
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
DEFINE_FLAGS="$DEFINE_FLAGS -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
;;
*)
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
Expand All @@ -350,26 +350,26 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
###

if test x"$enable_module_ecdh" = x"yes"; then
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
DEFINE_FLAGS="$DEFINE_FLAGS -DENABLE_MODULE_ECDH=1"
fi

if test x"$enable_module_recovery" = x"yes"; then
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
DEFINE_FLAGS="$DEFINE_FLAGS -DENABLE_MODULE_RECOVERY=1"
fi

if test x"$enable_module_schnorrsig" = x"yes"; then
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
DEFINE_FLAGS="$DEFINE_FLAGS -DENABLE_MODULE_SCHNORRSIG=1"
enable_module_extrakeys=yes
fi

# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
# module to set enable_module_extrakeys=yes
if test x"$enable_module_extrakeys" = x"yes"; then
AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module])
DEFINE_FLAGS="$DEFINE_FLAGS -DENABLE_MODULE_EXTRAKEYS=1"
fi

if test x"$enable_external_default_callbacks" = x"yes"; then
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
DEFINE_FLAGS="$DEFINE_FLAGS -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1"
fi

###
Expand All @@ -391,13 +391,13 @@ fi
### Generate output
###

AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
AC_SUBST(SECP_INCLUDES)
AC_SUBST(SECP_LIBS)
AC_SUBST(SECP_TEST_LIBS)
AC_SUBST(SECP_TEST_INCLUDES)
AC_SUBST(SECP_CFLAGS)
AC_SUBST(DEFINE_FLAGS)
AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
AM_CONDITIONAL([USE_TESTS], [test x"$enable_tests" != x"no"])
AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$enable_exhaustive_tests" != x"no"])
Expand Down
4 changes: 0 additions & 4 deletions src/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
* imply normality.
*/

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

#if defined(SECP256K1_WIDEMUL_INT128)
Expand Down
4 changes: 0 additions & 4 deletions src/field_5x52_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_FIELD_REPR_IMPL_H
#define SECP256K1_FIELD_REPR_IMPL_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"
#include "field.h"
#include "modinv64_impl.h"
Expand Down
4 changes: 0 additions & 4 deletions src/field_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_FIELD_IMPL_H
#define SECP256K1_FIELD_IMPL_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

#if defined(SECP256K1_WIDEMUL_INT128)
Expand Down
4 changes: 0 additions & 4 deletions src/modinv32.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_MODINV32_H
#define SECP256K1_MODINV32_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

/* A signed 30-bit limb representation of integers.
Expand Down
4 changes: 0 additions & 4 deletions src/modinv64.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_MODINV64_H
#define SECP256K1_MODINV64_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

#ifndef SECP256K1_WIDEMUL_INT128
Expand Down
6 changes: 0 additions & 6 deletions src/precompute_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#include <inttypes.h>
#include <stdio.h>

/* Autotools creates libsecp256k1-config.h, of which ECMULT_WINDOW_SIZE is needed.
ifndef guard so downstream users can define their own if they do not use autotools. */
#if !defined(ECMULT_WINDOW_SIZE)
#include "libsecp256k1-config.h"
#endif

#include "../include/secp256k1.h"
#include "assumptions.h"
#include "util.h"
Expand Down
3 changes: 0 additions & 3 deletions src/precomputed_ecmult.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/precomputed_ecmult_gen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

#include "util.h"

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#if defined(EXHAUSTIVE_TEST_ORDER)
#include "scalar_low.h"
#elif defined(SECP256K1_WIDEMUL_INT128)
Expand Down
4 changes: 0 additions & 4 deletions src/scalar_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include "scalar.h"
#include "util.h"

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#if defined(EXHAUSTIVE_TEST_ORDER)
#include "scalar_low_impl.h"
#elif defined(SECP256K1_WIDEMUL_INT128)
Expand Down
4 changes: 0 additions & 4 deletions src/testrand.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_TESTRAND_H
#define SECP256K1_TESTRAND_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

/* A non-cryptographic RNG used only for test infrastructure. */

/** Seed the pseudorandom number generator for testing. */
Expand Down
4 changes: 0 additions & 4 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
4 changes: 0 additions & 4 deletions src/tests_exhaustive.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
***********************************************************************/

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Expand Down
4 changes: 0 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#ifndef SECP256K1_UTIL_H
#define SECP256K1_UTIL_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
Expand Down

0 comments on commit b487615

Please sign in to comment.