Skip to content

Commit e5f5b48

Browse files
committed
Added application template.
1 parent ccd9f78 commit e5f5b48

File tree

2 files changed

+218
-0
lines changed

2 files changed

+218
-0
lines changed

templates/application/Makefile

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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+
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
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+
TARGET := $(notdir $(CURDIR))
33+
BUILD := build
34+
SOURCES := source
35+
DATA := data
36+
INCLUDES := include
37+
EXEFS_SRC := exefs_src
38+
39+
#---------------------------------------------------------------------------------
40+
# options for code generation
41+
#---------------------------------------------------------------------------------
42+
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
43+
44+
CFLAGS := -g -Wall -O2 \
45+
-ffast-math \
46+
$(ARCH) $(DEFINES)
47+
48+
CFLAGS += $(INCLUDE) -DSWITCH
49+
50+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
51+
52+
ASFLAGS := -g $(ARCH)
53+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
54+
55+
LIBS := -lnx
56+
57+
#---------------------------------------------------------------------------------
58+
# list of directories containing libraries, this must be the top level containing
59+
# include and lib
60+
#---------------------------------------------------------------------------------
61+
LIBDIRS := $(PORTLIBS) $(LIBNX)
62+
63+
64+
#---------------------------------------------------------------------------------
65+
# no real need to edit anything past this point unless you need to add additional
66+
# rules for different file extensions
67+
#---------------------------------------------------------------------------------
68+
ifneq ($(BUILD),$(notdir $(CURDIR)))
69+
#---------------------------------------------------------------------------------
70+
71+
export OUTPUT := $(CURDIR)/$(TARGET)
72+
export TOPDIR := $(CURDIR)
73+
74+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
75+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
76+
77+
export DEPSDIR := $(CURDIR)/$(BUILD)
78+
79+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
80+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
81+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
82+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
83+
84+
#---------------------------------------------------------------------------------
85+
# use CXX for linking C++ projects, CC for standard C
86+
#---------------------------------------------------------------------------------
87+
ifeq ($(strip $(CPPFILES)),)
88+
#---------------------------------------------------------------------------------
89+
export LD := $(CC)
90+
#---------------------------------------------------------------------------------
91+
else
92+
#---------------------------------------------------------------------------------
93+
export LD := $(CXX)
94+
#---------------------------------------------------------------------------------
95+
endif
96+
#---------------------------------------------------------------------------------
97+
98+
export OFILES := $(addsuffix .o,$(BINFILES)) \
99+
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
100+
101+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
102+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
103+
-I$(CURDIR)/$(BUILD)
104+
105+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
106+
107+
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
108+
109+
ifeq ($(strip $(ICON)),)
110+
icons := $(wildcard *.jpg)
111+
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
112+
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
113+
else
114+
ifneq (,$(findstring icon.jpg,$(icons)))
115+
export APP_ICON := $(TOPDIR)/icon.jpg
116+
endif
117+
endif
118+
else
119+
export APP_ICON := $(TOPDIR)/$(ICON)
120+
endif
121+
122+
ifeq ($(strip $(NO_ICON)),)
123+
export NROFLAGS += --icon=$(APP_ICON)
124+
endif
125+
126+
ifeq ($(strip $(NO_NACP)),)
127+
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
128+
endif
129+
130+
ifneq ($(APP_TITLEID),)
131+
export NACPFLAGS += --titleid=$(APP_TITLEID)
132+
endif
133+
134+
.PHONY: $(BUILD) clean all
135+
136+
#---------------------------------------------------------------------------------
137+
all: $(BUILD)
138+
139+
$(BUILD):
140+
@[ -d $@ ] || mkdir -p $@
141+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
142+
143+
#---------------------------------------------------------------------------------
144+
clean:
145+
@echo clean ...
146+
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf
147+
148+
149+
#---------------------------------------------------------------------------------
150+
else
151+
.PHONY: all
152+
153+
DEPENDS := $(OFILES:.o=.d)
154+
155+
#---------------------------------------------------------------------------------
156+
# main targets
157+
#---------------------------------------------------------------------------------
158+
all : $(OUTPUT).pfs0 $(OUTPUT).nro
159+
160+
$(OUTPUT).pfs0 : $(OUTPUT).nso
161+
162+
$(OUTPUT).nso : $(OUTPUT).elf
163+
164+
ifeq ($(strip $(NO_NACP)),)
165+
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
166+
else
167+
$(OUTPUT).nro : $(OUTPUT).elf
168+
endif
169+
170+
$(OUTPUT).elf : $(OFILES)
171+
172+
#---------------------------------------------------------------------------------
173+
# you need a rule like this for each extension you use as binary data
174+
#---------------------------------------------------------------------------------
175+
%.bin.o : %.bin
176+
#---------------------------------------------------------------------------------
177+
@echo $(notdir $<)
178+
@$(bin2o)
179+
180+
-include $(DEPENDS)
181+
182+
#---------------------------------------------------------------------------------------
183+
endif
184+
#---------------------------------------------------------------------------------------
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
4+
#include <switch.h>
5+
6+
int main(int argc, char **argv)
7+
{
8+
gfxInitDefault();
9+
consoleInit(NULL);
10+
11+
printf("Hello World!");
12+
13+
// Main loop
14+
while(appletMainLoop())
15+
{
16+
//Scan all the inputs. This should be done once for each frame
17+
hidScanInput();
18+
19+
// Your code goes here
20+
21+
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
22+
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
23+
24+
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
25+
26+
gfxFlushBuffers();
27+
gfxSwapBuffers();
28+
gfxWaitForVsync();
29+
}
30+
31+
gfxExit();
32+
return 0;
33+
}
34+

0 commit comments

Comments
 (0)