Add a secp256k1 makefile and building instructions (#24)
This commit is contained in:
parent
ac64b36818
commit
a43ee04d86
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "secp256k1/secp256k1-zkp"]
|
||||
path = secp256k1/secp256k1-zkp
|
||||
url = https://github.com/ElementsProject/secp256k1-zkp.git
|
||||
90
secp256k1/Makefile
Normal file
90
secp256k1/Makefile
Normal file
@ -0,0 +1,90 @@
|
||||
CROSS_DLL ?= 0
|
||||
TARGET = libsecp256k1
|
||||
ifeq ($(CROSS_DLL),1)
|
||||
PLATFORM = windows
|
||||
ARCH = amd64
|
||||
else ifeq ($(OS),Windows_NT)
|
||||
PLATFORM = windows
|
||||
ARCH = amd64
|
||||
else
|
||||
PLATFORM = $(shell uname -s | tr A-Z a-z)
|
||||
ARCH = $(shell uname -m)
|
||||
endif
|
||||
|
||||
# Paths
|
||||
LIB_DIR = secp256k1-zkp
|
||||
BUILD_DIR = build
|
||||
|
||||
# Tools
|
||||
ifeq ($(PLATFORM),windows)
|
||||
TOOLCHAIN_PREFIX ?= x86_64-w64-mingw32-
|
||||
else
|
||||
TOOLCHAIN_PREFIX ?=
|
||||
endif
|
||||
|
||||
CC := $(TOOLCHAIN_PREFIX)gcc
|
||||
ifeq ($(OS),Windows_NT)
|
||||
MKDIR_P = mkdir
|
||||
RM_R = rmdir /s /q
|
||||
else
|
||||
MKDIR_P = mkdir -p
|
||||
RM_R = rm -r
|
||||
endif
|
||||
|
||||
# C sources
|
||||
C_SOURCES = $(addprefix $(LIB_DIR)/src/,\
|
||||
secp256k1.c \
|
||||
)
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
$(LIB_DIR) \
|
||||
$(LIB_DIR)/src \
|
||||
config
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
HAVE_CONFIG_H
|
||||
|
||||
ifeq ($(PLATFORM),windows)
|
||||
C_DEFS += _WIN32
|
||||
endif
|
||||
|
||||
OBJS := $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
ifeq ($(PLATFORM),windows)
|
||||
CFLAGS = -O2 -std=c99 -MMD -MP -Werror -Wno-unused-function \
|
||||
$(addprefix -I,$(C_INCLUDES)) $(addprefix -D,$(C_DEFS))
|
||||
else
|
||||
CFLAGS = -fPIC -O2 -Werror -Wno-unused-function \
|
||||
$(addprefix -I,$(C_INCLUDES)) $(addprefix -D,$(C_DEFS))
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),windows)
|
||||
LDFLAGS = -shared -s \
|
||||
-Wl,--subsystem,windows,--out-implib,$(BUILD_DIR)/$(TARGET).a
|
||||
EXT = .dll
|
||||
else ifeq ($(PLATFORM),darwin)
|
||||
LDFLAGS = -dynamiclib
|
||||
EXT = .dylib
|
||||
else
|
||||
LDFLAGS = -shared
|
||||
EXT = .so
|
||||
endif
|
||||
|
||||
$(BUILD_DIR)/$(TARGET)_$(PLATFORM)_$(ARCH)$(EXT): $(OBJS) Makefile
|
||||
$(CC) $(OBJS) -o $@ $(LDFLAGS)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile
|
||||
$(MKDIR_P) "$(dir $@)"
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
$(RM_R) "$(BUILD_DIR)"
|
||||
|
||||
-include $(DEPS)
|
||||
58
secp256k1/README.md
Normal file
58
secp256k1/README.md
Normal file
@ -0,0 +1,58 @@
|
||||
# Building secp256k1 for embit
|
||||
|
||||
If you don't want to use prebuilt binary packaged with `embit` you can build it yourself.
|
||||
|
||||
We are using **libsecp256k1** fork -
|
||||
[**secp256k1-zkp**](https://github.com/ElementsProject/secp256k1-zkp).
|
||||
|
||||
# Building the library under target platform
|
||||
|
||||
To build the library run:
|
||||
|
||||
```sh
|
||||
make
|
||||
```
|
||||
|
||||
To clean build directory use:
|
||||
|
||||
```shell
|
||||
make clean
|
||||
```
|
||||
|
||||
# Cross-compiling Windows DLL
|
||||
|
||||
## Toolchain install
|
||||
|
||||
### Linux
|
||||
|
||||
In the console type:
|
||||
|
||||
```shell
|
||||
sudo apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 wine64
|
||||
```
|
||||
|
||||
### Mac
|
||||
|
||||
Assuming that [Homebrew](https://brew.sh/) package manager is installed, in the console type:
|
||||
|
||||
```shell
|
||||
brew install mingw-w64
|
||||
brew install --cask xquartz
|
||||
brew install --cask wine-stable
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
Assuming that [Chocolatey](https://chocolatey.org/) package manager is installed, in the **Powershell** type:
|
||||
|
||||
```shell
|
||||
choco install mingw make
|
||||
```
|
||||
|
||||
## Building the library
|
||||
|
||||
To build the Windows DLL and the companion library from other platforms run:
|
||||
|
||||
```shell
|
||||
make CROSS_DLL=1
|
||||
```
|
||||
44
secp256k1/config/libsecp256k1-config.h
Normal file
44
secp256k1/config/libsecp256k1-config.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef SECP256K1_CONFIG_H
|
||||
#define SECP256K1_CONFIG_H
|
||||
|
||||
#undef USE_ASM_X86_64
|
||||
#undef USE_ECMULT_STATIC_PRECOMPUTATION
|
||||
#undef USE_ENDOMORPHISM
|
||||
#undef USE_EXTERNAL_ASM
|
||||
#undef USE_EXTERNAL_DEFAULT_CALLBACKS
|
||||
#undef USE_FIELD_10X26
|
||||
#undef USE_FIELD_5X52
|
||||
#undef USE_FIELD_INV_BUILTIN
|
||||
#undef USE_FIELD_INV_NUM
|
||||
#undef USE_NUM_GMP
|
||||
#undef USE_NUM_NONE
|
||||
#undef USE_SCALAR_4X64
|
||||
#undef USE_SCALAR_8X32
|
||||
#undef USE_SCALAR_INV_BUILTIN
|
||||
#undef USE_SCALAR_INV_NUM
|
||||
#undef ECMULT_WINDOW_SIZE
|
||||
|
||||
#define ENABLE_MODULE_ECDH 1
|
||||
#define ENABLE_MODULE_RECOVERY 1
|
||||
#define ENABLE_MODULE_GENERATOR 1
|
||||
#define ENABLE_MODULE_RANGEPROOF 1
|
||||
#define ENABLE_MODULE_SURJECTIONPROOF 1
|
||||
#define ENABLE_MODULE_MUSIG 1
|
||||
#define ENABLE_MODULE_EXTRAKEYS 1
|
||||
#define ENABLE_MODULE_SCHNORRSIG 1
|
||||
|
||||
|
||||
#define USE_NUM_NONE 1
|
||||
#define USE_FIELD_INV_BUILTIN 1
|
||||
#define USE_SCALAR_INV_BUILTIN 1
|
||||
#define USE_FIELD_10X26 1
|
||||
#define USE_SCALAR_8X32 1
|
||||
|
||||
#define ECMULT_GEN_PREC_BITS 4
|
||||
#define ECMULT_WINDOW_SIZE 4
|
||||
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
#endif /* SECP256K1_CONFIG_H */
|
||||
1
secp256k1/secp256k1-zkp
Submodule
1
secp256k1/secp256k1-zkp
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit d9560e0af78d9059bba0c4845a310387abfa4e5e
|
||||
Loading…
Reference in New Issue
Block a user