-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
48 lines (35 loc) · 946 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
# Compiler
CC = gcc
# Directories
BUILD_DIR = build
DEBUG_DIR = $(BUILD_DIR)/debug
RELEASE_DIR = $(BUILD_DIR)/release
SRC_DIR = src
TEST_DIR = test
# Project name
PROJECT_NAME = purr
# Source files
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(DEBUG_DIR)/%.o,$(SRC_FILES))
# Flags
CFLAGS = -Wall -Wextra -I$(SRC_DIR) -g
LDFLAGS = -lm
# Targets
.PHONY: all debug release clean run
all: debug release
debug: $(DEBUG_DIR)/$(PROJECT_NAME)
release: $(RELEASE_DIR)/$(PROJECT_NAME)
$(DEBUG_DIR)/$(PROJECT_NAME): $(OBJ_FILES)
@mkdir -p $(DEBUG_DIR)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(RELEASE_DIR)/$(PROJECT_NAME): CFLAGS += -O2
$(RELEASE_DIR)/$(PROJECT_NAME): $(SRC_FILES)
@mkdir -p $(RELEASE_DIR)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(DEBUG_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(DEBUG_DIR)
$(CC) $(CFLAGS) -c $< -o $@
run: debug
@$(DEBUG_DIR)/$(PROJECT_NAME) $(ARGS)
clean:
@rm -rf $(BUILD_DIR)