|
| 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 | +export PORTLIBS := ../../portlibs/ppc |
| 10 | +export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) |
| 11 | +export LIBOGC_INC := $(DEVKITPRO)/libogc/include |
| 12 | +export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii |
| 13 | + |
| 14 | +PREFIX := powerpc-eabi- |
| 15 | + |
| 16 | +export AS := $(PREFIX)as |
| 17 | +export CC := $(PREFIX)gcc |
| 18 | +export CXX := $(PREFIX)g++ |
| 19 | +export AR := $(PREFIX)ar |
| 20 | +export LD := $(PREFIX)ld |
| 21 | +export OBJCOPY := $(PREFIX)objcopy |
| 22 | + |
| 23 | +#--------------------------------------------------------------------------------- |
| 24 | +# TARGET is the name of the output |
| 25 | +# BUILD is the directory where object files & intermediate files will be placed |
| 26 | +# SOURCES is a list of directories containing source code |
| 27 | +# INCLUDES is a list of directories containing extra header files |
| 28 | +#--------------------------------------------------------------------------------- |
| 29 | +TARGET := boot |
| 30 | +BUILD := build |
| 31 | +BUILD_DBG := $(BUILD)_dbg |
| 32 | +SOURCES := src |
| 33 | +DATA := data |
| 34 | +INCLUDES := |
| 35 | + |
| 36 | +#--------------------------------------------------------------------------------- |
| 37 | +# options for code generation |
| 38 | +#--------------------------------------------------------------------------------- |
| 39 | +CFLAGS := -std=gnu99 -nostdinc -fno-builtin $(INCLUDE) |
| 40 | +LDFLAGS := -nostartfiles -nostdlib |
| 41 | + |
| 42 | +#--------------------------------------------------------------------------------- |
| 43 | +# move loader to another location - THANKS CREDIAR - 0x81330000 for HBC |
| 44 | +#--------------------------------------------------------------------------------- |
| 45 | +#LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map |
| 46 | +#LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x80003f00 |
| 47 | +Q := @ |
| 48 | +MAKEFLAGS += --no-print-directory |
| 49 | +#--------------------------------------------------------------------------------- |
| 50 | +# any extra libraries we wish to link with the project |
| 51 | +#--------------------------------------------------------------------------------- |
| 52 | +#LIBS := |
| 53 | + |
| 54 | +#--------------------------------------------------------------------------------- |
| 55 | +# list of directories containing libraries, this must be the top level containing |
| 56 | +# include and lib |
| 57 | +#--------------------------------------------------------------------------------- |
| 58 | +#LIBDIRS := $(CURDIR) |
| 59 | + |
| 60 | +#--------------------------------------------------------------------------------- |
| 61 | +# no real need to edit anything past this point unless you need to add additional |
| 62 | +# rules for different file extensions |
| 63 | +#--------------------------------------------------------------------------------- |
| 64 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 65 | +#--------------------------------------------------------------------------------- |
| 66 | + |
| 67 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 68 | + |
| 69 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 70 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 71 | + |
| 72 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 73 | + |
| 74 | +#--------------------------------------------------------------------------------- |
| 75 | +# automatically build a list of object files for our project |
| 76 | +#--------------------------------------------------------------------------------- |
| 77 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 78 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 79 | +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 80 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) |
| 81 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 82 | +PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) |
| 83 | + |
| 84 | +#--------------------------------------------------------------------------------- |
| 85 | +# use CXX for linking C++ projects, CC for standard C |
| 86 | +#--------------------------------------------------------------------------------- |
| 87 | +export OFILES := $(addsuffix .o,$(BINFILES)) \ |
| 88 | + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ |
| 89 | + $(sFILES:.s=.o) $(SFILES:.S=.o) |
| 90 | + |
| 91 | +#--------------------------------------------------------------------------------- |
| 92 | +# build a list of include paths |
| 93 | +#--------------------------------------------------------------------------------- |
| 94 | +export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ |
| 95 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 96 | + -I$(CURDIR)/$(BUILD) \ |
| 97 | + -I$(LIBOGC_INC) |
| 98 | + |
| 99 | +#--------------------------------------------------------------------------------- |
| 100 | +# build a list of library paths |
| 101 | +#--------------------------------------------------------------------------------- |
| 102 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ |
| 103 | + -L$(LIBOGC_LIB) |
| 104 | + |
| 105 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 106 | +.PHONY: $(BUILD) clean install |
| 107 | + |
| 108 | +#--------------------------------------------------------------------------------- |
| 109 | +$(BUILD): |
| 110 | + @[ -d $@ ] || mkdir -p $@ |
| 111 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 112 | + |
| 113 | +#--------------------------------------------------------------------------------- |
| 114 | +clean: |
| 115 | + @echo clean ... |
| 116 | + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin |
| 117 | + |
| 118 | + #This should stop new builds from using old code (-SonyUSA) |
| 119 | + @rm -fr build |
| 120 | + #And just because I'm picky... (-SonyUSA) |
| 121 | + @mkdir bin |
| 122 | + @mv boot.elf /bin/ |
| 123 | + @mv build_dbg.elf /bin/ |
| 124 | + |
| 125 | +#--------------------------------------------------------------------------------- |
| 126 | +else |
| 127 | + |
| 128 | +DEPENDS := $(OFILES:.o=.d) |
| 129 | + |
| 130 | +#--------------------------------------------------------------------------------- |
| 131 | +# main targets |
| 132 | +#--------------------------------------------------------------------------------- |
| 133 | +$(OUTPUT).elf: $(OFILES) |
| 134 | + |
| 135 | +#--------------------------------------------------------------------------------- |
| 136 | +# This rule links in binary data with the .jpg extension |
| 137 | +#--------------------------------------------------------------------------------- |
| 138 | +%.elf: link.ld $(OFILES) |
| 139 | + @echo "linking ... $(TARGET).elf" |
| 140 | + $(Q)$(CC) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf |
| 141 | + $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ |
| 142 | + |
| 143 | +%.o: %.c |
| 144 | + @echo "$@" |
| 145 | + $(Q)$(CC) $(CFLAGS) -c $< -o $@ |
| 146 | + |
| 147 | +%.o: %.s |
| 148 | + @echo "$@" |
| 149 | + $(Q)$(CC) $(CFLAGS) -c $< -o $@ |
| 150 | + |
| 151 | +-include $(DEPENDS) |
| 152 | + |
| 153 | +#--------------------------------------------------------------------------------- |
| 154 | +endif |
| 155 | +#--------------------------------------------------------------------------------- |
0 commit comments