Makefile 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #---------------------------------------------------------------------------------
  2. # Clear the implicit built in rules
  3. #---------------------------------------------------------------------------------
  4. .SUFFIXES:
  5. #---------------------------------------------------------------------------------
  6. ifeq ($(strip $(DEVKITARM)),)
  7. $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
  8. endif
  9. LIBGBA := $(DEVKITPRO)/libgba
  10. #---------------------------------------------------------------------------------
  11. # path to tools - this can be deleted if you set the path in windows
  12. #---------------------------------------------------------------------------------
  13. export PATH := $(DEVKITARM)/bin:$(PATH)
  14. #---------------------------------------------------------------------------------
  15. # the prefix on the compiler executables
  16. #---------------------------------------------------------------------------------
  17. PREFIX := arm-eabi-
  18. export CC := $(PREFIX)gcc
  19. export CXX := $(PREFIX)g++
  20. export AS := $(PREFIX)as
  21. export AR := $(PREFIX)ar
  22. export OBJCOPY := $(PREFIX)objcopy
  23. define adjustdepends
  24. cp $(DEPSDIR)/$*.d $(DEPSDIR)/$*.P;
  25. sed -e 's/#.*//' -e 's/^[^:]*: \+//' -e 's/^ *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $(DEPSDIR)/$*.P >> $(DEPSDIR)/$*.d;
  26. rm $(DEPSDIR)/$*.P
  27. endef
  28. #---------------------------------------------------------------------------------
  29. %.a:
  30. #---------------------------------------------------------------------------------
  31. @echo "### " $(notdir $@)
  32. rm -f $@
  33. $(AR) -rc $@ $^
  34. #---------------------------------------------------------------------------------
  35. %.o: %.cpp
  36. @echo "### " $(notdir $<)
  37. $(CXX) -MMD -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@
  38. $(adjustdepends)
  39. #---------------------------------------------------------------------------------
  40. %.o: %.c
  41. @echo "### " $(notdir $<)
  42. $(CC) -MMD -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@
  43. $(adjustdepends)
  44. #---------------------------------------------------------------------------------
  45. %.o: %.s
  46. @echo $(notdir $<)
  47. $(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
  48. $(adjustdepends)
  49. #---------------------------------------------------------------------------------
  50. %.o: %.S
  51. @echo $(notdir $<)
  52. $(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
  53. $(adjustdepends)
  54. #---------------------------------------------------------------------------------
  55. # canned command sequence for binary data
  56. #---------------------------------------------------------------------------------
  57. define bin2o
  58. bin2s $< | $(AS) $(ARCH) -o $(@)
  59. echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
  60. echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
  61. echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
  62. endef
  63. #---------------------------------------------------------------------------------
  64. %.gba: %.elf
  65. $(OBJCOPY) -O binary $< $@
  66. @echo built ... $(notdir $@)
  67. @gbafix $@
  68. #---------------------------------------------------------------------------------
  69. %_mb.elf:
  70. @echo "### linking multiboot"
  71. $(LD) -specs=gba_mb.specs $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
  72. #---------------------------------------------------------------------------------
  73. %.elf:
  74. @echo "### linking cartridge"
  75. $(LD) $(LDFLAGS) -specs=gba.specs $(OFILES) $(LIBPATHS) $(LIBS) -o $@
  76. #---------------------------------------------------------------------------------
  77. # TARGET is the name of the output, if this ends with _mb generates a multiboot image
  78. # BUILD is the directory where object files & intermediate files will be placed
  79. # SOURCES is a list of directories containing source code
  80. # INCLUDES is a list of directories containing extra header files
  81. #---------------------------------------------------------------------------------
  82. TARGET := supertux
  83. BUILD := build
  84. SOURCES := src data
  85. INCLUDES :=
  86. #---------------------------------------------------------------------------------
  87. # options for code generation
  88. #---------------------------------------------------------------------------------
  89. ARCH := -mthumb -mthumb-interwork
  90. CFLAGS := -g -Wall -O3\
  91. -mcpu=arm7tdmi -mtune=arm7tdmi\
  92. -fomit-frame-pointer\
  93. -ffast-math \
  94. $(ARCH)
  95. CFLAGS += $(INCLUDE)
  96. CXXFLAGS := -g -Wall -O3\
  97. -mcpu=arm7tdmi -mtune=arm7tdmi\
  98. -fomit-frame-pointer\
  99. -ffast-math \
  100. $(ARCH)
  101. CXXFLAGS += $(INCLUDE)
  102. ASFLAGS := $(ARCH)
  103. LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map
  104. #---------------------------------------------------------------------------------
  105. # path to tools - this can be deleted if you set the path in windows
  106. #---------------------------------------------------------------------------------
  107. export PATH := $(DEVKITARM)/bin:$(PATH)
  108. #---------------------------------------------------------------------------------
  109. # any extra libraries we wish to link with the project
  110. #---------------------------------------------------------------------------------
  111. LIBS := -lgba -lm
  112. #---------------------------------------------------------------------------------
  113. # list of directories containing libraries, this must be the top level containing
  114. # include and lib
  115. #---------------------------------------------------------------------------------
  116. LIBDIRS := $(LIBGBA)
  117. #---------------------------------------------------------------------------------
  118. # no real need to edit anything past this point unless you need to add additional
  119. # rules for different file extensions
  120. #---------------------------------------------------------------------------------
  121. ifneq ($(BUILD),$(notdir $(CURDIR)))
  122. #---------------------------------------------------------------------------------
  123. export OUTPUT := $(CURDIR)/$(TARGET)
  124. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
  125. export PATH := $(DEVKITARM)/bin:$(PATH)
  126. export DEPSDIR := $(CURDIR)/$(BUILD)
  127. #---------------------------------------------------------------------------------
  128. # automatically build a list of object files for our project
  129. #---------------------------------------------------------------------------------
  130. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  131. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  132. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  133. RAWFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.raw)))
  134. #---------------------------------------------------------------------------------
  135. # use CXX for linking C++ projects, CC for standard C
  136. #---------------------------------------------------------------------------------
  137. ifeq ($(strip $(CPPFILES)),)
  138. #---------------------------------------------------------------------------------
  139. export LD := $(CC)
  140. #---------------------------------------------------------------------------------
  141. else
  142. #---------------------------------------------------------------------------------
  143. export LD := $(CXX)
  144. #---------------------------------------------------------------------------------
  145. endif
  146. #---------------------------------------------------------------------------------
  147. export OFILES := $(RAWFILES:.raw=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  148. #---------------------------------------------------------------------------------
  149. # build a list of include paths
  150. #---------------------------------------------------------------------------------
  151. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  152. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  153. -I$(CURDIR)/$(BUILD)
  154. #---------------------------------------------------------------------------------
  155. # build a list of library paths
  156. #---------------------------------------------------------------------------------
  157. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  158. .PHONY: $(BUILD) clean
  159. #---------------------------------------------------------------------------------
  160. $(BUILD):
  161. @[ -d $@ ] || mkdir -p $@
  162. make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  163. all : $(BUILD)
  164. #---------------------------------------------------------------------------------
  165. clean:
  166. rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
  167. #---------------------------------------------------------------------------------
  168. else
  169. DEPENDS := $(OFILES:.o=.d)
  170. #---------------------------------------------------------------------------------
  171. # main targets
  172. #---------------------------------------------------------------------------------
  173. $(OUTPUT).gba : $(OUTPUT).elf
  174. $(OUTPUT).elf : $(OFILES)
  175. %.o : %.raw
  176. @echo $(notdir $<)
  177. @$(bin2o)
  178. -include $(DEPENDS)
  179. #---------------------------------------------------------------------------------
  180. endif
  181. #---------------------------------------------------------------------------------