-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
45 lines (33 loc) · 787 Bytes
/
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
# flags (-g3 for debug options)
CFLAGS ?= -Wall -Wextra -std=c11 -g3
# executable name
TARGET ?= out
# directories
SRC_DIR ?= src
HEADER_DIR ?= include
BUILD_DIR ?= build
CFLAGS += -I$(HEADER_DIR)
ifdef DEFINES
CFLAGS += $(DEFINES)
endif
ifdef TEST
CFLAGS += "-DTEST"
endif
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC_FILES))
# default target
all: all
# create build folder
$(BUILD_DIR):
mkdir -p "$@"
# build the executable inside the build directory
$(BUILD_DIR)/$(TARGET): $(OBJ_FILES)
gcc $(CFLAGS) $^ -o $@
# build object files from source files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
gcc $(CFLAGS) -c $< -o $@
.PHONY: all
all: $(BUILD_DIR) $(BUILD_DIR)/$(TARGET)
.PHONY: run
run: all
./$(BUILD_DIR)/$(TARGET)