Skip to content

Commit b627ba7

Browse files
hebastoZenulAbidin
andcommitted
Remove dependency on src/libsecp256k1-config.h
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. Co-authored-by: Ali Sherief <ali@notatether.com>
1 parent 9a8d65f commit b627ba7

17 files changed

+25
-87
lines changed

Makefile.am

+11-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ noinst_HEADERS += examples/random.h
7373
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
7474
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
7575
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
76-
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
76+
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
7777

7878
if USE_EXTERNAL_ASM
7979
COMMON_LIB = libsecp256k1_common.la
@@ -92,7 +92,7 @@ endif
9292
endif
9393

9494
libsecp256k1_la_SOURCES = src/secp256k1.c
95-
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES)
95+
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
9696
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
9797
libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE)
9898

@@ -107,17 +107,17 @@ bench_SOURCES = src/bench.c
107107
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
108108
bench_internal_SOURCES = src/bench_internal.c
109109
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
110-
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
110+
bench_internal_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
111111
bench_ecmult_SOURCES = src/bench_ecmult.c
112112
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
113-
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
113+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
114114
endif
115115

116116
TESTS =
117117
if USE_TESTS
118118
noinst_PROGRAMS += tests
119119
tests_SOURCES = src/tests.c
120-
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
120+
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES) $(SECP_CONFIG_DEFINES)
121121
if VALGRIND_ENABLED
122122
tests_CPPFLAGS += -DVALGRIND
123123
noinst_PROGRAMS += valgrind_ctime_test
@@ -135,7 +135,7 @@ endif
135135
if USE_EXHAUSTIVE_TESTS
136136
noinst_PROGRAMS += exhaustive_tests
137137
exhaustive_tests_SOURCES = src/tests_exhaustive.c
138-
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
138+
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
139139
if !ENABLE_COVERAGE
140140
exhaustive_tests_CPPFLAGS += -DVERIFY
141141
endif
@@ -148,7 +148,7 @@ endif
148148
if USE_EXAMPLES
149149
noinst_PROGRAMS += ecdsa_example
150150
ecdsa_example_SOURCES = examples/ecdsa.c
151-
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
151+
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_CONFIG_DEFINES)
152152
ecdsa_example_LDADD = libsecp256k1.la
153153
ecdsa_example_LDFLAGS = -static
154154
if BUILD_WINDOWS
@@ -158,7 +158,7 @@ TESTS += ecdsa_example
158158
if ENABLE_MODULE_ECDH
159159
noinst_PROGRAMS += ecdh_example
160160
ecdh_example_SOURCES = examples/ecdh.c
161-
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
161+
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_CONFIG_DEFINES)
162162
ecdh_example_LDADD = libsecp256k1.la
163163
ecdh_example_LDFLAGS = -static
164164
if BUILD_WINDOWS
@@ -169,7 +169,7 @@ endif
169169
if ENABLE_MODULE_SCHNORRSIG
170170
noinst_PROGRAMS += schnorr_example
171171
schnorr_example_SOURCES = examples/schnorr.c
172-
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
172+
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_CONFIG_DEFINES)
173173
schnorr_example_LDADD = libsecp256k1.la
174174
schnorr_example_LDFLAGS = -static
175175
if BUILD_WINDOWS
@@ -184,11 +184,11 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen
184184
CLEANFILES = $(EXTRA_PROGRAMS)
185185

186186
precompute_ecmult_SOURCES = src/precompute_ecmult.c
187-
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES)
187+
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
188188
precompute_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
189189

190190
precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c
191-
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES)
191+
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
192192
precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)
193193

194194
# See Automake manual, Section "Errors with distclean".

configure.ac

+14-14
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fi
228228
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
229229

230230
if test x"$enable_coverage" = x"yes"; then
231-
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
231+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOVERAGE=1"
232232
SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS"
233233
LDFLAGS="--coverage $LDFLAGS"
234234
else
@@ -270,7 +270,7 @@ enable_external_asm=no
270270

271271
case $set_asm in
272272
x86_64)
273-
AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
273+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_ASM_X86_64=1"
274274
;;
275275
arm)
276276
enable_external_asm=yes
@@ -283,20 +283,20 @@ no)
283283
esac
284284

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

289289

290290
# Select wide multiplication implementation
291291
case $set_widemul in
292292
int128_struct)
293-
AC_DEFINE(USE_FORCE_WIDEMUL_INT128_STRUCT, 1, [Define this symbol to force the use of the structure for simulating (unsigned) int128 based wide multiplication])
293+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128_STRUCT=1"
294294
;;
295295
int128)
296-
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
296+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128=1"
297297
;;
298298
int64)
299-
AC_DEFINE(USE_FORCE_WIDEMUL_INT64, 1, [Define this symbol to force the use of the (u)int64_t based wide multiplication implementation])
299+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT64=1"
300300
;;
301301
auto)
302302
;;
@@ -323,7 +323,7 @@ case $set_ecmult_window in
323323
# not in range
324324
AC_MSG_ERROR($error_window_size)
325325
fi
326-
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
326+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_WINDOW_SIZE=$set_ecmult_window"
327327
;;
328328
esac
329329

@@ -336,7 +336,7 @@ fi
336336

