mirror of https://github.com/oxen-io/lokinet
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
Makefile
95 lines
2.5 KiB
Makefile
REPO := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
EXE = $(REPO)/llarpd
|
|
STATIC_LIB = $(REPO)/libllarp.a
|
|
SHARED_LIB = $(REPO)/libllarp.so
|
|
|
|
STATIC_SRC_CPP = $(wildcard $(REPO)/llarp/*.cpp)
|
|
STATIC_SRC_C = $(wildcard $(REPO)/llarp/*.c)
|
|
|
|
STATIC_OBJ = $(STATIC_SRC_CPP:.cpp=.cpp.o) $(STATIC_SRC_C:.c=.c.o)
|
|
|
|
DAEMON_SRC = $(wildcard $(REPO)/daemon/*.c)
|
|
DAEMON_OBJ = $(DAEMON_SRC:.c=.c.o)
|
|
|
|
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)
|
|
|
|
HDRS = $(wildcard $(REPO)/llarp/*.hpp) $(wildcard $(REPO)/include/*/*.h)
|
|
SRCS = $(DAEMON_SRC) $(STATIC_SRC_CPP) $(STATIC_SRC_C) $(TEST_SRC_C) $(TEST_SRC_CPP)
|
|
FORMAT = clang-format
|
|
|
|
SODIUM_FLAGS = $(shell pkg-config --cflags libsodium)
|
|
SODIUM_LIBS = $(shell pkg-config --libs libsodium)
|
|
|
|
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
|
|
|
|
ifeq ($(JEMALLOC),"1")
|
|
MALLOC_LIB=-ljemalloc
|
|
else
|
|
MALLOC_LIB=
|
|
endif
|
|
|
|
REQUIRED_CFLAGS = $(SODIUM_FLAGS) -I$(REPO)/include -std=c11 $(CFLAGS) $(DEBUG_FLAGS) $(VER_FLAGS) -Wall -fPIC
|
|
REQUIRED_CXXFLAGS = $(SODIUM_FLAGS) -I$(REPO)/include -std=c++17 $(CXXFLAGS) $(DEBUG_FLAGS) $(VER_FLAGS) -Wall -fPIC
|
|
LIB_LDFLAGS = $(MALLOC_LIB) $(SODIUM_LIBS) -pthread -lm -lstdc++ -lstdc++fs
|
|
REQUIRED_LDFLAGS = -L$(REPO) -lllarp
|
|
TEST_LDFLAGS = $(STATIC_LIB) $(LIB_LDFLAGS)
|
|
|
|
all: build
|
|
|
|
format:
|
|
$(FORMAT) -style=Google -i $(HDRS) $(SRCS)
|
|
|
|
build: shared $(EXE)
|
|
|
|
test: $(TEST_OBJ_CPP) $(TEST_OBJ_C)
|
|
|
|
shared: $(SHARED_LIB)
|
|
|
|
$(TEST_SRC): $(STATIC_LIB)
|
|
|
|
|
|
$(REPO)/test/%.cpp.bin: $(REPO)/test/%.cpp
|
|
$(CXX) $(REQUIRED_CXXFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
|
|
mv $<.bin $<.test
|
|
$<.test
|
|
valgrind --tool=callgrind $<.test
|
|
|
|
$(REPO)/test/%.c.bin: $(REPO)/test/%.c
|
|
$(CC) $(REQUIRED_CFLAGS) $< -o $<.bin $(TEST_LDFLAGS)
|
|
mv $<.bin $<.test
|
|
$<.test
|
|
#valgrind --tool=callgrind $<.test
|
|
|
|
$(EXE): $(DAEMON_OBJ) $(STATIC_LIB)
|
|
$(CXX) $(DAEMON_OBJ) $(STATIC_LIB) $(LIB_LDFLAGS) -o $(EXE)
|
|
|
|
%.cpp.o: %.cpp
|
|
$(CXX) $(REQUIRED_CXXFLAGS) -c $< -o $<.o
|
|
|
|
%.c.o: %.c
|
|
$(CC) $(REQUIRED_CFLAGS) -c $< -o $<.o
|
|
|
|
$(STATIC_LIB): $(STATIC_OBJ)
|
|
$(AR) -r $(STATIC_LIB) $(STATIC_OBJ)
|
|
|
|
$(SHARED_LIB): $(STATIC_OBJ)
|
|
$(CXX) -shared -o $(SHARED_LIB) $(STATIC_OBJ) $(LIB_LDFLAGS)
|
|
|
|
clean:
|
|
$(RM) $(DAEMON_OBJ) $(EXE) $(STATIC_OBJ) $(STATIC_LIB) $(TEST_OBJ) $(SHARED_LIB)
|