-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (81 loc) · 2.44 KB
/
Copy pathMakefile
File metadata and controls
101 lines (81 loc) · 2.44 KB
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
# Platform-specific configuration
ifeq ($(OS),Windows_NT)
CMD = cmd /C
FIND = powershell -Command "Get-ChildItem -Recurse -Include *.cpp,*.hpp src, include\jsocketpp, test | ForEach-Object { $_.FullName }"
else
CMD =
FIND = find src include/jsocketpp test -name '*.cpp' -o -name '*.hpp'
endif
# Compiler and tools
CXX ?= g++
AR = ar
ARFLAGS = rcvs
CLANG_FORMAT ?= clang-format
# Directories
SRC_FOLDER = src
BUILD = release
ARCH ?= x64
GTEST_DIR ?= /usr/local
# Default architecture flags
ifeq ($(ARCH),x64)
ARCHITECTURE = -m64
else ifeq ($(ARCH),x86)
ARCHITECTURE = -m32
else
$(error Unsupported architecture $(ARCH))
endif
# Source files (using platform-specific find command)
SRC := $(shell $(FIND))
# Preprocessor defines
DEFINES =
# Compiler flags
ifeq ($(BUILD),release)
OPTIMIZE = -O3 -s -DNDEBUG
else
OPTIMIZE = -O0 -g -DDEBUG -fsanitize=undefined -fsanitize=thread
WARNINGS = -Wall -Wextra -pedantic -Wmain -Weffc++ -Wswitch-default -Wswitch-enum \
-Wmissing-include-dirs -Wmissing-declarations -Wunreachable-code -Winline \
-Wfloat-equal -Wundef -Wcast-align -Wredundant-decls -Winit-self -Wshadow \
-Wnon-virtual-dtor -Wconversion
ifeq ($(CXX),g++)
WARNINGS += -Wzero-as-null-pointer-constant
endif
endif
# Combine all flags
CXXFLAGS = $(ARCHITECTURE) -std=c++20 $(DEFINES) $(WARNINGS) $(OPTIMIZE)
# GoogleTest flags (requires GTest installed or built separately)
GTEST_FLAGS = -I$(GTEST_DIR)/include -L$(GTEST_DIR)/lib -lgtest -lgtest_main -lpthread
.PHONY: all clean debug release release32 release64 debug32 debug64 tests format
# Default target (build everything)
all: src tests
# Build the source directory
src:
$(MAKE) -C src
# Build the test directory
tests:
$(MAKE) -C tests
# Clean the build
clean:
$(MAKE) -C src clean
$(MAKE) -C tests clean
# Build in debug mode
debug:
$(MAKE) BUILD=debug
# Build in release mode
release:
$(MAKE) BUILD=release
# Build for 32-bit release
release32:
$(MAKE) BUILD=release ARCH=x86
# Build for 64-bit release
release64:
$(MAKE) BUILD=release ARCH=x64
# Build for 32-bit debug
debug32:
$(MAKE) BUILD=debug ARCH=x86
# Build for 64-bit debug
debug64:
$(MAKE) BUILD=debug ARCH=x64
# Run clang-format on the source files
format:
$(CLANG_FORMAT) -i --style=file $(SRC)