-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.mk
118 lines (88 loc) · 2.8 KB
/
base.mk
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
107
108
109
110
111
112
113
114
115
116
117
118
DEBUG = -g -gdwarf-4
AFLAGS += --fatal-warnings
CFLAGS += -falign-functions=4 -ffunction-sections -fdata-sections -fshort-enums -ffreestanding -nostdlib -fno-builtin
CFLAGS += -Wall -Werror -Wfatal-errors
CFLAGS += -Wno-array-bounds
#CFLAGS += -Wno-error=narrowing -Wno-error=unused-variable -Wno-error=array-bounds=
CFLAGS += -Wno-error=maybe-uninitialized
CFLAGS += -Wno-error=unused-but-set-variable
CFLAGS += -Wno-error=unused-variable
CFLAGS += -Wno-error=unused-function
CXXFLAGS += -fno-exceptions -fno-non-call-exceptions -fno-rtti -fno-threadsafe-statics
# --print-gc-sections
LDFLAGS += --gc-sections --no-warn-rwx-segment --print-memory-usage --entry=_start --orphan-handling=error
DEPFLAGS = -MMD -MP
CC = $(TARGET)gcc
CXX = $(TARGET)g++
AS = $(TARGET)as
LD = $(TARGET)ld
OBJCOPY = $(TARGET)objcopy
OBJDUMP = $(TARGET)objdump
LIBGCC = $(shell $(CC) -print-file-name=libgcc.a)
define BUILD_BINARY_O
$(OBJCOPY) \
-I binary $(OBJARCH) \
--rename-section .data=.data.$(basename $@) \
$< $@
endef
makefile_path := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
makefile_relative = $(shell realpath --relative-to $(makefile_path) $(1))
as_obj_binary = _binary_$(subst .,_,$(subst /,_,$(subst .h,,$(call makefile_relative,$(1)))))
define BUILD_BINARY_H
@echo gen $(call makefile_relative,$@)
@echo '#pragma once' > $@
@echo '' >> $@
@echo '#include <stdint.h>' >> $@
@echo '' >> $@
@echo '#ifdef __cplusplus' >> $@
@echo 'extern "C" {' >> $@
@echo '#endif' >> $@
@echo '' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_start __asm("$(call as_obj_binary,$@)_start");' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_end __asm("$(call as_obj_binary,$@)_end");' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_size __asm("$(call as_obj_binary,$@)_size");' >> $@
@echo '' >> $@
@echo '#ifdef __cplusplus' >> $@
@echo '}' >> $@
@echo '#endif' >> $@
endef
%.txt.o: %.txt
$(BUILD_BINARY_O)
%.txt.h: %.txt
$(BUILD_BINARY_H)
%.bin.o: %.bin
$(BUILD_BINARY_O)
%.pcm.o: %.pcm
$(BUILD_BINARY_O)
%.data.o: %.data
$(BUILD_BINARY_O)
%.data.h: %.data
$(BUILD_BINARY_H)
%.data.pal.o: %.data.pal
$(BUILD_BINARY_O)
%.data.pal.h: %.data.pal
$(BUILD_BINARY_H)
%.alpha.h: %.alpha
$(BUILD_BINARY_H)
%.alpha.o: %.alpha
$(BUILD_BINARY_O)
%.alpha.pal.h: %.alpha.pal
$(BUILD_BINARY_H)
%.alpha.pal.o: %.alpha.pal
$(BUILD_BINARY_O)
%.vq.h: %.vq
$(BUILD_BINARY_H)
%.vq.o: %.vq
$(BUILD_BINARY_O)
%.o: %.s
$(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@
%.o: %.c
$(CC) $(CARCH) $(CFLAGS) -std=gnu23 $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@
%.o: %.cpp
$(CXX) $(CARCH) $(CFLAGS) -std=c++23 $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@
%.elf:
$(LD) $(LDFLAGS) -L $(LIB) -T $(LDSCRIPT) $^ -o $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
du -b $@
-include $(shell find -type f -name '*.d')