Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #
  16. # NO_SMDH: if set to anything, no SMDH file is generated.
  17. # APP_TITLE is the name of the app stored in the SMDH file (Optional)
  18. # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
  19. # APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
  20. # ICON is the filename of the icon (.png), relative to the project folder.
  21. # If not set, it attempts to use one of the following (in this order):
  22. # - <Project name>.png
  23. # - icon.png
  24. # - <libctru folder>/default_icon.png
  25. #---------------------------------------------------------------------------------
  26. TARGET := $(notdir $(CURDIR))
  27. BUILD := build
  28. SOURCES := src
  29. DATA := data
  30. INCLUDES := inc
  31. APP_TITLE := Sapphire
  32. APP_DESCRIPTION := The freeShop sysmodule
  33. APP_AUTHOR := arc13
  34. APP_PRODUCT_CODE:= CTR-N-SPMD
  35. APP_UNIQUE_ID := 0xF13EE
  36. APP_TITLE := $(shell echo "$(APP_TITLE)" | cut -c1-128)
  37. APP_DESCRIPTION := $(shell echo "$(APP_DESCRIPTION)" | cut -c1-256)
  38. APP_AUTHOR := $(shell echo "$(APP_AUTHOR)" | cut -c1-128)
  39. APP_PRODUCT_CODE:= $(shell echo $(APP_PRODUCT_CODE) | cut -c1-16)
  40. APP_UNIQUE_ID := $(shell echo $(APP_UNIQUE_ID) | cut -c1-8)
  41. #---------------------------------------------------------------------------------
  42. # options for code generation
  43. #---------------------------------------------------------------------------------
  44. ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
  45. CFLAGS := -g -Wall -Wno-format -O0 -mword-relocations \
  46. -fomit-frame-pointer -ffast-math \
  47. $(ARCH)
  48. CFLAGS += $(INCLUDE) -DARM11 -D_3DS
  49. CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++11
  50. ASFLAGS := -g $(ARCH)
  51. LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  52. LIBS := -lturbojpeg -lz -lctru -lm
  53. #---------------------------------------------------------------------------------
  54. # list of directories containing libraries, this must be the top level containing
  55. # include and lib
  56. #---------------------------------------------------------------------------------
  57. LIBDIRS := $(CTRULIB) $(DEVKITPRO)/portlibs/armv6k
  58. #---------------------------------------------------------------------------------
  59. # no real need to edit anything past this point unless you need to add additional
  60. # rules for different file extensions
  61. #---------------------------------------------------------------------------------
  62. ifneq ($(BUILD),$(notdir $(CURDIR)))
  63. #---------------------------------------------------------------------------------
  64. export OUTPUT := $(CURDIR)/$(TARGET)
  65. export TOPDIR := $(CURDIR)
  66. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  67. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  68. export DEPSDIR := $(CURDIR)/$(BUILD)
  69. CFILES := $(shell find $(SOURCES) -name '*.c' -printf "%P\n") #$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  70. CPPFILES := $(shell find $(SOURCES) -name '*.cpp' -printf "%P\n") #$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  71. SFILES := $(shell find $(SOURCES) -name '*.s' -printf "%P\n") #$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  72. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  73. #---------------------------------------------------------------------------------
  74. # use CXX for linking C++ projects, CC for standard C
  75. #---------------------------------------------------------------------------------
  76. ifeq ($(strip $(CPPFILES)),)
  77. #---------------------------------------------------------------------------------
  78. export LD := $(CC)
  79. #---------------------------------------------------------------------------------
  80. else
  81. #---------------------------------------------------------------------------------
  82. export LD := $(CXX)
  83. #---------------------------------------------------------------------------------
  84. endif
  85. #---------------------------------------------------------------------------------
  86. export OFILES := $(addsuffix .o,$(BINFILES)) \
  87. $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  88. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)/include) \
  89. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  90. -I$(CURDIR)/$(BUILD) \
  91. -I-$(CURDIR)/$(SOURCES)
  92. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
  93. $(foreach dir,$(INCLUDES),-L$(CURDIR)/$(dir)/lib)
  94. ifeq ($(strip $(ICON)),)
  95. icons := $(wildcard *.png)
  96. ifneq (,$(findstring $(TARGET).png,$(icons)))
  97. export APP_ICON := $(TOPDIR)/$(TARGET).png
  98. else
  99. ifneq (,$(findstring icon.png,$(icons)))
  100. export APP_ICON := $(TOPDIR)/icon.png
  101. endif
  102. endif
  103. else
  104. export APP_ICON := $(TOPDIR)/$(ICON)
  105. endif
  106. .PHONY: $(BUILD) clean all
  107. #---------------------------------------------------------------------------------
  108. all: $(BUILD)
  109. $(BUILD):
  110. @[ -d $@ ] || mkdir -p $@
  111. @find $(SOURCES) -type d -printf "%P\0" | xargs -0 -I {} mkdir -p $(BUILD)/{}
  112. @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  113. #---------------------------------------------------------------------------------
  114. clean:
  115. @echo clean ...
  116. @rm -rf $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET).3ds $(TARGET).cia
  117. #---------------------------------------------------------------------------------
  118. else
  119. DEPENDS := $(OFILES:.o=.d)
  120. #---------------------------------------------------------------------------------
  121. # main targets
  122. #---------------------------------------------------------------------------------
  123. ifeq ($(strip $(NO_SMDH)),)
  124. .PHONY: all
  125. all : $(OUTPUT).cia
  126. endif
  127. $(OUTPUT).elf : $(OFILES)
  128. $(OUTPUT)-stripped.elf: $(OUTPUT).elf
  129. @cp $(OUTPUT).elf $(OUTPUT)-stripped.elf
  130. @$(PREFIX)strip $(OUTPUT)-stripped.elf
  131. $(OUTPUT).cia: $(OUTPUT)-stripped.elf
  132. @makerom -f cia -o $(OUTPUT).cia -rsf $(TOPDIR)/res/cia.rsf -target t -exefslogo -elf $(OUTPUT)-stripped.elf -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(APP_PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(APP_UNIQUE_ID)"
  133. @echo "built ... $(notdir $@)"
  134. #---------------------------------------------------------------------------------
  135. # you need a rule like this for each extension you use as binary data
  136. #---------------------------------------------------------------------------------
  137. %.bin.o : %.bin
  138. #---------------------------------------------------------------------------------
  139. @echo $(notdir $<)
  140. @$(bin2o)
  141. -include $(DEPENDS)
  142. #---------------------------------------------------------------------------------------
  143. endif
  144. #---------------------------------------------------------------------------------------