-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
140 lines (118 loc) · 5.15 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
SHELL = bash -O globstar
TIDY ?= clang-tidy
LIBS = glm glfw3 glew stb assimp
BUILD_DIR ?= build
CACHE_DIR = cache
INSTALL_DIR ?= /usr/local/lib
HEADER_DIR ?= /usr/local/include
LIBRARY_NAME = libammonite.so.1
AMMONITE_OBJECTS_SOURCE = $(shell ls ./src/ammonite/**/*.cpp)
AMMONITE_HEADERS_SOURCE = $(shell ls ./src/ammonite/**/*.hpp)
AMMONITE_HEADER_INSTALL := $(subst src/ammonite,$(HEADER_DIR)/ammonite,$(AMMONITE_HEADERS_SOURCE))
HELPER_OBJECTS_SOURCE = $(shell ls ./src/helper/**/*.cpp)
HELPER_HEADERS_SOURCE = $(shell ls ./src/helper/**/*.hpp)
DEMO_OBJECTS_SOURCE = $(shell ls ./src/demos/**/*.cpp)
DEMO_HEADERS_SOURCE = $(shell ls ./src/demos/**/*.hpp)
ROOT_OBJECTS_SOURCE = $(shell ls ./src/*.cpp)
ALL_OBJECTS_SOURCE = $(AMMONITE_OBJECTS_SOURCE) $(HELPER_OBJECTS_SOURCE) $(DEMO_OBJECTS_SOURCE) \
$(ROOT_OBJECTS_SOURCE)
ALL_HEADERS_SOURCE = $(AMMONITE_HEADERS_SOURCE) $(HELPER_HEADERS_SOURCE) $(DEMO_HEADERS_SOURCE)
LINT_FILES = $(subst ./src,$(OBJECT_DIR),$(subst .cpp,.cpp.linted,$(ALL_OBJECTS_SOURCE)))
LINT_FILES += $(subst ./src,$(OBJECT_DIR),$(subst .hpp,.hpp.linted,$(ALL_HEADERS_SOURCE)))
OBJECT_DIR = $(BUILD_DIR)/objects
AMMONITE_OBJECTS = $(subst ./src,$(OBJECT_DIR),$(subst .cpp,.o,$(AMMONITE_OBJECTS_SOURCE)))
HELPER_OBJECTS = $(subst ./src,$(OBJECT_DIR),$(subst .cpp,.o,$(HELPER_OBJECTS_SOURCE)))
DEMO_OBJECTS = $(subst ./src,$(OBJECT_DIR),$(subst .cpp,.o,$(DEMO_OBJECTS_SOURCE)))
CXXFLAGS += $(shell pkg-config --cflags $(LIBS))
CXXFLAGS += -Wall -Wextra -Werror -std=c++23 -flto=auto -O3
LDFLAGS := $(shell pkg-config --libs $(LIBS)) -lm -latomic -pthread
ifeq ($(FAST),true)
CXXFLAGS += -march=native -DFAST
endif
ifeq ($(DEBUG),true)
CXXFLAGS += -DDEBUG -g -fno-omit-frame-pointer -fsanitize=address,undefined
CHECK_LEAKS = true
endif
ifeq ($(CHECK_LEAKS),true)
LDFLAGS += -fsanitize=leak
endif
ifeq ($(CHECK_THREADS),true)
CXXFLAGS += -fsanitize=thread
endif
$(BUILD_DIR)/demo: $(BUILD_DIR)/$(LIBRARY_NAME) $(HELPER_OBJECTS) $(DEMO_OBJECTS) $(OBJECT_DIR)/demoLoader.o
@mkdir -p "$(BUILD_DIR)"
$(CXX) -o "$(BUILD_DIR)/demo" $(HELPER_OBJECTS) $(DEMO_OBJECTS) $(OBJECT_DIR)/demoLoader.o $(CXXFLAGS) "-L$(BUILD_DIR)" -lammonite $(LDFLAGS)
$(BUILD_DIR)/threadTest: $(BUILD_DIR)/$(LIBRARY_NAME) $(OBJECT_DIR)/threadTest.o
@mkdir -p "$(BUILD_DIR)"
$(CXX) -o "$(BUILD_DIR)/threadTest" $(OBJECT_DIR)/threadTest.o $(CXXFLAGS) "-L$(BUILD_DIR)" -lammonite $(LDFLAGS)
$(BUILD_DIR)/libammonite.so: $(AMMONITE_OBJECTS)
@mkdir -p "$(OBJECT_DIR)"
$(CXX) -shared -o "$@" $(AMMONITE_OBJECTS) $(CXXFLAGS) "-Wl,-soname,$(LIBRARY_NAME)"
@if [[ "$(DEBUG)" != "true" ]]; then \
strip --strip-unneeded "$(BUILD_DIR)/libammonite.so"; \
fi
$(BUILD_DIR)/$(LIBRARY_NAME): $(BUILD_DIR)/libammonite.so
@rm -fv "$(BUILD_DIR)/$(LIBRARY_NAME)"
@ln -sv "libammonite.so" "$(BUILD_DIR)/$(LIBRARY_NAME)"
$(OBJECT_DIR)/ammonite/%.o: ./src/ammonite/%.cpp $(AMMONITE_HEADERS_SOURCE)
@mkdir -p "$$(dirname $@)"
$(CXX) "$<" -c $(CXXFLAGS) -fpic -o "$@"
$(OBJECT_DIR)/helper/%.o: ./src/helper/%.cpp $(HELPER_HEADERS_SOURCE)
@mkdir -p "$$(dirname $@)"
$(CXX) "$<" -c $(CXXFLAGS) -o "$@"
$(OBJECT_DIR)/demos/%.o: ./src/demos/%.cpp $(DEMO_HEADERS_SOURCE) $(AMMONITE_HEADERS_SOURCE)
@mkdir -p "$$(dirname $@)"
$(CXX) "$<" -c $(CXXFLAGS) -o "$@"
$(OBJECT_DIR)/%.o: ./src/%.cpp $(AMMONITE_HEADERS_SOURCE) $(HELPER_HEADERS_SOURCE)
@mkdir -p "$(OBJECT_DIR)"
$(CXX) "$<" -c $(CXXFLAGS) -o "$@"
$(BUILD_DIR)/compile_flags.txt: Makefile
@mkdir -p "$(BUILD_DIR)"
@rm -fv "$(BUILD_DIR)/compile_flags.txt"
@for arg in $(CXXFLAGS); do \
echo $$arg >> "$(BUILD_DIR)/compile_flags.txt"; \
done
$(OBJECT_DIR)/%.linted: ./src/% $(BUILD_DIR)/compile_flags.txt .clang-tidy
$(TIDY) --quiet -p "$(BUILD_DIR)" "$<"
@mkdir -p "$$(dirname $@)"
@touch "$@"
.PHONY: build demo threads debug library headers install uninstall clean lint cache icons $(AMMONITE_HEADER_INSTALL)
build: demo threads
demo: $(BUILD_DIR)/demo
@if [[ "$(DEBUG)" != "true" ]]; then \
strip --strip-unneeded "$(BUILD_DIR)/demo"; \
fi
threads: $(BUILD_DIR)/threadTest
@if [[ "$(DEBUG)" != "true" ]]; then \
strip --strip-unneeded "$(BUILD_DIR)/threadTest"; \
fi
debug: clean
@DEBUG="true" $(MAKE) build
library: $(BUILD_DIR)/$(LIBRARY_NAME)
headers: $(AMMONITE_HEADER_INSTALL)
$(AMMONITE_HEADER_INSTALL):
@targetFile="/$@"; \
targetDir="$$(dirname $$targetFile)"; \
origFile="$${targetFile//'$(HEADER_DIR)'/src}"; \
if [[ "$$targetDir/" != */internal/* ]]; then \
mkdir -p "$$targetDir" && \
cp -v "$$origFile" "$$targetFile"; \
fi
install:
@mkdir -p "$(INSTALL_DIR)/ammonite"
install "$(BUILD_DIR)/libammonite.so" "$(INSTALL_DIR)/ammonite/$(LIBRARY_NAME)"
ldconfig "$(INSTALL_DIR)/ammonite"
uninstall:
@rm -fv "$(INSTALL_DIR)/ammonite/libammonite.so"*
@if [[ -d "$(INSTALL_DIR)/ammonite" ]]; then rm -di "$(INSTALL_DIR)/ammonite"; fi
@if [[ -d "$(HEADER_DIR)/ammonite" ]]; then rm -rf "$(HEADER_DIR)/ammonite"; fi
clean: cache
@rm -rfv "$(BUILD_DIR)"
lint: $(LINT_FILES)
cache:
@rm -rfv "$(CACHE_DIR)"
icons:
for res in 256 128 64 32; do \
inkscape "--export-filename=./assets/icons/icon-$$res.png" -w "$$res" -h "$$res" "./assets/icons/icon.svg" > /dev/null 2>&1; \
done
optipng -o7 -strip all --quiet "./assets/icons/icon"*".png"