-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
84 lines (57 loc) · 2.45 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
CC := gcc
TARGET :=
TST_TARGET := tst_runner
SRC_DIR := src
INC_DIR := inc
BUILD_DIR := obj
TARGET_DIR := bin
LIB_DIR := lib
OBJ_EXT := o
SRC_EXT := c
DEP_EXT := d
TST_FMT := *_test*
CFLAGS := -Wall -Wextra
DFLAGS := -MMD -MP
LIB :=
INC := -I$(INC_DIR) -I/usr/local/include
INC_DEP := -I$(INC_DIR)
# -------------------------------------------------------------------
# TRY NOT TO EDIT BELOW
# -------------------------------------------------------------------
SOURCES := $(shell find $(SRC_DIR) -type f -name *.$(SRC_EXT) ! -iname "$(TST_FMT)")
OBJECTS := $(patsubst $(SRC_DIR)/%, $(BUILD_DIR)/%, $(SOURCES:.$(SRC_EXT)=.$(OBJ_EXT)))
all: directories $(TARGET)
# -------------------------------------------------------------------
TST_SOURCES := $(shell find $(SRC_DIR) -type f -name *.$(SRC_EXT) -iname "$(TST_FMT)")
TST_OBJECTS := $(patsubst $(SRC_DIR)/%, $(BUILD_DIR)/%, $(TST_SOURCES:.$(SRC_EXT)=.$(OBJ_EXT)))
test: directories $(TST_TARGET)
@echo "==============="
@./$(TARGET_DIR)/$(TST_TARGET)
# -------------------------------------------------------------------
remake: clean all
# -------------------------------------------------------------------
directories:
@mkdir -p $(TARGET_DIR) && echo "[OK] built $(TARGET_DIR)"
@mkdir -p $(BUILD_DIR) && echo "[OK] built $(BUILD_DIR)"
# -------------------------------------------------------------------
clean:
@rm -rf $(BUILD_DIR)/* && echo "[OK] cleaned $(BUILD_DIR)/"
@rm -f $(TARGET_DIR)/* && echo "[OK] cleaned $(TARGET_DIR)/"
# -------------------------------------------------------------------
cleaner: clean
@rm -rf $(BUILD_DIR) && echo "[OK] deleted $(BUILD_DIR)/"
@rm -rf $(TARGET_DIR) && echo "[OK] deleted $(TARGET_DIR)/"
# -------------------------------------------------------------------
-include $(OBJECTS:.$(OBJ_EXT)=.$(DEP_EXT))
# -------------------------------------------------------------------
$(TARGET): $(OBJECTS)
@$(CC) -o $(TARGET_DIR)/$@ $^ $(LIB) && echo "[OK] $@"
# -------------------------------------------------------------------
$(TST_TARGET): $(TST_OBJECTS)
@$(CC) -o $(TARGET_DIR)/$@ $^ $(LIB) && echo "[OK] $@"
# -------------------------------------------------------------------
$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(DFLAGS) $(INC) -c -o $@ $< && echo "[OK] $@"
# -------------------------------------------------------------------
.PHONY: remake, clean, all, resources, directories, cleaner, test