Guest User

Makefile

a guest
Feb 28th, 2024
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.35 KB | Source Code | 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. include $(DEVKITARM)/gba_rules
  10.  
  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. # INCLUDES is a list of directories containing extra header files
  16. # DATA is a list of directories containing binary data
  17. # GRAPHICS is a list of directories containing files to be processed by grit
  18. #
  19. # All directories are specified relative to the project directory where
  20. # the makefile is found
  21. #
  22. #---------------------------------------------------------------------------------
  23. TARGET := rom/$(notdir $(CURDIR))
  24. BUILD := build
  25. SOURCES := src
  26. INCLUDES    := include
  27. DATA :=
  28. MUSIC :=
  29.  
  30. #---------------------------------------------------------------------------------
  31. # options for code generation
  32. #---------------------------------------------------------------------------------
  33. ARCH    :=  -mthumb -mthumb-interwork
  34.  
  35. CFLAGS  :=  -g -Wall -O2\
  36.         -mcpu=arm7tdmi -mtune=arm7tdmi\
  37.         $(ARCH)
  38.  
  39. CFLAGS  +=  $(INCLUDE)
  40.  
  41. CXXFLAGS    :=  $(CFLAGS) -fno-rtti -fno-exceptions
  42.  
  43. ASFLAGS :=  -g $(ARCH)
  44. LDFLAGS =   -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  45.  
  46. #---------------------------------------------------------------------------------
  47. # any extra libraries we wish to link with the project
  48. #---------------------------------------------------------------------------------
  49. LIBS    := -lmm -lgba
  50.  
  51. #---------------------------------------------------------------------------------
  52. # list of directories containing libraries, this must be the top level containing
  53. # include and lib
  54. #---------------------------------------------------------------------------------
  55. LIBDIRS :=  $(LIBGBA)
  56.  
  57. #---------------------------------------------------------------------------------
  58. # no real need to edit anything past this point unless you need to add additional
  59. # rules for different file extensions
  60. #---------------------------------------------------------------------------------
  61.  
  62. ifneq ($(BUILD),$(notdir $(CURDIR)))
  63. #---------------------------------------------------------------------------------
  64.  
  65. export OUTPUT   :=  $(CURDIR)/$(TARGET)
  66.  
  67. export VPATH    :=  $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  68.             $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
  69.             $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
  70.  
  71. export DEPSDIR  :=  $(CURDIR)/$(BUILD)
  72.  
  73. CFILES :=   $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  74. CPPFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  75. SFILES :=   $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  76. BINFILES    :=  $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  77.  
  78. ifneq ($(strip $(MUSIC)),)
  79.     export AUDIOFILES   :=  $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(MUSIC)/$(dir))
  80.     BINFILES += soundbank.bin
  81. endif
  82.  
  83. #---------------------------------------------------------------------------------
  84. # use CXX for linking C++ projects, CC for standard C
  85. #---------------------------------------------------------------------------------
  86. ifeq ($(strip $(CPPFILES)),)
  87. #---------------------------------------------------------------------------------
  88.  export LD   :=  $(CC)
  89. #---------------------------------------------------------------------------------
  90. else
  91. #---------------------------------------------------------------------------------
  92.  export LD   :=  $(CXX)
  93. #---------------------------------------------------------------------------------
  94. endif
  95. #---------------------------------------------------------------------------------
  96.  
  97. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  98.  
  99. export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  100.  
  101. export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
  102.  
  103. export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  104.  
  105. export INCLUDE  :=  $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
  106.                     $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  107.                     -I$(CURDIR)/$(BUILD)
  108.  
  109. export LIBPATHS :=  $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  110.  
  111. .PHONY: $(BUILD) clean
  112.  
  113. #---------------------------------------------------------------------------------
  114. $(BUILD):
  115.     @[ -d $@ ]||mkdir -p $@
  116.     @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  117.  
  118. #---------------------------------------------------------------------------------
  119. clean:
  120.     @echo clean ...
  121.     @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
  122.  
  123. #---------------------------------------------------------------------------------
  124. else
  125.  
  126. #---------------------------------------------------------------------------------
  127. # main targets
  128. #---------------------------------------------------------------------------------
  129.  
  130. $(OUTPUT).gba   :   $(OUTPUT).elf
  131.  
  132. $(OUTPUT).elf   :   $(OFILES)
  133.  
  134. $(OFILES_SOURCES) : $(HFILES)
  135.  
  136. #---------------------------------------------------------------------------------
  137. # The bin2o rule should be copied and modified
  138. # for each extension used in the data directories
  139. #---------------------------------------------------------------------------------
  140.  
  141. #---------------------------------------------------------------------------------
  142. # rule to build soundbank from music files
  143. #---------------------------------------------------------------------------------
  144. soundbank.bin soundbank.h : $(AUDIOFILES)
  145. #---------------------------------------------------------------------------------
  146.     @mmutil $^ -osoundbank.bin -hsoundbank.h
  147. #---------------------------------------------------------------------------------
  148. # This rule links in binary data with the .bin extension
  149. #---------------------------------------------------------------------------------
  150. %.bin.o %_bin.h :   %.bin
  151. #---------------------------------------------------------------------------------
  152.     @echo $(notdir $<)
  153.     @$(bin2o)
  154.  
  155. -include $(DEPSDIR)/*.d
  156. #---------------------------------------------------------------------------------------
  157. endif
  158. #---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment