-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (82 loc) · 2.07 KB
/
Makefile
File metadata and controls
106 lines (82 loc) · 2.07 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Load .env file
ifneq (,$(wildcard ./.env))
include .env
export
endif
EXECUTABLE_NAME := yali
TARGET := $(EXECUTABLE_NAME).prg
PLATFORM := c128
BUILD_TYPE ?= Debug
SRC_DIR := src
ifeq ($(BUILD_TYPE),Release)
BUILD_DIR := build-$(PLATFORM)-release
else
BUILD_DIR := build-$(PLATFORM)-debug
endif
TESTS_DIR := tests
SOURCES := $(wildcard $(SRC_DIR)/*.c)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
ASSEMBLY := $(wildcard $(SRC_DIR)/*.asm)
TESTS := $(wildcard $(TESTS_DIR)/*.c)
CC65_BIN_PATH := $(CC65_PATH)/bin
CC65_LIB_PATH := $(CC65_PATH)/lib
CC65 := $(CC65_BIN_PATH)/cc65
CA65 := $(CC65_BIN_PATH)/ca65
LD65 := $(CC65_BIN_PATH)/ld65
WARNINGS := const-comparison,$\
error,$\
no-effect,$\
pointer-sign,$\
remap-zero,$\
return-type,$\
struct-param,$\
unknown-pragma,$\
unreachable-code,$\
unused-func,$\
unused-label,$\
unused-param,$\
unused-var,$\
const-overflow
CFLAGS := -t $(PLATFORM) -W $(WARNINGS)
ifeq ($(BUILD_TYPE),Debug)
CFLAGS += -g
else
CFLAGS += -Osir -Cl -DNDEBUG
endif
AFLAGS :=
ifeq ($(BUILD_TYPE),Debug)
AFLAGS += -g
endif
LDFLAGS := -t $(PLATFORM)
ifeq ($(BUILD_TYPE),Debug)
LDFLAGS += -m $(BUILD_DIR)/$(EXECUTABLE_NAME).map -Ln $(BUILD_DIR)/$(EXECUTABLE_NAME).lbl
endif
ASMFILES := $(patsubst %.c,$(BUILD_DIR)/%.s,$(notdir $(SOURCES)))
OBJFILES := $(patsubst %.c,$(BUILD_DIR)/%.o,$(notdir $(SOURCES)))
ASMOBJFILES := $(patsubst %.asm,$(BUILD_DIR)/%.o,$(notdir $(ASSEMBLY)))
.PHONY: all clean lint format test
all: $(BUILD_DIR)/$(TARGET)
# Disable built-in rules
%.o: %.c
# Don't delete object and assembly files
.PRECIOUS: $(BUILD_DIR)/%.o $(BUILD_DIR)/%.s
# All assembly files depend on all headers: Trigger total rebuild when a header changes
$(ASMFILES): $(HEADERS)
$(BUILD_DIR):
mkdir -p $@
$(BUILD_DIR)/%.s: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC65) $(CFLAGS) -o $@ $<
$(BUILD_DIR)/%.s: $(SRC_DIR)/%.asm
cp $< $@
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.s
$(CA65) $(AFLAGS) $<
$(BUILD_DIR)/$(TARGET): $(OBJFILES) $(ASMOBJFILES)
$(LD65) -o $@ $(LDFLAGS) $^ $(CC65_LIB_PATH)/$(PLATFORM).lib
clean:
$(RM) -r $(BUILD_DIR)/*
lint:
./tools lint
format:
./tools format
test:
./tools test