-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
49 lines (40 loc) · 987 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
# C compiler:
CC := gcc
CFLAGS := -std=c99 -Wall -Wextra -Werror
# Directories:
SRC_DIR := src
BIN_DIR := bin
# Files:
SRCS := $(wildcard $(SRC_DIR)/*.c)
HDRS := $(wildcard $(SRC_DIR)/*.h)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BIN_DIR)/%.o)
EXEC := $(BIN_DIR)/brainiac
# Add '.exe' extension to executable on Windows:
ifeq ($(OS),Windows_NT)
EXEC := $(EXEC).exe
endif
# Build Brainiac in release mode:
.PHONY: all
all: CFLAGS += -O2 -flto
all: $(EXEC)
# Build Brainiac in debug mode:
.PHONY: debug
debug: CFLAGS += -DBRAINIAC_DEBUG -g3 -Og
debug: $(EXEC)
# Clean binaries directory:
.PHONY: clean
clean:
@echo "Cleaning '$(BIN_DIR)'..."
@rm -rf -- $(BIN_DIR)
# Make binaries directory:
$(BIN_DIR):
@echo "Making '$@'..."
@mkdir $(BIN_DIR)
# Compile object from source:
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c $(HDRS) | $(BIN_DIR)
@echo "Compiling '$<'..."
@$(CC) $(CFLAGS) -c $< -o $@
# Link executable from objects:
$(EXEC): $(OBJS)
@echo "Linking '$@'..."
@$(CC) $(CFLAGS) $^ -o $@