-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
86 lines (71 loc) · 2.89 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
##################################################################################
# This file is under MIT License #
# https://mit-license.org/ #
# #
# Copyright (c) 2024 Totema #
# https://github.com/TotemaM #
##################################################################################
CC := gcc
VER :=
DBG = -g -O0 -Wall -Wextra -Wsign-compare -pedantic -Walloc-zero \
-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wformat-signedness \
-Winit-self -Wlogical-op -Wformat=2 -Wnull-dereference \
-Wsuggest-attribute=const -Wswitch-default -Wswitch -Wundef \
-Wduplicated-cond -Wduplicated-branches -Wunused-result -Wformat-security \
-Wformat-overflow -Wformat-truncation -Wformat-signedness
OUT_DIR := out
BLD_DIR := $(OUT_DIR)/build
$(shell mkdir -p $(OUT_DIR))
all: prog test
##################################################################################
# DEFAULT ENVIRONMENT #
##################################################################################
SRC_DIR := src
OUT := prog
SRC := $(shell find $(SRC_DIR) -type f -name *.c)
OBJ := $(patsubst $(SRC_DIR)/%.c, $(BLD_DIR)/$(SRC_DIR)/%.o, $(SRC))
INC := -I $(SRC_DIR)
LIB :=
DEP := $(OBJ:.o=.d)
prog: $(OBJ)
$(CC) $(VER) $(DBG) $^ -o $(OUT_DIR)/$(OUT) $(LIB) $(INC)
$(BLD_DIR)/$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(@D)
$(CC) $(VER) $(DBG) -MMD -MP -c $< -o $@ $(INC)
-include $(DEP)
##################################################################################
# TESTING ENVIRONMENT #
##################################################################################
TST_DIR := test
TST_OUT := test
TST_SRC := $(shell find $(TST_DIR) -type f -name '*.c')
TST_OBJ := $(patsubst $(TST_DIR)/%.c, $(BLD_DIR)/$(TST_DIR)/%.o, $(TST_SRC))
TST_OBJ += $(filter-out $(BLD_DIR)/$(SRC_DIR)/main.o $(BLD_DIR)/$(SRC_DIR)/main.d, $(OBJ))
TST_INC := $(INC) -I $(TST_DIR)
TST_LIB := $(LIB)
TST_DEP := $(TST_OBJ:.o=.d)
test: $(TST_OBJ)
$(CC) $(VER) $(DBG) $^ -o $(OUT_DIR)/$(TST_OUT) $(TST_LIB) $(TST_INC)
$(BLD_DIR)/$(TST_DIR)/%.o: $(TST_DIR)/%.c
mkdir -p $(@D)
$(CC) $(VER) $(DBG) -MMD -MP -c $< -o $@ $(TST_INC)
-include $(TST_DEP)
##################################################################################
# ALTERNATIVE TARGETS #
##################################################################################
# Address and memory leak sanitizing
lsan: DBG += -fsanitize=leak,address,undefined
lsan: all
# Thread Sanitizing
tsan: DBG += -fsanitize=thread,undefined
tsan: all
# Production build
prod: DBG := -O3
prod: all
##################################################################################
# FAKE TARGETS #
##################################################################################
.PHONY: clear
clear: # Delete build directory and program
rm -rf $(OUT_DIR)
clear