Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 7.39 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. #---------------------------------------------------------------------------------
  10. # canned command sequence for binary data
  11. #---------------------------------------------------------------------------------
  12. define bin2o
  13.     bin2s $< | $(AS) -o $(@)
  14.     echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
  15.     echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
  16.     echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
  17. endef
  18.  
  19.  
  20. #---------------------------------------------------------------------------------
  21. # path to tools
  22. #---------------------------------------------------------------------------------
  23. export PORTLIBS :=  $(DEVKITPRO)/portlibs/arm
  24. export PATH     :=  $(DEVKITARM)/bin:$(PORTLIBS)/bin:$(PATH)
  25. LIBNDS  :=  $(DEVKITPRO)/libnds
  26.  
  27. #---------------------------------------------------------------------------------
  28. # the prefix on the compiler executables
  29. #---------------------------------------------------------------------------------
  30. PREFIX      :=  arm-none-eabi-
  31.  
  32. export CC   :=  $(PREFIX)gcc
  33. export CXX  :=  $(PREFIX)g++
  34. export AS   :=  $(PREFIX)as
  35. export AR   :=  $(PREFIX)ar
  36. export OBJCOPY  :=  $(PREFIX)objcopy
  37. export OBJDUMP  :=  $(PREFIX)objdump
  38. export LD   :=  $(PREFIX)ld
  39.  
  40.  
  41. #---------------------------------------------------------------------------------
  42. # TARGET is the name of the output
  43. # BUILD is the directory where object files & intermediate files will be placed
  44. # SOURCES is a list of directories containing source code
  45. # INCLUDES is a list of directories containing extra header files
  46. # DATA is a list of directories containing binary files embedded using bin2o
  47. # GRAPHICS is a list of directories containing image files to be converted with grit
  48. #---------------------------------------------------------------------------------
  49. TARGET      :=  newcode
  50. BUILD       :=  build
  51. SOURCES     :=  source libfat_source source/storymode
  52. INCLUDES    :=  include source source/storymode
  53. DATA        :=  data  
  54. GRAPHICS    :=  gfx  
  55.  
  56. #---------------------------------------------------------------------------------
  57. # options for code generation
  58. #---------------------------------------------------------------------------------
  59. ARCH    := 
  60.  
  61. CFLAGS  :=  -g -Wall -O2\
  62.         -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
  63.         -ffast-math -fshort-wchar \
  64.         $(ARCH)
  65.  
  66. CFLAGS  +=  $(INCLUDE) -DARM9 -nodefaultlibs -I. -fno-builtin -c
  67. CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions
  68.  
  69. ASFLAGS :=  -g -march=armv5te -mtune=arm946e-s
  70. LDFLAGS =   -T $(CURDIR)/../symbols.x -T $(CURDIR)/../linker.x -g $(ARCH) -Map newcode.map
  71.  
  72. ifdef CODEADDR
  73.   LDFLAGS += -Ttext $(CODEADDR)
  74. endif
  75.  
  76. #---------------------------------------------------------------------------------
  77. # any extra libraries we wish to link with the project (order is important)
  78. #---------------------------------------------------------------------------------
  79. LIBS    := -lnds9 -lc -lgcc
  80.  
  81.  
  82. #---------------------------------------------------------------------------------
  83. # list of directories containing libraries, this must be the top level containing
  84. # include and lib
  85. #---------------------------------------------------------------------------------
  86. LIBDIRS :=  $(LIBNDS)  $(DEVKITARM) $(DEVKITARM)/arm-none-eabi
  87.  
  88. #---------------------------------------------------------------------------------
  89. ifneq ($(BUILD),$(notdir $(CURDIR)))
  90. #---------------------------------------------------------------------------------
  91.  
  92. export OUTPUT   :=  $(CURDIR)/$(TARGET)
  93.  
  94. export VPATH    :=  $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  95.                     $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
  96.                     $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
  97.  
  98. export DEPSDIR  :=  $(CURDIR)/$(BUILD)
  99.  
  100. CFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  101. CPPFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  102. SFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  103. PNGFILES    :=  $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
  104. BINFILES    :=  $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  105.  
  106. export OFILES   :=  $(addsuffix .o,$(BINFILES)) \
  107.                     $(PNGFILES:.png=.o) \
  108.                     $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  109.  
  110. export INCLUDE  :=  $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
  111.                     $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  112.                     -I$(CURDIR)/$(BUILD)
  113.  
  114. export LIBPATHS :=  $(foreach dir,$(LIBDIRS),-L$(dir)/lib) -L$(DEVKITARM)/lib/gcc/arm-none-eabi/9.1.0
  115.  
  116.  
  117. .PHONY: $(BUILD) clean
  118.  
  119. #---------------------------------------------------------------------------------
  120. $(BUILD):
  121.     @[ -d $@ ] || mkdir -p $@
  122.     @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  123.  
  124. #---------------------------------------------------------------------------------
  125. clean:
  126.     @echo clean ...
  127.     @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds
  128.  
  129. #---------------------------------------------------------------------------------
  130. else
  131.  
  132. #---------------------------------------------------------------------------------
  133. # main targets
  134. #---------------------------------------------------------------------------------
  135.  
  136. all: $(OUTPUT).bin $(OUTPUT).sym
  137.  
  138. $(OUTPUT).bin : $(OUTPUT).elf
  139.     $(OBJCOPY) -O binary $< $@
  140.     @echo built ... $(notdir $@)
  141.  
  142. $(OUTPUT).sym : $(OUTPUT).elf
  143.     $(OBJDUMP) -t $< > $@
  144.     @echo written the symbol table ... $(notdir $@)
  145.    
  146. #---------------------------------------------------------------------------------
  147. %.elf: $(OFILES)
  148.     @echo linking $(notdir $@)
  149.     $(LD)  $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
  150.  
  151. #---------------------------------------------------------------------------------
  152. %.bin.o :   %.bin
  153. #---------------------------------------------------------------------------------
  154.     @echo $(notdir $<)
  155.     $(bin2o)
  156.    
  157. #---------------------------------------------------------------------------------
  158. %.o: %.cpp
  159.     @echo $(notdir $<)
  160.     $(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
  161.    
  162. #---------------------------------------------------------------------------------
  163. %.o: %.c
  164.     @echo $(notdir $<)
  165.     $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
  166.    
  167. #---------------------------------------------------------------------------------
  168. %.o: %.s
  169.     @echo $(notdir $<)
  170.     $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
  171.  
  172. #---------------------------------------------------------------------------------
  173. # This rule creates assembly source files using grit
  174. # grit takes an image file and a .grit describing how the file is to be processed
  175. # add additional rules like this for each image extension
  176. # you use in the graphics folders
  177. #---------------------------------------------------------------------------------
  178. %.s %.h   : %.png %.grit
  179. #---------------------------------------------------------------------------------
  180.     grit $< -fts -o$*
  181.  
  182. -include $(DEPSDIR)/*.d
  183.  
  184. #---------------------------------------------------------------------------------------
  185. endif
  186. #---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement