lokinet/Makefile

279 lines
9.2 KiB
Makefile
Raw Normal View History

all: test
2018-05-16 16:41:20 +00:00
SIGN = gpg --sign --detach
REPO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2018-11-13 15:16:14 +00:00
prefix = $(DESTDIR)/usr/local
2018-11-03 13:19:18 +00:00
CC ?= cc
2018-06-28 15:10:25 +00:00
CXX ?= c++
2019-01-21 16:57:12 +00:00
PYTHON ?= python3
2018-12-04 16:16:43 +00:00
SETCAP ?= which setcap && setcap cap_net_admin,cap_net_bind_service=+eip
2018-10-28 14:28:13 +00:00
2018-06-06 17:02:57 +00:00
SHADOW_ROOT ?= $(HOME)/.shadow
SHADOW_BIN=$(SHADOW_ROOT)/bin/shadow
2018-06-07 17:36:17 +00:00
SHADOW_CONFIG=$(REPO)/shadow.config.xml
2019-03-07 22:53:36 +00:00
SHADOW_PLUGIN=$(BUILD_ROOT)/libshadow-plugin-lokinet-shared.so
2018-06-07 17:36:17 +00:00
SHADOW_LOG=$(REPO)/shadow.log.txt
2018-06-06 17:02:57 +00:00
2018-08-12 17:22:29 +00:00
SHADOW_SRC ?= $(HOME)/local/shadow
2019-03-07 22:53:36 +00:00
SHADOW_PARSE ?= $(PYTHON) $(SHADOW_SRC)/src/tools/parse-shadow.py - -m 0 --packet-data
SHADOW_PLOT ?= $(PYTHON) $(SHADOW_SRC)/src/tools/plot-shadow.py -d $(REPO) LokiNET -c $(SHADOW_CONFIG) -r 10000 -e '.*'
2019-03-11 13:01:43 +00:00
SHADOW_OPTS ?=
2018-07-20 04:50:28 +00:00
TESTNET_ROOT=/tmp/lokinet_testnet_tmp
TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf
TESTNET_LOG=$(TESTNET_ROOT)/testnet.log
2018-08-12 17:22:29 +00:00
TESTNET_EXE=$(REPO)/lokinet-testnet
TESTNET_CLIENTS ?= 50
TESTNET_SERVERS ?= 50
TESTNET_DEBUG ?= 0
TESTNET_IFNAME ?= lo
TESTNET_BASEPORT ?= 1900
TESTNET_IP ?= 127.0.0.1
TESTNET_NETID ?= loopback
2018-11-06 13:03:10 +00:00
ANDROID_NDK ?= $(HOME)/Android/Ndk
ANDROID_SDK ?= $(HOME)/Android/Sdk
2018-11-06 13:14:14 +00:00
ANDROID_ABI ?= armeabi-v7a
2019-04-08 14:27:55 +00:00
ANDROID_API_LEVEL ?= 24
2018-11-06 13:03:10 +00:00
2018-11-06 14:27:25 +00:00
ANDROID_DIR=$(REPO)/android
JNI_DIR=$(ANDROID_DIR)/jni
ANDROID_MK=$(JNI_DIR)/Android.mk
ANDROID_PROPS=$(ANDROID_DIR)/gradle.properties
ANDROID_LOCAL_PROPS=$(ANDROID_DIR)/local.properties
GRADLE ?= gradle
JAVA_HOME ?= /usr/lib/jvm/default-java
# jsonrpc server
2019-02-26 15:09:37 +00:00
JSONRPC ?= ON
# native avx2 code
2018-11-26 13:54:53 +00:00
AVX2 ?= OFF
# non x86 target
NON_PC_TARGET ?= OFF
# statically link
2018-11-08 12:31:50 +00:00
STATIC_LINK ?= OFF
# enable network namespace isolation
NETNS ?= OFF
# cross compile?
2018-11-21 21:52:35 +00:00
CROSS ?= OFF
# build liblokinet-shared.so
2019-02-26 15:09:37 +00:00
SHARED_LIB ?= OFF
2019-01-12 01:19:24 +00:00
# enable generating coverage
2019-01-13 01:41:25 +00:00
COVERAGE ?= OFF
COVERAGE_OUTDIR ?= "$(TMPDIR)/lokinet-coverage"
# cmake generator type
CMAKE_GEN ?= Unix Makefiles
ifdef NINJA
2019-02-08 13:12:07 +00:00
MAKE = $(NINJA)
CMAKE_GEN = Ninja
endif
2018-10-23 11:29:37 +00:00
BUILD_ROOT = $(REPO)/build
2018-10-27 18:26:08 +00:00
SCAN_BUILD ?= scan-build
2019-03-30 11:44:43 +00:00
UNAME = $(shell which uname)
ifeq ($(shell $(UNAME)),SunOS)
CONFIG_CMD = $(shell gecho -n "cd '$(BUILD_ROOT)' && " ; gecho -n "cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
ANALYZE_CONFIG_CMD = $(shell gecho -n "cd '$(BUILD_ROOT)' && " ; gecho -n "$(SCAN_BUILD) cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
COVERAGE_CONFIG_CMD = $(shell gecho -n "cd '$(BUILD_ROOT)' && " ; gecho -n "cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DWITH_COVERAGE=yes -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
else
2019-03-11 13:01:43 +00:00
CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
2019-03-11 13:01:43 +00:00
ANALYZE_CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "$(SCAN_BUILD) cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
2018-10-27 18:26:08 +00:00
2019-03-11 13:01:43 +00:00
COVERAGE_CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DUSE_LIBABYSS=$(JSONRPC) -DNON_PC_TARGET=$(NON_PC_TARGET) -DWITH_SHARED=$(SHARED_LIB) -DWITH_COVERAGE=yes -DCMAKE_EXPORT_COMPILE_COMMANDS=ON '$(REPO)'")
endif
2019-01-13 01:41:25 +00:00
2018-10-23 11:29:37 +00:00
TARGETS = $(REPO)/lokinet
SIGS = $(TARGETS:=.sig)
EXE = $(BUILD_ROOT)/lokinet
2019-02-11 00:02:20 +00:00
TEST_EXE = $(BUILD_ROOT)/test/testAll
ABYSS_EXE = $(BUILD_ROOT)/abyss-main
2018-10-23 11:29:37 +00:00
LINT_FILES = $(wildcard llarp/*.cpp)
LINT_CHECK = $(LINT_FILES:.cpp=.cpp-check)
clean:
2018-11-13 13:37:35 +00:00
rm -f $(TARGETS)
2018-10-23 11:29:37 +00:00
rm -rf $(BUILD_ROOT)
2018-06-06 17:02:57 +00:00
rm -f $(SHADOW_PLUGIN) $(SHADOW_CONFIG)
rm -f *.sig
rm -f *.a *.so
2018-05-16 15:59:24 +00:00
2018-10-23 11:29:37 +00:00
debug-configure:
mkdir -p '$(BUILD_ROOT)'
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)'
2018-05-16 15:59:24 +00:00
release-configure: clean
2018-11-03 13:19:18 +00:00
mkdir -p '$(BUILD_ROOT)'
$(CONFIG_CMD) -DSTATIC_LINK_RUNTIME=ON -DCMAKE_BUILD_TYPE=Debug -DRELEASE_MOTTO="$(shell cat motto.txt)" -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)'
debug: debug-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C $(BUILD_ROOT)
cp $(EXE) $(REPO)/lokinet
2018-05-21 14:28:15 +00:00
release-compile: release-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C $(BUILD_ROOT)
cp $(EXE) $(REPO)/lokinet
strip $(TARGETS)
$(TARGETS): release-compile
%.sig: $(TARGETS)
$(SIGN) $*
release: $(SIGS)
2018-06-06 13:17:03 +00:00
shadow-configure: clean
2018-11-08 15:15:02 +00:00
mkdir -p $(BUILD_ROOT)
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DSHADOW=ON
2018-06-06 13:17:03 +00:00
2018-06-06 17:02:57 +00:00
shadow-build: shadow-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C $(BUILD_ROOT)
2018-06-06 13:17:03 +00:00
2018-07-20 04:50:28 +00:00
shadow-run: shadow-build
$(PYTHON) $(REPO)/contrib/shadow/genconf.py $(SHADOW_CONFIG)
2019-03-11 13:01:43 +00:00
cp $(SHADOW_PLUGIN) $(REPO)/libshadow-plugin-lokinet.so
$(SHADOW_BIN) $(SHADOW_OPTS) $(SHADOW_CONFIG) | $(SHADOW_PARSE)
2018-07-20 04:50:28 +00:00
shadow-plot: shadow-run
$(SHADOW_PLOT)
shadow: shadow-plot
testnet-clean: clean
rm -rf $(TESTNET_ROOT)
testnet-configure: testnet-clean
2018-11-08 15:15:02 +00:00
mkdir -p $(BUILD_ROOT)
$(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Debug -DTESTNET=1
testnet-build: testnet-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C $(BUILD_ROOT)
2018-11-03 13:19:18 +00:00
testnet:
2018-08-12 17:22:29 +00:00
cp $(EXE) $(TESTNET_EXE)
mkdir -p $(TESTNET_ROOT)
$(PYTHON) $(REPO)/contrib/testnet/genconf.py --bin=$(TESTNET_EXE) --svc=$(TESTNET_SERVERS) --clients=$(TESTNET_CLIENTS) --dir=$(TESTNET_ROOT) --out $(TESTNET_CONF) --connect=4 --ifname=$(TESTNET_IFNAME) --baseport=$(TESTNET_BASEPORT) --ip=$(TESTNET_IP) --netid=$(TESTNET_NETID)
LLARP_DEBUG=$(TESTNET_DEBUG) supervisord -n -d $(TESTNET_ROOT) -l $(TESTNET_LOG) -c $(TESTNET_CONF)
2018-06-06 13:17:03 +00:00
2018-11-13 13:37:35 +00:00
$(TEST_EXE): debug
test: $(TEST_EXE)
2019-03-30 11:49:49 +00:00
test x$(CROSS) = xOFF && $(TEST_EXE) || test x$(CROSS) = xON
2018-06-14 14:04:42 +00:00
2018-11-06 14:27:25 +00:00
android-gradle-prepare:
rm -f $(ANDROID_PROPS)
rm -f $(ANDROID_LOCAL_PROPS)
echo "#auto generated don't modify kthnx" >> $(ANDROID_PROPS)
echo "lokinetCMake=$(REPO)/CMakeLists.txt" >> $(ANDROID_PROPS)
echo "org.gradle.parallel=true" >> $(ANDROID_PROPS)
2019-04-08 15:54:19 +00:00
echo "org.gradle.jvmargs=-Xmx1536M" >> $(ANDROID_PROPS)
2018-11-06 14:27:25 +00:00
echo "#auto generated don't modify kthnx" >> $(ANDROID_LOCAL_PROPS)
echo "sdk.dir=$(ANDROID_SDK)" >> $(ANDROID_LOCAL_PROPS)
echo "ndk.dir=$(ANDROID_NDK)" >> $(ANDROID_LOCAL_PROPS)
android-gradle: android-gradle-prepare
cd $(ANDROID_DIR) && JAVA_HOME=$(JAVA_HOME) $(GRADLE) clean assemble
2018-11-18 22:40:35 +00:00
2018-11-06 14:27:25 +00:00
android: android-gradle
cp -f $(ANDROID_DIR)/build/outputs/apk/*.apk $(REPO)
2018-11-06 14:06:09 +00:00
windows-debug-configure: clean
mkdir -p '$(BUILD_ROOT)'
$(CONFIG_CMD) -DCMAKE_TOOLCHAIN_FILE='$(REPO)/contrib/cross/mingw.cmake' -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ASM_FLAGS='$(ASFLAGS)' -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)'
windows-debug: windows-debug-configure
$(MAKE) -C '$(BUILD_ROOT)'
cp '$(BUILD_ROOT)/lokinet.exe' '$(REPO)/lokinet.exe'
2019-03-11 13:01:43 +00:00
windows-release-configure: clean
2018-11-09 12:49:29 +00:00
mkdir -p '$(BUILD_ROOT)'
$(CONFIG_CMD) -DCMAKE_TOOLCHAIN_FILE='$(REPO)/contrib/cross/mingw.cmake' -DCMAKE_BUILD_TYPE=Release -DCMAKE_ASM_FLAGS='$(ASFLAGS)' -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)'
2018-11-09 12:49:29 +00:00
2019-03-11 13:01:43 +00:00
windows-release: windows-release-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C '$(BUILD_ROOT)'
2018-11-09 12:49:29 +00:00
cp '$(BUILD_ROOT)/lokinet.exe' '$(REPO)/lokinet.exe'
windows: windows-debug
2019-03-11 13:01:43 +00:00
abyss: debug
$(ABYSS_EXE)
2018-05-21 14:28:15 +00:00
format:
clang-format -i $$(find daemon llarp include libabyss | grep -E '\.[h,c](pp)?$$')
analyze-config: clean
2018-10-27 19:03:23 +00:00
mkdir -p '$(BUILD_ROOT)'
$(ANALYZE_CONFIG_CMD)
analyze: analyze-config
2019-02-08 13:12:07 +00:00
$(SCAN_BUILD) $(MAKE) -C $(BUILD_ROOT)
2018-10-27 18:26:08 +00:00
2019-01-13 01:41:25 +00:00
coverage-config: clean
mkdir -p '$(BUILD_ROOT)'
$(COVERAGE_CONFIG_CMD)
coverage: coverage-config
2019-02-08 13:12:07 +00:00
$(MAKE) -C $(BUILD_ROOT)
test x$(CROSS) = xOFF && $(TEST_EXE) || true # continue even if tests fail
2019-01-13 01:41:25 +00:00
mkdir -p "$(COVERAGE_OUTDIR)"
ifeq ($(CLANG),OFF)
gcovr -r . --branches --html --html-details -o "$(COVERAGE_OUTDIR)/lokinet.html"
else
llvm-profdata merge default.profraw -output $(BUILD_ROOT)/profdata
llvm-cov show -format=html -output-dir="$(COVERAGE_OUTDIR)" -instr-profile "$(BUILD_ROOT)/profdata" "$(BUILD_ROOT)/testAll" $(shell find ./llarp -type f)
endif
lint: $(LINT_CHECK)
%.cpp-check: %.cpp
clang-tidy $^ -- -I$(REPO)/include -I$(REPO)/crypto/include -I$(REPO)/llarp -I$(REPO)/vendor/cppbackport-master/lib
2019-01-21 16:57:12 +00:00
docker-kubernetes:
docker build -f docker/loki-svc-kubernetes.Dockerfile .
install-pylokinet:
cd $(REPO)/contrib/py/pylokinet && $(PYTHON) setup.py install
kubernetes-install: install install-pylokinet
docker-debian:
docker build -f docker/debian.Dockerfile .
docker-fedora:
docker build -f docker/fedora.Dockerfile .
2018-11-13 13:37:35 +00:00
debian-configure:
mkdir -p '$(BUILD_ROOT)'
2019-03-29 20:13:57 +00:00
$(CONFIG_CMD) -DDEBIAN=ON -DRELEASE_MOTTO="$(shell cat $(REPO)/motto.txt)"
2018-11-13 13:37:35 +00:00
debian: debian-configure
2019-02-08 13:12:07 +00:00
$(MAKE) -C '$(BUILD_ROOT)'
2019-01-12 01:19:24 +00:00
cp $(EXE) lokinet
2018-11-13 13:37:35 +00:00
2018-11-13 15:16:14 +00:00
debian-test:
2019-03-30 11:49:49 +00:00
test x$(CROSS) = xOFF && $(TEST_EXE) || test x$(CROSS) = xON
2018-11-13 15:16:14 +00:00
2019-01-12 01:19:24 +00:00
install:
2019-02-08 13:12:07 +00:00
$(MAKE) -C '$(BUILD_ROOT)' install
2018-11-13 15:16:14 +00:00
.PHONY: debian-install