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 \
|
|
|
|
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
|
|
|
|
MACOSX_DEPLOYMENT_TARGET := 10.14
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET
|
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
LIBSTATUS_EXT := dll
|
|
|
|
else
|
|
|
|
LIBSTATUS_EXT := so
|
|
|
|
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
|
|
|
|
|
|
|
status-go: $(STATUSGO)
|
|
|
|
$(STATUSGO): | deps
|
|
|
|
echo -e $(BUILD_MSG) "status-go"
|
|
|
|
+ cd vendor/status-go && \
|
|
|
|
$(MAKE) statusgo-shared-library $(HANDLE_OUTPUT)
|
|
|
|
|
2021-09-15 23:08:53 +00:00
|
|
|
ifeq ($(detected_OS), Darwin)
|
|
|
|
install_name_tool -id \
|
|
|
|
@rpath/libstatus.$(LIBSTATUS_EXT) \
|
|
|
|
$(STATUSGO_LIBDIR)/libstatus.$(LIBSTATUS_EXT)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(detectedOS),Windows)
|
|
|
|
STATUSGO_LDFLAGS := -L$(shell cygpath -m $(STATUSGO_LIBDIR)) -lstatus
|
|
|
|
else ifeq ($(detected_OS),Darwin)
|
|
|
|
STATUSGO_LDFLAGS := -L$(STATUSGO_LIBDIR) -lstatus -rpath $(STATUSGO_LIBDIR)
|
|
|
|
else
|
|
|
|
STATUSGO_LDFLAGS := -L$(STATUSGO_LIBDIR) -lstatus
|
|
|
|
endif
|
|
|
|
|
2021-09-15 18:26:46 +00:00
|
|
|
LIBSTATUSLIB := build/libstatuslib.$(LIBSTATUS_EXT).0
|
|
|
|
libstatuslib: | $(STATUSGO)
|
2021-09-10 15:29:10 +00:00
|
|
|
echo -e $(BUILD_MSG) "$@" && \
|
2021-09-15 23:08:53 +00:00
|
|
|
$(ENV_SCRIPT) nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --passL:"$(STATUSGO_LDFLAGS)" -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) && \
|
2021-09-14 21:43:45 +00:00
|
|
|
ln -s $@.$(LIBSTATUS_EXT).0 build/$@.$(LIBSTATUS_EXT) && \
|
2021-09-15 18:26:46 +00:00
|
|
|
cp nimcache/libstatuslib/statuslib.h build/statuslib.h.for-reference-only && \
|
2021-09-10 15:29:10 +00:00
|
|
|
[[ $$? = 0 ]]
|
|
|
|
|
|
|
|
# libraries for dynamic linking of non-Nim objects
|
2021-09-15 23:08:53 +00:00
|
|
|
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lstatuslib -lm $(STATUSGO_LDFLAGS)
|
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" && \
|
2021-09-15 18:26:46 +00:00
|
|
|
$(CC) test/main.c -Wl,-rpath,'$$ORIGIN' -Iinclude/ $(EXTRA_LIBS_DYNAMIC) -g -o build/ctest
|
2021-09-10 15:29:10 +00:00
|
|
|
|
2021-09-29 12:52:30 +00:00
|
|
|
LD_LIBRARY_PATH_NIMBLE := $${LD_LIBRARY_PATH}
|
|
|
|
ifneq ($(detected_OS),Windows)
|
|
|
|
ifneq ($(detected_OS),Darwin)
|
|
|
|
LD_LIBRARY_PATH_NIMBLE := $(STATUSGO_LIBDIR):$(LD_LIBRARY_PATH_NIMBLE)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
PATH_NIMBLE := $${PATH}
|
|
|
|
ifeq ($(detected_OS),Windows)
|
|
|
|
PATH_NIMBLE := $(STATUSGO_LIBDIR):$(PATH_NIMBLE)
|
|
|
|
endif
|
|
|
|
|
|
|
|
NIMBLE_ENV = \
|
|
|
|
RELEASE=$(RELEASE)
|
|
|
|
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
|
2021-09-15 23:08:53 +00:00
|
|
|
echo -e "Running ctest:"
|
|
|
|
|
|
|
|
ifeq ($(detected_OS), Darwin)
|
|
|
|
./build/ctest
|
|
|
|
else ifeq ($(detected_OS), Windows)
|
2021-09-10 15:29:10 +00:00
|
|
|
./build/ctest
|
2021-09-15 23:08:53 +00:00
|
|
|
else
|
|
|
|
LD_LIBRARY_PATH="$(STATUSGO_LIBDIR):build/" \
|
|
|
|
./build/ctest
|
|
|
|
endif
|
2021-09-10 15:29:10 +00:00
|
|
|
|
2021-09-29 12:52:30 +00:00
|
|
|
test: | $(STATUSGO)
|
|
|
|
$(NIMBLE_ENV) $(ENV_SCRIPT) nimble tests
|
|
|
|
|
2021-09-10 15:29:10 +00:00
|
|
|
clean: | clean-common
|
2021-09-15 23:08:53 +00:00
|
|
|
rm -rf bin/* node_modules bottles/* pkg/* tmp/* $(STATUSGO) build/*
|
2021-09-10 15:29:10 +00:00
|
|
|
|
|
|
|
endif # "variables.mk" was not included
|