-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (41 loc) · 1.1 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
BIN_DIR = bin
SRC_DIR = src
INC_DIR = include
BUILD_DIR = build
TARGET = $(BIN_DIR)/fat12-file-system
SRC = $(wildcard $(SRC_DIR)/*.c)
INCLUDE = -I ./$(INC_DIR)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
CC = gcc
FLAGS = -g
TEST_BIN_DIR = test/bin
TEST_SRC_DIR = test/src
TEST_BUILD_DIR = test/build
TEST_TARGET = $(TEST_BIN_DIR)/gtest
TEST_SRC = $(wildcard $(TEST_SRC_DIR)/*.cpp)
TEST_OBJ = $(TEST_SRC:$(TEST_SRC_DIR)/%.cpp=$(TEST_BUILD_DIR)/%.o)
TEST_CC = g++
TEST_FLAGS = -lgtest -lpthread
TARGETS = $(TARGET) $(TEST_TARGET)
proj: $(TARGET)
all: $(TARGETS)
$(TARGET): $(OBJ)
@mkdir -p $(BIN_DIR)
$(CC) $^ -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(INCLUDE) $(FLAGS) -c $< -o $@
$(TEST_TARGET): $(TEST_OBJ) $(filter-out $(BUILD_DIR)/fat12-file-system.o, $(OBJ))
@mkdir -p $(TEST_BIN_DIR)
$(TEST_CC) $^ -o $@ $(TEST_FLAGS)
$(TEST_BUILD_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp
@mkdir -p $(TEST_BUILD_DIR)
$(TEST_CC) $(INCLUDE) $(FLAGS) -c $< -o $@
clean:
rm -rf $(BIN_DIR)
rm -rf $(BUILD_DIR)
rm -rf $(TEST_BIN_DIR)
rm -rf $(TEST_BUILD_DIR)
run-test:
$(MAKE) all
./test/bin/gtest