2020-06-22 14:44:45 +00:00
# Copyright (c) 2018-2020 Status Research & Development GmbH. Licensed under
2019-08-20 21:14:45 +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-06-22 14:44:45 +00:00
.PHONY : \
sanity-checks \
2020-12-02 21:35:05 +00:00
warn-update \
warn-jobs \
2020-06-22 14:44:45 +00:00
deps-common \
build-nim \
update-common \
update-remote \
nat-libs \
libminiupnpc.a \
libnatpmp.a \
2020-10-06 22:31:30 +00:00
clean-cross \
2020-06-22 14:44:45 +00:00
clean-common \
mrproper \
github-ssh \
status \
ntags \
ctags \
show-deps \
fetch-dlls
2019-08-20 21:14:45 +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 :
# dir
build :
2020-05-22 13:31:19 +00:00
mkdir -p $@
2019-08-20 21:14:45 +00:00
sanity-checks :
which $( CC) & >/dev/null || { echo " C compiler ( $( CC) ) not installed. Aborting. " ; exit 1; }
2020-12-02 21:35:05 +00:00
#- check if "make update" was executed
warn-update :
if [ [ -e $( UPDATE_TIMESTAMP) ] ] ; then \
if [ [ $$ ( cat $( UPDATE_TIMESTAMP) ) -ne $$ ( $( GET_CURRENT_COMMIT_TIMESTAMP) ) ] ] ; then \
2021-01-29 12:16:23 +00:00
echo -e " \nWarning: to ensure you are building in a supported repo state, please always run \" $$ (basename " $( MAKE) ") update\" after \"git pull\"\n(it looks like you've forgotten to do this).\nThis also applies whenever you switch to a new branch or commit, e.g.: whenever you run \"git checkout ...\".\n" ; \
2020-12-02 21:35:05 +00:00
fi ; \
fi
#- check if we're enabling multiple jobs - https://stackoverflow.com/a/48865939
warn-jobs :
+ if [ [ ! " ${ MAKEFLAGS } " = ~ --jobserver[ ^= ] += ] ] ; then \
NPROC = $$ ( $( NPROC_CMD) ) ; \
if [ [ $$ { NPROC} -gt 1 ] ] ; then \
echo -e " \nTip of the day: this will probably build faster if you use \" $$ (basename " $( MAKE) " ) -j $$ {NPROC} ...\".\n " ; \
fi ; \
fi
deps-common : | sanity -checks warn -update warn -jobs $( NIMBLE_DIR )
2020-04-15 16:25:36 +00:00
# - don't build our Nim target if it's not going to be used
i f e q ( $( USE_SYSTEM_NIM ) , 0 )
deps-common : $( NIM_BINARY )
e n d i f
2019-08-20 21:14:45 +00:00
#- conditionally re-builds the Nim compiler (not usually needed, because `make update` calls this rule; delete $(NIM_BINARY) to force it)
#- allows parallel building with the '+' prefix
#- 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)
#- 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
#- macOS is also a special case, with its "ln" not supporting "-r"
2020-11-22 16:09:28 +00:00
#- the AppVeyor 32-bit build is done on a 64-bit image, so we need to override the architecture detection with ARCH_OVERRIDE
2019-08-20 21:14:45 +00:00
build-nim : | sanity -checks
+ NIM_BUILD_MSG = " $( BUILD_MSG) Nim compiler " \
V = $( V) \
CC = $( CC) \
2020-09-03 12:01:32 +00:00
MAKE = " $( MAKE) " \
2019-08-20 21:14:45 +00:00
ARCH_OVERRIDE = $( ARCH_OVERRIDE) \
2020-12-26 15:04:58 +00:00
QUICK_AND_DIRTY_COMPILER = $( QUICK_AND_DIRTY_COMPILER) \
2020-01-30 00:09:52 +00:00
" $( CURDIR) / $( BUILD_SYSTEM_DIR) /scripts/build_nim.sh " " $( NIM_DIR) " ../Nim-csources ../nimble " $( CI_CACHE) "
2019-08-20 21:14:45 +00:00
2020-05-20 19:02:05 +00:00
#- for each submodule, delete checked out files (that might prevent a fresh checkout); skip dotfiles
2019-09-07 20:03:48 +00:00
#- in case of submodule URL changes, propagates that change in the parent repo's .git directory
2019-11-22 14:53:20 +00:00
#- initialises and updates the Git submodules
2020-05-20 18:00:17 +00:00
#- hard-resets the working copies of submodules
2020-09-20 13:13:10 +00:00
#- deletes "nimcache" directories
2020-12-02 21:35:05 +00:00
#- updates ".update.timestamp"
2020-05-15 12:25:17 +00:00
#- deletes the ".nimble" dir and executes the "deps" target
2019-08-20 21:14:45 +00:00
#- allows parallel building with the '+' prefix
#- rebuilds the Nim compiler if the corresponding submodule is updated
2020-04-15 16:25:36 +00:00
update-common : | sanity -checks
2020-05-20 19:02:05 +00:00
git submodule foreach --quiet 'git ls-files --exclude-standard --recurse-submodules -z -- ":!:.*" | xargs -0 rm -rf'
2019-11-27 18:23:10 +00:00
git submodule update --init --recursive || true
2019-11-18 08:16:20 +00:00
# changing URLs in a submodule's submodule means we have to sync and update twice
git submodule sync --quiet --recursive
2019-11-22 14:53:20 +00:00
git submodule update --init --recursive
2020-05-20 18:00:17 +00:00
git submodule foreach --quiet --recursive 'git reset --quiet --hard'
2020-09-20 13:13:10 +00:00
find . -type d -name nimcache -print0 | xargs -0 rm -rf
2020-12-02 21:35:05 +00:00
$( GET_CURRENT_COMMIT_TIMESTAMP) > $( UPDATE_TIMESTAMP)
2019-08-20 21:14:45 +00:00
rm -rf $( NIMBLE_DIR)
2020-09-03 12:01:32 +00:00
+ " $( MAKE) " --no-print-directory deps
2020-04-15 17:19:35 +00:00
i f e q ( $( USE_SYSTEM_NIM ) , 0 )
2020-09-03 12:01:32 +00:00
+ " $( MAKE) " --no-print-directory build-nim
2020-04-15 17:19:35 +00:00
e n d i f
2019-08-20 21:14:45 +00:00
2020-04-15 16:25:36 +00:00
#- rebuilds the Nim compiler if the corresponding submodule is updated
$(NIM_BINARY) : | sanity -checks
2020-09-03 12:01:32 +00:00
+ " $( MAKE) " --no-print-directory build-nim
2020-04-15 16:25:36 +00:00
2019-08-20 22:17:02 +00:00
# don't use this target, or you risk updating dependency repos that are not ready to be used in Nimbus
update-remote :
git submodule update --remote
2019-08-20 21:14:45 +00:00
nat-libs : | libminiupnpc .a libnatpmp .a
2019-09-04 17:13:28 +00:00
libminiupnpc.a : | sanity -checks
2019-08-20 21:14:45 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T )
+ [ -e vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/$@ ] || \
2020-10-06 23:00:57 +00:00
" $( MAKE) " -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc -f Makefile.mingw CC = gcc $@ $( HANDLE_OUTPUT)
2019-08-20 21:14:45 +00:00
e l s e
2020-09-03 12:01:32 +00:00
+ " $( MAKE) " -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc $@ $( HANDLE_OUTPUT)
2019-08-20 21:14:45 +00:00
e n d i f
2019-09-04 17:13:28 +00:00
libnatpmp.a : | sanity -checks
2019-08-20 21:14:45 +00:00
i f e q ( $( OS ) , W i n d o w s _ N T )
2020-10-06 22:31:30 +00:00
+ " $( MAKE) " -C vendor/nim-nat-traversal/vendor/libnatpmp-upstream CC = gcc CFLAGS = " -Wall -Os -DWIN32 -DNATPMP_STATICLIB -DENABLE_STRNATPMPERR -DNATPMP_MAX_RETRIES=4 $( CFLAGS) " $@ $( HANDLE_OUTPUT)
2019-08-20 21:14:45 +00:00
e l s e
2020-10-06 22:31:30 +00:00
+ " $( MAKE) " CFLAGS = " -Wall -Os -DENABLE_STRNATPMPERR -DNATPMP_MAX_RETRIES=4 $( CFLAGS) " -C vendor/nim-nat-traversal/vendor/libnatpmp-upstream $@ $( HANDLE_OUTPUT)
2019-08-20 21:14:45 +00:00
e n d i f
#- depends on Git submodules being initialised
#- 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)
2020-04-15 16:25:36 +00:00
$(NIMBLE_DIR) :
2019-08-20 21:14:45 +00:00
mkdir -p $( NIMBLE_DIR) /pkgs
NIMBLE_DIR = " $( CURDIR) / $( NIMBLE_DIR) " PWD_CMD = " $( PWD) " \
2020-09-03 20:26:40 +00:00
git submodule foreach --recursive --quiet '$(CURDIR)/$(BUILD_SYSTEM_DIR)/scripts/create_nimble_link.sh "$$sm_path"'
2019-08-20 21:14:45 +00:00
2020-10-06 22:31:30 +00:00
clean-cross :
2020-09-03 12:01:32 +00:00
+ [ [ -e vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc ] ] && " $( MAKE) " -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc clean $( HANDLE_OUTPUT) || true
2020-10-06 22:31:30 +00:00
+ [ [ -e vendor/nim-nat-traversal/vendor/libnatpmp-upstream ] ] && " $( MAKE) " -C vendor/nim-nat-traversal/vendor/libnatpmp-upstream clean $( HANDLE_OUTPUT) || true
clean-common : clean -cross
rm -rf build/{ *.exe,*.so,*.so.0} $( NIMBLE_DIR) $( NIM_BINARY) $( NIM_DIR) /bin/timestamp $( NIM_DIR) /nimcache nimcache
2019-08-20 21:14:45 +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
# for when you want to use SSH keys with GitHub
github-ssh :
git config url."git@github.com:" .insteadOf "https://github.com/"
git submodule foreach --recursive 'git config url."git@github.com:".insteadOf "https://github.com/"'
# runs `git status` in all Git repos
status : | $( REPOS )
$( eval CMD := $( GIT_STATUS) )
$( RUN_CMD_IN_ALL_REPOS)
# https://bitbucket.org/nimcontrib/ntags/ - currently fails with "out of memory"
ntags :
ntags -R .
#- 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= '/func\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 \
--exclude= $( REPOS_DIR) /nim-bncurve/tests/tvectors.nim \
.
2020-07-16 19:02:06 +00:00
# list all Git submodule URLs and commit hashes, including the nested ones
2020-05-20 16:42:30 +00:00
show-deps :
2020-07-16 19:02:06 +00:00
{ " $( CURDIR) / $( BUILD_SYSTEM_DIR) /scripts/git_show_deps.sh " ; \
git submodule foreach --quiet --recursive " $( CURDIR) / $( BUILD_SYSTEM_DIR) /scripts/git_show_deps.sh " ; } \
| sort -u
2020-05-20 16:42:30 +00:00
2019-08-20 21:14:45 +00:00
############################
# Windows-specific section #
############################
i f e q ( $( OS ) , W i n d o w s _ N T )
# no tabs allowed for indentation here
2020-11-22 16:09:28 +00:00
# the AppVeyor 32-bit build is done on a 64-bit image, so we need to override the architecture detection
2019-08-20 21:14:45 +00:00
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)
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-08-20 23:33:01 +00:00
fetch-dlls : | build
2019-08-20 21:14:45 +00:00
cd build && \
$( CURL) $( ROCKSDB_URL) && \
$( CURL) https://nim-lang.org/download/dlls.zip && \
$( UNZIP) $( ROCKSDB_ARCHIVE) && \
cp -a $( ROCKSDB_DIR) /*.dll . && \
2019-08-20 21:47:27 +00:00
$( UNZIP) dlls.zip
2019-08-20 21:14:45 +00:00
e n d i f