-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (38 loc) · 1.06 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
.PHONY: all test run clean
#Compilation variables
CC = gcc
CFLAGS = -Wall -std=gnu11 -MMD -Wextra -ggdb
LDLIBS = -lreadline -lc
#Executable name
TARGET = slash
TEST_TARGET = test/test_slash
#Build directory
BUILD_DIR = build
SRC_DIR = src
TEST_DIR = test
#Source files
SOURCES = $(filter-out $(SRC_DIR)/$(TARGET).c, $(wildcard $(SRC_DIR)/*.c))
TEST_SOURCES = $(wildcard $(TEST_DIR)/*.c)
#Binaries names
OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/%.o)
TEST_OBJECTS = $(TEST_SOURCES:%.c=$(BUILD_DIR)/%.o)
TARGET_OBJECT = $(BUILD_DIR)/$(SRC_DIR)/$(TARGET).o
#Binaries dependencies
DEPENDENCIES = $(OBJECT:%.o=%.d) $(TEST_OBJECTS:%.o=%.d) $(TARGET_OBJECT:%.o:%.d)
#JOBS
all: $(TARGET)
run: $(TARGET)
@./$(TARGET)
test: $(TEST_TARGET)
@./$(TEST_TARGET)
-include $(DEPENDENCIES)
$(TARGET): $(TARGET_OBJECT) $(OBJECTS)
@$(CC) $(CFLAGS) $^ -o $(TARGET) $(LDLIBS)
$(TEST_TARGET): $(TEST_OBJECTS) $(OBJECTS)
@$(CC) $(CFLAGS) -o $(TEST_TARGET) $^
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -o $@ -c $<
clean:
@rm -rf $(BUILD_DIR)
@rm -f $(TARGET) $(TEST_TARGET)