Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 7.38 KB | None | 0 0
  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. #
  19. # NO_SMDH: if set to anything, no SMDH file is generated.
  20. # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
  21. # APP_TITLE is the name of the app stored in the SMDH file (Optional)
  22. # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
  23. # APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
  24. # ICON is the filename of the icon (.png), relative to the project folder.
  25. #   If not set, it attempts to use one of the following (in this order):
  26. #     - <Project name>.png
  27. #     - icon.png
  28. #     - <libctru folder>/default_icon.png
  29. #---------------------------------------------------------------------------------
  30. TARGET      :=  $(notdir $(CURDIR))
  31. BUILD       :=  build
  32. SOURCES     :=  source
  33. DATA        :=  data
  34. INCLUDES    :=  include
  35. #ROMFS      :=  romfs
  36.  
  37. #---------------------------------------------------------------------------------
  38. # options for code generation
  39. #---------------------------------------------------------------------------------
  40. ARCH    :=  -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
  41.  
  42. CFLAGS  :=  -g -Wall -O2 -mword-relocations \
  43.             -fomit-frame-pointer -ffunction-sections \
  44.             $(ARCH)
  45.  
  46. CFLAGS  +=  $(INCLUDE) -DARM11 -D_3DS
  47.  
  48. CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
  49.  
  50. ASFLAGS :=  -g $(ARCH)
  51. LDFLAGS =   -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  52.  
  53. LIBS    := -lctru -lm
  54.  
  55. #---------------------------------------------------------------------------------
  56. # list of directories containing libraries, this must be the top level containing
  57. # include and lib
  58. #---------------------------------------------------------------------------------
  59. LIBDIRS := $(CTRULIB)
  60.  
  61.  
  62. #---------------------------------------------------------------------------------
  63. # no real need to edit anything past this point unless you need to add additional
  64. # rules for different file extensions
  65. #---------------------------------------------------------------------------------
  66. ifneq ($(BUILD),$(notdir $(CURDIR)))
  67. #---------------------------------------------------------------------------------
  68.  
  69. export OUTPUT   :=  $(CURDIR)/$(TARGET)
  70. export TOPDIR   :=  $(CURDIR)
  71.  
  72. export VPATH    :=  $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  73.             $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  74.  
  75. export DEPSDIR  :=  $(CURDIR)/$(BUILD)
  76.  
  77. CFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  78. CPPFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  79. SFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  80. PICAFILES   :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
  81. SHLISTFILES :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
  82. BINFILES    :=  $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  83.  
  84. #---------------------------------------------------------------------------------
  85. # use CXX for linking C++ projects, CC for standard C
  86. #---------------------------------------------------------------------------------
  87. ifeq ($(strip $(CPPFILES)),)
  88. #---------------------------------------------------------------------------------
  89.     export LD   :=  $(CC)
  90. #---------------------------------------------------------------------------------
  91. else
  92. #---------------------------------------------------------------------------------
  93.     export LD   :=  $(CXX)
  94. #---------------------------------------------------------------------------------
  95. endif
  96. #---------------------------------------------------------------------------------
  97.  
  98. export OFILES   :=  $(addsuffix .o,$(BINFILES)) \
  99.             $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
  100.             $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  101.  
  102. export INCLUDE  :=  $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  103.             $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  104.             -I$(CURDIR)/$(BUILD)
  105.  
  106. export LIBPATHS :=  $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  107.  
  108. ifeq ($(strip $(ICON)),)
  109.     icons := $(wildcard *.png)
  110.     ifneq (,$(findstring $(TARGET).png,$(icons)))
  111.         export APP_ICON := $(TOPDIR)/$(TARGET).png
  112.     else
  113.         ifneq (,$(findstring icon.png,$(icons)))
  114.             export APP_ICON := $(TOPDIR)/icon.png
  115.         endif
  116.     endif
  117. else
  118.     export APP_ICON := $(TOPDIR)/$(ICON)
  119. endif
  120.  
  121. ifeq ($(strip $(NO_SMDH)),)
  122.     export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
  123. endif
  124.  
  125. ifneq ($(ROMFS),)
  126.     export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
  127. endif
  128.  
  129. .PHONY: $(BUILD) clean all
  130.  
  131. #---------------------------------------------------------------------------------
  132. all: $(BUILD)
  133.  
  134. $(BUILD):
  135.     @[ -d $@ ] || mkdir -p $@
  136.     @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  137.  
  138. #---------------------------------------------------------------------------------
  139. clean:
  140.     @echo clean ...
  141.     @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
  142.  
  143.  
  144. #---------------------------------------------------------------------------------
  145. else
  146.  
  147. DEPENDS :=  $(OFILES:.o=.d)
  148.  
  149. #---------------------------------------------------------------------------------
  150. # main targets
  151. #---------------------------------------------------------------------------------
  152. ifeq ($(strip $(NO_SMDH)),)
  153. $(OUTPUT).3dsx  :   $(OUTPUT).elf $(OUTPUT).smdh
  154. else
  155. $(OUTPUT).3dsx  :   $(OUTPUT).elf
  156. endif
  157.  
  158. $(OUTPUT).elf   :   $(OFILES)
  159.  
  160. #---------------------------------------------------------------------------------
  161. # you need a rule like this for each extension you use as binary data
  162. #---------------------------------------------------------------------------------
  163. %.bin.o :   %.bin
  164. #---------------------------------------------------------------------------------
  165.     @echo $(notdir $<)
  166.     @$(bin2o)
  167.  
  168. #---------------------------------------------------------------------------------
  169. # rules for assembling GPU shaders
  170. #---------------------------------------------------------------------------------
  171. define shader-as
  172.     $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
  173.     picasso -o $(CURBIN) $1
  174.     bin2s $(CURBIN) | $(AS) -o $@
  175.     echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
  176.     echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
  177.     echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
  178. endef
  179.  
  180. %.shbin.o : %.v.pica %.g.pica
  181.     @echo $(notdir $^)
  182.     @$(call shader-as,$^)
  183.  
  184. %.shbin.o : %.v.pica
  185.     @echo $(notdir $<)
  186.     @$(call shader-as,$<)
  187.  
  188. %.shbin.o : %.shlist
  189.     @echo $(notdir $<)
  190.     @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
  191.  
  192. -include $(DEPENDS)
  193.  
  194. #---------------------------------------------------------------------------------------
  195. endif
  196. #---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement