Makefile 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. export DEVKITPRO=/opt/devkitpro
  2. export DEVKITARM=/opt/devkitpro/devkitARM
  3. #---------------------------------------------------------------------------------
  4. .SUFFIXES:
  5. #---------------------------------------------------------------------------------
  6. ifeq ($(strip $(DEVKITARM)),)
  7. $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  8. endif
  9. TOPDIR ?= $(CURDIR)
  10. include $(DEVKITARM)/3ds_rules
  11. #---------------------------------------------------------------------------------
  12. # TARGET is the name of the output
  13. # BUILD is the directory where object files & intermediate files will be placed
  14. # SOURCES is a list of directories containing source code
  15. # DATA is a list of directories containing data files
  16. # INCLUDES is a list of directories containing header files
  17. #
  18. # NO_SMDH: if set to anything, no SMDH file is generated.
  19. # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
  20. # APP_TITLE is the name of the app stored in the SMDH file (Optional)
  21. # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
  22. # APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
  23. # ICON is the filename of the icon (.png), relative to the project folder.
  24. # If not set, it attempts to use one of the following (in this order):
  25. # - <Project name>.png
  26. # - icon.png
  27. # - <libctru folder>/default_icon.png
  28. #---------------------------------------------------------------------------------
  29. TARGET := sdlpal
  30. BUILD := build
  31. SOURCES := . .. ../adplug ../libmad
  32. APP_TITLE := SDLPAL
  33. APP_DESCRIPTION := Pal DOS for 3DS
  34. APP_AUTHOR := Ported by ZephRay
  35. ICON := icon.png
  36. #---------------------------------------------------------------------------------
  37. # options for code generation
  38. #---------------------------------------------------------------------------------
  39. ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
  40. CFLAGS := -g -Wall -O2 -mword-relocations \
  41. -fomit-frame-pointer -ffunction-sections \
  42. $(ARCH)
  43. CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D__3DS__ -D__N3DS__ -DPAL_HAS_PLATFORM_SPECIFIC_UTILS -I.
  44. CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++14
  45. ASFLAGS := -g $(ARCH)
  46. LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  47. LIBS := -lSDL -lcitro3d -lctru -lm
  48. #---------------------------------------------------------------------------------
  49. # list of directories containing libraries, this must be the top level containing
  50. # include and lib
  51. #---------------------------------------------------------------------------------
  52. LIBDIRS := $(CTRULIB) $(PORTLIBS)
  53. #---------------------------------------------------------------------------------
  54. # no real need to edit anything past this point unless you need to add additional
  55. # rules for different file extensions
  56. #---------------------------------------------------------------------------------
  57. ifneq ($(BUILD),$(notdir $(CURDIR)))
  58. #---------------------------------------------------------------------------------
  59. export OUTPUT := $(CURDIR)/$(TARGET)
  60. export TOPDIR := $(CURDIR)
  61. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  62. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  63. export DEPSDIR := $(CURDIR)/$(BUILD)
  64. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  65. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  66. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  67. PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
  68. SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
  69. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  70. #---------------------------------------------------------------------------------
  71. # use CXX for linking C++ projects, CC for standard C
  72. #---------------------------------------------------------------------------------
  73. ifeq ($(strip $(CPPFILES)),)
  74. #---------------------------------------------------------------------------------
  75. export LD := $(CC)
  76. #---------------------------------------------------------------------------------
  77. else
  78. #---------------------------------------------------------------------------------
  79. export LD := $(CXX)
  80. #---------------------------------------------------------------------------------
  81. endif
  82. #---------------------------------------------------------------------------------
  83. export OFILES := $(addsuffix .o,$(BINFILES)) \
  84. $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
  85. $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  86. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  87. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  88. $(foreach dir,$(LIBDIRS),-I$(dir)/include/SDL) \
  89. -I$(CURDIR)/$(BUILD)
  90. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  91. ifeq ($(strip $(ICON)),)
  92. icons := $(wildcard *.png)
  93. ifneq (,$(findstring $(TARGET).png,$(icons)))
  94. export APP_ICON := $(TOPDIR)/$(TARGET).png
  95. else
  96. ifneq (,$(findstring icon.png,$(icons)))
  97. export APP_ICON := $(TOPDIR)/icon.png
  98. endif
  99. endif
  100. else
  101. export APP_ICON := $(TOPDIR)/$(ICON)
  102. endif
  103. ifeq ($(strip $(NO_SMDH)),)
  104. export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
  105. endif
  106. ifneq ($(ROMFS),)
  107. export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
  108. endif
  109. .PHONY: $(BUILD) clean all
  110. #---------------------------------------------------------------------------------
  111. all: $(BUILD)
  112. $(BUILD):
  113. @[ -d $@ ] || mkdir -p $@
  114. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  115. #---------------------------------------------------------------------------------
  116. clean:
  117. @echo clean ...
  118. @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET).cia $(TARGET)-strip.elf
  119. #---------------------------------------------------------------------------------
  120. $(TARGET)-strip.elf: $(BUILD)
  121. @$(STRIP) $(TARGET).elf -o $(TARGET)-strip.elf
  122. #---------------------------------------------------------------------------------
  123. cci: $(TARGET)-strip.elf
  124. @makerom -f cci -rsf resources/$(TARGET).rsf -target d -exefslogo -elf $(TARGET)-strip.elf -o $(TARGET).3ds
  125. @echo "built ... 3ds"
  126. #---------------------------------------------------------------------------------
  127. cia: $(TARGET)-strip.elf
  128. @makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf $(TARGET).rsf -icon icon.bin -banner banner.bin -exefslogo -target t
  129. @echo "built ... cia"
  130. #---------------------------------------------------------------------------------
  131. else
  132. DEPENDS := $(OFILES:.o=.d)
  133. #---------------------------------------------------------------------------------
  134. # main targets
  135. #---------------------------------------------------------------------------------
  136. ifeq ($(strip $(NO_SMDH)),)
  137. $(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
  138. else
  139. $(OUTPUT).3dsx : $(OUTPUT).elf
  140. endif
  141. $(OUTPUT).elf : $(OFILES)
  142. #---------------------------------------------------------------------------------
  143. # you need a rule like this for each extension you use as binary data
  144. #---------------------------------------------------------------------------------
  145. %.bin.o : %.bin
  146. #---------------------------------------------------------------------------------
  147. @echo $(notdir $<)
  148. @$(bin2o)
  149. #---------------------------------------------------------------------------------
  150. # rules for assembling GPU shaders
  151. #---------------------------------------------------------------------------------
  152. define shader-as
  153. $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
  154. picasso -o $(CURBIN) $1
  155. bin2s $(CURBIN) | $(AS) -o $@
  156. echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
  157. echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
  158. echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
  159. endef
  160. %.shbin.o : %.v.pica %.g.pica
  161. @echo $(notdir $^)
  162. @$(call shader-as,$^)
  163. %.shbin.o : %.v.pica
  164. @echo $(notdir $<)
  165. @$(call shader-as,$<)
  166. %.shbin.o : %.shlist
  167. @echo $(notdir $<)
  168. @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
  169. -include $(DEPENDS)
  170. #---------------------------------------------------------------------------------------
  171. endif
  172. #---------------------------------------------------------------------------------------