-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
228 lines (189 loc) · 6.82 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
CXX := g++
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -Wno-error=unused-function -Wfatal-errors -std=c++20 -O3 -g
LDFLAGS := -L /usr/lib -lstdc++ -lm
BUILD := ./build
OBJ_DIR := $(BUILD)/objects
GEN_DIR := $(BUILD)/generated
APP_DIR := $(BUILD)/apps
BASE_NAME := libghoti.io-util.so
MAJOR_VERSION := 0
MINOR_VERSION := 0.0
SO_NAME := $(BASE_NAME).$(MAJOR_VERSION)
TARGET := $(SO_NAME).$(MINOR_VERSION)
INCLUDE := -I include/
LIBOBJECTS := $(OBJ_DIR)/errorCode.o \
$(OBJ_DIR)/file.o \
$(OBJ_DIR)/shared_string_view.o
TESTFLAGS := `pkg-config --libs --cflags gtest`
UTILLIBRARY := -L $(APP_DIR) -lghoti.io-util
all: $(APP_DIR)/$(TARGET) ## Build the shared library
####################################################################
# Dependency Variables
####################################################################
DEP_ERRORCODE = \
include/util/errorCode.hpp
DEP_ERROROR = \
include/util/errorOr.hpp
DEP_FILE = \
$(DEP_ERRORCODE) \
include/util/file.hpp
DEP_ANYMAP = \
$(DEP_ERRORCODE) \
$(DEP_ERROROR) \
include/util/anyMap.hpp
DEP_HASPARAMETERS = \
$(DEP_ERRORCODE) \
$(DEP_ERROROR) \
include/util/hasParameters.hpp
DEP_SSV = \
include/util/shared_string_view.hpp
####################################################################
# Object Files
####################################################################
$(LIBOBJECTS) :
@echo "\n### Compiling $@ ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@ -fPIC
$(OBJ_DIR)/errorCode.o: \
src/errorCode.cpp \
$(DEP_ERRORCODE)
$(OBJ_DIR)/shared_string_view.o: \
src/shared_string_view.cpp \
$(DEP_SSV)
$(OBJ_DIR)/file.o: \
src/file.cpp \
$(DEP_FILE)
####################################################################
# Shared Library
####################################################################
$(APP_DIR)/$(TARGET): \
$(LIBOBJECTS)
@echo "\n### Compiling Ghoti.io Util Shared Library ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -shared -o $@ $^ $(LDFLAGS) -Wl,-soname,$(SO_NAME)
@ln -f -s $(TARGET) $(APP_DIR)/$(SO_NAME)
@ln -f -s $(SO_NAME) $(APP_DIR)/$(BASE_NAME)
####################################################################
# Helper data files
####################################################################
$(APP_DIR)/fileExists.txt:
@mkdir -p $(@D)
echo "Hello World" > $(APP_DIR)/fileExists.txt
####################################################################
# Unit Tests
####################################################################
OBJDEP_ERRORCODE = \
$(OBJ_DIR)/errorCode.o
$(APP_DIR)/test-errorOr: \
test/test-errorOr.cpp \
$(DEP_ERROROR)
@echo "\n### Compiling ErrorOr Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS)
OBJDEP_ANYMAP = \
$(OBJDEP_ERRORCODE)
$(APP_DIR)/test-anyMap: \
test/test-anyMap.cpp \
$(DEP_ANYMAP) \
$(OBJDEP_ANYMAP)
@echo "\n### Compiling AnyMap Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS) $(OBJDEP_ANYMAP)
OBJDEP_HASPARAMETERS = \
$(OBJDEP_ERRORCODE)
$(APP_DIR)/test-hasParameters: \
test/test-hasParameters.cpp \
$(DEP_HASPARAMETERS) \
$(OBJDEP_HASPARAMETERS)
@echo "\n### Compiling HasParameters Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS) $(OBJDEP_HASPARAMETERS)
OBJDEP_FILE = \
$(OBJDEP_ERRORCODE) \
$(OBJ_DIR)/file.o
$(APP_DIR)/test-file: \
test/test-file.cpp \
$(APP_DIR)/fileExists.txt \
$(OBJDEP_FILE)
@echo "\n### Compiling File Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS) $(OBJDEP_FILE)
OBJDEP_SSV = \
$(OBJ_DIR)/shared_string_view.o
$(APP_DIR)/test-ssv: \
test/test-ssv.cpp \
$(OBJDEP_SSV)
@echo "\n### Compiling Shared String View Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS) $(OBJDEP_SSV)
####################################################################
# Commands
####################################################################
.PHONY: all clean cloc docs docs-pdf install test test-watch watch
watch: ## Watch the file directory for changes and compile the target
@while true; do \
make all; \
echo "\033[0;32m"; \
echo "#########################"; \
echo "# Waiting for changes.. #"; \
echo "#########################"; \
echo "\033[0m"; \
inotifywait -qr -e modify -e create -e delete -e move src include test Makefile --exclude '/\.'; \
done
test-watch: ## Watch the file directory for changes and run the unit tests
@while true; do \
make test; \
echo "\033[0;32m"; \
echo "#########################"; \
echo "# Waiting for changes.. #"; \
echo "#########################"; \
echo "\033[0m"; \
inotifywait -qr -e modify -e create -e delete -e move src include test Makefile --exclude '/\.'; \
done
test: ## Make and run the Unit tests
test: \
$(APP_DIR)/test-errorOr \
$(APP_DIR)/test-anyMap \
$(APP_DIR)/test-hasParameters \
$(APP_DIR)/test-file \
$(APP_DIR)/test-ssv
@echo "\033[0;32m"
@echo "############################"
@echo "### Running normal tests ###"
@echo "############################"
@echo "\033[0m"
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test-errorOr --gtest_brief=1
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test-anyMap --gtest_brief=1
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test-hasParameters --gtest_brief=1
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test-file --gtest_brief=1
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test-ssv --gtest_brief=1
clean: ## Remove all contents of the build directories.
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
-@rm -rvf $(GEN_DIR)/*
install: ## Install the library globally, requires sudo
install: all
# Install the Shared Library
@mkdir -p /usr/local/lib/ghoti.io
@cp $(APP_DIR)/$(TARGET) /usr/local/lib/ghoti.io/
@ln -f -s $(TARGET) /usr/local/lib/ghoti.io/$(SO_NAME)
@ln -f -s $(SO_NAME) /usr/local/lib/ghoti.io/$(BASE_NAME)
@echo "/usr/local/lib/ghoti.io" > /etc/ld.so.conf.d/ghoti.io-util.conf
# Install the headers
@mkdir -p /usr/local/include/ghoti.io/util
@cp include/util/*.hpp /usr/local/include/ghoti.io/util
# Install the pkgconfig files
@mkdir -p /usr/local/share/pkgconfig
@cp pkgconfig/ghoti.io-util.pc /usr/local/share/pkgconfig/
# Run ldconfig
@ldconfig >> /dev/null 2>&1
@echo "Ghoti.io Util installed"
docs: ## Generate the documentation in the ./docs subdirectory
doxygen
docs-pdf: docs ## Generate the documentation as a pdf, in ./docs/shared_string_view-docs.pdf
cd ./docs/latex/ && make
mv -f ./docs/latex/refman.pdf ./docs/util-docs.pdf
cloc: ## Count the lines of code used in the project
cloc src include test Makefile
help: ## Display this help
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'