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