-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
149 lines (104 loc) · 3.4 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: GPL-3.0-only
#
# Copyright (c) 2021 Antonio Niño Díaz
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro)
endif
# User options
# ------------
TARGET := $(notdir $(CURDIR))
GAME_TITLE := "UCITYADVANCE"
GAME_CODE := "UCAD"
BUILDDIR := build
SOURCEDIR := source
INCLUDEDIRS := source
BUILTASSETS := built_assets
LIBUGBA := $(CURDIR)/libugba
UMOD_PLAYER := $(CURDIR)/umod-player/player
LIBS := -lugba -lumod
LIBDIRS := $(LIBUGBA) $(UMOD_PLAYER)
# Look for source files
# ---------------------
CFILES := $(shell find $(SOURCEDIR) -type f -name '*.c')
CPPFILES := $(shell find $(SOURCEDIR) -type f -name '*.cpp')
SFILES := $(shell find $(SOURCEDIR) -type f -name '*.s')
OBJS := $(patsubst $(SOURCEDIR)/%.c,$(BUILDDIR)/%.o,$(CFILES)) \
$(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(CPPFILES)) \
$(patsubst $(SOURCEDIR)/%.s,$(BUILDDIR)/%.o,$(SFILES))
DEPS := $(OBJS:.o=.d)
# Files related to assets
ASSETCFILES := $(shell find $(BUILTASSETS) -type f -name '*.c')
INCLUDEDIRS += $(BUILTASSETS)
OBJS += $(patsubst $(BUILTASSETS)/%.c,$(BUILDDIR)/assets/%.o,$(ASSETCFILES))
# Includes
INCLUDES += $(foreach dir,$(INCLUDEDIRS),-I$(dir))
# Libraries
INCLUDES += $(foreach dir,$(LIBDIRS),-I$(dir)/include)
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
# Toolchain
# ---------
export PATH := $(DEVKITPRO)/tools/bin:$(DEVKITPRO)/devkitARM/bin:$(PATH)
PREFIX := arm-none-eabi-
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
AS := $(PREFIX)as
OBJCOPY := $(PREFIX)objcopy
# Use C++ compiler to link if there are C++ files
ifeq ($(strip $(CPPFILES)),)
LD := $(CC)
else
LD := $(CXX)
endif
# Other tools
MKDIR := mkdir
# Toolchain options
# -----------------
WARNFLAGS := -Wall -Wextra -Wunused-parameter
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -O2 -flto -mcpu=arm7tdmi -mtune=arm7tdmi \
$(WARNFLAGS) $(ARCH) $(INCLUDES) -D__GBA__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS := -g -flto $(ARCH) -Wl,-Map,$(BUILDDIR)/$(TARGET).map \
-Wno-stringop-overflow -Wno-stringop-overread
# Build options
# -------------
ifeq ($(V),1)
QUIET :=
else
QUIET := @
endif
# Build targets
# -------------
.PHONY: all clean
all : $(TARGET).gba
$(TARGET).gba: $(TARGET).elf
@echo " OBJCOPY $@"
$(QUIET)$(OBJCOPY) -O binary $< $@
@echo " GBAFIX $@"
$(QUIET)gbafix $@ -t$(GAME_TITLE) -c$(GAME_CODE)
$(TARGET).elf: $(OBJS)
@echo " LD $@"
$(QUIET)$(LD) $(LDFLAGS) -specs=gba.specs $(OBJS) $(LIBPATHS) $(LIBS) -o $@
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp
@echo " CXX $<"
@$(MKDIR) -p $(@D)
$(QUIET)$(CXX) -MMD -MP $(CXXFLAGS) -c $< -o
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
@echo " CC $<"
@$(MKDIR) -p $(@D)
$(QUIET)$(CC) -MMD -MP $(CFLAGS) -c $< -o $@
$(BUILDDIR)/assets/%.o: $(BUILTASSETS)/%.c
@echo " CC $<"
@$(MKDIR) -p $(@D)
$(QUIET)$(CC) -MMD -MP $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.s
@echo " AS $<"
@$(MKDIR) -p $(@D)
$(QUIET)$(CC) -MMD -MP -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
clean:
@echo " CLEAN"
@rm -fr $(BUILDDIR) $(TARGET).elf $(TARGET).gba
# Include dependency files if they exist
# --------------------------------------
-include $(DEPS)