2018-06-06 05:33:27 +02:00
|
|
|
SUBMODULES = \
|
|
|
|
external/libsodium \
|
|
|
|
external/libwally-core \
|
2020-08-11 08:27:37 +02:00
|
|
|
external/gheap \
|
2018-06-06 05:33:27 +02:00
|
|
|
external/jsmn \
|
|
|
|
external/libbacktrace
|
|
|
|
|
2020-01-29 21:13:09 +01:00
|
|
|
TOP := ../..
|
2019-11-20 16:54:50 +01:00
|
|
|
ifdef BUILD
|
|
|
|
CROSSCOMPILE_OPTS := --host="$(MAKE_HOST)" --build="$(BUILD)"
|
2020-06-29 03:02:04 +02:00
|
|
|
TARGET_DIR := external/$(MAKE_HOST)
|
2020-01-30 00:15:32 +01:00
|
|
|
else
|
2020-06-29 03:02:04 +02:00
|
|
|
TARGET_DIR := external/$(shell ${CC} -dumpmachine)
|
2019-11-20 16:54:50 +01:00
|
|
|
endif
|
|
|
|
|
2017-08-28 18:11:01 +02:00
|
|
|
LIBSODIUM_HEADERS := external/libsodium/src/libsodium/include/sodium.h
|
|
|
|
LIBWALLY_HEADERS := external/libwally-core/include/wally_bip32.h \
|
|
|
|
external/libwally-core/include/wally_core.h \
|
2020-08-31 03:22:51 +02:00
|
|
|
external/libwally-core/include/wally_psbt.h \
|
2017-08-28 18:11:01 +02:00
|
|
|
external/libwally-core/include/wally_crypto.h
|
|
|
|
LIBSECP_HEADERS := external/libwally-core/src/secp256k1/include/secp256k1_ecdh.h \
|
2020-09-09 12:35:10 +02:00
|
|
|
external/libwally-core/src/secp256k1/include/secp256k1_recovery.h \
|
2017-08-28 18:11:01 +02:00
|
|
|
external/libwally-core/src/secp256k1/include/secp256k1.h
|
|
|
|
JSMN_HEADERS := external/jsmn/jsmn.h
|
2020-08-31 03:22:51 +02:00
|
|
|
GHEAP_HEADERS := external/gheap/gheap.h
|
|
|
|
LIBBACKTRACE_HEADERS := external/libbacktrace/backtrace.h
|
2017-08-28 18:11:01 +02:00
|
|
|
|
2020-08-31 03:22:51 +02:00
|
|
|
EXTERNAL_HEADERS := $(LIBSODIUM_HEADERS) $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) $(JSMN_HEADERS) $(GHEAP_HEADERS) $(LIBBACKTRACE_HEADERS)
|
2020-01-30 00:15:32 +01:00
|
|
|
EXTERNAL_LIBS := ${TARGET_DIR}/libwallycore.a ${TARGET_DIR}/libsecp256k1.a ${TARGET_DIR}/libjsmn.a ${TARGET_DIR}/libbacktrace.a
|
2017-08-28 18:11:01 +02:00
|
|
|
|
|
|
|
EXTERNAL_INCLUDE_FLAGS := \
|
|
|
|
-I external/libwally-core/include/ \
|
|
|
|
-I external/libwally-core/src/secp256k1/include/ \
|
|
|
|
-I external/jsmn/ \
|
2018-03-22 08:10:23 +01:00
|
|
|
-I external/libbacktrace/ \
|
2020-08-11 08:27:37 +02:00
|
|
|
-I external/gheap/ \
|
2020-01-30 00:15:32 +01:00
|
|
|
-I ${TARGET_DIR}/libbacktrace-build
|
2017-08-28 18:13:01 +02:00
|
|
|
|
2019-02-07 21:36:50 +01:00
|
|
|
ifneq ($(HAVE_GOOD_LIBSODIUM),1)
|
2020-01-30 00:15:32 +01:00
|
|
|
EXTERNAL_INCLUDE_FLAGS += -I external/libsodium/src/libsodium/include \
|
|
|
|
-I external/libsodium/src/libsodium/include/sodium \
|
|
|
|
-I $(TARGET_DIR)/libsodium-build/src/libsodium/include
|
|
|
|
EXTERNAL_LIBS += ${TARGET_DIR}/libsodium.a
|
2019-02-07 21:36:50 +01:00
|
|
|
else
|
|
|
|
LDLIBS += -lsodium
|
|
|
|
endif
|
|
|
|
|
2020-01-30 00:15:32 +01:00
|
|
|
EXTERNAL_LDLIBS := -L${TARGET_DIR} $(patsubst lib%.a,-l%,$(notdir $(EXTERNAL_LIBS)))
|
2017-08-28 18:11:01 +02:00
|
|
|
|
2018-06-06 05:33:27 +02:00
|
|
|
submodcheck: FORCE
|
|
|
|
@tools/refresh-submodules.sh $(SUBMODULES)
|
2020-11-30 01:17:08 +01:00
|
|
|
@cd external/libwally-core && ../../tools/refresh-submodules.sh src/secp256k1
|
2018-01-29 05:30:53 +01:00
|
|
|
|
2020-08-31 03:22:51 +02:00
|
|
|
$(EXTERNAL_HEADERS): submodcheck
|
|
|
|
|
2017-08-28 18:11:01 +02:00
|
|
|
# We build libsodium, since Ubuntu xenial has one too old.
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libsodium.a: $(TARGET_DIR)/libsodium-build/src/libsodium/libsodium.la
|
|
|
|
$(MAKE) -C $(TARGET_DIR)/libsodium-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec
|
2017-08-28 18:11:01 +02:00
|
|
|
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libsodium-build/src/libsodium/libsodium.la: external/libsodium/src/libsodium/include/sodium.h
|
|
|
|
cd external/libsodium && ./autogen.sh
|
|
|
|
mkdir -p ${TARGET_DIR}/libsodium-build
|
2020-03-03 16:48:31 +01:00
|
|
|
cd $(TARGET_DIR)/libsodium-build && $(TOP)/libsodium/configure CC="$(CC)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE)
|
2017-08-28 18:11:01 +02:00
|
|
|
|
|
|
|
# libsecp included in libwally.
|
|
|
|
# Wildcards here are magic. See http://stackoverflow.com/questions/2973445/gnu-makefile-rule-generating-a-few-targets-from-a-single-source-file
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libsecp256k1.% $(TARGET_DIR)/libwallycore.%: $(TARGET_DIR)/libwally-core-build/src/secp256k1/libsecp256k1.la $(TARGET_DIR)/libwally-core-build/src/libwallycore.la
|
|
|
|
$(MAKE) -C $(TARGET_DIR)/libwally-core-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec
|
2017-08-28 18:11:01 +02:00
|
|
|
|
2020-02-26 17:58:57 +01:00
|
|
|
# Build libwally-core.
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libwally-core-build/src/libwallycore.% $(TARGET_DIR)/libwally-core-build/src/secp256k1/libsecp256k1.%: $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS)
|
2020-11-30 01:17:08 +01:00
|
|
|
cd external/libwally-core && ./tools/autogen.sh
|
2020-01-30 00:15:32 +01:00
|
|
|
mkdir -p ${TARGET_DIR}/libwally-core-build
|
2021-01-21 11:33:37 +01:00
|
|
|
cd ${TARGET_DIR}/libwally-core-build \
|
|
|
|
&& PYTHON_VERSION=3 CFLAGS=-std=c99 ${TOP}/libwally-core/configure CC="$(CC)" \
|
|
|
|
--enable-static=yes \
|
|
|
|
$(CROSSCOMPILE_OPTS) \
|
|
|
|
--enable-module-recovery \
|
|
|
|
--enable-module-extrakeys \
|
|
|
|
--enable-module-schnorrsig \
|
|
|
|
--enable-elements \
|
|
|
|
--enable-shared=no \
|
|
|
|
--prefix=/ \
|
|
|
|
--libdir=/ \
|
|
|
|
--enable-debug \
|
|
|
|
&& $(MAKE)
|
2017-08-28 18:11:01 +02:00
|
|
|
|
|
|
|
# If we tell Make that the above builds both, it runs it twice in
|
|
|
|
# parallel. So we lie :(
|
|
|
|
external/jsmn/jsmn.c: external/jsmn/jsmn.h
|
|
|
|
[ -f $@ ]
|
|
|
|
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/jsmn-build/jsmn.o: external/jsmn/jsmn.c Makefile
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(COMPILE.c) -DJSMN_STRICT=1 -o $@ $<
|
2017-08-28 18:11:01 +02:00
|
|
|
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libjsmn.a: $(TARGET_DIR)/jsmn-build/jsmn.o
|
2017-08-28 18:11:01 +02:00
|
|
|
$(AR) rc $@ $<
|
|
|
|
|
2017-09-12 06:56:26 +02:00
|
|
|
# Need separate build dir: changes inside submodule make git think it's dirty.
|
2020-01-30 00:15:32 +01:00
|
|
|
$(TARGET_DIR)/libbacktrace.a: external/libbacktrace/backtrace.h
|
2020-08-31 03:22:56 +02:00
|
|
|
mkdir -p $(TARGET_DIR)/libbacktrace-build
|
2020-01-30 00:15:32 +01:00
|
|
|
cd $(TARGET_DIR)/libbacktrace-build && $(TOP)/libbacktrace/configure CC="$(CC)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE)
|
|
|
|
$(MAKE) -C $(TARGET_DIR)/libbacktrace-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec
|
2017-09-12 06:56:26 +02:00
|
|
|
|
2017-08-28 18:11:01 +02:00
|
|
|
distclean: external-distclean
|
|
|
|
clean: external-clean
|
|
|
|
|
|
|
|
external-clean:
|
2020-01-30 00:15:32 +01:00
|
|
|
$(RM) $(EXTERNAL_LIBS) $(TARGET_DIR)/*.la $(TARGET_DIR)/*.o
|
2020-05-13 05:18:09 +02:00
|
|
|
$(RM) $(TARGET_DIR)/jsmn-build/jsmn.o
|
2020-01-30 00:15:32 +01:00
|
|
|
if [ -f ${TARGET_DIR}/libsodium-build/Makefile ]; then make -C ${TARGET_DIR}/libsodium-build clean; fi
|
|
|
|
if [ -f ${TARGET_DIR}/libwally-core-build/Makefile ]; then make -C ${TARGET_DIR}/libwally-core-build clean; fi
|
|
|
|
if [ -f ${TARGET_DIR}/libwally-core-build/src/Makefile ]; then make -C ${TARGET_DIR}/libwally-core-build/src clean; fi
|
2020-10-25 17:08:07 +01:00
|
|
|
if [ -f ${TARGET_DIR}/libbacktrace-build/Makefile ]; then make -C ${TARGET_DIR}/libbacktrace-build clean; fi
|
2017-08-28 18:11:01 +02:00
|
|
|
|
|
|
|
external-distclean:
|
|
|
|
make -C external/libsodium distclean || true
|
2020-05-13 05:18:09 +02:00
|
|
|
$(RM) -rf ${TARGET_DIR}/libbacktrace-build ${TARGET_DIR}/libsodium-build ${TARGET_DIR}/libwally-core-build ${TARGET_DIR}/jsmn-build
|
2017-11-23 04:03:07 +01:00
|
|
|
$(RM) -r `git status --ignored --porcelain external/libwally-core | grep '^!! ' | cut -c3-`
|