Skip to content

Commit a0ce16d

Browse files
committed
add sdl2 demo using romfs for data
1 parent 25cdf12 commit a0ce16d

File tree

9 files changed

+435
-0
lines changed

9 files changed

+435
-0
lines changed

graphics/sdl2/sdl2-demo/Makefile

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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+
TARGET := $(notdir $(CURDIR))
41+
BUILD := build
42+
SOURCES := source
43+
DATA := data
44+
INCLUDES := include
45+
ROMFS := romfs
46+
47+
APP_TITLE := SDL2+mixer+image Demo
48+
APP_AUTHOR := carstene1ns
49+
50+
#---------------------------------------------------------------------------------
51+
# options for code generation
52+
#---------------------------------------------------------------------------------
53+
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
54+
55+
CFLAGS := `$(PREFIX)pkg-config --cflags sdl2 SDL2_mixer SDL2_image` -Wall -O2 -ffunction-sections \
56+
$(ARCH) $(DEFINES)
57+
58+
CFLAGS += $(INCLUDE) -D__SWITCH__
59+
60+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
61+
62+
ASFLAGS := -g $(ARCH)
63+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
64+
65+
LIBS := `$(PREFIX)pkg-config --libs sdl2 SDL2_mixer SDL2_image` \
66+
-lnx
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++ and libEGL dependent projects
97+
#---------------------------------------------------------------------------------
98+
export LD := $(CXX)
99+
100+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
101+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
102+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
103+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
104+
105+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
106+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
107+
-I$(CURDIR)/$(BUILD)
108+
109+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
110+
111+
ifeq ($(strip $(CONFIG_JSON)),)
112+
jsons := $(wildcard *.json)
113+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
114+
export APP_JSON := $(TOPDIR)/$(TARGET).json
115+
else
116+
ifneq (,$(findstring config.json,$(jsons)))
117+
export APP_JSON := $(TOPDIR)/config.json
118+
endif
119+
endif
120+
else
121+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
122+
endif
123+
124+
ifeq ($(strip $(ICON)),)
125+
icons := $(wildcard *.jpg)
126+
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
127+
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
128+
else
129+
ifneq (,$(findstring icon.jpg,$(icons)))
130+
export APP_ICON := $(TOPDIR)/icon.jpg
131+
endif
132+
endif
133+
else
134+
export APP_ICON := $(TOPDIR)/$(ICON)
135+
endif
136+
137+
ifeq ($(strip $(NO_ICON)),)
138+
export NROFLAGS += --icon=$(APP_ICON)
139+
endif
140+
141+
ifeq ($(strip $(NO_NACP)),)
142+
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
143+
endif
144+
145+
ifneq ($(APP_TITLEID),)
146+
export NACPFLAGS += --titleid=$(APP_TITLEID)
147+
endif
148+
149+
ifneq ($(ROMFS),)
150+
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
151+
endif
152+
153+
.PHONY: $(BUILD) clean all
154+
155+
#---------------------------------------------------------------------------------
156+
all: $(BUILD)
157+
158+
$(BUILD):
159+
@[ -d $@ ] || mkdir -p $@
160+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
161+
162+
#---------------------------------------------------------------------------------
163+
clean:
164+
@echo clean ...
165+
ifeq ($(strip $(APP_JSON)),)
166+
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
167+
else
168+
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
169+
endif
170+
171+
172+
#---------------------------------------------------------------------------------
173+
else
174+
.PHONY: all
175+
176+
DEPENDS := $(OFILES:.o=.d)
177+
178+
#---------------------------------------------------------------------------------
179+
# main targets
180+
#---------------------------------------------------------------------------------
181+
ifeq ($(strip $(APP_JSON)),)
182+
183+
all : $(OUTPUT).nro
184+
185+
ifeq ($(strip $(NO_NACP)),)
186+
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
187+
else
188+
$(OUTPUT).nro : $(OUTPUT).elf
189+
endif
190+
191+
else
192+
193+
all : $(OUTPUT).nsp
194+
195+
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
196+
197+
$(OUTPUT).nso : $(OUTPUT).elf
198+
199+
endif
200+
201+
$(OUTPUT).elf : $(OFILES)
202+
203+
$(OFILES_SRC) : $(HFILES_BIN)
204+
205+
#---------------------------------------------------------------------------------
206+
# you need a rule like this for each extension you use as binary data
207+
#---------------------------------------------------------------------------------
208+
%.bin.o %_bin.h : %.bin
209+
#---------------------------------------------------------------------------------
210+
@echo $(notdir $<)
211+
@$(bin2o)
212+
213+
-include $(DEPENDS)
214+
215+
#---------------------------------------------------------------------------------------
216+
endif
217+
#---------------------------------------------------------------------------------------
198 KB
Binary file not shown.
68.8 KB
Binary file not shown.
50.2 KB
Binary file not shown.
54.7 KB
Binary file not shown.
48 KB
Binary file not shown.
8.19 KB
Loading
1.7 KB
Loading

0 commit comments

Comments
 (0)