|
| 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 | +ifeq ($(strip $(TTYDTOOLS)),) |
| 11 | +$(error "Please set TTYDTOOLS in your environment. export TTYDTOOLS=<path to>ttyd-tools") |
| 12 | +endif |
| 13 | + |
| 14 | +include $(DEVKITPPC)/gamecube_rules |
| 15 | + |
| 16 | +export ELF2REL := $(TTYDTOOLS)/bin/elf2rel |
| 17 | +export GCIPACK := python $(TTYDTOOLS)/gcipack/gcipack.py |
| 18 | + |
| 19 | +#--------------------------------------------------------------------------------- |
| 20 | +# TARGET is the name of the output |
| 21 | +# BUILD is the directory where object files & intermediate files will be placed |
| 22 | +# SOURCES is a list of directories containing source code |
| 23 | +# INCLUDES is a list of directories containing extra header files |
| 24 | +#--------------------------------------------------------------------------------- |
| 25 | +TARGET := $(notdir $(CURDIR)) |
| 26 | +BUILD := build |
| 27 | +SOURCES := source |
| 28 | +DATA := data |
| 29 | +INCLUDES := include |
| 30 | + |
| 31 | +#--------------------------------------------------------------------------------- |
| 32 | +# options for code generation |
| 33 | +#--------------------------------------------------------------------------------- |
| 34 | + |
| 35 | +MACHDEP = -mno-sdata -mgcn -DGEKKO -mcpu=750 -meabi -mhard-float |
| 36 | + |
| 37 | +CFLAGS = -nostdlib -ffunction-sections -fdata-sections -g -O3 -Wall $(MACHDEP) $(INCLUDE) |
| 38 | +CXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++17 $(CFLAGS) |
| 39 | + |
| 40 | +LDFLAGS = -r -s -e _prolog -u _prolog -u _epilog -u _unresolved -Wl,--gc-sections -nostartfiles -g $(MACHDEP) -Wl,-Map,$(notdir $@).map |
| 41 | + |
| 42 | +#--------------------------------------------------------------------------------- |
| 43 | +# any extra libraries we wish to link with the project |
| 44 | +#--------------------------------------------------------------------------------- |
| 45 | +LIBS := -lm |
| 46 | + |
| 47 | +#--------------------------------------------------------------------------------- |
| 48 | +# list of directories containing libraries, this must be the top level containing |
| 49 | +# include and lib |
| 50 | +#--------------------------------------------------------------------------------- |
| 51 | +LIBDIRS := |
| 52 | + |
| 53 | +#--------------------------------------------------------------------------------- |
| 54 | +# no real need to edit anything past this point unless you need to add additional |
| 55 | +# rules for different file extensions |
| 56 | +#--------------------------------------------------------------------------------- |
| 57 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 58 | +#--------------------------------------------------------------------------------- |
| 59 | + |
| 60 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 61 | + |
| 62 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 63 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 64 | + |
| 65 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 66 | + |
| 67 | +#--------------------------------------------------------------------------------- |
| 68 | +# automatically build a list of object files for our project |
| 69 | +#--------------------------------------------------------------------------------- |
| 70 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 71 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 72 | +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 73 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) |
| 74 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 75 | + |
| 76 | +#--------------------------------------------------------------------------------- |
| 77 | +# use CXX for linking C++ projects, CC for standard C |
| 78 | +#--------------------------------------------------------------------------------- |
| 79 | +ifeq ($(strip $(CPPFILES)),) |
| 80 | + export LD := $(CC) |
| 81 | +else |
| 82 | + export LD := $(CXX) |
| 83 | +endif |
| 84 | + |
| 85 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) |
| 86 | +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) |
| 87 | +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) |
| 88 | + |
| 89 | +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) |
| 90 | + |
| 91 | +# For REL linking |
| 92 | +export LDFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ld))) |
| 93 | +export MAPFILE := $(CURDIR)/include/ttyd.lst |
| 94 | +export BANNERFILE := $(CURDIR)/banner.raw |
| 95 | +export ICONFILE := $(CURDIR)/icon.raw |
| 96 | + |
| 97 | +#--------------------------------------------------------------------------------- |
| 98 | +# build a list of include paths |
| 99 | +#--------------------------------------------------------------------------------- |
| 100 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 101 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 102 | + -I$(CURDIR)/$(BUILD) \ |
| 103 | + -I$(LIBOGC_INC) |
| 104 | + |
| 105 | +#--------------------------------------------------------------------------------- |
| 106 | +# build a list of library paths |
| 107 | +#--------------------------------------------------------------------------------- |
| 108 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ |
| 109 | + -L$(LIBOGC_LIB) |
| 110 | + |
| 111 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 112 | +.PHONY: $(BUILD) clean |
| 113 | + |
| 114 | +#--------------------------------------------------------------------------------- |
| 115 | +$(BUILD): |
| 116 | + @[ -d $@ ] || mkdir -p $@ |
| 117 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 118 | + |
| 119 | +#--------------------------------------------------------------------------------- |
| 120 | +clean: |
| 121 | + @echo clean ... |
| 122 | + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol $(OUTPUT).rel $(OUTPUT).gci |
| 123 | + |
| 124 | +#--------------------------------------------------------------------------------- |
| 125 | +else |
| 126 | + |
| 127 | +DEPENDS := $(OFILES:.o=.d) |
| 128 | + |
| 129 | +#--------------------------------------------------------------------------------- |
| 130 | +# main targets |
| 131 | +#--------------------------------------------------------------------------------- |
| 132 | +$(OUTPUT).gci: $(OUTPUT).rel |
| 133 | +$(OUTPUT).rel: $(OUTPUT).elf |
| 134 | +$(OUTPUT).elf: $(LDFILES) $(OFILES) |
| 135 | + |
| 136 | +$(OFILES_SOURCES) : $(HFILES) |
| 137 | + |
| 138 | +# REL linking |
| 139 | +%.rel: %.elf |
| 140 | + @echo output ... $(notdir $@) |
| 141 | + @$(ELF2REL) $< $(MAPFILE) |
| 142 | + |
| 143 | +%.gci: %.rel |
| 144 | + @echo packing ... $(notdir $@) |
| 145 | + @$(GCIPACK) $< "rel" "Paper Mario" "TTYD Debug Menu" $(BANNERFILE) $(ICONFILE) |
| 146 | + |
| 147 | +#--------------------------------------------------------------------------------- |
| 148 | +# This rule links in binary data with the .jpg extension |
| 149 | +#--------------------------------------------------------------------------------- |
| 150 | +%.jpg.o %_jpg.h : %.jpg |
| 151 | +#--------------------------------------------------------------------------------- |
| 152 | + @echo $(notdir $<) |
| 153 | + $(bin2o) |
| 154 | + |
| 155 | +-include $(DEPENDS) |
| 156 | + |
| 157 | +#--------------------------------------------------------------------------------- |
| 158 | +endif |
| 159 | +#--------------------------------------------------------------------------------- |
0 commit comments