-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
204 lines (154 loc) · 5.65 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Adrian "asie" Siekierka, 2023
WONDERFUL_TOOLCHAIN ?= /opt/wonderful
CONFIG ?= config.mk
TARGET = wswan/small
include $(WONDERFUL_TOOLCHAIN)/target/$(TARGET)/makedefs.mk
# Configuration
# -------------
include config/config.defaults.mk
include $(CONFIG)
CONFIG_FILES := config/config.defaults.mk $(CONFIG)
NAME_BIOS := $(NAME)BIOS-$(VERSION)-$(FLAVOR)
NAME_OS := $(NAME)OS-$(VERSION)-$(FLAVOR)
SRC_BIOS := bios bios/bank bios/comm bios/disp bios/key bios/sound bios/system bios/text bios/timer bios/util
SRC_OS := os
# Defines
# -------
SRC_BIOS += bios/comm/$(BIOS_COMM_DRIVER)
SRC_BIOS += bios/timer/$(BIOS_TIMER_RTC)
DEFINES += -DATHENA_FLAVOR_$(FLAVOR)
DEFINES += -DBIOS_BANK_MAPPER_$(BIOS_BANK_MAPPER)
DEFINES += -DBIOS_BANK_ROM_FORCE_COUNT=$(BIOS_BANK_ROM_FORCE_COUNT)
BIOS_BANK_MEMORY_IMPL := $(BIOS_BANK_MEMORY)
ifneq ($(filter $(BIOS_BANK_MEMORY),rom ram),)
DEFINES += -DBIOS_BANK_MAPPER_NO_PORT_CE_SUPPORT
endif
ifneq ($(filter $(BIOS_BANK_MEMORY),rom rom_ce),)
BIOS_BANK_MEMORY_IMPL := simple
DEFINES += -DBIOS_BANK_MAPPER_SIMPLE_ROM
endif
ifneq ($(filter $(BIOS_BANK_MEMORY),ram ram_ce),)
BIOS_BANK_MEMORY_IMPL := simple
DEFINES += -DBIOS_BANK_MAPPER_SIMPLE_RAM
endif
SRC_BIOS += bios/bank/$(BIOS_BANK_MEMORY_IMPL)
# Tool paths
# ----------
PYTHON := python3
BIN2S := $(WONDERFUL_TOOLCHAIN)/bin/wf-bin2s
# File paths
# ----------
BUILDDIR_SHARED := build/shared
BUILDDIR := build/$(FLAVOR)
DISTDIR := dist
BUILDDIR_BIOS := $(BUILDDIR)/$(SRC_BIOS)
BUILDDIR_OS := $(BUILDDIR)/$(SRC_OS)
ELF_BIOS := $(BUILDDIR)/$(NAME_BIOS).elf
ELF_OS := $(BUILDDIR)/$(NAME_OS).elf
MAP_BIOS := $(BUILDDIR)/$(NAME_BIOS).map
MAP_OS := $(BUILDDIR)/$(NAME_OS).map
RAW_BIOS := $(DISTDIR)/$(NAME_BIOS).raw
RAW_OS := $(DISTDIR)/$(NAME_OS).raw
BIN_OS := $(DISTDIR)/$(NAME_OS).bin
# Libraries
# ---------
LIBS := -lws
LIBDIRS := $(WF_ARCH_LIBDIRS)
# Verbose flag
# ------------
ifeq ($(V),1)
_V :=
else
_V := @
endif
# Source files
# ------------
SOURCES_BIOS_S := $(shell find -L $(SRC_BIOS) -maxdepth 1 -name "*.s")
SOURCES_BIOS_C := $(shell find -L $(SRC_BIOS) -maxdepth 1 -name "*.c")
SOURCES_OS_S := $(shell find -L $(SRC_OS) -maxdepth 1 -name "*.s")
SOURCES_OS_C := $(shell find -L $(SRC_OS) -maxdepth 1 -name "*.c")
# Compiler and linker flags
# -------------------------
WARNFLAGS := -Wall
INCLUDEFLAGS := $(foreach path,$(LIBDIRS),-isystem $(path)/include)
LIBDIRSFLAGS := $(foreach path,$(LIBDIRS),-L$(path)/lib)
ASFLAGS += -x assembler-with-cpp $(DEFINES) $(WF_ARCH_CFLAGS) \
$(INCLUDEFLAGS) -ffunction-sections -fdata-sections -fno-common
CFLAGS += -std=gnu11 $(WARNFLAGS) $(DEFINES) $(WF_ARCH_CFLAGS) \
$(INCLUDEFLAGS) -ffunction-sections -fdata-sections -fno-common -Os
LDFLAGS := $(LIBDIRSFLAGS) $(WF_ARCH_LDFLAGS) $(LIBS)
CFLAGS_BIOS := -Ibios
CFLAGS_OS := -Ios
# Intermediate build files
# ------------------------
OBJS_BIOS := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_BIOS_S))) \
$(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_BIOS_C)))
OBJS_OS := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_OS_S))) \
$(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_OS_C)))
OBJS_BIOS += $(BUILDDIR)/fonts/font_ank_dat.o $(BUILDDIR)/fonts/font_sjis_dat.o
OBJS := $(OBJS_BIOS) $(OBJS_OS)
DEPS := $(OBJS:.o=.d)
# Targets
# -------
.PHONY: all clean
all: $(RAW_BIOS) $(RAW_OS) $(BIN_OS)
$(BIN_OS): $(RAW_OS)
@echo " UPDATE $@"
@$(MKDIR) -p $(@D)
$(_V)$(PYTHON) tools/convert_update.py $< $@
$(RAW_BIOS): $(ELF_BIOS)
@echo " OBJCOPY $@"
@$(MKDIR) -p $(@D)
$(_V)$(OBJCOPY) -O binary $< $@
$(RAW_OS): $(ELF_OS)
@echo " OBJCOPY $@"
@$(MKDIR) -p $(@D)
$(_V)$(OBJCOPY) -O binary $< $@
$(ELF_BIOS): $(OBJS_BIOS) bios/link.ld
@echo " LD $@"
@$(MKDIR) -p $(@D)
$(_V)$(CC) -o $(ELF_BIOS) -Tbios/link.ld -Wl,-Map,$(MAP_BIOS) -Wl,--gc-sections $(OBJS_BIOS) $(LDFLAGS)
$(ELF_OS): $(OBJS_OS) os/link.ld
@echo " LD $@"
@$(MKDIR) -p $(@D)
$(_V)$(CC) -o $(ELF_OS) -Tos/link.ld -Wl,-Map,$(MAP_OS) -Wl,--gc-sections $(OBJS_OS) $(LDFLAGS)
clean:
@echo " CLEAN"
$(_V)$(RM) $(DISTDIR) $(BUILDDIR)
# Rules
# -----
$(BUILDDIR)/fonts/font_ank_dat.o : $(BIOS_FONT_ANK) tools/ank_font_pack.py $(CONFIG_FILES)
@echo " FONT $<"
@mkdir -p $(@D)
$(PYTHON) tools/ank_font_pack.py $(BIOS_FONT_ANK) $(patsubst %_dat.o,%.dat,$@)
@echo " BIN2S $(patsubst %_dat.o,%.dat,$@)"
$(_V)$(BIN2S) --section ".text" $(@D) $(patsubst %_dat.o,%.dat,$@)
$(_V)$(CC) $(ASFLAGS) -c -o $@ $(patsubst %.o,%.s,$@)
$(BUILDDIR)/fonts/font_sjis_dat.o : $(BIOS_FONT_SJIS) tools/sjis_font_pack.py $(CONFIG_FILES)
@echo " FONT $<"
@mkdir -p $(@D)
$(PYTHON) tools/sjis_font_pack.py $(BIOS_FONT_SJIS) $(patsubst %_dat.o,%.dat,$@)
@echo " BIN2S $(patsubst %_dat.o,%.dat,$@)"
$(_V)$(BIN2S) --section ".text" $(@D) $(patsubst %_dat.o,%.dat,$@)
$(_V)$(CC) $(ASFLAGS) -c -o $@ $(patsubst %.o,%.s,$@)
$(BUILDDIR)/bios/%.s.o : bios/%.s $(CONFIG_FILES)
@echo " AS $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(ASFLAGS) $(CFLAGS_BIOS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
$(BUILDDIR)/bios/%.c.o : bios/%.c $(CONFIG_FILES)
@echo " CC $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(CFLAGS) $(CFLAGS_BIOS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
$(BUILDDIR)/os/%.s.o : os/%.s $(CONFIG_FILES)
@echo " AS $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(ASFLAGS) $(CFLAGS_OS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
$(BUILDDIR)/os/%.c.o : os/%.c $(CONFIG_FILES)
@echo " CC $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(CFLAGS) $(CFLAGS_OS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
# Include dependency files if they exist
# --------------------------------------
-include $(DEPS)