Skip to content

Commit 081e69d

Browse files
committed
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.
1 parent 694ce8f commit 081e69d

17 files changed

+24
-86
lines changed

Diff for: Makefile.am

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ noinst_HEADERS += examples/random.h
6767
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
6868
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
6969
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
70-
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES)
70+
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
7171

7272
if USE_EXTERNAL_ASM
7373
COMMON_LIB = libsecp256k1_common.la
@@ -86,7 +86,7 @@ endif
8686
endif
8787

8888
libsecp256k1_la_SOURCES = src/secp256k1.c
89-
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES)
89+
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
9090
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
9191
libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE)
9292

@@ -101,17 +101,17 @@ bench_SOURCES = src/bench.c
101101
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
102102
bench_internal_SOURCES = src/bench_internal.c
103103
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
104-
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
104+
bench_internal_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
105105
bench_ecmult_SOURCES = src/bench_ecmult.c
106106
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
107-
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
107+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
108108
endif
109109

110110
TESTS =
111111
if USE_TESTS
112112
noinst_PROGRAMS += tests
113113
tests_SOURCES = src/tests.c
114-
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
114+
tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES) $(SECP_DEFINE_FLAGS)
115115
if VALGRIND_ENABLED
116116
tests_CPPFLAGS += -DVALGRIND
117117
noinst_PROGRAMS += valgrind_ctime_test
@@ -129,7 +129,7 @@ endif
129129
if USE_EXHAUSTIVE_TESTS
130130
noinst_PROGRAMS += exhaustive_tests
131131
exhaustive_tests_SOURCES = src/tests_exhaustive.c
132-
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
132+
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
133133
if !ENABLE_COVERAGE
134134
exhaustive_tests_CPPFLAGS += -DVERIFY
135135
endif
@@ -142,7 +142,7 @@ endif
142142
if USE_EXAMPLES
143143
noinst_PROGRAMS += ecdsa_example
144144
ecdsa_example_SOURCES = examples/ecdsa.c
145-
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
145+
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_DEFINE_FLAGS)
146146
ecdsa_example_LDADD = libsecp256k1.la
147147
ecdsa_example_LDFLAGS = -static
148148
if BUILD_WINDOWS
@@ -152,7 +152,7 @@ TESTS += ecdsa_example
152152
if ENABLE_MODULE_ECDH
153153
noinst_PROGRAMS += ecdh_example
154154
ecdh_example_SOURCES = examples/ecdh.c
155-
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
155+
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_DEFINE_FLAGS)
156156
ecdh_example_LDADD = libsecp256k1.la
157157
ecdh_example_LDFLAGS = -static
158158
if BUILD_WINDOWS
@@ -163,7 +163,7 @@ endif
163163
if ENABLE_MODULE_SCHNORRSIG
164164
noinst_PROGRAMS += schnorr_example
165165
schnorr_example_SOURCES = examples/schnorr.c
166-
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
166+
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include $(SECP_DEFINE_FLAGS)
167167
schnorr_example_LDADD = libsecp256k1.la
168168
schnorr_example_LDFLAGS = -static
169169
if BUILD_WINDOWS
@@ -178,11 +178,11 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen
178178
CLEANFILES = $(EXTRA_PROGRAMS)
179179

180180
precompute_ecmult_SOURCES = src/precompute_ecmult.c
181-
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES)
181+
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
182182
precompute_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
183183

184184
precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c
185-
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES)
185+
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES) $(SECP_DEFINE_FLAGS)
186186
precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)
187187

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

Diff for: configure.ac

+13-13
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fi
224224
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
225225

226226
if test x"$enable_coverage" = x"yes"; then
227-
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
227+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DCOVERAGE=1"
228228
SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS"
229229
LDFLAGS="--coverage $LDFLAGS"
230230
else
@@ -266,7 +266,7 @@ enable_external_asm=no
266266

267267
case $set_asm in
268268
x86_64)
269-
AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
269+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DUSE_ASM_X86_64=1"
270270
;;
271271
arm)
272272
enable_external_asm=yes
@@ -279,17 +279,17 @@ no)
279279
esac
280280

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

285285

