Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4. ifeq ($(strip $(DEVKITARM)),)
  5. $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  6. endif
  7. TOPDIR ?= $(CURDIR)
  8. include $(DEVKITARM)/3ds_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. # GRAPHICS is a list of directories containing graphics files
  16. # GFXBUILD is the directory where converted graphics files will be placed
  17. # If set to $(BUILD), it will statically link in the converted
  18. # files as if they were data files.
  19. #
  20. # NO_SMDH: if set to anything, no SMDH file is generated.
  21. # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
  22. # APP_TITLE is the name of the app stored in the SMDH file (Optional)
  23. # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
  24. # APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
  25. # ICON is the filename of the icon (.png), relative to the project folder.
  26. # If not set, it attempts to use one of the following (in this order):
  27. # - <Project name>.png
  28. # - icon.png
  29. # - <libctru folder>/default_icon.png
  30. #---------------------------------------------------------------------------------
  31. # Your values.
  32. APP_TITLE := freeShop - EOL
  33. APP_DESCRIPTION := freeShop - End of Life version
  34. APP_AUTHOR := freeShop team
  35. TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
  36. OUTDIR := out
  37. BUILD := build
  38. SOURCES := source source/quirc
  39. INCLUDES := include
  40. ROMFS := romfs
  41. GRAPHICS := gfx
  42. GFXBUILD := $(ROMFS)/gfx
  43. # Path to the files
  44. # If left blank, will try to use "icon.png", "$(TARGET).png", or the default ctrulib icon, in that order
  45. ICON := meta/icon.png
  46. BANNER_AUDIO := meta/audio.wav
  47. BANNER_IMAGE := meta/banner.png
  48. RSF_PATH := meta/app.rsf
  49. # If left blank, makerom will use the default Homebrew logo
  50. LOGO :=
  51. # If left blank, makerom will use default values (0xff3ff and CTR-P-CTAP, respectively)
  52. # Be careful if UNIQUE_ID is the same as other apps: it will overwrite the previously installed one
  53. UNIQUE_ID := 0xF12EE
  54. PRODUCT_CODE := freeshop
  55. # Don't really need to change this
  56. ICON_FLAGS := nosavebackups,visible
  57. ifeq ($(strip $(NOGIT)),)
  58. VERSION := $(shell git describe --tags --match v[0-9]* --abbrev=7 | sed 's/-[0-9]*-g/-/')
  59. VERSION_MAJOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f1 -d.)
  60. VERSION_MINOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f2 -d.)
  61. VERSION_BUILD := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f3 -d.)
  62. ifeq ($(strip $(VERSION_BUILD)),)
  63. VERSION_BUILD := 0
  64. endif
  65. endif
  66. #---------------------------------------------------------------------------------
  67. # options for code generation
  68. #---------------------------------------------------------------------------------
  69. ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
  70. CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
  71. -ffunction-sections \
  72. $(ARCH)
  73. CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DVERSION="\"$(VERSION)\"" -DUSER_AGENT="\"$(APP_TITLE)/$(VERSION)\"" -DAPP_TITLE="\"$(APP_TITLE)\""
  74. ifneq ($(strip $(CITRA_MODE)),)
  75. CFLAGS += -DCITRA_MODE
  76. endif
  77. CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
  78. ASFLAGS := -g $(ARCH)
  79. LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  80. LIBS := -lcitro2d -lcitro3d -lctrud -lm
  81. #---------------------------------------------------------------------------------
  82. # list of directories containing libraries, this must be the top level containing
  83. # include and lib
  84. #---------------------------------------------------------------------------------
  85. LIBDIRS := $(CTRULIB) $(PORTLIBS)
  86. #---------------------------------------------------------------------------------
  87. # no real need to edit anything past this point unless you need to add additional
  88. # rules for different file extensions
  89. #---------------------------------------------------------------------------------
  90. ifneq ($(BUILD),$(notdir $(CURDIR)))
  91. #---------------------------------------------------------------------------------
  92. export OUTPUT := $(CURDIR)/$(OUTDIR)/$(TARGET)
  93. export TOPDIR := $(CURDIR)
  94. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  95. $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
  96. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  97. export DEPSDIR := $(CURDIR)/$(BUILD)
  98. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  99. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  100. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  101. PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
  102. SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
  103. GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
  104. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  105. #---------------------------------------------------------------------------------
  106. # use CXX for linking C++ projects, CC for standard C
  107. #---------------------------------------------------------------------------------
  108. ifeq ($(strip $(CPPFILES)),)
  109. #---------------------------------------------------------------------------------
  110. export LD := $(CC)
  111. #---------------------------------------------------------------------------------
  112. else
  113. #---------------------------------------------------------------------------------
  114. export LD := $(CXX)
  115. #---------------------------------------------------------------------------------
  116. endif
  117. #---------------------------------------------------------------------------------
  118. export T3XFILES := $(GFXFILES:.t3s=.t3x)
  119. export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  120. export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
  121. $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
  122. $(if $(filter $(BUILD),$(GFXBUILD)),$(addsuffix .o,$(T3XFILES)))
  123. export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
  124. export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
  125. $(addsuffix .h,$(subst .,_,$(BINFILES))) \
  126. $(GFXFILES:.t3s=.h)
  127. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  128. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  129. -I$(CURDIR)/$(BUILD)
  130. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  131. export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh)
  132. ifeq ($(strip $(ICON)),)
  133. icons := $(wildcard *.png)
  134. ifneq (,$(findstring $(TARGET).png,$(icons)))
  135. export APP_ICON := $(TOPDIR)/$(TARGET).png
  136. else
  137. ifneq (,$(findstring icon.png,$(icons)))
  138. export APP_ICON := $(TOPDIR)/icon.png
  139. endif
  140. endif
  141. else
  142. export APP_ICON := $(TOPDIR)/$(ICON)
  143. endif
  144. ifeq ($(strip $(NO_SMDH)),)
  145. export _3DSXFLAGS += --smdh=$(OUTPUT).smdh
  146. endif
  147. ifneq ($(ROMFS),)
  148. export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
  149. endif
  150. .PHONY: all clean
  151. #---------------------------------------------------------------------------------
  152. MAKEROM ?= makerom
  153. MAKEROM_ARGS := -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)"
  154. ifeq ($(strip $(NOGIT)),)
  155. MAKEROM_ARGS += -major $(VERSION_MAJOR) -minor $(VERSION_MINOR) -micro $(VERSION_BUILD)
  156. endif
  157. ifneq ($(strip $(LOGO)),)
  158. MAKEROM_ARGS += -logo "$(LOGO)"
  159. endif
  160. ifneq ($(strip $(ROMFS)),)
  161. MAKEROM_ARGS += -DAPP_ROMFS="$(ROMFS)"
  162. endif
  163. BANNERTOOL ?= bannertool
  164. ifeq ($(suffix $(BANNER_IMAGE)),.cgfx)
  165. BANNER_IMAGE_ARG := -ci
  166. else
  167. BANNER_IMAGE_ARG := -i
  168. endif
  169. ifeq ($(suffix $(BANNER_AUDIO)),.cwav)
  170. BANNER_AUDIO_ARG := -ca
  171. else
  172. BANNER_AUDIO_ARG := -a
  173. endif
  174. #---------------------------------------------------------------------------------
  175. all:
  176. @mkdir -p $(BUILD) $(GFXBUILD) $(OUTDIR)
  177. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  178. @cp "meta/banner.bnr" "$(BUILD)/banner.bnr"
  179. @$(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(APP_ICON)" -f "$(ICON_FLAGS)" -o "$(BUILD)/icon.icn"
  180. $(MAKEROM) -f cia -o "$(OUTPUT).cia" -target t -exefslogo $(MAKEROM_ARGS)
  181. #---------------------------------------------------------------------------------
  182. clean:
  183. @echo clean ...
  184. @rm -fr $(BUILD) $(GFXBUILD) $(OUTDIR)
  185. #---------------------------------------------------------------------------------
  186. else
  187. #---------------------------------------------------------------------------------
  188. # main targets
  189. #---------------------------------------------------------------------------------
  190. $(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS)
  191. $(OFILES_SOURCES) : $(HFILES)
  192. $(OUTPUT).elf : $(OFILES)
  193. #---------------------------------------------------------------------------------
  194. # you need a rule like this for each extension you use as binary data
  195. #---------------------------------------------------------------------------------
  196. %.bin.o %_bin.h : %.bin
  197. #---------------------------------------------------------------------------------
  198. @echo $(notdir $<)
  199. @$(bin2o)
  200. #---------------------------------------------------------------------------------
  201. .PRECIOUS : %.t3x
  202. %.t3x.o %_t3x.h : %.t3x
  203. #---------------------------------------------------------------------------------
  204. @$(bin2o)
  205. #---------------------------------------------------------------------------------
  206. # rules for assembling GPU shaders
  207. #---------------------------------------------------------------------------------
  208. define shader-as
  209. $(eval CURBIN := $*.shbin)
  210. $(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
  211. echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
  212. echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
  213. echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
  214. echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
  215. picasso -o $(CURBIN) $1
  216. bin2s $(CURBIN) | $(AS) -o $*.shbin.o
  217. endef
  218. %.shbin.o %_shbin.h : %.v.pica %.g.pica
  219. @echo $(notdir $^)
  220. @$(call shader-as,$^)
  221. %.shbin.o %_shbin.h : %.v.pica
  222. @echo $(notdir $<)
  223. @$(call shader-as,$<)
  224. %.shbin.o %_shbin.h : %.shlist
  225. @echo $(notdir $<)
  226. @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
  227. #---------------------------------------------------------------------------------
  228. %.t3x %.h : %.t3s
  229. #---------------------------------------------------------------------------------
  230. @echo $(notdir $<)
  231. @tex3ds -i $< -H $*.h -d $*.d -o $(TOPDIR)/$(GFXBUILD)/$*.t3x
  232. -include $(DEPSDIR)/*.d
  233. #---------------------------------------------------------------------------------------
  234. endif
  235. #---------------------------------------------------------------------------------------