You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.7KB

  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. TARGET := $(notdir $(CURDIR))
  17. BUILD := build
  18. SOURCES := source source/3ds
  19. DATA :=
  20. INCLUDES := include include/3ds
  21. #---------------------------------------------------------------------------------
  22. # options for code generation
  23. #---------------------------------------------------------------------------------
  24. ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=soft -mtp=soft
  25. DEFINES := -DARM11 -D_3DS
  26. CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -Wno-unused-value -Os -flto -mword-relocations \
  27. -fomit-frame-pointer -ffunction-sections -fdata-sections \
  28. -fno-exceptions -fno-ident -fno-unwind-tables -fno-asynchronous-unwind-tables \
  29. $(ARCH) $(DEFINES)
  30. CFLAGS += $(INCLUDE)
  31. CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
  32. ASFLAGS := -g $(ARCH)
  33. LDFLAGS = -specs=3dsx.specs -nostartfiles -nostdlib \
  34. -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  35. LIBS :=
  36. #---------------------------------------------------------------------------------
  37. # list of directories containing libraries, this must be the top level containing
  38. # include and lib
  39. #---------------------------------------------------------------------------------
  40. LIBDIRS := $(TOPDIR)
  41. #---------------------------------------------------------------------------------
  42. # no real need to edit anything past this point unless you need to add additional
  43. # rules for different file extensions
  44. #---------------------------------------------------------------------------------
  45. ifneq ($(BUILD),$(notdir $(CURDIR)))
  46. #---------------------------------------------------------------------------------
  47. export OUTPUT := $(CURDIR)/$(TARGET)
  48. export TOPDIR := $(CURDIR)
  49. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  50. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  51. export DEPSDIR := $(CURDIR)/$(BUILD)
  52. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  53. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  54. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  55. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  56. #---------------------------------------------------------------------------------
  57. # use CXX for linking C++ projects, CC for standard C
  58. #---------------------------------------------------------------------------------
  59. ifeq ($(strip $(CPPFILES)),)
  60. #---------------------------------------------------------------------------------
  61. export LD := $(CC)
  62. #---------------------------------------------------------------------------------
  63. else
  64. #---------------------------------------------------------------------------------
  65. export LD := $(CXX)
  66. #---------------------------------------------------------------------------------
  67. endif
  68. #---------------------------------------------------------------------------------
  69. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  70. export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  71. export OFILES := $(OFILES_BIN) $(OFILES_SRC)
  72. export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  73. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  74. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  75. -I$(CURDIR)/$(BUILD)
  76. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  77. .PHONY: $(BUILD) clean all
  78. #---------------------------------------------------------------------------------
  79. all: $(BUILD)
  80. $(BUILD):
  81. @[ -d $@ ] || mkdir -p $@
  82. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  83. #---------------------------------------------------------------------------------
  84. clean:
  85. @echo clean ...
  86. @rm -fr $(BUILD) $(TARGET).cxi $(TARGET).elf
  87. #---------------------------------------------------------------------------------
  88. else
  89. .PHONY: all
  90. DEPENDS := $(OFILES:.o=.d)
  91. #---------------------------------------------------------------------------------
  92. # main targets
  93. #---------------------------------------------------------------------------------
  94. all : $(OUTPUT).cxi
  95. $(OUTPUT).cxi : $(OUTPUT).elf $(OUTPUT).rsf
  96. @makerom -f ncch -rsf $(word 2,$^) -o $@ -elf $<
  97. @echo built ... $(notdir $@)
  98. $(OUTPUT).elf : $(OFILES)
  99. %.elf: $(OFILES)
  100. @echo linking $(notdir $@)
  101. $(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
  102. @$(NM) -CSn $@ > $(notdir $*.lst)
  103. $(OFILES_SRC) : $(HFILES_BIN)
  104. #---------------------------------------------------------------------------------
  105. # you need a rule like this for each extension you use as binary data
  106. #---------------------------------------------------------------------------------
  107. %.bin.o %_bin.h: %.bin
  108. #---------------------------------------------------------------------------------
  109. @echo $(notdir $<)
  110. @$(bin2o)
  111. #---------------------------------------------------------------------------------
  112. %.xml.o %_xml.h: %.xml
  113. #---------------------------------------------------------------------------------
  114. @echo $(notdir $<)
  115. @$(bin2o)
  116. -include $(DEPENDS)
  117. #---------------------------------------------------------------------------------------
  118. endif
  119. #---------------------------------------------------------------------------------------