2019-01-23 12:59:26 +00:00
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH. Licensed under
|
|
|
|
# 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.
|
|
|
|
|
2019-09-10 00:48:34 +00:00
|
|
|
SHELL := bash # the shell used internally by "make"
|
|
|
|
|
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
|
|
|
|
2019-08-20 22:03:15 +00:00
|
|
|
# we don't want an error here, so we can handle things later, in the build-system-checks target
|
|
|
|
-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-01-20 15:18:18 +00:00
|
|
|
TOOLS := premix persist debug dumper hunter regress tracerTestGen persistBlockTestGen
|
2020-01-16 13:30:53 +00:00
|
|
|
TOOLS_DIRS := premix tests waku
|
2019-02-27 23:07:23 +00:00
|
|
|
# comma-separated values for the "clean" target
|
|
|
|
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
2020-02-09 16:31:37 +00:00
|
|
|
# "--import" can't be added to config.nims, for some reason
|
|
|
|
# "--define:release" implies "--stacktrace:off" and it cannot be added to config.nims either
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:release --import:libbacktrace
|
2019-02-27 23:07:23 +00:00
|
|
|
|
2020-02-09 16:31:37 +00:00
|
|
|
.PHONY: all $(TOOLS) build-system-checks deps update nimbus test test-reproducibility clean libnimbus.so libnimbus.a wrappers wrappers-static libbacktrace
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
# default target, because it's the first one that doesn't start with '.'
|
2019-08-20 22:03:15 +00:00
|
|
|
all: build-system-checks $(TOOLS) nimbus
|
|
|
|
|
|
|
|
# must be included after the default target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
|
|
|
|
|
|
|
|
GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
|
|
|
|
build-system-checks:
|
|
|
|
@[[ -e "$(BUILD_SYSTEM_DIR)/makefiles" ]] || { \
|
|
|
|
echo -e "'$(BUILD_SYSTEM_DIR)/makefiles' not found. Running '$(GIT_SUBMODULE_UPDATE)'.\n"; \
|
|
|
|
$(GIT_SUBMODULE_UPDATE); \
|
|
|
|
echo -e "\nYou can now run '$(MAKE)' again."; \
|
|
|
|
exit 1; \
|
|
|
|
}
|
|
|
|
|
2020-02-09 16:31:37 +00:00
|
|
|
deps: | deps-common nimbus.nims libbacktrace
|
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 && \
|
|
|
|
$(MAKE) nimbus.nims
|
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:
|
|
|
|
+ $(MAKE) -C vendor/nim-libbacktrace
|
|
|
|
|
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-02-09 16:31:37 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT)
|
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
|
2019-09-04 17:14:54 +00:00
|
|
|
wrappers: | build deps libnimbus.so go-checks
|
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
|
2019-09-04 17:14:54 +00:00
|
|
|
wrappers-static: | build deps libnimbus.a go-checks
|
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
|
|
|
|
2019-12-12 18:40:34 +00:00
|
|
|
wakunode: | build deps
|
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
|
|
|
$(ENV_SCRIPT) nim wakunode $(NIM_PARAMS) nimbus.nims
|
2020-01-14 22:35:47 +00:00
|
|
|
|
|
|
|
wakusim: | build deps wakunode
|
|
|
|
echo -e $(BUILD_MSG) "build/$@" && \
|
2020-01-17 16:52:34 +00:00
|
|
|
$(ENV_SCRIPT) nim wakusim $(NIM_PARAMS) nimbus.nims
|