-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (94 loc) · 2.42 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
##
#libft
#
#@file
#@version 0.1
#Compiler and flags
CC := cc
CXX := g++
CFLAGS := -Wall -Wextra -Werror
CFLAGS += -Iincludes
CXXFLAGS := -Wall -Wextra
CXXFLAGS += -Iincludes
LDFLAGS := -lgtest -lgtest_main -pthread
BSD := -lbsd
# Test Flags
FSANITIZE = -fsanitize=address
#Directories and extensions
SRC_DIR = ./src
SRC_DIR_BONUS = ./src_bonus
OBJ_DIR := ./obj
BIN_DIR := ./bin
BUILD_DIR := ./build
TESTS_DIR := ./tests
#Source files
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
SRC_FILES_BONUS := $(wildcard $(SRC_DIR_BONUS)/*.c)
OBJ_FILES := $(SRC_FILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
OBJ_FILES_BONUS := $(SRC_FILES_BONUS:$(SRC_DIR_BONUS)/%.c=$(OBJ_DIR)/%.o)
TEST_FILES := $(wildcard $(TESTS_DIR)/*.cpp)
TEST_OBJ_FILES := $(TEST_FILES:$(TESTS_DIR)/%.cpp=$(OBJ_DIR)/%.o)
#Library name
NAME := $(BIN_DIR)/libft.a
# Executable names
TEST_TARGET := $(BIN_DIR)/run_tests
.DEFAULT_GOAL := all
############ Rules ##################
#Mandatory targets
all: $(NAME)
$(NAME): $(OBJ_FILES)
@mkdir -p $(BIN_DIR)
ar rc $@ $^
bonus: $(OBJ_FILES_BONUS)
ar r $(NAME) $^
# Compile C source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR_BONUS)/%.c
$(CC) $(CFLAGS) -c $< -o $@
# Compile C++ test files to object files
$(OBJ_DIR)/%.o: $(TESTS_DIR)/%.cpp
@mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@ $(BSD) $(LDFLAGS)
# Build the tests executable
$(TEST_TARGET)-FSANITIZE: $(OBJ_FILES) $(TEST_OBJ_FILES) $(OBJ_FILES_BONUS)
@mkdir -p $(BIN_DIR)
$(CXX) $(FSANITIZE) -o $@ $^ $(BSD) $(LDFLAGS)
############ PHONY ##################
clean:
rm -f $(OBJ_FILES) $(OBJ_FILES_BONUS) $(TEST_OBJ_FILES)
fclean: clean
rm -f $(BIN_DIR)/*
rm -rf $(BIN_DIR)
rm -rf $(OBJ_DIR)
rm -rf $(BUILD_DIR)
re: fclean all
bear: $(OBJ_FILES) $(TEST_OBJ_FILES)
test-fsanitize: $(TEST_TARGET)-FSANITIZE
- $(TEST_TARGET)-FSANITIZE
test:
- cmake -S . -B build
- cmake --build build
- cd build && ctest -V
norminette:
norminette -R CheckForbiddenSourceHeader -R CheckDefine src
############ PRINTING ##################
#Phony targets
.PHONY: all bonus clean fclean re bear test-fsanitize norminette
#Printing
print_srcs:
@echo $(SRC_FILES)
print_srcs_bonus:
@echo $(SRC_FILES_BONUS)
print_objs:
@echo $(OBJ_FILES)
print_objs_bonus:
@echo $(OBJ_FILES_BONUS)
print_test_files:
@echo $(TEST_FILES)
print_test_objs:
@echo $(TEST_OBJ_FILES)
print_test_target:
@echo $(TEST_TARGET)
#end