-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (58 loc) · 1.61 KB
/
Copy pathMakefile
File metadata and controls
71 lines (58 loc) · 1.61 KB
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
62
63
64
65
66
67
68
69
70
71
# -------- Project --------
TARGET := quickbill
BUILD_DIR := build
SRC_DIR := src
DATA_DIR := data
# -------- Toolchain --------
CC := gcc
# Debug by default; toggle with `make MODE=release`
MODE ?= debug
CWARN := -Wall -Wextra -Wpedantic
CSTD := -std=c11
ifeq ($(MODE),release)
COPT := -O2 -DNDEBUG
else
COPT := -O0 -g
endif
CFLAGS := $(CSTD) $(CWARN) $(COPT)
# Windows exe suffix
ifeq ($(OS),Windows_NT)
EXE := .exe
RM := del /Q
MKDIR := mkdir
else
EXE :=
RM := rm -f
MKDIR := mkdir -p
endif
# -------- Sources / Objects --------
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC))
# -------- Default --------
.PHONY: all
all: $(TARGET)$(EXE)
# -------- Link --------
$(TARGET)$(EXE): $(OBJ)
@$(MKDIR) $(BUILD_DIR)
$(CC) $(CFLAGS) -o $@ $(OBJ)
# -------- Compile --------
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@$(MKDIR) $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# -------- Utilities --------
.PHONY: run
run: all
./$(TARGET)$(EXE)
.PHONY: clean
clean:
$(RM) $(BUILD_DIR)/* $(TARGET)$(EXE)
# Seed minimal runtime files if missing (safe defaults)
.PHONY: init
init:
@$(MKDIR) $(DATA_DIR)
@if [ ! -f "$(DATA_DIR)/cidupdate.txt" ]; then echo 1 > $(DATA_DIR)/cidupdate.txt; fi
@if [ ! -f "$(DATA_DIR)/password.txt" ] && [ -f "$(DATA_DIR)/password_sample.txt" ]; then cp $(DATA_DIR)/password_sample.txt $(DATA_DIR)/password.txt; fi
# Optional: code format (requires clang-format if installed)
.PHONY: format
format:
@command -v clang-format >/dev/null 2>&1 && clang-format -i $(SRC) || echo "clang-format not found; skipping"