2017-09-28 17:02:05 +00:00
|
|
|
REPO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
|
2018-01-25 15:38:14 +00:00
|
|
|
EXE = $(REPO)/llarpd
|
|
|
|
STATIC_LIB = $(REPO)/libllarp.a
|
2018-02-01 17:06:49 +00:00
|
|
|
SHARED_LIB = $(REPO)/libllarp.so
|
2017-09-28 17:02:05 +00:00
|
|
|
|
2018-01-25 15:38:14 +00:00
|
|
|
STATIC_SRC_CPP = $(wildcard $(REPO)/llarp/*.cpp)
|
|
|
|
STATIC_SRC_C = $(wildcard $(REPO)/llarp/*.c)
|
2018-01-08 13:49:05 +00:00
|
|
|
|
|
|
|
STATIC_OBJ = $(STATIC_SRC_CPP:.cpp=.cpp.o) $(STATIC_SRC_C:.c=.c.o)
|
2017-09-28 17:02:05 +00:00
|
|
|
|
|
|
|
DAEMON_SRC = $(wildcard $(REPO)/daemon/*.c)
|
2018-01-08 13:49:05 +00:00
|
|
|
DAEMON_OBJ = $(DAEMON_SRC:.c=.c.o)
|
2017-09-28 17:02:05 +00:00
|
|
|
|
2018-01-31 19:59:26 +00:00
|
|
|
TEST_SRC_C = $(wildcard $(REPO)/test/*.c)
|
|
|
|
TEST_SRC_CPP = $(wildcard $(REPO)/test/*.cpp)
|
|
|
|
|
|
|
|
TEST_OBJ_C = $(TEST_SRC_C:.c=.c.bin)
|
|
|
|
TEST_OBJ_CPP = $(TEST_SRC_CPP:.cpp=.cpp.bin)
|
|
|
|
|
|
|
|
TEST_SRC = $(TEST_SRC_C) $(TEST_SRC_CPP)
|
|
|
|
|
|
|
|
TEST_OBJ = $(TEST_OBJ_C) $(TEST_OBJ_CPP)
|
|
|
|
|
2018-01-29 14:27:24 +00:00
|
|
|
HDRS = $(wildcard $(REPO)/llarp/*.hpp) $(wildcard $(REPO)/include/*/*.h)
|
2018-01-31 19:59:26 +00:00
|
|
|
SRCS = $(DAEMON_SRC) $(STATIC_SRC_CPP) $(STATIC_SRC_C) $(TEST_SRC_C) $(TEST_SRC_CPP)
|
2018-01-29 14:27:24 +00:00
|
|
|
FORMAT = clang-format
|
|
|
|
|
2017-11-28 14:05:31 +00:00
|
|
|
SODIUM_FLAGS = $(shell pkg-config --cflags libsodium)
|
|
|
|
SODIUM_LIBS = $(shell pkg-config --libs libsodium)
|
2017-09-28 17:02:05 +00:00
|
|
|
|
2018-01-08 13:49:05 +00:00
|
|
|
LIBUV_FLAGS = $(shell pkg-config --cflags libuv)
|
|
|
|
LIBUV_LIBS = $(shell pkg-config --libs libuv)
|
|
|
|
|
2018-01-25 16:11:45 +00:00
|
|
|
DEBUG_FLAGS = -g
|
|
|
|
|
|
|
|
GIT_VERSION ?= $(shell test -e .git && git rev-parse --short HEAD || true)
|
|
|
|
|
|
|
|
ifneq ($(GIT_VERSION),"")
|
|
|
|
VER_FLAGS=-DGIT_REV=\"$(GIT_VERSION)\"
|
|
|
|
endif
|
|
|
|
|
2018-04-04 16:10:27 +00:00
|
|
|
ifeq ($(JEMALLOC),"1")
|
|
|
|
MALLOC_LIB=-ljemalloc
|
|
|
|
else
|
|
|
|
MALLOC_LIB=
|
2018-04-04 15:19:11 +00:00
|
|
|
endif
|
|
|
|
|
2018-04-04 16:10:27 +00:00
|
|
|
REQUIRED_CFLAGS = $(LIBUV_FLAGS) $(SODIUM_FLAGS) -I$(REPO)/include -std=c11 $(CFLAGS) $(DEBUG_FLAGS) $(VER_FLAGS) -Wall -fPIC
|
2018-04-08 12:18:16 +00:00
|
|
|
REQUIRED_CXXFLAGS = $(LIBUV_FLAGS) $(SODIUM_FLAGS) -I$(REPO)/include -std=c++17 $(CXXFLAGS) $(DEBUG_FLAGS) $(VER_FLAGS) -Wall -fPIC
|
|
|
|
LIB_LDFLAGS = $(MALLOC_LIB) $(SODIUM_LIBS) $(LIBUV_LIBS) -lm -lstdc++ -lstdc++fs
|
2018-02-01 17:06:49 +00:00
|
|
|
REQUIRED_LDFLAGS = -L$(REPO) -lllarp
|
2018-02-01 19:59:03 +00:00
|
|
|
TEST_LDFLAGS = $(STATIC_LIB) $(LIB_LDFLAGS)
|
2017-09-28 17:02:05 +00:00
|
|
|
|
|
|
|
all: build
|
|
|
|
|
2018-02-01 13:21:00 +00:00
|
|
|
format:
|
|
|
|
$(FORMAT) -style=Google -i $(HDRS) $(SRCS)
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-02-01 22:04:58 +00:00
|
|
|
build: shared $(EXE)
|
2017-09-28 17:02:05 +00:00
|
|
|
|
2018-01-31 19:59:26 +00:00
|
|
|
test: $(TEST_OBJ_CPP) $(TEST_OBJ_C)
|
|
|
|
|
2018-02-01 22:04:58 +00:00
|
|
|
shared: $(SHARED_LIB)
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2018-02-01 19:59:03 +00:00
|
|
|
$(TEST_SRC): $(STATIC_LIB)
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2018-02-01 22:04:58 +00:00
|
|
|
|
|
|
|
$(REPO)/test/%.cpp.bin: $(REPO)/test/%.cpp
|
2018-02-01 19:59:03 +00:00
|
|
|
$(CXX) $(REQUIRED_CXXFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
|
2018-01-31 19:59:26 +00:00
|
|
|
mv $<.bin $<.test
|
|
|
|
$<.test
|
2018-02-15 17:09:27 +00:00
|
|
|
valgrind --tool=callgrind $<.test
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2018-02-01 22:04:58 +00:00
|
|
|
$(REPO)/test/%.c.bin: $(REPO)/test/%.c
|
2018-02-01 19:59:03 +00:00
|
|
|
$(CC) $(REQUIRED_CFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
|
2018-01-31 19:59:26 +00:00
|
|
|
mv $<.bin $<.test
|
|
|
|
$<.test
|
2018-04-30 14:57:13 +00:00
|
|
|
#valgrind --tool=callgrind $<.test
|
2018-01-31 19:59:26 +00:00
|
|
|
|
2017-09-28 17:02:05 +00:00
|
|
|
$(EXE): $(DAEMON_OBJ) $(STATIC_LIB)
|
2018-02-01 17:06:49 +00:00
|
|
|
$(CXX) $(DAEMON_OBJ) $(STATIC_LIB) $(LIB_LDFLAGS) -o $(EXE)
|
2017-10-03 19:14:46 +00:00
|
|
|
|
|
|
|
%.cpp.o: %.cpp
|
2018-01-08 13:49:05 +00:00
|
|
|
$(CXX) $(REQUIRED_CXXFLAGS) -c $< -o $<.o
|
|
|
|
|
|
|
|
%.c.o: %.c
|
|
|
|
$(CC) $(REQUIRED_CFLAGS) -c $< -o $<.o
|
2017-09-28 17:02:05 +00:00
|
|
|
|
2018-02-01 17:06:49 +00:00
|
|
|
$(STATIC_LIB): $(STATIC_OBJ)
|
2017-09-28 17:02:05 +00:00
|
|
|
$(AR) -r $(STATIC_LIB) $(STATIC_OBJ)
|
|
|
|
|
2018-02-01 17:06:49 +00:00
|
|
|
$(SHARED_LIB): $(STATIC_OBJ)
|
|
|
|
$(CXX) -shared -o $(SHARED_LIB) $(STATIC_OBJ) $(LIB_LDFLAGS)
|
|
|
|
|
2017-09-28 17:02:05 +00:00
|
|
|
clean:
|
2018-02-01 17:06:49 +00:00
|
|
|
$(RM) $(DAEMON_OBJ) $(EXE) $(STATIC_OBJ) $(STATIC_LIB) $(TEST_OBJ) $(SHARED_LIB)
|