Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. APP_TITLE := GameCard Installer
  30. APP_AUTHOR := TotalJustice
  31. APP_VERSION := 2.0.5
  32. TARGET := gamecard_installer
  33. BUILD := build
  34. SOURCES := source source/ui source/gfx source/sound source/nx source/util
  35. DATA := data
  36. INCLUDES := includes includes/ui includes/gfx includes/sound includes/nx includes/util
  37. ROMFS := romfs
  38. #---------------------------------------------------------------------------------
  39. # options for code generation
  40. #---------------------------------------------------------------------------------
  41. #DEBUG := -D DEBUG
  42. ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
  43. CFLAGS := -g -Wall -O3 $(DEBUG) -ffunction-sections \
  44. $(ARCH) $(DEFINES)
  45. CFLAGS += $(INCLUDE) -D__SWITCH__ `freetype-config --cflags` `sdl2-config --cflags`
  46. CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
  47. ASFLAGS := -g $(ARCH)
  48. LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  49. LIBS := -lSDL2_mixer -lSDL2_ttf -lSDL2_image -lSDL2 -lSDL2_gfx `sdl2-config --libs` `freetype-config --libs` \
  50. -lwebp -lpng -lturbojpeg -lmodplug -lmpg123 -lFLAC -lopusfile -lopus -lvorbisidec -logg -lz \
  51. -lnx
  52. #---------------------------------------------------------------------------------
  53. # list of directories containing libraries, this must be the top level containing
  54. # include and lib
  55. #---------------------------------------------------------------------------------
  56. LIBDIRS := $(PORTLIBS) $(LIBNX)
  57. #---------------------------------------------------------------------------------
  58. # no real need to edit anything past this point unless you need to add additional
  59. # rules for different file extensions
  60. #---------------------------------------------------------------------------------
  61. ifneq ($(BUILD),$(notdir $(CURDIR)))
  62. #---------------------------------------------------------------------------------
  63. export OUTPUT := $(CURDIR)/$(TARGET)
  64. export TOPDIR := $(CURDIR)
  65. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  66. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  67. export DEPSDIR := $(CURDIR)/$(BUILD)
  68. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  69. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  70. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  71. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  72. #---------------------------------------------------------------------------------
  73. # use CXX for linking C++ projects, CC for standard C
  74. #---------------------------------------------------------------------------------
  75. ifeq ($(strip $(CPPFILES)),)
  76. #---------------------------------------------------------------------------------
  77. export LD := $(CXX)
  78. #---------------------------------------------------------------------------------
  79. else
  80. #---------------------------------------------------------------------------------
  81. export LD := $(CXX)
  82. #---------------------------------------------------------------------------------
  83. endif
  84. #---------------------------------------------------------------------------------
  85. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  86. export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  87. export OFILES := $(OFILES_BIN) $(OFILES_SRC)
  88. export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  89. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  90. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  91. -I$(CURDIR)/$(BUILD)
  92. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  93. ifeq ($(strip $(ICON)),)
  94. icons := $(wildcard *.jpg)
  95. ifneq (,$(findstring $(TARGET).jpg,$(icons)))
  96. export APP_ICON := $(TOPDIR)/$(TARGET).jpg
  97. else
  98. ifneq (,$(findstring icon.jpg,$(icons)))
  99. export APP_ICON := $(TOPDIR)/icon.jpg
  100. endif
  101. endif
  102. else
  103. export APP_ICON := $(TOPDIR)/$(ICON)
  104. endif
  105. ifeq ($(strip $(NO_ICON)),)
  106. export NROFLAGS += --icon=$(APP_ICON)
  107. endif
  108. ifeq ($(strip $(NO_NACP)),)
  109. export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
  110. endif
  111. ifneq ($(APP_TITLEID),)
  112. export NACPFLAGS += --titleid=$(APP_TITLEID)
  113. endif
  114. ifneq ($(ROMFS),)
  115. export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
  116. endif
  117. .PHONY: $(BUILD) clean all
  118. #---------------------------------------------------------------------------------
  119. all: $(BUILD)
  120. $(BUILD):
  121. @[ -d $@ ] || mkdir -p $@
  122. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  123. #---------------------------------------------------------------------------------
  124. clean:
  125. @echo clean ...
  126. ifeq ($(strip $(APP_JSON)),)
  127. @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
  128. else
  129. @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
  130. endif
  131. #---------------------------------------------------------------------------------
  132. dist: all
  133. @echo making dist ...
  134. rm -rf out/
  135. rm gamecard_installer.zip
  136. mkdir -p out
  137. mkdir -p out/switch
  138. mkdir -p out/switch/gamecard_installer
  139. cp $(CURDIR)/$(TARGET).nro out/switch/gamecard_installer
  140. cd out; zip -r ../gamecard_installer.zip ./*; cd ../;
  141. #---------------------------------------------------------------------------------
  142. nxlink: all
  143. @echo making and nxlinking ...
  144. nxlink $(CURDIR)/$(TARGET).nro
  145. #---------------------------------------------------------------------------------
  146. else
  147. .PHONY: all
  148. DEPENDS := $(OFILES:.o=.d)
  149. #---------------------------------------------------------------------------------
  150. # main targets
  151. #---------------------------------------------------------------------------------
  152. all : $(OUTPUT).nro
  153. ifeq ($(strip $(NO_NACP)),)
  154. $(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
  155. else
  156. $(OUTPUT).nro : $(OUTPUT).elf
  157. endif
  158. $(OUTPUT).elf : $(OFILES)
  159. $(OFILES_SRC) : $(HFILES_BIN)
  160. #---------------------------------------------------------------------------------
  161. # you need a rule like this for each extension you use as binary data
  162. #---------------------------------------------------------------------------------
  163. %.bin.o %_bin.h : %.bin
  164. #---------------------------------------------------------------------------------
  165. @echo $(notdir $<)
  166. @$(bin2o)
  167. -include $(DEPENDS)
  168. #---------------------------------------------------------------------------------------
  169. endif
  170. #---------------------------------------------------------------------------------------