-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (107 loc) · 3.61 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
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Adrian "asie" Siekierka, 2023
WONDERFUL_TOOLCHAIN ?= /opt/wonderful
TARGET = wswan/medium
include $(WONDERFUL_TOOLCHAIN)/target/$(TARGET)/makedefs.mk
# Metadata
# --------
NAME := parallax
# Source code paths
# -----------------
INCLUDEDIRS := include
SOURCEDIRS := src
ASSETDIRS := assets
CBINDIRS := cbin
# Defines passed to all files
# ---------------------------
DEFINES :=
# Libraries
# ---------
LIBS := -lwsx -lws
LIBDIRS := $(WF_TARGET_DIR)
# Build artifacts
# ---------------
BUILDDIR := build
ELF := build/$(NAME).elf
ELF_STAGE1 := build/$(NAME)_stage1.elf
ROM := $(NAME).wsc
# Verbose flag
# ------------
ifeq ($(V),1)
_V :=
else
_V := @
endif
# Source files
# ------------
ifneq ($(ASSETDIRS),)
SOURCES_WFPROCESS := $(shell find -L $(ASSETDIRS) -name "*.lua")
INCLUDEDIRS += $(addprefix $(BUILDDIR)/,$(ASSETDIRS))
endif
ifneq ($(CBINDIRS),)
SOURCES_CBIN := $(shell find -L $(CBINDIRS) -name "*.bin")
INCLUDEDIRS += $(addprefix $(BUILDDIR)/,$(CBINDIRS))
endif
SOURCES_S := $(shell find -L $(SOURCEDIRS) -name "*.s")
SOURCES_C := $(shell find -L $(SOURCEDIRS) -name "*.c")
# Compiler and linker flags
# -------------------------
WARNFLAGS := -Wall
INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \
$(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 -O2
LDFLAGS := -T$(WF_LDSCRIPT) $(LIBDIRSFLAGS) \
$(WF_ARCH_LDFLAGS) $(LIBS)
BUILDROMFLAGS :=
# Intermediate build files
# ------------------------
OBJS_ASSETS := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_CBIN))) \
$(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_WFPROCESS)))
OBJS_SOURCES := $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_S))) \
$(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SOURCES_C)))
OBJS := $(OBJS_ASSETS) $(OBJS_SOURCES)
DEPS := $(OBJS:.o=.d)
# Targets
# -------
.PHONY: all clean
all: $(ROM) compile_commands.json
$(ROM) $(ELF): $(ELF_STAGE1)
@echo " ROM $@"
$(_V)$(BUILDROM) -o $(ROM) --output-elf $(ELF) $(BUILDROMFLAGS) $<
$(ELF_STAGE1): $(OBJS)
@echo " LD $@"
$(_V)$(CC) -r -o $(ELF_STAGE1) $(OBJS) $(WF_CRT0) $(LDFLAGS)
clean:
@echo " CLEAN"
$(_V)$(RM) $(ROM) $(BUILDDIR) compile_commands.json
compile_commands.json: $(OBJS) | Makefile
@echo " MERGE compile_commands.json"
$(_V)$(WF)/bin/wf-compile-commands-merge $@ $(patsubst %.o,%.cc.json,$^)
# Rules
# -----
$(BUILDDIR)/%.s.o : %.s | $(OBJS_ASSETS)
@echo " AS $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(ASFLAGS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
$(BUILDDIR)/%.c.o : %.c | $(OBJS_ASSETS)
@echo " CC $<"
@$(MKDIR) -p $(@D)
$(_V)$(CC) $(CFLAGS) -MMD -MP -MJ $(patsubst %.o,%.cc.json,$@) -c -o $@ $<
$(BUILDDIR)/%.bin.o $(BUILDDIR)/%_bin.h : %.bin
@echo " BIN2C $<"
@$(MKDIR) -p $(@D)
$(_V)$(WF)/bin/wf-bin2c -a 2 --address-space __far $(@D) $<
$(_V)$(CC) $(CFLAGS) -MMD -MP -c -o $(BUILDDIR)/$*.bin.o $(BUILDDIR)/$*_bin.c
$(BUILDDIR)/%.lua.o : %.lua
@echo " PROCESS $<"
@$(MKDIR) -p $(@D)
$(_V)$(WF)/bin/wf-process -o $(BUILDDIR)/$*.c -t $(TARGET) --depfile $(BUILDDIR)/$*.lua.d --depfile-target $(BUILDDIR)/$*.lua.o $<
$(_V)$(CC) $(CFLAGS) -MMD -MP -c -o $(BUILDDIR)/$*.lua.o $(BUILDDIR)/$*.c
# Include dependency files if they exist
# --------------------------------------
-include $(DEPS)