1
+ # ---------------------------------------------------------------------------------
2
+ .SUFFIXES :
3
+ # ---------------------------------------------------------------------------------
4
+
5
+ ifeq ($(strip $(DEVKITPRO ) ) ,)
6
+ $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
7
+ endif
8
+
9
+ TOPDIR ?= $(CURDIR )
10
+ include $(DEVKITPRO ) /libnx/switch_rules
11
+
12
+ # ---------------------------------------------------------------------------------
13
+ # TARGET is the name of the output
14
+ # BUILD is the directory where object files & intermediate files will be placed
15
+ # SOURCES is a list of directories containing source code
16
+ # DATA is a list of directories containing data files
17
+ # INCLUDES is a list of directories containing header files
18
+ # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
19
+ #
20
+ # NO_ICON: if set to anything, do not use icon.
21
+ # NO_NACP: if set to anything, no .nacp file is generated.
22
+ # APP_TITLE is the name of the app stored in the .nacp file (Optional)
23
+ # APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
24
+ # APP_VERSION is the version of the app stored in the .nacp file (Optional)
25
+ # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
26
+ # ICON is the filename of the icon (.jpg), relative to the project folder.
27
+ # If not set, it attempts to use one of the following (in this order):
28
+ # - <Project name>.jpg
29
+ # - icon.jpg
30
+ # - <libnx folder>/default_icon.jpg
31
+ #
32
+ # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
33
+ # If not set, it attempts to use one of the following (in this order):
34
+ # - <Project name>.json
35
+ # - config.json
36
+ # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
37
+ # of a homebrew executable (.nro). This is intended to be used for sysmodules.
38
+ # NACP building is skipped as well.
39
+ # ---------------------------------------------------------------------------------
40
+
41
+ APP_TITLE := BotW Unexplored
42
+ APP_AUTHOR := BigBear
43
+
44
+ TARGET := $(notdir $(CURDIR ) )
45
+ BUILD := build
46
+ SOURCES := source source/Graphics
47
+ DATA := data
48
+ INCLUDES := include
49
+ ROMFS := romfs
50
+
51
+ # ---------------------------------------------------------------------------------
52
+ # options for code generation
53
+ # ---------------------------------------------------------------------------------
54
+ ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
55
+
56
+ CFLAGS := -g -Wall -O2 -ffunction-sections \
57
+ $(ARCH ) $(DEFINES ) ` freetype-config --cflags `
58
+
59
+ CFLAGS += $(INCLUDE ) -D__SWITCH__
60
+
61
+ CXXFLAGS := $(CFLAGS ) -fno-rtti -fno-exceptions
62
+
63
+ ASFLAGS := -g $(ARCH )
64
+ LDFLAGS = -specs=$(DEVKITPRO ) /libnx/switch.specs -g $(ARCH ) -Wl,-Map,$(notdir $* .map)
65
+
66
+ LIBS := -lglad -lEGL -lglapi -ldrm_nouveau -lnx ` freetype-config --libs `
67
+
68
+ # ---------------------------------------------------------------------------------
69
+ # list of directories containing libraries, this must be the top level containing
70
+ # include and lib
71
+ # ---------------------------------------------------------------------------------
72
+ LIBDIRS := $(PORTLIBS ) $(LIBNX )
73
+
74
+
75
+ # ---------------------------------------------------------------------------------
76
+ # no real need to edit anything past this point unless you need to add additional
77
+ # rules for different file extensions
78
+ # ---------------------------------------------------------------------------------
79
+ ifneq ($(BUILD ) ,$(notdir $(CURDIR ) ) )
80
+ # ---------------------------------------------------------------------------------
81
+
82
+ export OUTPUT := $(CURDIR ) /$(TARGET )
83
+ export TOPDIR := $(CURDIR )
84
+
85
+ export VPATH := $(foreach dir,$(SOURCES ) ,$(CURDIR ) /$(dir ) ) \
86
+ $(foreach dir,$(DATA ) ,$(CURDIR ) /$(dir ) )
87
+
88
+ export DEPSDIR := $(CURDIR ) /$(BUILD )
89
+
90
+ CFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .c) ) )
91
+ CPPFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .cpp) ) )
92
+ SFILES := $(foreach dir,$(SOURCES ) ,$(notdir $(wildcard $(dir ) /* .s) ) )
93
+ BINFILES := $(foreach dir,$(DATA ) ,$(notdir $(wildcard $(dir ) /* .* ) ) )
94
+
95
+ # ---------------------------------------------------------------------------------
96
+ # use CXX for linking C++ projects, CC for standard C
97
+ # ---------------------------------------------------------------------------------
98
+ ifeq ($(strip $(CPPFILES ) ) ,)
99
+ # ---------------------------------------------------------------------------------
100
+ export LD := $(CC)
101
+ # ---------------------------------------------------------------------------------
102
+ else
103
+ # ---------------------------------------------------------------------------------
104
+ export LD := $(CXX)
105
+ # ---------------------------------------------------------------------------------
106
+ endif
107
+ # ---------------------------------------------------------------------------------
108
+
109
+ export OFILES_BIN := $(addsuffix .o,$(BINFILES ) )
110
+ export OFILES_SRC := $(CPPFILES:.cpp=.o ) $(CFILES:.c=.o ) $(SFILES:.s=.o )
111
+ export OFILES := $(OFILES_BIN ) $(OFILES_SRC )
112
+ export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES ) ) )
113
+
114
+ export INCLUDE := $(foreach dir,$(INCLUDES ) ,-I$(CURDIR ) /$(dir ) ) \
115
+ $(foreach dir,$(LIBDIRS ) ,-I$(dir ) /include) \
116
+ -I$(CURDIR ) /$(BUILD )
117
+
118
+ export LIBPATHS := $(foreach dir,$(LIBDIRS ) ,-L$(dir ) /lib)
119
+
120
+ ifeq ($(strip $(CONFIG_JSON ) ) ,)
121
+ jsons := $(wildcard *.json)
122
+ ifneq (,$(findstring $(TARGET).json,$(jsons)))
123
+ export APP_JSON := $(TOPDIR)/$(TARGET).json
124
+ else
125
+ ifneq (,$(findstring config.json,$(jsons)))
126
+ export APP_JSON := $(TOPDIR)/config.json
127
+ endif
128
+ endif
129
+ else
130
+ export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
131
+ endif
132
+
133
+ ifeq ($(strip $(ICON ) ) ,)
134
+ icons := $(wildcard *.jpg)
135
+ ifneq (,$(findstring $(TARGET).jpg,$(icons)))
136
+ export APP_ICON := $(TOPDIR)/$(TARGET).jpg
137
+ else
138
+ ifneq (,$(findstring icon.jpg,$(icons)))
139
+ export APP_ICON := $(TOPDIR)/icon.jpg
140
+ endif
141
+ endif
142
+ else
143
+ export APP_ICON := $(TOPDIR)/$(ICON)
144
+ endif
145
+
146
+ ifeq ($(strip $(NO_ICON ) ) ,)
147
+ export NROFLAGS += --icon=$(APP_ICON)
148
+ endif
149
+
150
+ ifeq ($(strip $(NO_NACP ) ) ,)
151
+ export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
152
+ endif
153
+
154
+ ifneq ($(APP_TITLEID ) ,)
155
+ export NACPFLAGS += --titleid=$(APP_TITLEID)
156
+ endif
157
+
158
+ ifneq ($(ROMFS ) ,)
159
+ export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
160
+ endif
161
+
162
+ .PHONY : $(BUILD ) clean all
163
+
164
+ # ---------------------------------------------------------------------------------
165
+ all : $(BUILD )
166
+
167
+ $(BUILD ) :
168
+ @[ -d $@ ] || mkdir -p $@
169
+ @$(MAKE ) --no-print-directory -C $(BUILD ) -f $(CURDIR ) /Makefile
170
+
171
+ # ---------------------------------------------------------------------------------
172
+ clean :
173
+ @echo clean ...
174
+ ifeq ($(strip $(APP_JSON ) ) ,)
175
+ @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
176
+ else
177
+ @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
178
+ endif
179
+
180
+
181
+ # ---------------------------------------------------------------------------------
182
+ else
183
+ .PHONY : all
184
+
185
+ DEPENDS := $(OFILES:.o=.d )
186
+
187
+ # ---------------------------------------------------------------------------------
188
+ # main targets
189
+ # ---------------------------------------------------------------------------------
190
+ ifeq ($(strip $(APP_JSON ) ) ,)
191
+
192
+ all : $(OUTPUT ) .nro
193
+
194
+ ifeq ($(strip $(NO_NACP ) ) ,)
195
+ $(OUTPUT ) .nro : $(OUTPUT ) .elf $(OUTPUT ) .nacp
196
+ else
197
+ $(OUTPUT ) .nro : $(OUTPUT ) .elf
198
+ endif
199
+
200
+ else
201
+
202
+ all : $(OUTPUT ) .nsp
203
+
204
+ $(OUTPUT ) .nsp : $(OUTPUT ) .nso $(OUTPUT ) .npdm
205
+
206
+ $(OUTPUT ) .nso : $(OUTPUT ) .elf
207
+
208
+ endif
209
+
210
+ $(OUTPUT ) .elf : $(OFILES )
211
+
212
+ $(OFILES_SRC ) : $(HFILES_BIN )
213
+
214
+ # ---------------------------------------------------------------------------------
215
+ # you need a rule like this for each extension you use as binary data
216
+ # ---------------------------------------------------------------------------------
217
+ % .bin.o % _bin.h : % .bin
218
+ # ---------------------------------------------------------------------------------
219
+ @echo $(notdir $<)
220
+ @$(bin2o)
221
+
222
+ -include $(DEPENDS )
223
+
224
+ # ---------------------------------------------------------------------------------------
225
+ endif
226
+ # ---------------------------------------------------------------------------------------
0 commit comments