-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
61 lines (46 loc) · 1.15 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
# Compiler and flags
CC := gcc
CFLAGS := -Wall -Wextra
# Debug flags with sanitizers
DEBUG_FLAGS := -fsanitize=address,undefined
# Source and object files
SRC_DIR := ./src
INCLUDE_DIR := ./include
BIN_DIR := ./bin
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c, $(BIN_DIR)/%.o, $(SRC_FILES))
# Installation directory
INSTALL_DIR := /usr/local/bin
# Output target
TARGET := 2048
# Phony targets
.PHONY: all debug release run install uninstall clean
# Default target
all: debug
# Build rule
$(BIN_DIR)/$(TARGET): $(OBJ_FILES)
$(CC) -I $(INCLUDE_DIR) $(CFLAGS) $^ -o $@
# Compile source files
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c | $(BIN_DIR)
$(CC) -I $(INCLUDE_DIR) $(CFLAGS) -c $< -o $@
# Create bin directory
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Debug build
debug: CFLAGS += $(DEBUG_FLAGS)
debug: $(BIN_DIR)/$(TARGET)
# Release build
release: clean $(BIN_DIR)/$(TARGET)
# Compile and run
run: debug
$(BIN_DIR)/$(TARGET)
# Install the executable
install: release
cp $(BIN_DIR)/$(TARGET) $(INSTALL_DIR)
# Uninstall the executable
uninstall:
rm -f $(INSTALL_DIR)/$(TARGET)
# Clean up
clean:
rm -f $(BIN_DIR)/*.o
rm -f $(BIN_DIR)/$(TARGET)