2021-09-10 15:29:10 +00:00
|
|
|
# Copyright (c) 2021 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.
|
|
|
|
|
|
|
|
SHELL := bash # the shell used internally by Make
|
|
|
|
|
|
|
|
# used inside the included makefiles
|
|
|
|
BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
|
|
|
|
|
|
|
# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/variables.mk
|
|
|
|
|
|
|
|
.PHONY: \
|
|
|
|
all \
|
|
|
|
bottles \
|
|
|
|
clean \
|
|
|
|
deps \
|
|
|
|
libstatuslib \
|
|
|
|
status-go \
|
2021-10-04 21:21:07 +00:00
|
|
|
keycard-go \
|
2021-09-10 15:29:10 +00:00
|
|
|
update \
|
|
|
|
build_ctest \
|
2021-09-28 21:00:43 +00:00
|
|
|
ctest \
|
|
|
|
test
|
2021-09-10 15:29:10 +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.
|
|
|
|
|
|
|
|
all: libstatuslib
|
|
|
|
|
|
|
|
# must be included after the default target
|
|
|
|
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
|
|
|
|
|
|
|
|
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
|
|
|
|
detected_OS := Windows
|
|
|
|
else
|
|
|
|
detected_OS := $(strip $(shell uname))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(detected_OS),Darwin)
|
|
|
|
CFLAGS := -mmacosx-version-min=10.14
|
|
|
|
export CFLAGS
|
|
|
|
CGO_CFLAGS := -mmacosx-version-min=10.14
|
|
|
|
export CGO_CFLAGS
|
|
|
|
LIBSTATUS_EXT := dylib
|
2021-10-04 21:21:07 +00:00
|
|
|
LIBKEYCARD_EXT := dylib
|
2021-09-10 15:29:10 +00:00
|
|
|
MACOSX_DEPLOYMENT_TARGET := 10.14
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
LIBSTATUS_EXT := dll
|
2021-10-04 21:21:07 +00:00
|
|
|
LIBKEYCARD_EXT := dll
|
2021-09-10 15:29:10 +00:00
|
|
|
else
|
|
|
|
LIBSTATUS_EXT := so
|
2021-10-04 21:21:07 +00:00
|
|
|
LIBKEYCARD_EXT := so
|
2021-09-10 15:29:10 +00:00
|
|
|
endif
|
|
|
|
|
2021-09-29 12:52:30 +00:00
|
|
|
# ifeq ($(detected_OS),Darwin)
|
|
|
|
# BOTTLES_DIR := $(shell pwd)/bottles
|
|
|
|
# BOTTLES := $(addprefix $(BOTTLES_DIR)/,openssl@1.1 pcre)
|
|
|
|
#
|
|
|
|
# $(BOTTLES): | $(BOTTLES_DIR)
|
|
|
|
# echo -e "\e[92mFetching:\e[39m $(notdir $@) bottle"
|
|
|
|
# ./scripts/fetch-brew-bottle.sh $(notdir $@)
|
|
|
|
#
|
|
|
|
# $(BOTTLES_DIR):
|
|
|
|
# echo -e "\e[92mUpdating:\e[39m macOS Homebrew"
|
|
|
|
# if [[ $$(stat -f %u /usr/local/var/homebrew) -ne "$${UID}" ]]; then \
|
|
|
|
# echo "Missing permissions to update Homebrew formulae!" >&2; \
|
|
|
|
# else \
|
|
|
|
# brew update >/dev/null; \
|
|
|
|
# mkdir -p $(BOTTLES_DIR); \
|
|
|
|
# fi
|
|
|
|
#
|
|
|
|
# bottles: $(BOTTLES)
|
|
|
|
# endif
|
2021-09-10 15:29:10 +00:00
|
|
|
|
|
|
|
deps: | deps-common bottles
|
|
|
|
|
|
|
|
update: | update-common
|
|
|
|
|
|
|
|
RELEASE ?= false
|
|
|
|
ifeq ($(RELEASE),false)
|
|
|
|
# We need `-d:debug` to get Nim's default stack traces
|
|
|
|
NIM_PARAMS += -d:debug
|
|
|
|
# Enable debugging symbols in DOtherSide, in case we need GDB backtraces
|
|
|
|
CFLAGS += -g
|
|
|
|
CXXFLAGS += -g
|
|
|
|
else
|
|
|
|
# Additional optimization flags for release builds are not included at present;
|
|
|
|
# adding them will involve refactoring config.nims in the root of this repo
|
|
|
|
NIM_PARAMS += -d:release
|
|
|
|
endif
|
|
|
|
|
|
|
|
NIM_PARAMS += --outdir:./build
|
|
|
|
|
|
|
|
STATUSGO := vendor/status-go/build/bin/libstatus.$(LIBSTATUS_EXT)
|
|
|
|
STATUSGO_LIBDIR := $(shell pwd)/$(shell dirname "$(STATUSGO)")
|
2021-09-28 21:00:43 +00:00
|
|
|
export STATUSGO
|
2021-09-10 15:29:10 +00:00
|
|
|
export STATUSGO_LIBDIR
|
2021-09-28 21:00:43 +00:00
|
|
|
export LIBSTATUS_EXT
|
2021-09-10 15:29:10 +00:00
|
|
|
|
2021-10-04 21:21:07 +00:00
|
|
|
KEYCARDGO := vendor/nim-keycard-go/go/keycard/build/libkeycard/libkeycard.$(LIBKEYCARD_EXT)
|
|
|
|
KEYCARDGO_LIBDIR := $(shell pwd)/$(shell dirname "$(KEYCARDGO)")
|
|
|
|
export KEYCARDGO
|
|
|
|
export KEYCARDGO_LIBDIR
|
|
|
|
export LIBKEYCARD_EXT
|
|
|
|
|
2021-09-10 15:29:10 +00:00
|
|
|
status-go: $(STATUSGO)
|
|
|
|
$(STATUSGO): | deps
|
|
|
|
echo -e $(BUILD_MSG) "status-go"
|
|
|
|
+ cd vendor/status-go && \
|
|
|
|
$(MAKE) statusgo-shared-library $(HANDLE_OUTPUT)
|
|
|
|
|
2021-10-04 21:21:07 +00:00
|
|
|
keycard-go: $(KEYCARDGO)
|
|
|
|
$(KEYCARDGO): | deps
|
|
|
|
echo -e $(BUILD_MSG) "keycard-go"
|
|
|
|
+ cd vendor/nim-keycard-go && \
|
|
|
|
$(MAKE) build-keycard-go $(HANDLE_OUTPUT)
|
|
|
|
|
2021-09-14 21:46:13 +00:00
|
|
|
LIBSTATUSLIB := build/$@.$(LIBSTATUS_EXT).0
|
2021-10-04 21:21:07 +00:00
|
|
|
libstatuslib: | $(STATUSGO) $(KEYCARDGO)
|
2021-09-10 15:29:10 +00:00
|
|
|
echo -e $(BUILD_MSG) "$@" && \
|
2021-10-04 21:21:07 +00:00
|
|
|
$(ENV_SCRIPT) nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" --passL:"-L$(KEYCARDGO_LIBDIR)" --passL="-lkeycard" -o:build/$@.$(LIBSTATUS_EXT).0 -d:ssl --app:lib --noMain --header --nimcache:nimcache/libstatuslib statuslib.nim && \
|
2021-09-10 15:29:10 +00:00
|
|
|
rm -f build/$@.$(LIBSTATUS_EXT) && \
|
|
|
|
ln -s $@.$(LIBSTATUS_EXT).0 build/$@.so && \
|
|
|
|
cp nimcache/libstatuslib/*.h build/. && \
|
|
|
|
[[ $$? = 0 ]]
|
|
|
|
|
|
|
|
# libraries for dynamic linking of non-Nim objects
|
2021-10-04 21:21:07 +00:00
|
|
|
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lstatuslib -lm -L"$(STATUSGO_LIBDIR)" -lstatus -L"$(KEYCARDGO_LIBDIR)" -lkeycard
|
2021-09-14 21:46:13 +00:00
|
|
|
build_ctest: | $(LIBSTATUSLIB) build deps
|
2021-09-10 15:29:10 +00:00
|
|
|
echo -e $(BUILD_MSG) "build/ctest" && \
|
|
|
|
$(CC) test/main.c -Wl,-rpath,'$$ORIGIN' -I./vendor/nimbus-build-system/vendor/Nim/lib $(EXTRA_LIBS_DYNAMIC) -g -o build/ctest
|
|
|
|
|
2021-09-29 12:52:30 +00:00
|
|
|
LD_LIBRARY_PATH_NIMBLE := $${LD_LIBRARY_PATH}
|
|
|
|
ifneq ($(detected_OS),Windows)
|
|
|
|
ifneq ($(detected_OS),Darwin)
|
2021-10-04 21:21:07 +00:00
|
|
|
LD_LIBRARY_PATH_NIMBLE := $(STATUSGO_LIBDIR):$(KEYCARDGO_LIBDIR):$(LD_LIBRARY_PATH_NIMBLE)
|
2021-09-29 12:52:30 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
PATH_NIMBLE := $${PATH}
|
|
|
|
ifeq ($(detected_OS),Windows)
|
2021-10-04 21:21:07 +00:00
|
|
|
PATH_NIMBLE := $(STATUSGO_LIBDIR):$(KEYCARDGO_LIBDIR):$(PATH_NIMBLE)
|
2021-09-29 12:52:30 +00:00
|
|
|
endif
|
|
|
|
|
2021-10-04 21:21:07 +00:00
|
|
|
RUN_AFTER_BUILD ?= true
|
|
|
|
|
2021-09-29 12:52:30 +00:00
|
|
|
NIMBLE_ENV = \
|
2021-10-04 21:21:07 +00:00
|
|
|
RELEASE=$(RELEASE) \
|
|
|
|
RUN_AFTER_BUILD=$(RUN_AFTER_BUILD)
|
2021-09-29 12:52:30 +00:00
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
NIMBLE_ENV += PATH="$(PATH_NIMBLE)"
|
|
|
|
PCRE_LDFLAGS := -L$(shell cygpath -m /ucrt64/lib) -lpcre
|
|
|
|
NIMBLE_ENV += PCRE_LDFLAGS="$(PCRE_LDFLAGS)"
|
|
|
|
else ifneq ($(detected_OS),Darwin)
|
|
|
|
NIMBLE_ENV += LD_LIBRARY_PATH="$(LD_LIBRARY_PATH_NIMBLE)"
|
|
|
|
endif
|
|
|
|
|
2021-09-10 15:29:10 +00:00
|
|
|
ctest: | build_ctest
|
|
|
|
echo -e "Running ctest:" && \
|
2021-10-04 21:21:07 +00:00
|
|
|
LD_LIBRARY_PATH="$(STATUSGO_LIBDIR):$(KEYCARDGO_LIBDIR)" \
|
2021-09-10 15:29:10 +00:00
|
|
|
./build/ctest
|
|
|
|
|
2021-10-04 21:21:07 +00:00
|
|
|
test: | $(STATUSGO) $(KEYCARDGO)
|
2021-09-29 12:52:30 +00:00
|
|
|
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble tests
|
|
|
|
|
2021-09-10 15:29:10 +00:00
|
|
|
clean: | clean-common
|
2021-10-04 21:21:07 +00:00
|
|
|
rm -rf bin/* node_modules bottles/* pkg/* tmp/* $(STATUSGO) $(KEYCARDGO)
|
2021-09-10 15:29:10 +00:00
|
|
|
|
|
|
|
endif # "variables.mk" was not included
|