-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (79 loc) · 2.9 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
# **************************************************************************** #
# PROGRAM #
# **************************************************************************** #
NAME = libmarg.a
# **************************************************************************** #
# VARS #
# **************************************************************************** #
UNAME_S := $(shell uname -s)
MAKE = make
CP = cp
MV = mv
MKDIR = mkdir -p
RM = rm -rf
MAX_OPTIONS ?= 50
# **************************************************************************** #
# COMPILER #
# **************************************************************************** #
CC = gcc
CPPFLAGS = -MMD
CFLAGS = -Wall -Wextra -Werror -Wpedantic -Wshadow
CFLAGS += -D MAX_OPTIONS=$(MAX_OPTIONS)
AR = ar
ARFLAGS = rcs
# **************************************************************************** #
# DIRS #
# **************************************************************************** #
SRC_DIR = src
OBJ_DIR = build
INC_DIR = include
# **************************************************************************** #
# SOURCES #
# **************************************************************************** #
SRC_FILES = \
marg.c \
marg_utils.c \
OBJ_FILES = $(SRC_FILES:%.c=%.o)
SRC = $(addprefix $(SRC_DIR)/, $(SRC_FILES))
OBJ = $(addprefix $(OBJ_DIR)/, $(OBJ_FILES))
DEP = $(OBJ:%.o=%.d)
# **************************************************************************** #
# FLAGS #
# **************************************************************************** #
CFLAGS += -I./$(INC_DIR)
# **************************************************************************** #
# RULES #
# **************************************************************************** #
PHONY := all
all: $(NAME)
$(NAME): $(OBJ)
$(AR) $(ARFLAGS) $@ $^
PHONY += debug
debug:: CFLAGS += -g3
debug:: $(NAME)
PHONY += sanitize
ifeq ($(UNAME_S),Linux)
sanitize:: CFLAGS += -g3 -fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=bounds -fsanitize=null
endif
ifeq ($(UNAME_S),Darwin)
sanitize:: CFLAGS += -g3 -fsanitize=address
endif
sanitize:: $(NAME)
PHONY += thread
thread:: CFLAGS += -g3 -fsanitize=thread
thread:: $(NAME)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR):
$(MKDIR) $(OBJ_DIR)
PHONY += clean
clean:
$(RM) $(OBJ_DIR)
PHONY += fclean
fclean: clean
$(RM) $(NAME)
PHONY += re
re:: fclean
re:: all
-include $(DEP)
.PHONY: $(PHONY)