-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (80 loc) · 2.66 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
# Define compiler
CC = cc
BREW = $(shell which brew | rev | cut -c 9- | rev)
BREW_VERSION = $(shell ls $(BREW)/Cellar/glfw/)
GLFW = $(BREW)Cellar/glfw/$(BREW_VERSION)
LIBS = -L$(GLFW)/lib -lglfw -L./lib/MLX42/build -lmlx42 -L./lib/libft -lft ./lib/gnl/get_next_line.c ./lib/gnl/get_next_line_utils.c
# Define source directories
SRCDIR = src
TEST_SRCDIR = test/src
UNITY_SRCDIR = test/Unity/src
# Define object directories
OBJDIR = obj
TEST_OBJDIR = test/obj
UNITY_OBJDIR = test/Unity/obj
# Define include directories
INCLUDES = -I./src/include
GLFW_INCLUDES = -I$(GLFW)/include/GLFW
MLX42_INCLUDES = -I./lib/MLX42/include/MLX42
TEST_INCLUDES = -I./$(UNITY_SRCDIR) $(INCLUDES) $(GLFW_INCLUDES) $(MLX42_INCLUDES)
# Define compiler flags
CFLAGS = -g -fsanitize=address
TEST_CFLAGS = -g -fsanitize=address
# Define main source file
MAIN = main.c
# Define source files
MAIN_SRC = $(SRCDIR)/$(MAIN)
SRC := $(filter-out $(MAIN_SRC), $(shell find $(SRCDIR) -name '*.c'))
TEST_SRC = $(TEST_SRCDIR)/test_my_module.c
UNITY_SRC = $(UNITY_SRCDIR)/unity.c
# Define object files
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
MAIN_OBJ = obj/main.o
TEST_OBJ = $(TEST_OBJDIR)/test_my_module.o
UNITY_OBJ = $(UNITY_OBJDIR)/unity.o
# Define executables
EXE = cub3D
TEST_EXE = test.out
# Define default target
all: libft mlx42 $(EXE) $(TEST_EXE)
# Comment out the line above and uncomment the line below to compile without tests
# all: $(EXE)
# Define build target for production executable
$(EXE): $(OBJ) $(MAIN_OBJ)
$(CC) $(CFLAGS) $(OBJ) $(MAIN_OBJ) $(LIBS) -o $(EXE)
# Define build target for test executable
$(TEST_EXE): $(OBJ) $(TEST_OBJ) $(UNITY_OBJ)
$(CC) $(TEST_CFLAGS) $(OBJ) $(TEST_OBJ) $(UNITY_OBJ) $(LIBS) -o $(TEST_EXE)
# Define build target for production object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
mkdir -p $(dir $@) # Automatically create the necessary directories
$(CC) $(CFLAGS) $(INCLUDES) $(GLFW_INCLUDES) $(MLX42_INCLUDES) -c $< -o $@
# Define build target for test object files
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
mkdir -p $(TEST_OBJDIR)
$(CC) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@
$(UNITY_OBJDIR)/%.o: $(UNITY_SRCDIR)/%.c
mkdir -p $(UNITY_OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Define target to run tests
test: all
./$(TEST_EXE)
run: all
./$(EXE)
# Define target to clean up build files
clean:
rm -rf obj $(TEST_OBJDIR)
make -C lib/libft clean
fclean : clean
rm -f $(EXE) $(TEST_EXE)
make -C lib/libft fclean
re : fclean all
debug: CFLAGS += -g -fsanitize=address
debug: TEST_CFLAGS += -g -fsanitize=address
debug: re
libft:
make -C lib/libft
# Define build target for mlx42 library
mlx42:
cd lib/MLX42 && cmake -B build && cmake --build build -j4
.PHONY: all test clean fclean re