diff --git a/Makefile b/Makefile index f18ca43..14cba8a 100644 --- a/Makefile +++ b/Makefile @@ -3,39 +3,44 @@ FLAGS_PROD:=-DNDEBUG -O2 -march=native FLAGS_DEBUG:=-DVERIFY -ggdb3 -O1 FLAGS_TEST:=-DVERIFY -ggdb3 -O2 -march=native -SECP256K1_FILES := num.h field.h field_5x52.h group.h ecmult.h ecdsa.h \ - num.cpp field.cpp field_5x52.cpp group.cpp ecmult.cpp ecdsa.cpp +SECP256K1_FILES := src/num.h src/field.h src/field_5x52.h src/group.h src/ecmult.h src/ecdsa.h \ + src/num.cpp src/field.cpp src/field_5x52.cpp src/group.cpp src/ecmult.cpp src/ecdsa.cpp + ifndef CONF CONF := gmp endif +OBJS := obj/secp256k1-$(CONF).o + default: all ifeq ($(CONF), openssl) -FLAGS_CONF:=-DUSE_NUM_OPENSSL -DUSE_FIELDINVERSE_BUILTIN +FLAGS_CONF:=-DUSE_NUM_OPENSSL -DUSE_FIELD_INV_BUILTIN LIBS:=-lcrypto -SECP256K1_FILES := $(SECP256K1_FILES) num_openssl.h num_openssl.cpp field_5x52_int128.cpp +SECP256K1_FILES := $(SECP256K1_FILES) src/num_openssl.h src/num_openssl.cpp src/field_5x52_int128.cpp else ifeq ($(CONF), gmp) FLAGS_CONF:=-DUSE_NUM_GMP LIBS:=-lgmp -SECP256K1_FILES := $(SECP256K1_FILES) num_gmp.h num_gmp.cpp field_5x52_int128.cpp +SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.cpp src/field_5x52_int128.cpp else ifeq ($(CONF), gmpasm) -FLAGS_CONF:=-DUSE_NUM_GMP -DINLINE_ASM +FLAGS_CONF:=-DUSE_NUM_GMP -DUSE_FIELD_5X52_ASM LIBS:=-lgmp obj/field_5x52_asm.o -SECP256K1_FILES := $(SECP256K1_FILES) num_gmp.h num_gmp.cpp field_5x52_asm.cpp obj/field_5x52_asm.o +OBJS:=$(OBJS) obj/field_5x52_asm.o +SECP256K1_FILES := $(SECP256K1_FILES) src/num_gmp.h src/num_gmp.cpp src/field_5x52_asm.cpp -obj/field_5x52_asm.o: field_5x52_asm.asm - yasm -f elf64 -o obj/field_5x52_asm.o field_5x52_asm.asm +obj/field_5x52_asm.o: src/field_5x52_asm.asm + yasm -f elf64 -o obj/field_5x52_asm.o src/field_5x52_asm.asm else -SECP256K1_FILES := $(SECP256K1_FILES) field_5x52_int128.cpp +SECP256K1_FILES := $(SECP256K1_FILES) src/field_5x52_int128.cpp endif endif endif -all: *.cpp *.asm *.h + +all: src/*.cpp src/*.asm src/*.h include/*.h +make CONF=openssl all-openssl +make CONF=gmp all-gmp +make CONF=gmpasm all-gmpasm @@ -48,16 +53,19 @@ clean: bench-any: bench-$(CONF) tests-any: tests-$(CONF) -all-$(CONF): bench-$(CONF) tests-$(CONF) obj/secp256k1-$(CONF).o +all-$(CONF): bench-$(CONF) tests-$(CONF) libsecp256k1-$(CONF).a clean-$(CONF): - rm -f bench-$(CONF) tests-$(CONF) obj/secp256k1-$(CONF).o + rm -f bench-$(CONF) tests-$(CONF) libsecp256k1-$(CONF).a obj/* -obj/secp256k1-$(CONF).o: $(SECP256K1_FILES) - $(CXX) $(FLAGS_COMMON) $(FLAGS_PROD) $(FLAGS_CONF) secp256k1.cpp -c -o obj/secp256k1-$(CONF).o +obj/secp256k1-$(CONF).o: $(SECP256K1_FILES) src/secp256k1.cpp include/secp256k1.h + $(CXX) $(FLAGS_COMMON) $(FLAGS_PROD) $(FLAGS_CONF) src/secp256k1.cpp -c -o obj/secp256k1-$(CONF).o -bench-$(CONF): $(SECP256K1_FILES) bench.cpp - $(CXX) $(FLAGS_COMMON) $(FLAGS_PROD) $(FLAGS_CONF) bench.cpp $(LIBS) -o bench-$(CONF) +bench-$(CONF): $(OBJS) src/bench.cpp + $(CXX) $(FLAGS_COMMON) $(FLAGS_PROD) $(FLAGS_CONF) src/bench.cpp $(LIBS) -o bench-$(CONF) -tests-$(CONF): $(SECP256K1_FILES) tests.cpp - $(CXX) $(FLAGS_COMMON) $(FLAGS_TEST) $(FLAGS_CONF) tests.cpp $(LIBS) -o tests-$(CONF) +tests-$(CONF): $(OBJS) src/tests.cpp + $(CXX) $(FLAGS_COMMON) $(FLAGS_TEST) $(FLAGS_CONF) src/tests.cpp $(LIBS) -o tests-$(CONF) + +libsecp256k1-$(CONF).a: $(OBJS) + $(AR) -rs $@ $(OBJS) diff --git a/secp256k1.h b/include/secp256k1.h similarity index 100% rename from secp256k1.h rename to include/secp256k1.h diff --git a/bench.cpp b/src/bench.cpp similarity index 100% rename from bench.cpp rename to src/bench.cpp diff --git a/ecdsa.cpp b/src/ecdsa.cpp similarity index 100% rename from ecdsa.cpp rename to src/ecdsa.cpp diff --git a/ecdsa.h b/src/ecdsa.h similarity index 100% rename from ecdsa.h rename to src/ecdsa.h diff --git a/ecmult.cpp b/src/ecmult.cpp similarity index 100% rename from ecmult.cpp rename to src/ecmult.cpp diff --git a/ecmult.h b/src/ecmult.h similarity index 100% rename from ecmult.h rename to src/ecmult.h diff --git a/field.cpp b/src/field.cpp similarity index 99% rename from field.cpp rename to src/field.cpp index 9c214e6..94d19d6 100644 --- a/field.cpp +++ b/src/field.cpp @@ -135,7 +135,7 @@ void static secp256k1_fe_inv(secp256k1_fe_t *r, const secp256k1_fe_t *a) { } void static secp256k1_fe_inv_var(secp256k1_fe_t *r, const secp256k1_fe_t *a) { -#if defined(USE_FIELDINVERSE_BUILTIN) +#if defined(USE_FIELD_INV_BUILTIN) secp256k1_fe_inv(r, a); #else unsigned char b[32]; diff --git a/field.h b/src/field.h similarity index 100% rename from field.h rename to src/field.h diff --git a/field_5x52.cpp b/src/field_5x52.cpp similarity index 99% rename from field_5x52.cpp rename to src/field_5x52.cpp index acc4444..3f063b3 100644 --- a/field_5x52.cpp +++ b/src/field_5x52.cpp @@ -3,7 +3,7 @@ #include "num.h" #include "field.h" -#ifdef INLINE_ASM +#ifdef USE_FIELD_5X52_ASM #include "field_5x52_asm.cpp" #else #include "field_5x52_int128.cpp" diff --git a/field_5x52.h b/src/field_5x52.h similarity index 100% rename from field_5x52.h rename to src/field_5x52.h diff --git a/field_5x52_asm.asm b/src/field_5x52_asm.asm similarity index 100% rename from field_5x52_asm.asm rename to src/field_5x52_asm.asm diff --git a/field_5x52_asm.cpp b/src/field_5x52_asm.cpp similarity index 100% rename from field_5x52_asm.cpp rename to src/field_5x52_asm.cpp diff --git a/field_5x52_int128.cpp b/src/field_5x52_int128.cpp similarity index 100% rename from field_5x52_int128.cpp rename to src/field_5x52_int128.cpp diff --git a/group.cpp b/src/group.cpp similarity index 100% rename from group.cpp rename to src/group.cpp diff --git a/group.h b/src/group.h similarity index 100% rename from group.h rename to src/group.h diff --git a/num.cpp b/src/num.cpp similarity index 100% rename from num.cpp rename to src/num.cpp diff --git a/num.h b/src/num.h similarity index 100% rename from num.h rename to src/num.h diff --git a/num_builtin.h b/src/num_builtin.h similarity index 100% rename from num_builtin.h rename to src/num_builtin.h diff --git a/num_gmp.cpp b/src/num_gmp.cpp similarity index 100% rename from num_gmp.cpp rename to src/num_gmp.cpp diff --git a/num_gmp.h b/src/num_gmp.h similarity index 100% rename from num_gmp.h rename to src/num_gmp.h diff --git a/num_openssl.cpp b/src/num_openssl.cpp similarity index 100% rename from num_openssl.cpp rename to src/num_openssl.cpp diff --git a/num_openssl.h b/src/num_openssl.h similarity index 100% rename from num_openssl.h rename to src/num_openssl.h diff --git a/num_openssl_.cpp b/src/num_openssl_.cpp similarity index 100% rename from num_openssl_.cpp rename to src/num_openssl_.cpp diff --git a/secp256k1.cpp b/src/secp256k1.cpp similarity index 100% rename from secp256k1.cpp rename to src/secp256k1.cpp diff --git a/tests.cpp b/src/tests.cpp similarity index 100% rename from tests.cpp rename to src/tests.cpp