Makefile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4. ifeq ($(strip $(DEVKITARM)),)
  5. $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  6. endif
  7. include $(DEVKITARM)/gba_rules
  8. #---------------------------------------------------------------------------------
  9. # TARGET is the name of the output
  10. # BUILD is the directory where object files & intermediate files will be placed
  11. # SOURCES is a list of directories containing source code
  12. # INCLUDES is a list of directories containing extra header files
  13. # DATA is a list of directories containing binary data
  14. # GRAPHICS is a list of directories containing files to be processed by grit
  15. #
  16. # All directories are specified relative to the project directory where
  17. # the makefile is found
  18. #
  19. #---------------------------------------------------------------------------------
  20. TARGET := $(notdir $(CURDIR))
  21. BUILD := build
  22. SOURCES := source
  23. INCLUDES := include
  24. DATA := data
  25. MUSIC := music
  26. #---------------------------------------------------------------------------------
  27. # Disable LTO for IWRAM
  28. #---------------------------------------------------------------------------------
  29. %.iwram.o: %.iwram.cpp
  30. $(SILENTMSG) $(notdir $<)
  31. $(SILENTCMD)$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.iwram.d $(CXXFLAGS) -fno-lto -marm -c $< -o $@ $(ERROR_FILTER)
  32. #---------------------------------------------------------------------------------
  33. %.iwram.o: %.iwram.c
  34. $(SILENTMSG) $(notdir $<)
  35. $(SILENTCMD)$(CC) -MMD -MP -MF $(DEPSDIR)/$*.iwram.d $(CFLAGS) -fno-lto -marm -c $< -o $@ $(ERROR_FILTER)
  36. #---------------------------------------------------------------------------------
  37. # options for code generation
  38. #---------------------------------------------------------------------------------
  39. ARCH := -mthumb -mthumb-interwork
  40. CFLAGS := -g -Wall -O3 -fgcse-after-reload -gdwarf-4\
  41. -mcpu=arm7tdmi -mtune=arm7tdmi -flto\
  42. $(ARCH)
  43. CFLAGS += $(INCLUDE)
  44. CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
  45. ASFLAGS := -g $(ARCH)
  46. LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  47. #---------------------------------------------------------------------------------
  48. # any extra libraries we wish to link with the project
  49. #---------------------------------------------------------------------------------
  50. LIBS := -lmm -lgba
  51. #---------------------------------------------------------------------------------
  52. # list of directories containing libraries, this must be the top level containing
  53. # include and lib
  54. #---------------------------------------------------------------------------------
  55. LIBDIRS := $(LIBGBA)
  56. #---------------------------------------------------------------------------------
  57. # no real need to edit anything past this point unless you need to add additional
  58. # rules for different file extensions
  59. #---------------------------------------------------------------------------------
  60. ifneq ($(BUILD),$(notdir $(CURDIR)))
  61. #---------------------------------------------------------------------------------
  62. export OUTPUT := $(CURDIR)/$(TARGET)
  63. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  64. $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
  65. $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
  66. export DEPSDIR := $(CURDIR)/$(BUILD)
  67. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  68. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  69. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  70. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  71. ifneq ($(strip $(MUSIC)),)
  72. export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
  73. BINFILES += soundbank.bin
  74. endif
  75. #---------------------------------------------------------------------------------
  76. # use CXX for linking C++ projects, CC for standard C
  77. #---------------------------------------------------------------------------------
  78. ifeq ($(strip $(CPPFILES)),)
  79. #---------------------------------------------------------------------------------
  80. export LD := $(CC)
  81. #---------------------------------------------------------------------------------
  82. else
  83. #---------------------------------------------------------------------------------
  84. export LD := $(CXX)
  85. #---------------------------------------------------------------------------------
  86. endif
  87. #---------------------------------------------------------------------------------
  88. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  89. export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  90. export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
  91. export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  92. export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
  93. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  94. -I$(CURDIR)/$(BUILD)
  95. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  96. .PHONY: $(BUILD) clean
  97. #---------------------------------------------------------------------------------
  98. $(BUILD):
  99. @[ -d $@ ] || mkdir -p $@
  100. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  101. #---------------------------------------------------------------------------------
  102. clean:
  103. @echo clean ...
  104. @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
  105. #---------------------------------------------------------------------------------
  106. else
  107. #---------------------------------------------------------------------------------
  108. # main targets
  109. #---------------------------------------------------------------------------------
  110. $(OUTPUT).gba : $(OUTPUT).elf
  111. $(OUTPUT).elf : $(OFILES)
  112. $(OFILES_SOURCES) : $(HFILES)
  113. #---------------------------------------------------------------------------------
  114. # The bin2o rule should be copied and modified
  115. # for each extension used in the data directories
  116. #---------------------------------------------------------------------------------
  117. #---------------------------------------------------------------------------------
  118. # rule to build soundbank from music files
  119. #---------------------------------------------------------------------------------
  120. soundbank.bin soundbank.h : $(AUDIOFILES)
  121. #---------------------------------------------------------------------------------
  122. @mmutil $^ -osoundbank.bin -hsoundbank.h
  123. #---------------------------------------------------------------------------------
  124. # This rule links in binary data with the .wad extension
  125. #---------------------------------------------------------------------------------
  126. %.bin.o %_bin.h : %.bin
  127. #---------------------------------------------------------------------------------
  128. @echo $(notdir $<)
  129. @$(bin2o)
  130. -include $(DEPSDIR)/*.d
  131. #---------------------------------------------------------------------------------------
  132. endif
  133. #---------------------------------------------------------------------------------------