337337
case $set_ecmult_gen_precision in
338338
2|4|8)
339-
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
339+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
340340
;;
341341
*)
342342
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
@@ -357,26 +357,26 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
357357
###
358358

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

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

367367
if test x"$enable_module_schnorrsig" = x"yes"; then
368-
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
368+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
369369
enable_module_extrakeys=yes
370370
fi
371371

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

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

382382
###
@@ -398,13 +398,13 @@ fi
398398
### Generate output
399399
###
400400

401-
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
402401
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
403402
AC_SUBST(SECP_INCLUDES)
404403
AC_SUBST(SECP_LIBS)
405404
AC_SUBST(SECP_TEST_LIBS)
406405
AC_SUBST(SECP_TEST_INCLUDES)
407406
AC_SUBST(SECP_CFLAGS)
407+
AC_SUBST(SECP_CONFIG_DEFINES)
408408
AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
409409
AM_CONDITIONAL([USE_TESTS], [test x"$enable_tests" != x"no"])
410410
AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$enable_exhaustive_tests" != x"no"])

src/field.h

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
* imply normality.
1919
*/
2020

21-
#if defined HAVE_CONFIG_H
22-
#include "libsecp256k1-config.h"
23-
#endif
24-
2521
#include "util.h"
2622

2723
#if defined(SECP256K1_WIDEMUL_INT128)

src/field_5x52_impl.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_FIELD_REPR_IMPL_H
88
#define SECP256K1_FIELD_REPR_IMPL_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
#include "util.h"
1511
#include "field.h"
1612
#include "modinv64_impl.h"

src/field_impl.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_FIELD_IMPL_H
88
#define SECP256K1_FIELD_IMPL_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
#include "util.h"
1511

1612
#if defined(SECP256K1_WIDEMUL_INT128)

src/modinv32.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_MODINV32_H
88
#define SECP256K1_MODINV32_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
#include "util.h"
1511

1612
/* A signed 30-bit limb representation of integers.

src/modinv64.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_MODINV64_H
88
#define SECP256K1_MODINV64_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
#include "util.h"
1511

1612
#ifndef SECP256K1_WIDEMUL_INT128

src/precompute_ecmult.c

-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
#include <inttypes.h>
88
#include <stdio.h>
99

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

1812
#include "assumptions.h"
@@ -74,9 +68,6 @@ int main(void) {
7468
fprintf(fp, "/* This file contains an array secp256k1_pre_g with odd multiples of the base point G and\n");
7569
fprintf(fp, " * an array secp256k1_pre_g_128 with odd multiples of 2^128*G for accelerating the computation of a*P + b*G.\n");
7670
fprintf(fp, " */\n");
77-
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
78-
fprintf(fp, "# include \"libsecp256k1-config.h\"\n");
79-
fprintf(fp, "#endif\n");
8071
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
8172
fprintf(fp, "#include \"group.h\"\n");
8273
fprintf(fp, "#include \"ecmult.h\"\n");

src/precompute_ecmult_gen.c

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ int main(int argc, char **argv) {
3333

3434
fprintf(fp, "/* This file was automatically generated by precompute_ecmult_gen. */\n");
3535
fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n");
36-
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
37-
fprintf(fp, "# include \"libsecp256k1-config.h\"\n");
38-
fprintf(fp, "#endif\n");
3936
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
4037
fprintf(fp, "#include \"group.h\"\n");
4138
fprintf(fp, "#include \"ecmult_gen.h\"\n");

src/precomputed_ecmult.c

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/precomputed_ecmult_gen.c

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scalar.h

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99

1010
#include "util.h"
1111

12-
#if defined HAVE_CONFIG_H
13-
#include "libsecp256k1-config.h"
14-
#endif
15-
1612
#if defined(EXHAUSTIVE_TEST_ORDER)
1713
#include "scalar_low.h"
1814
#elif defined(SECP256K1_WIDEMUL_INT128)

src/scalar_impl.h

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include "scalar.h"
1515
#include "util.h"
1616

17-
#if defined HAVE_CONFIG_H
18-
#include "libsecp256k1-config.h"
19-
#endif
20-
2117
#if defined(EXHAUSTIVE_TEST_ORDER)
2218
#include "scalar_low_impl.h"
2319
#elif defined(SECP256K1_WIDEMUL_INT128)

src/testrand.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_TESTRAND_H
88
#define SECP256K1_TESTRAND_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
/* A non-cryptographic RNG used only for test infrastructure. */
1511

1612
/** Seed the pseudorandom number generator for testing. */

src/tests.c

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7-
#if defined HAVE_CONFIG_H
8-
#include "libsecp256k1-config.h"
9-
#endif
10-
117
#include <stdio.h>
128
#include <stdlib.h>
139
#include <string.h>

src/tests_exhaustive.c

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
55
***********************************************************************/
66

7-
#if defined HAVE_CONFIG_H
8-
#include "libsecp256k1-config.h"
9-
#endif
10-
117
#include <stdio.h>
128
#include <stdlib.h>
139
#include <time.h>

src/util.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#ifndef SECP256K1_UTIL_H
88
#define SECP256K1_UTIL_H
99

10-
#if defined HAVE_CONFIG_H
11-
#include "libsecp256k1-config.h"
12-
#endif
13-
1410
#include <stdlib.h>
1511
#include <stdint.h>
1612
#include <stdio.h>

0 commit comments

Comments
 (0)