-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
42 lines (30 loc) · 880 Bytes
/
Copy pathMakefile
File metadata and controls
42 lines (30 loc) · 880 Bytes
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
CC := gcc
BASE_FLAGS = -I. -Wall -Wextra -Wstrict-prototypes -Wno-builtin-declaration-mismatch --std=gnu23
DEBUG_FLAGS := $(BASE_FLAGS) -g -O0 -DDEBUG -Wno-unused
RELEASE_FLAGS := $(BASE_FLAGS) -O2 -DNDEBUG
# По умолчанию debug, можно переопределить через make MODE=release
MODE ?= debug
BUILD_BASE_DIR := build
BUILD_DIR = $(BUILD_BASE_DIR)/$(MODE)
SRC_DIR := src
OBJ_DIR = $(BUILD_DIR)/obj
TARGET = $(BUILD_DIR)/program.exe
SOURCES := $(shell find $(SRC_DIR) -name "*.c")
OBJECTS := $(patsubst src/%.c, $(OBJ_DIR)/%.o, $(SOURCES))
ifeq ($(MODE), debug)
CFLAGS = $(DEBUG_FLAGS)
else
CFLAGS = $(RELEASE_FLAGS)
endif
all: build
$(TARGET): $(OBJECTS)
$(CC) $^ -o $@
$(OBJ_DIR)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: build run clean
build: $(TARGET)
run: build
./$(TARGET)
clean:
rm -rf build