aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
blob: aac38568d2d1176f3d9a0c9320fa3b13137c9694 (plain)
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
RM = rm -f

TARGET = main

# platform is ds (desktop) or stm (stm32)
PLATFORM = ds
# if your editor uses compile_commands.json for autocomplete, you should run `make compile_commands.json` again

HOST=$(strip $(shell uname -o))

ifeq ($(PLATFORM),stm)
STM = true
include stm32.mk
endif
ifeq ($(PLATFORM),ds)
DESKTOP = true
include ds.mk
endif

SHARED_FLAGS += -g
SHARED_FLAGS += -Wall
SHARED_FLAGS += -Wextra
SHARED_FLAGS += -I.
# SHARED_FLAGS += -O1
LFLAGS += -lm
# LFLAGS += -lc
CFLAGS += $(if $(STM), -DHH_TARGET_STM32, )
CFLAGS += $(if $(DESKTOP), -DHH_TARGET_DESKTOP, )

LOCAL_SRCS += main.c \
							ppu/internals.c \
							ppu/ppu.c \
							demo.c \
							engine/engine.c \
							engine/sprite_controller.c \
							engine/player_controller.c \
							engine/draw_screen.c \
							engine/camera.c \
							engine/maths.c \
							engine/entity.c \
							engine/bullet.c \
							engine/title_screen.c \
							engine/animator.c \
							GameLoop/shop.c \
							GameLoop/startingScreen.c

CFLAGS += $(SHARED_FLAGS)
LFLAGS += $(SHARED_FLAGS)
AFLAGS += $(SHARED_FLAGS)

SRCS += $(LOCAL_SRCS)
SRCS += $(if $(STM), $(STM_SRCS), )
SRCS += $(if $(DESKTOP), $(DESKTOP_SRCS), )

ifeq ($(PLATFORM),stm)
OBJS := $(patsubst %.c,%-stm.o, $(patsubst %.s,%-stm.o, $(SRCS)))
all: $(TARGET).bin
endif
ifeq ($(PLATFORM),ds)
OBJS := $(patsubst %.c,%-ds.o, $(SRCS))
all: $(TARGET)
endif

%-stm.o: %.s
	$(CC) -c $(AFLAGS) $< -o $@

lib/%-stm.o: lib/%.c
	$(CC) -c $(CFLAGS) -w $< -o $@

%-stm.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

$(TARGET).elf: $(OBJS)
	$(LD) $^ $(LFLAGS) -o $@

$(TARGET).bin: $(TARGET).elf
	$(OC) -O binary $< $@
	$(OS) $<

PHONY += flash
flash: $(TARGET).bin
	st-flash --reset write $(TARGET).bin 0x08000000

%-ds.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

$(TARGET): $(OBJS)
	$(LD) $^ $(LFLAGS) -o $@

compile_commands.json: makefile stm32.mk ds.mk
	compiledb make -Bn
	../scripts/compiledb-full-path-mingw.sh compile_commands.json

PHONY += format
format:
	clang-format -i $(LOCAL_SRCS) $(DESKTOP_SRCS)
	clang-tidy --fix-errors $(LOCAL_SRCS) $(DESKTOP_SRCS)

PHONY += clean
clean:
	$(RM) $(TARGET).bin $(TARGET).elf $(OBJS)

.PHONY: $(PHONY)