Facebook
From Scanty Kitten, 3 Years ago, written in Make.
Embed
Download Paste or View Raw
Hits: 66
  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4.  
  5. ifeq ($(strip $(DEVKITARM)),)
  6. $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  7. endif
  8.  
  9. TOPDIR ?= $(CURDIR)
  10. include $(DEVKITARM)/3ds_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. # GRAPHICS is a list of directories containing graphics files
  19. # GFXBUILD is the directory where converted graphics files will be placed
  20. #   If set to $(BUILD), it will statically link in the converted
  21. #   files as if they were data files.
  22. #
  23. # NO_SMDH: if set to anything, no SMDH file is generated.
  24. # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
  25. # APP_TITLE is the name of the app stored in the SMDH file (Optional)
  26. # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
  27. # APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
  28. # ICON is the filename of the icon (.png), relative to the project folder.
  29. #   If not set, it attempts to use one of the following (in this order):
  30. #     - <Project name>.png
  31. #     - icon.png
  32. #     - <libctru folder>/default_icon.png
  33. #---------------------------------------------------------------------------------
  34. TARGET          :=      $(notdir $(CURDIR))
  35. BUILD           :=      build
  36. SOURCES         :=      source
  37. DATA            :=      data
  38. INCLUDES        :=      include
  39. GRAPHICS        :=      gfx
  40. #GFXBUILD       :=      $(BUILD)
  41. ROMFS           :=      romfs
  42. GFXBUILD        :=      $(ROMFS)/gfx
  43.  
  44. APP_TITLE       := 3Dio
  45. APP_DESCRIPTION := Downloadmanager for .3dsx files
  46. APP_AUTHOR      := Chris
  47. #---------------------------------------------------------------------------------
  48. # options for code generation
  49. #---------------------------------------------------------------------------------
  50. ARCH    :=      -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
  51.  
  52. CFLAGS  :=      -g -Wall -O2 -mword-relocations \
  53.                         -fomit-frame-pointer -ffunction-sections \
  54.                         $(ARCH)
  55.  
  56. CFLAGS  +=      $(INCLUDE) -DARM11 -D_3DS
  57.  
  58. CXXFLAGS        := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
  59.  
  60. ASFLAGS :=      -g $(ARCH)
  61. LDFLAGS =       -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  62.  
  63. LIBS    := -lcitro2d -lcitro3d -lctru -lm
  64.  
  65. #---------------------------------------------------------------------------------
  66. # list of directories containing libraries, this must be the top level containing
  67. # include and lib
  68. #---------------------------------------------------------------------------------
  69. LIBDIRS := $(CTRULIB)
  70.  
  71.  
  72. #---------------------------------------------------------------------------------
  73. # no real need to edit anything past this point unless you need to add additional
  74. # rules for different file extensions
  75. #---------------------------------------------------------------------------------
  76. ifneq ($(BUILD),$(notdir $(CURDIR)))
  77. #---------------------------------------------------------------------------------
  78.  
  79. export OUTPUT   :=      $(CURDIR)/$(TARGET)
  80. export TOPDIR   :=      $(CURDIR)
  81.  
  82. export VPATH    :=      $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  83.                         $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
  84.                         $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  85.  
  86. export DEPSDIR  :=      $(CURDIR)/$(BUILD)
  87.  
  88. CFILES          :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  89. CPPFILES        :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  90. SFILES          :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  91. PICAFILES       :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
  92. SHLISTFILES     :=      $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
  93. GFXFILES        :=      $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
  94. BINFILES        :=      $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  95.  
  96. #---------------------------------------------------------------------------------
  97. # use CXX for linking C++ projects, CC for standard C
  98. #---------------------------------------------------------------------------------
  99. ifeq ($(strip $(CPPFILES)),)
  100. #---------------------------------------------------------------------------------
  101.         export LD       :=      $(CC)
  102. #---------------------------------------------------------------------------------
  103. else
  104. #---------------------------------------------------------------------------------
  105.         export LD       :=      $(CXX)
  106. #---------------------------------------------------------------------------------
  107. endif
  108. #---------------------------------------------------------------------------------
  109.  
  110. #---------------------------------------------------------------------------------
  111. ifeq ($(GFXBUILD),$(BUILD))
  112. #---------------------------------------------------------------------------------
  113. export T3XFILES :=  $(GFXFILES:.t3s=.t3x)
  114. #---------------------------------------------------------------------------------
  115. else
  116. #---------------------------------------------------------------------------------
  117. export ROMFS_T3XFILES   :=      $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES))
  118. export T3XHFILES                :=      $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES))
  119. #---------------------------------------------------------------------------------
  120. endif
  121. #---------------------------------------------------------------------------------
  122.  
  123. export OFILES_SOURCES   :=      $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  124.  
  125. export OFILES_BIN       :=      $(addsuffix .o,$(BINFILES)) \
  126.                         $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
  127.                         $(addsuffix .o,$(T3XFILES))
  128.  
  129. export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
  130.  
  131. export HFILES   :=      $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
  132.                         $(addsuffix .h,$(subst .,_,$(BINFILES))) \
  133.                         $(GFXFILES:.t3s=.h)
  134.  
  135. export INCLUDE  :=      $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  136.                         $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  137.                         -I$(CURDIR)/$(BUILD)
  138.  
  139. export LIBPATHS :=      $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  140.  
  141. export _3DSXDEPS        :=      $(if $(NO_SMDH),,$(OUTPUT).smdh)
  142.  
  143. ifeq ($(strip $(ICON)),)
  144.         icons := $(wildcard *.png)
  145.         ifneq (,$(findstring $(TARGET).png,$(icons)))
  146.                 export APP_ICON := $(TOPDIR)/$(TARGET).png
  147.         else
  148.                 ifneq (,$(findstring icon.png,$(icons)))
  149.                         export APP_ICON := $(TOPDIR)/icon.png
  150.                 endif
  151.         endif
  152. else
  153.         export APP_ICON := $(TOPDIR)/$(ICON)
  154. endif
  155.  
  156. ifeq ($(strip $(NO_SMDH)),)
  157.         export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
  158. endif
  159.  
  160. ifneq ($(ROMFS),)
  161.         export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
  162. endif
  163.  
  164. .PHONY: all clean
  165.  
  166. #---------------------------------------------------------------------------------
  167. all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
  168.         @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  169.  
  170. $(BUILD):
  171.         @mkdir -p $@
  172.  
  173. ifneq ($(GFXBUILD),$(BUILD))
  174. $(GFXBUILD):
  175.         @mkdir -p $@
  176. endif
  177.  
  178. ifneq ($(DEPSDIR),$(BUILD))
  179. $(DEPSDIR):
  180.         @mkdir -p $@
  181. endif
  182.  
  183. #---------------------------------------------------------------------------------
  184. clean:
  185.         @echo clean ...
  186.         @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
  187.         #@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(OUTPUT).cia Resources/hblauncher_loader.icn Resources/hblauncher_loader.bnr
  188.  
  189. #---------------------------------------------------------------------------------
  190. $(GFXBUILD)/%.t3x       $(BUILD)/%.h    :       %.t3s
  191. #---------------------------------------------------------------------------------
  192.         @echo $(notdir $<)
  193.         @tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x
  194.  
  195. #---------------------------------------------------------------------------------
  196. else
  197.  
  198. #---------------------------------------------------------------------------------
  199. # main targets
  200. #---------------------------------------------------------------------------------
  201. $(OUTPUT).3dsx  :       $(OUTPUT).elf $(_3DSXDEPS)
  202.  
  203. $(OFILES_SOURCES) : $(HFILES)
  204.  
  205. $(OUTPUT).elf   :       $(OFILES)
  206.  
  207. # ifeq ($(strip $(NO_SMDH)),)
  208. # $(OUTPUT).3dsx        :       $(OUTPUT).elf $(OUTPUT).smdh $(OUTPUT).cia
  209. # else
  210. # $(OUTPUT).3dsx        :       $(OUTPUT).elf
  211. # endif
  212.  
  213. # $(OUTPUT).elf :       $(OFILES)
  214.  
  215. # #../Resources/hblauncher_loader.icn   :       $(APP_ICON)
  216. # icon.png      :       $(APP_ICON)
  217. #       tools/bannertool.exe makesmdh -i "$(APP_ICON)" -o "$@" -s "$(APP_TITLE)" -l "$(APP_TITLE)" -p "$(APP_AUTHOR)" $(ICON_FLAGS)
  218.  
  219. #  banner.png   :        banner.png
  220. #       tools/bannertool.exe makebanner -i "$<" -ca ../Resources/hblauncher_loader.cwav -o "$@"
  221.  
  222. # $(OUTPUT).cia :       $(OUTPUT).elf  $(_3DSXDEPS)
  223. # #tools/makerom.exe -f cia -o "$@" -elf $(OUTPUT).elf -rsf /hblauncher_loader.rsf -icon /hblauncher_loader.icn -banner /hblauncher_loader.bnr -exefslogo -ver 1072
  224. # #tools/makerom.exe -f cia -o "$@" -elf $(OUTPUT).elf -icon icon.png -banner banner.cgfx -exefslogo -ver 1072
  225. # #tools/makerom.exe -f cia -o "$@" -elf $(OUTPUT).elf -rsf cia_workaround.rsf -icon icon.png -banner banner.png -exefslogo -ver 1072
  226. # #tools/makerom.exe -f cia -o "$@" -elf $(OUTPUT).elf -rsf tools/template-cia.rsf -icon icon.png -banner banner.png -exefslogo -ver 1072
  227. #       resources/makerom.exe -f cia -o "$@" -elf $(OUTPUT).elf -rsf resources/build_cia.rsf -icon icon.png -banner banner.cgfx -exefslogo -target t
  228. #       @echo "built ... $(OUTPUT).cia"
  229.  
  230. #---------------------------------------------------------------------------------
  231. # you need a rule like this for each extension you use as binary data
  232. #---------------------------------------------------------------------------------
  233. %.bin.o %_bin.h :       %.bin
  234. #---------------------------------------------------------------------------------
  235.         @echo $(notdir $<)
  236.         @$(bin2o)
  237.  
  238. #---------------------------------------------------------------------------------
  239. .PRECIOUS       :       %.t3x
  240. #---------------------------------------------------------------------------------
  241. %.t3x.o %_t3x.h :       %.t3x
  242. #---------------------------------------------------------------------------------
  243.         @echo $(notdir $<)
  244.         @$(bin2o)
  245.  
  246. #---------------------------------------------------------------------------------
  247. # rules for assembling GPU shaders
  248. #---------------------------------------------------------------------------------
  249. define shader-as
  250.         $(eval CURBIN := $*.shbin)
  251.         $(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
  252.         echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
  253.         echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
  254.         echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
  255.         echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
  256.         picasso -o $(CURBIN) $1
  257.         bin2s $(CURBIN) | $(AS) -o $*.shbin.o
  258. endef
  259.  
  260. %.shbin.o %_shbin.h : %.v.pica %.g.pica
  261.         @echo $(notdir $^)
  262.         @$(call shader-as,$^)
  263.  
  264. %.shbin.o %_shbin.h : %.v.pica
  265.         @echo $(notdir $<)
  266.         @$(call shader-as,$<)
  267.  
  268. %.shbin.o %_shbin.h : %.shlist
  269.         @echo $(notdir $<)
  270.         @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
  271.  
  272. #---------------------------------------------------------------------------------
  273. %.t3x   %.h     :       %.t3s
  274. #---------------------------------------------------------------------------------
  275.         @echo $(notdir $<)
  276.         @tex3ds -i $< -H $*.h -d $*.d -o $*.t3x
  277.  
  278. -include $(DEPSDIR)/*.d
  279.  
  280. #---------------------------------------------------------------------------------------
  281. endif
  282. #---------------------------------------------------------------------------------------
  283.  
captcha