|
| 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 | +ifeq ($(strip $(DEVKITPRO)),) |
| 10 | +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO") |
| 11 | +endif |
| 12 | +export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) |
| 13 | +export LIBOGC_INC := $(DEVKITPRO)/libogc/include |
| 14 | +export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii |
| 15 | +export PORTLIBS := $(DEVKITPRO)/portlibs/ppc |
| 16 | + |
| 17 | +PREFIX := powerpc-eabi- |
| 18 | + |
| 19 | +export AS := $(PREFIX)as |
| 20 | +export CC := $(PREFIX)gcc |
| 21 | +export CXX := $(PREFIX)g++ |
| 22 | +export AR := $(PREFIX)ar |
| 23 | +export OBJCOPY := $(PREFIX)objcopy |
| 24 | + |
| 25 | +#--------------------------------------------------------------------------------- |
| 26 | +# TARGET is the name of the output |
| 27 | +# BUILD is the directory where object files & intermediate files will be placed |
| 28 | +# SOURCES is a list of directories containing source code |
| 29 | +# INCLUDES is a list of directories containing extra header files |
| 30 | +#--------------------------------------------------------------------------------- |
| 31 | +TARGET := tcpgecko |
| 32 | +BUILD := build |
| 33 | +BUILD_DBG := $(TARGET)_dbg |
| 34 | +SOURCES := src \ |
| 35 | + src/dynamic_libs \ |
| 36 | + src/game \ |
| 37 | + src/fs \ |
| 38 | + src/kernel \ |
| 39 | + src/patcher \ |
| 40 | + src/system \ |
| 41 | + src/utils |
| 42 | +DATA := |
| 43 | + |
| 44 | +INCLUDES := src |
| 45 | + |
| 46 | +#--------------------------------------------------------------------------------- |
| 47 | +# options for code generation |
| 48 | +#--------------------------------------------------------------------------------- |
| 49 | +CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ |
| 50 | + -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) |
| 51 | +CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ |
| 52 | + -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) |
| 53 | +ASFLAGS := -mregnames |
| 54 | +LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections |
| 55 | + |
| 56 | +#--------------------------------------------------------------------------------- |
| 57 | +Q := @ |
| 58 | +MAKEFLAGS += --no-print-directory |
| 59 | +#--------------------------------------------------------------------------------- |
| 60 | +# any extra libraries we wish to link with the project |
| 61 | +#--------------------------------------------------------------------------------- |
| 62 | +LIBS := |
| 63 | + |
| 64 | +#--------------------------------------------------------------------------------- |
| 65 | +# list of directories containing libraries, this must be the top level containing |
| 66 | +# include and lib |
| 67 | +#--------------------------------------------------------------------------------- |
| 68 | +LIBDIRS := $(CURDIR) \ |
| 69 | + $(DEVKITPPC)/lib \ |
| 70 | + $(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 |
| 71 | + |
| 72 | + |
| 73 | +#--------------------------------------------------------------------------------- |
| 74 | +# no real need to edit anything past this point unless you need to add additional |
| 75 | +# rules for different file extensions |
| 76 | +#--------------------------------------------------------------------------------- |
| 77 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 78 | +#--------------------------------------------------------------------------------- |
| 79 | +export PROJECTDIR := $(CURDIR) |
| 80 | +export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) |
| 81 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 82 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 83 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 84 | + |
| 85 | +#--------------------------------------------------------------------------------- |
| 86 | +# automatically build a list of object files for our project |
| 87 | +#--------------------------------------------------------------------------------- |
| 88 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 89 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 90 | +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 91 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) |
| 92 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 93 | +TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf))) |
| 94 | +PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) |
| 95 | + |
| 96 | +#--------------------------------------------------------------------------------- |
| 97 | +# use CXX for linking C++ projects, CC for standard C |
| 98 | +#--------------------------------------------------------------------------------- |
| 99 | +ifeq ($(strip $(CPPFILES)),) |
| 100 | + export LD := $(CC) |
| 101 | +else |
| 102 | + export LD := $(CXX) |
| 103 | +endif |
| 104 | + |
| 105 | +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ |
| 106 | + $(sFILES:.s=.o) $(SFILES:.S=.o) \ |
| 107 | + $(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES)) |
| 108 | + |
| 109 | +#--------------------------------------------------------------------------------- |
| 110 | +# build a list of include paths |
| 111 | +#--------------------------------------------------------------------------------- |
| 112 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 113 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 114 | + -I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \ |
| 115 | + -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 |
| 116 | + |
| 117 | +#--------------------------------------------------------------------------------- |
| 118 | +# build a list of library paths |
| 119 | +#--------------------------------------------------------------------------------- |
| 120 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ |
| 121 | + -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib |
| 122 | + |
| 123 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 124 | +.PHONY: $(BUILD) clean install |
| 125 | + |
| 126 | +#--------------------------------------------------------------------------------- |
| 127 | +$(BUILD): |
| 128 | + @[ -d $@ ] || mkdir -p $@ |
| 129 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 130 | + |
| 131 | +#--------------------------------------------------------------------------------- |
| 132 | +clean: |
| 133 | + @echo clean ... |
| 134 | + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf |
| 135 | + |
| 136 | +#--------------------------------------------------------------------------------- |
| 137 | +else |
| 138 | + |
| 139 | +DEPENDS := $(OFILES:.o=.d) |
| 140 | + |
| 141 | +#--------------------------------------------------------------------------------- |
| 142 | +# main targets |
| 143 | +#--------------------------------------------------------------------------------- |
| 144 | +$(OUTPUT).elf: $(OFILES) |
| 145 | + |
| 146 | +#--------------------------------------------------------------------------------- |
| 147 | +# This rule links in binary data with the .jpg extension |
| 148 | +#--------------------------------------------------------------------------------- |
| 149 | +%.elf: link.ld $(OFILES) |
| 150 | + @echo "linking ... $(TARGET).elf" |
| 151 | + $(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) |
| 152 | + $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ |
| 153 | + |
| 154 | +../data/loader.bin: |
| 155 | + $(MAKE) -C ../loader clean |
| 156 | + $(MAKE) -C ../loader |
| 157 | +#--------------------------------------------------------------------------------- |
| 158 | +%.a: |
| 159 | +#--------------------------------------------------------------------------------- |
| 160 | + @echo $(notdir $@) |
| 161 | + @rm -f $@ |
| 162 | + @$(AR) -rc $@ $^ |
| 163 | + |
| 164 | +#--------------------------------------------------------------------------------- |
| 165 | +%.o: %.cpp |
| 166 | + @echo $(notdir $<) |
| 167 | + @$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER) |
| 168 | + |
| 169 | +#--------------------------------------------------------------------------------- |
| 170 | +%.o: %.c |
| 171 | + @echo $(notdir $<) |
| 172 | + @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER) |
| 173 | + |
| 174 | +#--------------------------------------------------------------------------------- |
| 175 | +%.o: %.S |
| 176 | + @echo $(notdir $<) |
| 177 | + @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) |
| 178 | + |
| 179 | +#--------------------------------------------------------------------------------- |
| 180 | +%.png.o : %.png |
| 181 | + @echo $(notdir $<) |
| 182 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 183 | + |
| 184 | +#--------------------------------------------------------------------------------- |
| 185 | +%.jpg.o : %.jpg |
| 186 | + @echo $(notdir $<) |
| 187 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 188 | + |
| 189 | +#--------------------------------------------------------------------------------- |
| 190 | +%.ttf.o : %.ttf |
| 191 | + @echo $(notdir $<) |
| 192 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 193 | + |
| 194 | +#--------------------------------------------------------------------------------- |
| 195 | +%.bin.o : %.bin |
| 196 | + @echo $(notdir $<) |
| 197 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 198 | + |
| 199 | +#--------------------------------------------------------------------------------- |
| 200 | +%.wav.o : %.wav |
| 201 | + @echo $(notdir $<) |
| 202 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 203 | + |
| 204 | +#--------------------------------------------------------------------------------- |
| 205 | +%.mp3.o : %.mp3 |
| 206 | + @echo $(notdir $<) |
| 207 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 208 | + |
| 209 | +#--------------------------------------------------------------------------------- |
| 210 | +%.ogg.o : %.ogg |
| 211 | + @echo $(notdir $<) |
| 212 | + @bin2s -a 32 $< | $(AS) -o $(@) |
| 213 | + |
| 214 | +-include $(DEPENDS) |
| 215 | + |
| 216 | +#--------------------------------------------------------------------------------- |
| 217 | +endif |
| 218 | +#--------------------------------------------------------------------------------- |
0 commit comments