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-03-26 16:39:57 +00:00
|
|
|
# common parts
|
|
|
|
include common.mk
|
|
|
|
|
2018-12-24 16:03:27 +00:00
|
|
|
GIT_CLONE := git clone --quiet --recurse-submodules
|
|
|
|
GIT_PULL := git pull --recurse-submodules
|
|
|
|
GIT_STATUS := git status
|
|
|
|
#- the Nimble dir can't be "[...]/vendor", or Nimble will start looking for
|
|
|
|
# version numbers in repo dirs (because those would be in its subdirectories)
|
|
|
|
#- duplicated in "env.sh" for the env var with the same name
|
|
|
|
NIMBLE_DIR := vendor/.nimble
|
2019-01-09 16:13:36 +00:00
|
|
|
REPOS_DIR := vendor
|
2019-02-12 15:06:00 +00:00
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
PWD := pwd -W
|
|
|
|
else
|
|
|
|
PWD := pwd
|
|
|
|
endif
|
2018-12-24 16:03:27 +00:00
|
|
|
# we want a "recursively expanded" (delayed interpolation) variable here, so we can set CMD in rule recipes
|
2019-02-12 15:06:00 +00:00
|
|
|
RUN_CMD_IN_ALL_REPOS = git submodule foreach --recursive --quiet 'echo -e "\n\e[32m$$name:\e[39m"; $(CMD)'; echo -e "\n\e[32m$$($(PWD)):\e[39m"; $(CMD)
|
2018-12-24 16:03:27 +00:00
|
|
|
# absolute path, since it will be run at various subdirectory depths
|
|
|
|
ENV_SCRIPT := "$(CURDIR)/env.sh"
|
|
|
|
# duplicated in "env.sh" to prepend NIM_DIR/bin to PATH
|
|
|
|
NIM_DIR := vendor/Nim
|
2019-03-11 19:45:46 +00:00
|
|
|
|
2019-02-08 00:13:37 +00:00
|
|
|
#- forces a rebuild of csources, Nimble and a complete compiler rebuild, in case we're called after pulling a new Nim version
|
|
|
|
#- uses our Git submodules for csources and Nimble (Git doesn't let us place them in another submodule)
|
2019-02-12 15:06:00 +00:00
|
|
|
#- build_all.sh looks at the parent dir to decide whether to copy the resulting csources binary there,
|
|
|
|
# but this is broken when using symlinks, so build csources separately (we get parallel compiling as a bonus)
|
|
|
|
#- Windows is a special case, as usual
|
2019-02-15 23:02:48 +00:00
|
|
|
#- macOS is also a special case, with its "ln" not supporting "-r"
|
2019-02-12 15:06:00 +00:00
|
|
|
ifeq ($(OS), Windows_NT)
|
2019-02-16 05:01:05 +00:00
|
|
|
# the AppVeyor 32-build is done on a 64-bit image, so we need to override the architecture detection
|
|
|
|
ifeq ($(ARCH_OVERRIDE), x86)
|
|
|
|
UCPU := ucpu=i686
|
|
|
|
else
|
|
|
|
UCPU :=
|
|
|
|
endif
|
|
|
|
|
2019-02-12 15:06:00 +00:00
|
|
|
BUILD_CSOURCES := \
|
2019-02-17 01:53:45 +00:00
|
|
|
$(MAKE) myos=windows $(UCPU) clean $(HANDLE_OUTPUT) && \
|
|
|
|
$(MAKE) myos=windows $(UCPU) CC=gcc LD=gcc $(HANDLE_OUTPUT)
|
2019-02-16 03:52:31 +00:00
|
|
|
EXE_SUFFIX := .exe
|
2019-02-12 15:06:00 +00:00
|
|
|
else
|
|
|
|
BUILD_CSOURCES := \
|
2019-02-17 01:53:45 +00:00
|
|
|
$(MAKE) clean $(HANDLE_OUTPUT) && \
|
|
|
|
$(MAKE) LD=$(CC) $(HANDLE_OUTPUT)
|
2019-02-16 03:52:31 +00:00
|
|
|
EXE_SUFFIX :=
|
2019-02-12 15:06:00 +00:00
|
|
|
endif
|
2019-03-29 17:08:39 +00:00
|
|
|
BUILD_NIM := echo -e $(BUILD_MSG) "Nim compiler" && \
|
2019-03-29 14:27:19 +00:00
|
|
|
cd $(NIM_DIR) && \
|
2018-12-24 16:03:27 +00:00
|
|
|
rm -rf bin/nim_csources csources dist/nimble && \
|
2019-02-15 23:02:48 +00:00
|
|
|
ln -s ../Nim-csources csources && \
|
2019-02-12 15:06:00 +00:00
|
|
|
mkdir -p dist && \
|
2019-02-15 23:02:48 +00:00
|
|
|
ln -s ../../nimble dist/nimble && \
|
2019-02-12 15:06:00 +00:00
|
|
|
cd csources && \
|
|
|
|
$(BUILD_CSOURCES) && \
|
2019-02-17 15:05:36 +00:00
|
|
|
cd - >/dev/null && \
|
2019-02-12 15:06:00 +00:00
|
|
|
[ -e csources/bin ] && { \
|
|
|
|
cp -a csources/bin/nim bin/nim && \
|
|
|
|
cp -a csources/bin/nim bin/nim_csources && \
|
|
|
|
rm -rf csources/bin; \
|
|
|
|
} || { \
|
|
|
|
cp -a bin/nim bin/nim_csources; \
|
|
|
|
} && \
|
2019-04-12 13:33:12 +00:00
|
|
|
sh build_all.sh $(HANDLE_OUTPUT)
|
2019-02-16 03:52:31 +00:00
|
|
|
NIM_BINARY := $(NIM_DIR)/bin/nim$(EXE_SUFFIX)
|
2019-02-17 00:58:32 +00:00
|
|
|
# md5sum - macOS is a special case
|
|
|
|
ifeq ($(shell uname), Darwin)
|
|
|
|
MD5SUM := md5 -r
|
|
|
|
else
|
|
|
|
MD5SUM := md5sum
|
|
|
|
endif
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-27 23:07:23 +00:00
|
|
|
# debugging tools + testing tools
|
|
|
|
TOOLS := premix persist debug dumper hunter regress tracerTestGen persistBlockTestGen
|
2019-03-26 16:39:57 +00:00
|
|
|
TOOLS_DIRS := premix tests
|
2019-02-27 23:07:23 +00:00
|
|
|
# comma-separated values for the "clean" target
|
|
|
|
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
|
|
|
|
2019-04-17 01:56:28 +00:00
|
|
|
.PHONY: all $(TOOLS) deps github-ssh build-nim update status ntags ctags nimbus testsuite test clean mrproper fetch-dlls test-libp2p-daemon nat-libs libminiupnpc.a libnatpmp.a
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
# default target, because it's the first one that doesn't start with '.'
|
2019-02-27 23:07:23 +00:00
|
|
|
all: $(TOOLS) nimbus
|
2019-01-23 12:59:26 +00:00
|
|
|
|
2019-03-29 17:08:39 +00:00
|
|
|
#- when the special ".SILENT" target is present, all recipes are silenced as if they all had a "@" prefix
|
|
|
|
#- by setting SILENT_TARGET_PREFIX to a non-empty value, the name of this target becomes meaningless to `make`
|
|
|
|
#- idea stolen from http://make.mad-scientist.net/managing-recipe-echoing/
|
|
|
|
$(SILENT_TARGET_PREFIX).SILENT:
|
|
|
|
|
2019-02-27 23:07:23 +00:00
|
|
|
# builds the tools, wherever they are
|
2019-04-17 02:19:56 +00:00
|
|
|
$(TOOLS): | build deps nat-libs
|
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-04-17 01:56:28 +00:00
|
|
|
nimbus: | build deps nat-libs
|
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
|
|
|
|
|
|
|
# dir
|
|
|
|
build:
|
|
|
|
mkdir $@
|
|
|
|
|
2019-02-08 00:45:26 +00:00
|
|
|
#- runs only the first time and after `make update`, so have "normal"
|
|
|
|
# (timestamp-checked) prerequisites here
|
2019-02-16 03:52:31 +00:00
|
|
|
#- $(NIM_BINARY) is both a proxy for submodules having been initialised
|
2019-02-08 00:45:26 +00:00
|
|
|
# and a check for the actual compiler build
|
2019-02-16 21:45:19 +00:00
|
|
|
deps: $(NIM_BINARY) $(NIMBLE_DIR) nimbus.nims
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-04-17 01:56:28 +00:00
|
|
|
nat-libs: | libminiupnpc.a libnatpmp.a
|
|
|
|
|
|
|
|
libminiupnpc.a: | deps
|
2019-04-17 10:26:40 +00:00
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
+ [ -e vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/$@ ] || \
|
|
|
|
$(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc -f Makefile.mingw CC=gcc init $@ $(HANDLE_OUTPUT)
|
|
|
|
else
|
2019-04-17 01:56:28 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc $@ $(HANDLE_OUTPUT)
|
2019-04-17 10:26:40 +00:00
|
|
|
endif
|
2019-04-17 01:56:28 +00:00
|
|
|
|
|
|
|
libnatpmp.a: | deps
|
2019-04-17 10:26:40 +00:00
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp CC=gcc CFLAGS="-Wall -Os -DWIN32 -DNATPMP_STATICLIB -DENABLE_STRNATPMPERR" $@ $(HANDLE_OUTPUT)
|
|
|
|
else
|
2019-04-17 01:56:28 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp $@ $(HANDLE_OUTPUT)
|
2019-04-17 10:26:40 +00:00
|
|
|
endif
|
2019-04-17 01:56:28 +00:00
|
|
|
|
2019-02-16 03:52:31 +00:00
|
|
|
#- depends on Git submodules being initialised
|
2019-02-08 00:45:26 +00:00
|
|
|
#- fakes a Nimble package repository with the minimum info needed by the Nim compiler
|
|
|
|
# for runtime path (i.e.: the second line in $(NIMBLE_DIR)/pkgs/*/*.nimble-link)
|
2019-02-16 03:52:31 +00:00
|
|
|
$(NIMBLE_DIR): | $(NIM_BINARY)
|
2019-02-05 15:06:29 +00:00
|
|
|
mkdir -p $(NIMBLE_DIR)/pkgs
|
|
|
|
git submodule foreach --quiet '\
|
|
|
|
[ `ls -1 *.nimble 2>/dev/null | wc -l ` -gt 0 ] && { \
|
|
|
|
mkdir -p $$toplevel/$(NIMBLE_DIR)/pkgs/$${sm_path#*/}-#head;\
|
2019-02-12 15:06:00 +00:00
|
|
|
echo -e "$$($(PWD))\n$$($(PWD))" > $$toplevel/$(NIMBLE_DIR)/pkgs/$${sm_path#*/}-#head/$${sm_path#*/}.nimble-link;\
|
2019-02-08 00:13:37 +00:00
|
|
|
} || true'
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-16 21:45:19 +00:00
|
|
|
# symlink
|
|
|
|
nimbus.nims:
|
|
|
|
ln -s nimbus.nimble $@
|
|
|
|
|
2019-03-17 00:54:30 +00:00
|
|
|
# builds and runs the test suite
|
2019-04-17 02:19:56 +00:00
|
|
|
test: | build deps nat-libs
|
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
|
|
|
|
clean:
|
2019-03-28 15:32:03 +00:00
|
|
|
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*.exe} vendor/go/bin \
|
2019-02-17 15:05:36 +00:00
|
|
|
$(NIMBLE_DIR) $(NIM_BINARY) $(NIM_DIR)/nimcache nimcache
|
2019-04-17 01:56:28 +00:00
|
|
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc clean $(HANDLE_OUTPUT)
|
|
|
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp clean $(HANDLE_OUTPUT)
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
# dangerous cleaning, because you may have not-yet-pushed branches and commits in those vendor repos you're about to delete
|
|
|
|
mrproper: clean
|
|
|
|
rm -rf vendor
|
|
|
|
|
2019-02-08 00:45:26 +00:00
|
|
|
# for when you want to use SSH keys with GitHub
|
2018-12-24 16:03:27 +00:00
|
|
|
github-ssh:
|
2019-02-21 22:46:28 +00:00
|
|
|
git config url."git@github.com:".insteadOf "https://github.com/"
|
|
|
|
git submodule foreach --recursive 'git config url."git@github.com:".insteadOf "https://github.com/"'
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
#- re-builds the Nim compiler (not usually needed, because `make update` does it when necessary)
|
2019-02-12 15:06:00 +00:00
|
|
|
#- allows parallel building with the '+' prefix
|
2019-02-05 15:06:29 +00:00
|
|
|
build-nim: | deps
|
2019-02-12 15:06:00 +00:00
|
|
|
+ $(BUILD_NIM)
|
2018-12-24 16:03:27 +00:00
|
|
|
|
2019-02-12 15:06:00 +00:00
|
|
|
#- initialises and updates the Git submodules
|
2019-02-08 00:45:26 +00:00
|
|
|
#- deletes the ".nimble" dir to force the execution of the "deps" target
|
2019-02-12 15:06:00 +00:00
|
|
|
#- allows parallel building with the '+' prefix
|
2019-04-12 12:39:37 +00:00
|
|
|
#- rebuilds the Nim compiler after the corresponding submodule is updated
|
2019-02-16 03:52:31 +00:00
|
|
|
$(NIM_BINARY) update:
|
2019-02-12 15:06:00 +00:00
|
|
|
git submodule update --init --recursive
|
2019-02-05 15:06:29 +00:00
|
|
|
rm -rf $(NIMBLE_DIR)
|
2019-04-12 12:39:37 +00:00
|
|
|
+ [[ -e $(NIM_BINARY) && $(NIM_BINARY) -nt $(NIM_DIR)/lib/system.nim ]] || { $(BUILD_NIM); }
|
2019-02-05 15:06:29 +00:00
|
|
|
|
2019-02-08 00:45:26 +00:00
|
|
|
# don't use this target, or you risk updating dependency repos that are not ready to be used in Nimbus
|
2019-02-05 15:06:29 +00:00
|
|
|
update-remote:
|
2019-02-15 17:17:26 +00:00
|
|
|
git submodule update --remote
|
2018-12-24 16:03:27 +00:00
|
|
|
|
|
|
|
# runs `git status` in all Git repos
|
|
|
|
status: | $(REPOS)
|
|
|
|
$(eval CMD := $(GIT_STATUS))
|
|
|
|
$(RUN_CMD_IN_ALL_REPOS)
|
|
|
|
|
2019-02-26 22:13:31 +00:00
|
|
|
vendor/go/bin/p2pd:
|
|
|
|
cd vendor/go/src/github.com/libp2p/go-libp2p-daemon && \
|
2019-03-07 00:11:48 +00:00
|
|
|
$(ENV_SCRIPT) go get ./... && \
|
|
|
|
$(ENV_SCRIPT) go install ./...
|
2019-02-26 22:13:31 +00:00
|
|
|
|
|
|
|
test-libp2p-daemon: | vendor/go/bin/p2pd deps
|
|
|
|
cd vendor/nim-libp2p && \
|
|
|
|
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) tests/testdaemon.nim && \
|
|
|
|
rm -f tests/testdaemon
|
|
|
|
|
|
|
|
# https://bitbucket.org/nimcontrib/ntags/ - currently fails with "out of memory"
|
|
|
|
ntags:
|
|
|
|
ntags -R .
|
|
|
|
|
2018-12-24 16:03:27 +00:00
|
|
|
#- a few files need to be excluded because they trigger an infinite loop in https://github.com/universal-ctags/ctags
|
|
|
|
#- limiting it to Nim files, because there are a lot of C files we don't care about
|
|
|
|
ctags:
|
|
|
|
ctags -R --verbose=yes \
|
|
|
|
--langdef=nim \
|
|
|
|
--langmap=nim:.nim \
|
|
|
|
--regex-nim='/(\w+)\*?\s*=\s*object/\1/c,class/' \
|
|
|
|
--regex-nim='/(\w+)\*?\s*=\s*enum/\1/e,enum/' \
|
|
|
|
--regex-nim='/(\w+)\*?\s*=\s*tuple/\1/t,tuple/' \
|
|
|
|
--regex-nim='/(\w+)\*?\s*=\s*range/\1/s,subrange/' \
|
|
|
|
--regex-nim='/(\w+)\*?\s*=\s*proc/\1/p,proctype/' \
|
|
|
|
--regex-nim='/proc\s+(\w+)/\1/f,procedure/' \
|
|
|
|
--regex-nim='/method\s+(\w+)/\1/m,method/' \
|
|
|
|
--regex-nim='/proc\s+`([^`]+)`/\1/o,operator/' \
|
|
|
|
--regex-nim='/template\s+(\w+)/\1/u,template/' \
|
|
|
|
--regex-nim='/macro\s+(\w+)/\1/v,macro/' \
|
|
|
|
--languages=nim \
|
|
|
|
--exclude=nimcache \
|
|
|
|
--exclude='*/Nim/tinyc' \
|
|
|
|
--exclude='*/Nim/tests' \
|
|
|
|
--exclude='*/Nim/csources' \
|
|
|
|
--exclude=nimbus/genesis_alloc.nim \
|
2019-01-09 16:13:36 +00:00
|
|
|
--exclude=$(REPOS_DIR)/nim-bncurve/tests/tvectors.nim \
|
2018-12-24 16:03:27 +00:00
|
|
|
.
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Windows-specific section #
|
|
|
|
############################
|
|
|
|
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
# no tabs allowed for indentation here
|
|
|
|
|
2019-02-16 05:01:05 +00:00
|
|
|
# the AppVeyor 32-build is done on a 64-bit image, so we need to override the architecture detection
|
|
|
|
ifeq ($(ARCH_OVERRIDE), x86)
|
|
|
|
ARCH := x86
|
|
|
|
else
|
|
|
|
ifeq ($(PROCESSOR_ARCHITEW6432), AMD64)
|
|
|
|
ARCH := x64
|
|
|
|
else
|
|
|
|
ifeq ($(PROCESSOR_ARCHITECTURE), AMD64)
|
|
|
|
ARCH := x64
|
|
|
|
endif
|
|
|
|
ifeq ($(PROCESSOR_ARCHITECTURE), x86)
|
|
|
|
ARCH := x86
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ARCH), x86)
|
|
|
|
ROCKSDB_DIR := x86
|
|
|
|
endif
|
|
|
|
ifeq ($(ARCH), x64)
|
2018-12-24 16:03:27 +00:00
|
|
|
ROCKSDB_DIR := x64
|
|
|
|
endif
|
|
|
|
|
|
|
|
ROCKSDB_ARCHIVE := nimbus-deps.zip
|
|
|
|
ROCKSDB_URL := https://github.com/status-im/nimbus-deps/releases/download/nimbus-deps/$(ROCKSDB_ARCHIVE)
|
|
|
|
CURL := curl -O -L
|
|
|
|
UNZIP := unzip -o
|
|
|
|
|
|
|
|
#- back to tabs
|
|
|
|
#- copied from .appveyor.yml
|
|
|
|
#- this is why we can't delete the whole "build" dir in the "clean" target
|
2019-04-12 12:12:27 +00:00
|
|
|
fetch-dlls: | build deps
|
2018-12-24 16:03:27 +00:00
|
|
|
cd build && \
|
|
|
|
$(CURL) $(ROCKSDB_URL) && \
|
2019-04-12 12:12:27 +00:00
|
|
|
$(CURL) https://nim-lang.org/download/dlls.zip && \
|
2018-12-24 16:03:27 +00:00
|
|
|
$(UNZIP) $(ROCKSDB_ARCHIVE) && \
|
2019-04-12 12:12:27 +00:00
|
|
|
cp -a $(ROCKSDB_DIR)/*.dll . && \
|
|
|
|
$(UNZIP) dlls.zip && \
|
|
|
|
mkdir -p vendor/nim-beacon-chain/build && \
|
|
|
|
cp -a *.dll vendor/nim-beacon-chain/build/
|
2018-12-24 16:03:27 +00:00
|
|
|
endif
|