286286
# Select wide multiplication implementation
287287
case $set_widemul in
288288
int128)
289-
AC_DEFINE(USE_FORCE_WIDEMUL_INT128, 1, [Define this symbol to force the use of the (unsigned) __int128 based wide multiplication implementation])
289+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DUSE_FORCE_WIDEMUL_INT128=1"
290290
;;
291291
int64)
292-
AC_DEFINE(USE_FORCE_WIDEMUL_INT64, 1, [Define this symbol to force the use of the (u)int64_t based wide multiplication implementation])
292+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DUSE_FORCE_WIDEMUL_INT64=1"
293293
;;
294294
auto)
295295
;;
@@ -316,7 +316,7 @@ case $set_ecmult_window in
316316
# not in range
317317
AC_MSG_ERROR($error_window_size)
318318
fi
319-
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
319+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DECMULT_WINDOW_SIZE=$set_ecmult_window"
320320
;;
321321
esac
322322

@@ -329,7 +329,7 @@ fi
329329

330330
case $set_ecmult_gen_precision in
331331
2|4|8)
332-
AC_DEFINE_UNQUOTED(ECMULT_GEN_PREC_BITS, $set_ecmult_gen_precision, [Set ecmult gen precision bits])
332+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DECMULT_GEN_PREC_BITS=$set_ecmult_gen_precision"
333333
;;
334334
*)
335335
AC_MSG_ERROR(['ecmult gen precision not 2, 4, 8 or "auto"'])
@@ -350,26 +350,26 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
350350
###
351351

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

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

360360
if test x"$enable_module_schnorrsig" = x"yes"; then
361-
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
361+
SECP_DEFINE_FLAGS="$SECP_DEFINE_FLAGS -DENABLE_MODULE_SCHNORRSIG=1"
362362
enable_module_extrakeys=yes
363363
fi
364364

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

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

375375
###
@@ -391,13 +391,13 @@ fi
391391
### Generate output
392392
###
393393

394-
AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
395394
AC_CONFIG_FILES([Makefile libsecp256k1.pc])
396395
AC_SUBST(SECP_INCLUDES)
397396
AC_SUBST(SECP_LIBS)
398397
AC_SUBST(SECP_TEST_LIBS)
399398
AC_SUBST(SECP_TEST_INCLUDES)
400399
AC_SUBST(SECP_CFLAGS)
400+
AC_SUBST(SECP_DEFINE_FLAGS)
401401
AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
402402
AM_CONDITIONAL([USE_TESTS], [test x"$enable_tests" != x"no"])
403403
AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$enable_exhaustive_tests" != x"no"])

Diff for: 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)

Diff for: 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"

Diff for: 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)

Diff for: 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.

Diff for: 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

Diff for: 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
#include "assumptions.h"
1812
#include "util.h"
@@ -71,9 +65,6 @@ int main(void) {
7165
fprintf(fp, "/* This file contains an array secp256k1_pre_g with odd multiples of the base point G and\n");
7266
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");
7367
fprintf(fp, " */\n");
74-
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
75-
fprintf(fp, "# include \"libsecp256k1-config.h\"\n");
76-
fprintf(fp, "#endif\n");
7768
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
7869
fprintf(fp, "#include \"group.h\"\n");
7970
fprintf(fp, "#include \"ecmult.h\"\n");

Diff for: src/precompute_ecmult_gen.c

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

3131
fprintf(fp, "/* This file was automatically generated by precompute_ecmult_gen. */\n");
3232
fprintf(fp, "/* See ecmult_gen_impl.h for details about the contents of this file. */\n");
33-
fprintf(fp, "#if defined HAVE_CONFIG_H\n");
34-
fprintf(fp, "# include \"libsecp256k1-config.h\"\n");
35-
fprintf(fp, "#endif\n");
3633
fprintf(fp, "#include \"../include/secp256k1.h\"\n");
3734
fprintf(fp, "#include \"group.h\"\n");
3835
fprintf(fp, "#include \"ecmult_gen.h\"\n");

Diff for: src/precomputed_ecmult.c

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

Diff for: src/precomputed_ecmult_gen.c

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

Diff for: 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)

Diff for: 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)

Diff for: 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. */

Diff for: 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>

Diff for: 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>

Diff for: 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)