2020-04-18 12:56:40 +00:00
|
|
|
# Copyright (c) 2018-2020 Status Research & Development GmbH. Licensed under
|
2019-01-23 12:59:26 +00:00
|
|
|
# either of:
|
|
|
|
# - Apache License, version 2.0
|
|
|
|
# - MIT license
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2020-04-18 12:56:40 +00:00
|
|
|
SHELL := bash # the shell used internally by Make
|
2019-09-10 00:48:34 +00:00
|
|
|
|
2019-08-20 22:03:15 +00:00
|
|
|
# used inside the included makefiles
|
|
|
|
BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
2019-03-26 16:39:57 +00:00
|
|
|
|
2020-04-18 12:56:40 +00:00
|
|
|
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
|
2019-08-20 22:03:15 +00:00
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-27 23:07:23 +00:00
|
|
|
# debugging tools + testing tools
|
2020-02-13 19:18:27 +00:00
|
|
|
TOOLS := \
|
2020-07-21 04:28:03 +00:00
|
|
|
test_tools_build
|
2020-02-13 19:18:27 +00:00
|
|
|
TOOLS_DIRS := \
|
2020-05-07 15:32:44 +00:00
|
|
|
tests
|
2019-02-27 23:07:23 +00:00
|
|
|
# comma-separated values for the "clean" target
|
|
|
|
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
2020-02-13 19:18:27 +00:00
|
|
|
|
|
|
|
.PHONY: \
|
|
|
|
all \
|
|
|
|
$(TOOLS) \
|
|
|
|
deps \
|
|
|
|
update \
|
|
|
|
nimbus \
|
|
|
|
test \
|
|
|
|
test-reproducibility \
|
|
|
|
clean \
|
|
|
|
libnimbus.so \
|
|
|
|
libnimbus.a \
|
|
|
|
wrappers \
|
|
|
|
wrappers-static \
|
|
|
|
libbacktrace
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2020-04-18 12:56:40 +00:00
|
|
|
ifeq ($(NIM_PARAMS),)
|
|
|
|
# "variables.mk" was not included, so we update the submodules.
|
|
|
|
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
|
|
|
|
.DEFAULT:
|
|
|
|
+@ echo -e "Git submodules not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \
|
|
|
|
$(GIT_SUBMODULE_UPDATE); \
|
|
|
|
echo
|
|
|
|
# Now that the included *.mk files appeared, and are newer than this file, Make will restart itself:
|
|
|
|
# https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles
|
|
|
|
#
|
|
|
|
# After restarting, it will execute its original goal, so we don't have to start a child Make here
|
|
|
|
# with "$(MAKE) $(MAKECMDGOALS)". Isn't hidden control flow great?
|
|
|
|
|
|
|
|
else # "variables.mk" was included. Business as usual until the end of this file.
|
|
|
|
|
2018-12-24 16:03:27 +00:00
|
|
|
# default target, because it's the first one that doesn't start with '.'
|
2020-04-18 12:56:40 +00:00
|
|
|
all: | $(TOOLS) nimbus
|
2019-08-20 22:03:15 +00:00
|
|
|
|
|
|
|
# must be included after the default target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
|
|
|
|
|
2021-04-01 07:36:13 +00:00
|
|
|
LINK_PCRE := 0
|
|
|
|
|
2021-01-19 09:02:24 +00:00
|
|
|
# default: use blst
|
|
|
|
USE_MIRACL := 0
|
|
|
|
|
|
|
|
# default: use nim native evm
|
|
|
|
ENABLE_EVMC := 0
|
|
|
|
|
2020-04-18 12:56:40 +00:00
|
|
|
# "-d:release" implies "--stacktrace:off" and it cannot be added to config.nims
|
|
|
|
ifeq ($(USE_LIBBACKTRACE), 0)
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:debug -d:disable_libbacktrace
|
|
|
|
else
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:release
|
|
|
|
endif
|
2019-08-20 22:03:15 +00:00
|
|
|
|
2021-01-19 02:24:39 +00:00
|
|
|
ifneq ($(USE_MIRACL), 0)
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:BLS_FORCE_BACKEND=miracl
|
|
|
|
endif
|
|
|
|
|
2021-01-19 09:02:24 +00:00
|
|
|
ifneq ($(ENABLE_EVMC), 0)
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:evmc_enabled
|
|
|
|
endif
|
|
|
|
|
2020-06-22 15:12:12 +00:00
|
|
|
deps: | deps-common nat-libs nimbus.nims
|
2020-04-15 22:21:58 +00:00
|
|
|
ifneq ($(USE_LIBBACKTRACE), 0)
|
|
|
|
deps: | libbacktrace
|
|
|
|
endif
|
2019-01-23 12:59:26 +00:00
|
|
|
|
2019-08-20 22:03:15 +00:00
|
|
|
#- deletes and recreates "nimbus.nims" which on Windows is a copy instead of a proper symlink
|
|
|
|
update: | update-common
|
|
|
|
rm -rf nimbus.nims && \
|
2020-04-15 22:21:58 +00:00
|
|
|
$(MAKE) nimbus.nims $(HANDLE_OUTPUT)
|
2019-03-29 17:08:39 +00:00
|
|
|
|
2019-02-27 23:07:23 +00:00
|
|
|
# builds the tools, wherever they are
|
2019-09-04 17:14:54 +00:00
|
|
|
$(TOOLS): | build deps
|
2019-03-26 16:39:57 +00:00
|
|
|
for D in $(TOOLS_DIRS); do [ -e "$${D}/$@.nim" ] && TOOL_DIR="$${D}" && break; done && \
|
2019-03-29 17:08:39 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
|
|
|
$(ENV_SCRIPT) nim c $(NIM_PARAMS) -o:build/$@ "$${TOOL_DIR}/$@.nim"
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-27 23:07:23 +00:00
|
|
|
# a phony target, because teaching `make` how to do conditional recompilation of Nim projects is too complicated
|
2019-09-04 17:14:54 +00:00
|
|
|
nimbus: | build deps
|
2019-03-29 17:08:39 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
|
|
|
$(ENV_SCRIPT) nim nimbus $(NIM_PARAMS) nimbus.nims
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-16 21:45:19 +00:00
|
|
|
# symlink
|
|
|
|
nimbus.nims:
|
|
|
|
ln -s nimbus.nimble $@
|
|
|
|
|
2020-02-09 16:31:37 +00:00
|
|
|
# nim-libbacktrace
|
|
|
|
libbacktrace:
|
2020-04-18 12:56:40 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0
|
2020-02-09 16:31:37 +00:00
|
|
|
|
2019-03-17 00:54:30 +00:00
|
|
|
# builds and runs the test suite
|
2019-09-04 17:14:54 +00:00
|
|
|
test: | build deps
|
2019-02-16 21:23:17 +00:00
|
|
|
$(ENV_SCRIPT) nim test $(NIM_PARAMS) nimbus.nims
|
|
|
|
|
|
|
|
# primitive reproducibility test
|
|
|
|
test-reproducibility:
|
|
|
|
+ [ -e build/nimbus ] || $(MAKE) V=0 nimbus; \
|
2019-02-17 16:42:04 +00:00
|
|
|
MD5SUM1=$$($(MD5SUM) build/nimbus | cut -d ' ' -f 1) && \
|
|
|
|
rm -rf nimcache/*/nimbus && \
|
|
|
|
$(MAKE) V=0 nimbus && \
|
|
|
|
MD5SUM2=$$($(MD5SUM) build/nimbus | cut -d ' ' -f 1) && \
|
2019-02-17 18:01:40 +00:00
|
|
|
[ "$$MD5SUM1" = "$$MD5SUM2" ] && echo -e "\e[92mSuccess: identical binaries.\e[39m" || \
|
|
|
|
{ echo -e "\e[91mFailure: the binary changed between builds.\e[39m"; exit 1; }
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
# usual cleaning
|
2019-08-20 22:03:15 +00:00
|
|
|
clean: | clean-common
|
|
|
|
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*_wrapper_test}
|
2020-04-15 22:21:58 +00:00
|
|
|
ifneq ($(USE_LIBBACKTRACE), 0)
|
2020-02-09 16:31:37 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT)
|
2020-04-15 22:21:58 +00:00
|
|
|
endif
|
2019-02-26 22:13:31 +00:00
|
|
|
|
2019-09-04 17:14:54 +00:00
|
|
|
libnimbus.so: | build deps
|
2019-07-31 11:54:48 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
2019-08-02 16:59:47 +00:00
|
|
|
$(ENV_SCRIPT) nim c --app:lib --noMain --nimcache:nimcache/libnimbus $(NIM_PARAMS) -o:build/$@.0 wrappers/libnimbus.nim && \
|
2019-07-31 11:54:48 +00:00
|
|
|
rm -f build/$@ && \
|
|
|
|
ln -s $@.0 build/$@
|
|
|
|
|
2020-02-09 16:31:37 +00:00
|
|
|
# libraries for dynamic linking of non-Nim objects
|
|
|
|
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lnimbus -lm
|
2020-04-15 22:21:58 +00:00
|
|
|
wrappers: | build deps libnimbus.so
|
2019-08-01 00:44:27 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/C_wrapper_example" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
$(CC) wrappers/wrapper_example.c -Wl,-rpath,'$$ORIGIN' $(EXTRA_LIBS_DYNAMIC) -g -o build/C_wrapper_example
|
2019-08-01 00:44:27 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/go_wrapper_example" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
go build -ldflags "-linkmode external -extldflags '$(EXTRA_LIBS_DYNAMIC)'" -o build/go_wrapper_example wrappers/wrapper_example.go wrappers/cfuncs.go
|
2019-09-12 16:32:07 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/go_wrapper_whisper_example" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
go build -ldflags "-linkmode external -extldflags '$(EXTRA_LIBS_DYNAMIC)'" -o build/go_wrapper_whisper_example wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
|
2019-07-31 11:54:48 +00:00
|
|
|
|
2019-09-04 17:14:54 +00:00
|
|
|
libnimbus.a: | build deps
|
2019-08-01 11:14:00 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
2019-08-02 16:59:47 +00:00
|
|
|
rm -f build/$@ && \
|
2019-11-26 17:53:04 +00:00
|
|
|
$(ENV_SCRIPT) nim c --app:staticlib --noMain --nimcache:nimcache/libnimbus_static $(NIM_PARAMS) -o:build/$@ wrappers/libnimbus.nim && \
|
|
|
|
[[ -e "$@" ]] && mv "$@" build/ # workaround for https://github.com/nim-lang/Nim/issues/12745
|
2019-08-01 11:14:00 +00:00
|
|
|
|
2020-02-09 16:31:37 +00:00
|
|
|
# These libraries are for statically linking non-Nim objects to libnimbus.a
|
|
|
|
# (where "vendor/nim-libbacktrace/libbacktrace.nim" doesn't get to set its LDFLAGS)
|
|
|
|
EXTRA_LIBS_STATIC := -L"$(CURDIR)/build" -lnimbus -L"$(CURDIR)/vendor/nim-libbacktrace/install/usr/lib" -lbacktracenim -lbacktrace -lm -ldl -lpcre
|
|
|
|
ifeq ($(shell uname), Darwin)
|
|
|
|
USE_VENDORED_LIBUNWIND := 1
|
|
|
|
endif # macOS
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
USE_VENDORED_LIBUNWIND := 1
|
|
|
|
endif # Windows
|
|
|
|
ifeq ($(USE_VENDORED_LIBUNWIND), 1)
|
|
|
|
EXTRA_LIBS_STATIC := $(EXTRA_LIBS_STATIC) -lunwind
|
|
|
|
endif # USE_VENDORED_LIBUNWIND
|
2020-04-15 22:21:58 +00:00
|
|
|
wrappers-static: | build deps libnimbus.a
|
2019-08-01 11:14:00 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/C_wrapper_example_static" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
$(CC) wrappers/wrapper_example.c -static -pthread $(EXTRA_LIBS_STATIC) -g -o build/C_wrapper_example_static
|
2019-08-01 11:14:00 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/go_wrapper_example_static" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
go build -ldflags "-linkmode external -extldflags '-static $(EXTRA_LIBS_STATIC)'" -o build/go_wrapper_example_static wrappers/wrapper_example.go wrappers/cfuncs.go
|
2019-11-26 15:09:58 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/go_wrapper_whisper_example_static" && \
|
2020-02-09 16:31:37 +00:00
|
|
|
go build -ldflags "-linkmode external -extldflags '-static $(EXTRA_LIBS_STATIC)'" -o build/go_wrapper_whisper_example_static wrappers/wrapper_whisper_example.go wrappers/cfuncs.go
|
2019-08-01 11:14:00 +00:00
|
|
|
|
2020-04-18 12:56:40 +00:00
|
|
|
endif # "variables.mk" was not included
|
|
|
|
|