|
| 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 := src |
| 43 | +DATA := data |
| 44 | +INCLUDES := include |
| 45 | +#ROMFS := romfs |
| 46 | + |
| 47 | +#--------------------------------------------------------------------------------- |
| 48 | +# options for code generation |
| 49 | +#--------------------------------------------------------------------------------- |
| 50 | +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE |
| 51 | + |
| 52 | +CFLAGS := -g -Wall -O2 -ffunction-sections \ |
| 53 | + $(ARCH) $(DEFINES) $(BUILD_FLAGS) |
| 54 | + |
| 55 | +CFLAGS += $(INCLUDE) -D__SWITCH__ |
| 56 | + |
| 57 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions |
| 58 | + |
| 59 | +ASFLAGS := -g $(ARCH) |
| 60 | +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) |
| 61 | + |
| 62 | +LIBS := -lnx -lm |
| 63 | + |
| 64 | +#--------------------------------------------------------------------------------- |
| 65 | +# list of directories containing libraries, this must be the top level containing |
| 66 | +# include and lib |
| 67 | +#--------------------------------------------------------------------------------- |
| 68 | +LIBDIRS := $(PORTLIBS) $(LIBNX) |
| 69 | + |
| 70 | + |
| 71 | +#--------------------------------------------------------------------------------- |
| 72 | +# no real need to edit anything past this point unless you need to add additional |
| 73 | +# rules for different file extensions |
| 74 | +#--------------------------------------------------------------------------------- |
| 75 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 76 | +#--------------------------------------------------------------------------------- |
| 77 | + |
| 78 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 79 | +export TOPDIR := $(CURDIR) |
| 80 | + |
| 81 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 82 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 83 | + |
| 84 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 85 | + |
| 86 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 87 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 88 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 89 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 90 | + |
| 91 | +#--------------------------------------------------------------------------------- |
| 92 | +# use CXX for linking C++ projects, CC for standard C |
| 93 | +#--------------------------------------------------------------------------------- |
| 94 | +ifeq ($(strip $(CPPFILES)),) |
| 95 | +#--------------------------------------------------------------------------------- |
| 96 | + export LD := $(CC) |
| 97 | +#--------------------------------------------------------------------------------- |
| 98 | +else |
| 99 | +#--------------------------------------------------------------------------------- |
| 100 | + export LD := $(CXX) |
| 101 | +#--------------------------------------------------------------------------------- |
| 102 | +endif |
| 103 | +#--------------------------------------------------------------------------------- |
| 104 | + |
| 105 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) |
| 106 | +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 107 | +export OFILES := $(OFILES_BIN) $(OFILES_SRC) |
| 108 | +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) |
| 109 | + |
| 110 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 111 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 112 | + -I$(CURDIR)/$(BUILD) |
| 113 | + |
| 114 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 115 | + |
| 116 | +ifeq ($(strip $(ICON)),) |
| 117 | + icons := $(wildcard *.jpg) |
| 118 | + ifneq (,$(findstring $(TARGET).jpg,$(icons))) |
| 119 | + export APP_ICON := $(TOPDIR)/$(TARGET).jpg |
| 120 | + else |
| 121 | + ifneq (,$(findstring icon.jpg,$(icons))) |
| 122 | + export APP_ICON := $(TOPDIR)/icon.jpg |
| 123 | + endif |
| 124 | + endif |
| 125 | +else |
| 126 | + export APP_ICON := $(TOPDIR)/$(ICON) |
| 127 | +endif |
| 128 | + |
| 129 | +ifeq ($(strip $(NO_ICON)),) |
| 130 | + export NROFLAGS += --icon=$(APP_ICON) |
| 131 | +endif |
| 132 | + |
| 133 | +ifeq ($(strip $(NO_NACP)),) |
| 134 | + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp |
| 135 | +endif |
| 136 | + |
| 137 | +ifneq ($(APP_TITLEID),) |
| 138 | + export NACPFLAGS += --titleid=$(APP_TITLEID) |
| 139 | +endif |
| 140 | + |
| 141 | +ifneq ($(ROMFS),) |
| 142 | + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) |
| 143 | +endif |
| 144 | + |
| 145 | +.PHONY: $(BUILD) clean all applet |
| 146 | + |
| 147 | +#--------------------------------------------------------------------------------- |
| 148 | +all: $(BUILD) |
| 149 | + |
| 150 | +applet: |
| 151 | + @[ -d $(BUILD) ] || mkdir -p $(BUILD) |
| 152 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile \ |
| 153 | + BUILD_FLAGS=-DAPPLET |
| 154 | + |
| 155 | +$(BUILD): |
| 156 | + @[ -d $@ ] || mkdir -p $@ |
| 157 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile \ |
| 158 | + CONFIG_JSON=sysmodule.json \ |
| 159 | + APP_JSON=$(TOPDIR)/sysmodule.json |
| 160 | + |
| 161 | +#--------------------------------------------------------------------------------- |
| 162 | +clean: |
| 163 | + @echo clean ... |
| 164 | + @rm -fr $(BUILD) $(TARGET).elf |
| 165 | + @rm -fr $(TARGET).nro $(TARGET).nacp $(TARGET).nsp $(TARGET).nso $(TARGET).npdm |
| 166 | + |
| 167 | + |
| 168 | +#--------------------------------------------------------------------------------- |
| 169 | +else |
| 170 | +.PHONY: all |
| 171 | + |
| 172 | +DEPENDS := $(OFILES:.o=.d) |
| 173 | + |
| 174 | +#--------------------------------------------------------------------------------- |
| 175 | +# main targets |
| 176 | +#--------------------------------------------------------------------------------- |
| 177 | +ifeq ($(strip $(APP_JSON)),) |
| 178 | + |
| 179 | +all : $(OUTPUT).nro |
| 180 | + |
| 181 | +ifeq ($(strip $(NO_NACP)),) |
| 182 | +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp |
| 183 | +else |
| 184 | +$(OUTPUT).nro : $(OUTPUT).elf |
| 185 | +endif |
| 186 | + |
| 187 | +else |
| 188 | + |
| 189 | +all : $(OUTPUT).nsp |
| 190 | + |
| 191 | +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm |
| 192 | + |
| 193 | +$(OUTPUT).nso : $(OUTPUT).elf |
| 194 | + |
| 195 | +endif |
| 196 | + |
| 197 | +$(OUTPUT).elf : $(OFILES) |
| 198 | + |
| 199 | +$(OFILES_SRC) : $(HFILES_BIN) |
| 200 | + |
| 201 | +#--------------------------------------------------------------------------------- |
| 202 | +# you need a rule like this for each extension you use as binary data |
| 203 | +#--------------------------------------------------------------------------------- |
| 204 | +%.bin.o %_bin.h : %.bin |
| 205 | +#--------------------------------------------------------------------------------- |
| 206 | + @echo $(notdir $<) |
| 207 | + @$(bin2o) |
| 208 | + |
| 209 | +-include $(DEPENDS) |
| 210 | + |
| 211 | +#--------------------------------------------------------------------------------------- |
| 212 | +endif |
| 213 | +#--------------------------------------------------------------------------------------- |
0 commit comments