-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (36 loc) · 865 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
46
47
48
49
50
# Compiler settings
CC := gcc
# Project structure
BUILD_DIR := build
SRC_DIR := ./
BUILD_TYPE ?= debug
TARGET ?= cgrad
ifeq ($(BUILD_TYPE),debug)
CFLAGS := -g -O0 -Wall -Werror
else ifeq ($(BUILD_TYPE),release)
CFLAGS := -O3 -Wall -Werror
else
$(error "Invalid BUILD_TYPE: $(BUILD_TYPE)")
endif
# Files
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC_FILES))
# Targets
EXECUTABLE := $(BUILD_DIR)/$(TARGET)-$(BUILD_TYPE)
# Phony targets
.PHONY: all clean debug release
all: $(EXECUTABLE)
run: $(EXECUTABLE)
./$(EXECUTABLE)
debug:
$(MAKE) BUILD_TYPE=debug
release:
$(MAKE) BUILD_TYPE=release
$(EXECUTABLE): $(OBJ_FILES) | $(BUILD_DIR)
$(CC) $(CFLAGS) $^ -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR):
mkdir -p $@
clean:
rm -rf $(BUILD_DIR)