A homebrew application for the Nintendo Switch that will automatically update your CFW with the latest from Kosmos.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
8.6 KiB

  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4. ifeq ($(strip $(DEVKITPRO)),)
  5. $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
  6. endif
  7. TOPDIR ?= $(CURDIR)
  8. include $(DEVKITPRO)/libnx/switch_rules
  9. #---------------------------------------------------------------------------------
  10. # TARGET is the name of the output
  11. # BUILD is the directory where object files & intermediate files will be placed
  12. # SOURCES is a list of directories containing source code
  13. # DATA is a list of directories containing data files
  14. # INCLUDES is a list of directories containing header files
  15. # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
  16. #
  17. # NO_ICON: if set to anything, do not use icon.
  18. # NO_NACP: if set to anything, no .nacp file is generated.
  19. # APP_TITLE is the name of the app stored in the .nacp file (Optional)
  20. # APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
  21. # APP_VERSION is the version of the app stored in the .nacp file (Optional)
  22. # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
  23. # ICON is the filename of the icon (.jpg), relative to the project folder.
  24. # If not set, it attempts to use one of the following (in this order):
  25. # - <Project name>.jpg
  26. # - icon.jpg
  27. # - <libnx folder>/default_icon.jpg
  28. #
  29. # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
  30. # If not set, it attempts to use one of the following (in this order):
  31. # - <Project name>.json
  32. # - config.json
  33. # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
  34. # of a homebrew executable (.nro). This is intended to be used for sysmodules.
  35. # NACP building is skipped as well.
  36. #---------------------------------------------------------------------------------
  37. TARGET := $(notdir $(CURDIR))
  38. BUILD := build
  39. SOURCES := source source/models source/scenes source/views
  40. DATA := data
  41. INCLUDES := include
  42. ROMFS := romfs
  43. APP_TITLE := Kosmos Updater
  44. APP_AUTHOR := Nichole Mattera
  45. APP_VERSION := 3.1.0
  46. APP_VERSION_MAJOR := 3
  47. APP_VERSION_MINOR := 1
  48. APP_VERSION_PATCH := 0
  49. SETTING_CONFIG_VERSION := 2
  50. INTERNAL_CONFIG_VERSION := 2
  51. #---------------------------------------------------------------------------------
  52. # options for code generation
  53. #---------------------------------------------------------------------------------
  54. ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
  55. DEFINES += -D__SWITCH__ \
  56. -DVERSION=\"$(APP_VERSION)\" \
  57. -DVERSION_MAJOR=$(APP_VERSION_MAJOR) \
  58. -DVERSION_MINOR=$(APP_VERSION_MINOR) \
  59. -DVERSION_PATCH=$(APP_VERSION_PATCH) \
  60. -DSETTING_CONFIG_VERSION=$(SETTING_CONFIG_VERSION) \
  61. -DINTERNAL_CONFIG_VERSION=$(INTERNAL_CONFIG_VERSION)
  62. CFLAGS := -g -Wall -O2 -ffunction-sections \
  63. $(ARCH) $(DEFINES) $(INCLUDE)
  64. CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17
  65. ASFLAGS := -g $(ARCH)
  66. LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
  67. -Wl,-Map,$(notdir $*.map)
  68. LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx -lfreetype -lwebp -lpng -ljpeg \
  69. -ljansson -lSwurl -lcurl -lz -lSimpleIniParser -lminizip -lconfig \
  70. -lnx `sdl2-config --libs` `freetype-config --libs`
  71. #---------------------------------------------------------------------------------
  72. # list of directories containing libraries, this must be the top level containing
  73. # include and lib
  74. #---------------------------------------------------------------------------------
  75. LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/SimpleIniParser $(CURDIR)/Swurl
  76. #---------------------------------------------------------------------------------
  77. # no real need to edit anything past this point unless you need to add additional
  78. # rules for different file extensions
  79. #---------------------------------------------------------------------------------
  80. ifneq ($(BUILD),$(notdir $(CURDIR)))
  81. #---------------------------------------------------------------------------------
  82. export OUTPUT := $(CURDIR)/$(TARGET)
  83. export TOPDIR := $(CURDIR)
  84. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  85. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  86. export DEPSDIR := $(CURDIR)/$(BUILD)
  87. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  88. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  89. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  90. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  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. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  105. export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  106. export OFILES := $(OFILES_BIN) $(OFILES_SRC)
  107. export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  108. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  109. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  110. -I$(CURDIR)/$(BUILD)
  111. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  112. ifeq ($(strip $(CONFIG_JSON)),)
  113. jsons := $(wildcard *.json)
  114. ifneq (,$(findstring $(TARGET).json,$(jsons)))
  115. export APP_JSON := $(TOPDIR)/$(TARGET).json
  116. else
  117. ifneq (,$(findstring config.json,$(jsons)))
  118. export APP_JSON := $(TOPDIR)/config.json
  119. endif
  120. endif
  121. else
  122. export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
  123. endif
  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. ifeq ($(strip $(NO_ICON)),)
  137. export NROFLAGS += --icon=$(APP_ICON)
  138. endif
  139. ifeq ($(strip $(NO_NACP)),)
  140. export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
  141. endif
  142. ifneq ($(APP_TITLEID),)
  143. export NACPFLAGS += --titleid=$(APP_TITLEID)
  144. endif
  145. ifneq ($(ROMFS),)
  146. export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
  147. endif
  148. .PHONY: $(BUILD) clean all
  149. #---------------------------------------------------------------------------------
  150. all: $(BUILD)
  151. $(BUILD):
  152. ifeq ($(wildcard $(CURDIR)/SimpleIniParser/LICENSE),)
  153. @$(error "Please run 'git submodule update --init' before running 'make'")
  154. endif
  155. ifeq ($(wildcard $(CURDIR)/Swurl/LICENSE),)
  156. @$(error "Please run 'git submodule update --init' before running 'make'")
  157. endif
  158. @[ -d $@ ] || mkdir -p $@
  159. @$(MAKE) -C $(CURDIR)/SimpleIniParser -f $(CURDIR)/SimpleIniParser/Makefile
  160. @$(MAKE) -C $(CURDIR)/Swurl -f $(CURDIR)/Swurl/Makefile
  161. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  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. else
  172. .PHONY: all
  173. DEPENDS := $(OFILES:.o=.d)
  174. #---------------------------------------------------------------------------------
  175. # main targets
  176. #---------------------------------------------------------------------------------
  177. ifeq ($(strip $(APP_JSON)),)
  178. all : $(OUTPUT).nro
  179. ifeq ($(strip $(NO_NACP)),)
  180. $(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
  181. else
  182. $(OUTPUT).nro : $(OUTPUT).elf
  183. endif
  184. else
  185. all : $(OUTPUT).nsp
  186. $(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
  187. $(OUTPUT).nso : $(OUTPUT).elf
  188. endif
  189. $(OUTPUT).elf : $(OFILES)
  190. $(OFILES_SRC) : $(HFILES_BIN)
  191. #---------------------------------------------------------------------------------
  192. # you need a rule like this for each extension you use as binary data
  193. #---------------------------------------------------------------------------------
  194. %.bin.o %_bin.h : %.bin
  195. #---------------------------------------------------------------------------------
  196. @echo $(notdir $<)
  197. @$(bin2o)
  198. -include $(DEPENDS)
  199. #---------------------------------------------------------------------------------------
  200. endif
  201. #---------------------------------------------------------------------------------------