Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #---------------------------------------------------------------------------------
  2. # Clear the implicit built in rules
  3. #---------------------------------------------------------------------------------
  4. .SUFFIXES:
  5. #---------------------------------------------------------------------------------
  6. ifeq ($(strip $(DEVKITPPC)),)
  7. $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
  8. endif
  9. #---------------------------------------------------------------------------------
  10. # build for wii by default, make HW_TYPE=gamecube will do what it sounds like
  11. # NOTE: gamecube build may require use of dollz3 before running, if sending over BBA
  12. #---------------------------------------------------------------------------------
  13. HW_TYPE = wii
  14. include $(DEVKITPPC)/$(HW_TYPE)_rules
  15. #---------------------------------------------------------------------------------
  16. # TARGET is the name of the output
  17. # BUILD is the directory where object files & intermediate files will be placed
  18. # SOURCES is a list of directories containing source code
  19. # INCLUDES is a list of directories containing extra header files
  20. #---------------------------------------------------------------------------------
  21. TARGET := $(notdir $(CURDIR))_$(HW_TYPE)
  22. BUILD := build
  23. SOURCES := .
  24. DATA := data
  25. INCLUDES := include ../Core/Common .
  26. #---------------------------------------------------------------------------------
  27. # options for code generation
  28. #---------------------------------------------------------------------------------
  29. CFLAGS = -save-temps -O2 -Wall --no-strict-aliasing $(MACHDEP) $(INCLUDE)
  30. CXXFLAGS = -std=c++17 -Wno-register $(CFLAGS)
  31. LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
  32. #---------------------------------------------------------------------------------
  33. # any extra libraries we wish to link with the project
  34. #---------------------------------------------------------------------------------
  35. ifeq ($(HW_TYPE), gamecube)
  36. LIBS := -lfat -ldb -logc -lm
  37. else
  38. LIBS := -lfat -lwiiuse -lbte -logc -lm
  39. endif
  40. #---------------------------------------------------------------------------------
  41. # list of directories containing libraries, this must be the top level containing
  42. # include and lib
  43. #---------------------------------------------------------------------------------
  44. LIBDIRS :=
  45. #---------------------------------------------------------------------------------
  46. # no real need to edit anything past this point unless you need to add additional
  47. # rules for different file extensions
  48. #---------------------------------------------------------------------------------
  49. ifneq ($(BUILD),$(notdir $(CURDIR)))
  50. #---------------------------------------------------------------------------------
  51. export OUTPUT := $(CURDIR)/$(TARGET)
  52. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  53. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  54. export DEPSDIR := $(CURDIR)/$(BUILD)
  55. #---------------------------------------------------------------------------------
  56. # automatically build a list of object files for our project
  57. #---------------------------------------------------------------------------------
  58. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  59. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  60. sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  61. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
  62. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  63. #---------------------------------------------------------------------------------
  64. # use CXX for linking C++ projects, CC for standard C
  65. #---------------------------------------------------------------------------------
  66. ifeq ($(strip $(CPPFILES)),)
  67. export LD := $(CC)
  68. else
  69. export LD := $(CXX)
  70. endif
  71. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  72. export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
  73. export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
  74. export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  75. #---------------------------------------------------------------------------------
  76. # build a list of include paths
  77. #---------------------------------------------------------------------------------
  78. export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
  79. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  80. -I$(CURDIR)/$(BUILD) \
  81. -I$(LIBOGC_INC)
  82. #---------------------------------------------------------------------------------
  83. # build a list of library paths
  84. #---------------------------------------------------------------------------------
  85. export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  86. export OUTPUT := $(CURDIR)/$(TARGET)
  87. .PHONY: $(BUILD) clean
  88. #---------------------------------------------------------------------------------
  89. $(BUILD):
  90. @[ -d $@ ] || mkdir -p $@
  91. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  92. #---------------------------------------------------------------------------------
  93. clean:
  94. @echo clean ...
  95. @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
  96. #---------------------------------------------------------------------------------
  97. run:
  98. ifeq ($(HW_TYPE), gamecube)
  99. PSOload $(OUTPUT).dol
  100. else
  101. wiiload $(OUTPUT).dol
  102. endif
  103. #---------------------------------------------------------------------------------
  104. else
  105. DEPENDS := $(OFILES:.o=.d)
  106. #%.biz: %.ds
  107. # gcdsptool -c $< -o $@
  108. #%.h: %.biz
  109. # raw2c $< $@
  110. #---------------------------------------------------------------------------------
  111. # main targets
  112. #---------------------------------------------------------------------------------
  113. $(OUTPUT).dol: $(OUTPUT).elf
  114. $(OUTPUT).elf: $(OFILES)
  115. $(OFILES_SOURCES) : $(HFILES)
  116. #---------------------------------------------------------------------------------
  117. # This rule links in binary data with the .bin extension
  118. #---------------------------------------------------------------------------------
  119. #%.bin.o : %.bin
  120. #---------------------------------------------------------------------------------
  121. # @echo $(notdir $<)
  122. # $(bin2o)
  123. -include $(DEPENDS)
  124. #---------------------------------------------------------------------------------
  125. endif
  126. #---------------------------------------------------------------------------------