-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
165 lines (134 loc) · 5.28 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
NAME := 3DViewer
PREFIX := /.local
SRC_DIR := src
LIB_DIR := lib
TEST_DIR := test
INCLUDE_DIR := include
CIMGUI_DIR := cimgui
LIBCIMGUI := $(LIB_DIR)/libcimgui.a
NFD_DIR := nativefiledialog
LIBNFD := $(LIB_DIR)/libnfd.a
SRC := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c)
OBJ := $(SRC:.c=.o)
TEST_SRC := $(wildcard $(TEST_DIR)/*.c $(SRC_DIR)/*/*.c)
TEST_OBJ := $(TEST_SRC:.c=.o)
TEST_EXEC := run_tests
TEST_LIBS := -lcheck
# TODO set correct flags
CC := gcc -fdiagnostics-color=always
CPPFLAGS := -I $(INCLUDE_DIR) -I $(NFD_DIR)/src/include -MMD -MP -DCIMGUI_USE_OPENGL3 -DCIMGUI_USE_GLFW
CFLAGS := -std=c11 -pedantic -O2 -Wall -Wextra -Werror
LDFLAGS := -L $(LIB_DIR)
LDLIBS := -lcimgui -lnfd -lstdc++
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux) #LINUX
LDLIBS += -lGL `pkg-config --static --libs glfw3` `pkg-config --libs gtk+-3.0`
NFD_MAKE := $(NFD_DIR)/build/gmake_linux
TEST_LIBS += -lm -lpthread -lrt -lsubunit
OPEN := xdg-open
endif
ifeq ($(UNAME_S), Darwin) #APPLE
# CPPFLAGS += -I/usr/local/include -I/opt/local/include -I/opt/homebrew/include
# CPPFLAGS += -I/Users/$(USER)/.brew/Cellar/glfw/3.3.8/include #MacOS brew/goinfree
CPPFLAGS += -I/Users/$(USER)/Documents/21school/homebrew/opt/glfw/include #MacOS sber
CPPFLAGS += -I/usr/local/include -I/opt/local/include -I/Users/$(USER)/goinfre/homebrew/opt/glfw/include
# CPPFLAGS += -I/opt/local/include -I/Users/$(USER)/.brew/Cellar/glfw/3.3.8/include #tmp mmicheli
# LDFLAGS += -L/usr/local/lib -L/opt/local/lib -L/opt/homebrew/lib
# LDFLAGS += -L/usr/local/lib -L/Users/$(USER)/goinfre/homebrew/opt/glfw/lib
LDFLAGS += -L/usr/local/lib -L/Users/$(USER)/Documents/21school/homebrew/opt/glfw/lib #MacOS sber
# LDFLAGS += -L/Users/$(USER)/.brew/Cellar/glfw/3.3.8/lib #MacOS brew/goinfree mmicheli
LDLIBS += -lglfw -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
NFD_MAKE := $(NFD_DIR)/build/gmake_macosx
OPEN := open
endif
.PHONY: all bonus clean_obj clean fclean re tests html dist install uninstall style
all: $(NAME)
bonus: $(NAME)
$(LIBCIMGUI): $(LIB_DIR)
$(MAKE) --directory=$(CIMGUI_DIR) static
cp $(CIMGUI_DIR)/libcimgui.a $(LIB_DIR)
$(LIBNFD): $(LIB_DIR)
$(MAKE) --directory=$(NFD_MAKE)
cp $(NFD_DIR)/build/lib/Release/x64/libnfd.a $(LIB_DIR)
$(NAME): $(OBJ) $(LIBCIMGUI) $(LIBNFD)
$(CC) $(LDFLAGS) $(OBJ) $(LDLIBS) -o $@
# Turns out you don't have to have a rule for object files. 'Make' uses CFLAGS
# and CPPFLAGS variables to compile .o files.
# %.o: %.c
# $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(LIB_DIR):
mkdir -p $@
clean_obj:
@rm -vf $(OBJ)
@rm -vf $(wildcard $(TEST_DIR)/*.o)
clean: clean_obj
@rm -vf $(OBJ:.o=.d)
@rm -vf $(wildcard $(TEST_DIR)/*.d)
$(MAKE) clean --directory=$(CIMGUI_DIR)
$(MAKE) clean --directory=$(NFD_MAKE)
@rm -rvf $(NFD_DIR)/build/obj
fclean: clean
@rm -vf $(NAME)
@rm -vf $(TEST_EXEC)
@rm -rvf $(LIB_DIR)
@rm -rvf gcov_report
@rm -vf gcov_report.info
@rm -vf $(shell find $(SRC_DIR) -type f -name "*.gcda")
@rm -vf $(shell find $(SRC_DIR) -type f -name "*.gcno")
@rm -vf $(shell find $(TEST_DIR) -type f -name "*.gcno")
@rm -vf $(shell find $(TEST_DIR) -type f -name "*.gcno")
@rm -rvf docs_generated
@rm -rf 3DViewer_v1.0.tar.gz
$(MAKE) fclean --directory=$(CIMGUI_DIR)
re: fclean all
tests: $(TEST_EXEC)
@echo "-------TESTS-------"
@./$(TEST_EXEC) 2> /dev/null
@echo "-------------------"
$(TEST_EXEC): $(TEST_OBJ) $(LIBCIMGUI) $(LIBNFD)
$(CC) $(LDFLAGS) $(TEST_OBJ) $(LDLIBS) $(TEST_LIBS) -o $@
add_coverage_flag:
$(eval CFLAGS += --coverage)
$(eval LDFLAGS += --coverage)
# TODO wasteful `gcov_report`
# Currently deletes all `.o` files, generates new ones with `--coverage`,
# then deletes them again. Far from optimal!
gcov_report: add_coverage_flag clean_obj tests
@lcov --directory . -t "3DViewer_tests" -o gcov_report.info -c --no-external
@lcov -q --remove gcov_report.info "`pwd`/test/*" -o gcov_report.info
@lcov -q --remove gcov_report.info "`pwd`/src/3rd-party/*" -o gcov_report.info
@genhtml -o $@ gcov_report.info
@$(OPEN) ./gcov_report/index.html
@rm -vf $(OBJ) $(wildcard $(TEST_DIR)/*.o)
dvi: html
html:
@doxygen doxygen.conf
@$(OPEN) docs_generated/html/index.html
dist: fclean
mkdir -p 3DViewer_v1.0_dist
ln -s "`pwd`/Makefile" 3DViewer_v1.0_dist/Makefile
ln -s "`pwd`/doxygen.conf" 3DViewer_v1.0_dist/doxygen.conf
ln -s "`pwd`/imgui.ini" 3DViewer_v1.0_dist/imgui.ini
ln -s "`pwd`/.clang-format" 3DViewer_v1.0_dist/.clang-format
ln -s "`pwd`/$(SRC_DIR)" 3DViewer_v1.0_dist/$(SRC_DIR)
ln -s "`pwd`/$(INCLUDE_DIR)" 3DViewer_v1.0_dist/$(INCLUDE_DIR)
ln -s "`pwd`/docs" 3DViewer_v1.0_dist/docs
ln -s "`pwd`/models" 3DViewer_v1.0_dist/models
ln -s "`pwd`/$(CIMGUI_DIR)" 3DViewer_v1.0_dist/$(CIMGUI_DIR)
ln -s "`pwd`/$(NFD_DIR)" 3DViewer_v1.0_dist/$(NFD_DIR)
tar -h -cvzf 3DViewer_v1.0.tar.gz 3DViewer_v1.0_dist
rm -rvf 3DViewer_v1.0_dist
# Example usage:
# make install DESTDIR=~
install: $(NAME)
mkdir -p $(DESTDIR)$(PREFIX)/bin
install -m 755 $(NAME) $(DESTDIR)$(PREFIX)/bin
cp imgui.ini $(DESTDIR)$(PREFIX)/bin
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(NAME)
rm -f $(DESTDIR)$(PREFIX)/bin/imgui.ini
style:
@clang-format -n $(shell find $(SRC_DIR) -type f -name "*.[ch]") \
$(shell find $(TEST_DIR) -type f -name "*.[ch]") \
$(wildcard $(INCLUDE_DIR)/*.h)
-include $(OBJ:.o=.d)