Skip to content

Commit 517644e

Browse files
committed
Optionally compile the examples in autotools, compile+run in travis
1 parent 422a7cc commit 517644e

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

.cirrus.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ env:
2323
BENCH: yes
2424
SECP256K1_BENCH_ITERS: 2
2525
CTIMETEST: yes
26+
# Compile and run the tests
27+
EXAMPLES: yes
2628

2729
cat_logs_snippet: &CAT_LOGS
2830
always:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ exhaustive_tests
66
precompute_ecmult_gen
77
precompute_ecmult
88
valgrind_ctime_test
9+
ecdh_example
10+
ecdsa_example
11+
schnorr_example
912
*.exe
1013
*.so
1114
*.a
1215
*.csv
1316
!.gitignore
17+
*.log
18+
*.trs
1419

1520
Makefile
1621
configure

Makefile.am

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ noinst_HEADERS += contrib/lax_der_parsing.h
6363
noinst_HEADERS += contrib/lax_der_parsing.c
6464
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
6565
noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
66+
noinst_HEADERS += examples/random.h
6667

6768
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
6869
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
@@ -139,6 +140,40 @@ exhaustive_tests_LDFLAGS = -static
139140
TESTS += exhaustive_tests
140141
endif
141142

143+
if USE_EXAMPLES
144+
noinst_PROGRAMS += ecdsa_example
145+
ecdsa_example_SOURCES = examples/ecdsa.c
146+
ecdsa_example_CPPFLAGS = -I$(top_srcdir)/include
147+
ecdsa_example_LDADD = libsecp256k1.la
148+
ecdsa_example_LDFLAGS = -static
149+
if BUILD_WINDOWS
150+
ecdsa_example_LDFLAGS += -lbcrypt
151+
endif
152+
TESTS += ecdsa_example
153+
if ENABLE_MODULE_ECDH
154+
noinst_PROGRAMS += ecdh_example
155+
ecdh_example_SOURCES = examples/ecdh.c
156+
ecdh_example_CPPFLAGS = -I$(top_srcdir)/include
157+
ecdh_example_LDADD = libsecp256k1.la
158+
ecdh_example_LDFLAGS = -static
159+
if BUILD_WINDOWS
160+
ecdh_example_LDFLAGS += -lbcrypt
161+
endif
162+
TESTS += ecdh_example
163+
endif
164+
if ENABLE_MODULE_SCHNORRSIG
165+
noinst_PROGRAMS += schnorr_example
166+
schnorr_example_SOURCES = examples/schnorr.c
167+
schnorr_example_CPPFLAGS = -I$(top_srcdir)/include
168+
schnorr_example_LDADD = libsecp256k1.la
169+
schnorr_example_LDFLAGS = -static
170+
if BUILD_WINDOWS
171+
schnorr_example_LDFLAGS += -lbcrypt
172+
endif
173+
TESTS += schnorr_example
174+
endif
175+
endif
176+
142177
### Precomputed tables
143178
EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen
144179
CLEANFILES = $(EXTRA_PROGRAMS)

ci/cirrus.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ valgrind --version || true
1919
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
2020
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
2121
--enable-module-schnorrsig="$SCHNORRSIG" \
22+
--enable-examples="$EXAMPLES" \
2223
--with-valgrind="$WITH_VALGRIND" \
2324
--host="$HOST" $EXTRAFLAGS
2425

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ if test x"$ac_cv_prog_cc_c89" = x"no"; then
4545
fi
4646
AM_PROG_AS
4747

48+
build_windows=no
49+
4850
case $host_os in
4951
*darwin*)
5052
if test x$cross_compiling != xyes; then
@@ -68,6 +70,9 @@ case $host_os in
6870
fi
6971
fi
7072
;;
73+
cygwin*|mingw*)
74+
build_windows=yes
75+
;;
7176
esac
7277

7378
# Try if some desirable compiler flags are supported and append them to SECP_CFLAGS.
@@ -135,6 +140,11 @@ AC_ARG_ENABLE(exhaustive_tests,
135140
[use_exhaustive_tests=$enableval],
136141
[use_exhaustive_tests=yes])
137142

143+
AC_ARG_ENABLE(examples,
144+
AS_HELP_STRING([--enable-examples],[compile the examples [default=no]]),
145+
[use_examples=$enableval],
146+
[use_examples=no])
147+
138148
AC_ARG_ENABLE(module_ecdh,
139149
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]),
140150
[enable_module_ecdh=$enableval],
@@ -393,13 +403,15 @@ AC_SUBST(SECP_CFLAGS)
393403
AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
394404
AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
395405
AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
406+
AM_CONDITIONAL([USE_EXAMPLES], [test x"$use_examples" != x"no"])
396407
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
397408
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
398409
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
399410
AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"])
400411
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
401412
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
402413
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
414+
AM_CONDITIONAL([BUILD_WINDOWS], [test "$build_windows" = "yes"])
403415
AC_SUBST(LIB_VERSION_CURRENT, _LIB_VERSION_CURRENT)
404416
AC_SUBST(LIB_VERSION_REVISION, _LIB_VERSION_REVISION)
405417
AC_SUBST(LIB_VERSION_AGE, _LIB_VERSION_AGE)
@@ -417,6 +429,7 @@ echo " with external callbacks = $use_external_default_callbacks"
417429
echo " with benchmarks = $use_benchmark"
418430
echo " with tests = $use_tests"
419431
echo " with coverage = $enable_coverage"
432+
echo " with examples = $use_examples"
420433
echo " module ecdh = $enable_module_ecdh"
421434
echo " module recovery = $enable_module_recovery"
422435
echo " module extrakeys = $enable_module_extrakeys"

0 commit comments

Comments
 (0)