-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
141 lines (114 loc) · 4.38 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
CXX := g++
CXXFLAGS := -pedantic-errors -Wall -Wextra -Werror -Wno-error=unused-function -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-pool.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)/pool.o
TESTFLAGS := `pkg-config --libs --cflags gtest`
POOLLIBRARY := -L $(APP_DIR) -lghoti.io-pool
all: $(APP_DIR)/$(TARGET) ## Build the shared library
####################################################################
# Dependency Variables
####################################################################
DEP_POOL = \
include/pool.hpp
####################################################################
# Object Files
####################################################################
$(LIBOBJECTS) :
@echo "\n### Compiling $@ ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@ -fPIC
$(OBJ_DIR)/pool.o: \
src/pool.cpp \
$(DEP_POOL)
####################################################################
# Shared Library
####################################################################
$(APP_DIR)/$(TARGET): \
$(LIBOBJECTS)
@echo "\n### Compiling Ghoti.io Pool 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)
####################################################################
# Unit Tests
####################################################################
$(APP_DIR)/test: \
test/test.cpp \
$(DEP_POOL) \
$(APP_DIR)/$(TARGET)
@echo "\n### Compiling Pool Test ###"
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $@ $< $(LDFLAGS) $(TESTFLAGS) $(POOLLIBRARY)
####################################################################
# 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
@echo "\033[0;32m"
@echo "############################"
@echo "### Running normal tests ###"
@echo "############################"
@echo "\033[0m"
env LD_LIBRARY_PATH="$(APP_DIR)" $(APP_DIR)/test --gtest_brief=1
install: ## Install the library
# 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-pool.conf
# Install the headers
@mkdir -p /usr/local/include/ghoti.io/
@cp include/pool.hpp /usr/local/include/ghoti.io/
# Install the pkgconfig files
@mkdir -p /usr/local/share/pkgconfig
@cp pkgconfig/ghoti.io-pool.pc /usr/local/share/pkgconfig/
# Run ldconfig
@ldconfig >> /dev/null 2>&1
@echo "Ghoti.io Pool installed"
clean: ## Remove all contents of the build directories.
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
-@rm -rvf $(GEN_DIR)/*
docs: ## Generate the documentation in the ./docs subdirectory
doxygen
docs-pdf: docs ## Generate the documentation as a pdf, in ./docs/pool-docs.pdf
cd ./docs/latex/ && make
mv -f ./docs/latex/refman.pdf ./docs/pool-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}'