-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
115 lines (92 loc) · 2.84 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
CC = g++
CFLAGS = -O1 -Iinclude -Wall -Wextra -pedantic -std=c++23
TARGET = lunas
PREFIX = /usr
INSTALL_DIR = $(PREFIX)/bin
LIB = $(shell pkg-config --cflags --libs libssh) -pthread
BUILD_DIR = build
HEADER_DIR = include
MANPAGE_DIR = $(PREFIX)/share/man/man1
SRC_DIR = src
SRCS := $(wildcard src/*.cpp)
HEADERS := $(wildcard include/*.h)
OBJS := $(addprefix build/, $(notdir $(SRCS:.cpp=.o)))
DEP := $(OBJS:.o=.d)
ifneq ($(findstring clang++, $(CC)),)
CFLAGS += -D__cpp_concepts=202002L -Wno-builtin-macro-redefined -Wno-macro-redefined
endif
all: mkdir_build pkg_version $(OBJS) $(TARGET)
debug: append_debug_option all
asan: append_asan_option all
tsan: append_tsan_option all
local: local_options all
build/%.o: src/%.cpp
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(LIB) $^ -o $@
install:
$(info :: Installing $(TARGET))
install -Dm755 $(TARGET) $(INSTALL_DIR)/$(TARGET)
mkdir -p $(INSTALL_DIR) $(MANPAGE_DIR)
install -Dm644 man/$(TARGET).1 $(MANPAGE_DIR)/
uninstall:
$(info :: Uninstalling $(TARGET))
rm $(INSTALL_DIR)/$(TARGET)
rm $(MANPAGE_DIR)/$(TARGET).1
mkdir_build:
@for i in $(BUILD_DIR); do\
if [ ! -f "$$i" ]; then\
mkdir -p $$i;\
fi;\
done
clean:
$(info :: cleaning build)
@for i in $(BUILD_DIR) $(TARGET); do\
if [ -f "$$i" ] || [ -d "$$i" ]; then\
rm -r "$$i";\
fi;\
done
define pkg_version
@pkg-config --atleast-version=$(1) $(2); \
STATUS=$$?; \
if [ $$STATUS -ne 0 ]; then \
echo -e "\x1b[1;31m-[X] $(2) >= $(1) is required to compile $(TARGET) \x1b[1;0m"; \
fi
endef
pkg_version:
$(call pkg_version,0.11.0,libssh)
append_debug_option:
$(eval CFLAGS=$(CFLAGS) -g)
append_asan_option:
$(info :: compiling with asan)
$(eval CFLAGS=$(CFLAGS) -g -fsanitize=address -fsanitize=undefined -fsanitize=float-cast-overflow\
-fsanitize=float-divide-by-zero -fno-sanitize-recover=all -fsanitize=leak\
-fsanitize=alignment -fno-omit-frame-pointer)
append_tsan_option:
$(info :: compiling with tsan)
$(eval CFLAGS=$(CFLAGS) -g -fsanitize=undefined -fsanitize=float-cast-overflow\
-fsanitize=float-divide-by-zero -fno-sanitize-recover=all -fsanitize=thread\
-fsanitize=alignment -fno-omit-frame-pointer)
$(eval CC=clang++ -D__cpp_concepts=202002L -Wno-builtin-macro-redefined -Wno-macro-redefined)
local_options:
$(info :: compiling without remote support)
$(eval LIB= -pthread)
$(eval CFLAGS=$(CFLAGS) -D DISABLE_REMOTE)
cppcheck: mkdir_build
$(info :: running static code analysis)
$(info )
cppcheck --cppcheck-build-dir=$(BUILD_DIR) --std=c++23 --check-level=exhaustive --suppress=unreadVariable\
--suppress=missingIncludeSystem --enable=all -I $(HEADER_DIR) $(SRC_DIR)
run-test:
$(info :: running unit tests)
$(info )
cd test && \
make
clean-test:
$(info :: cleaning unit test files)
$(info )
cd test && \
go run clean.go
format:
clang-format -i $(SRCS) $(HEADERS)
-include $(DEP)