Replaced the template makefile with a fully annotated makefile and addressed http://code.google.com/p/grrlib/issues/detail?id=3

This commit is contained in:
csBlueChip 2009-08-23 15:19:47 +00:00
parent 6120bbd7c3
commit b62e9d73bc
2 changed files with 113 additions and 139 deletions

View file

@ -1,139 +1,113 @@
#--------------------------------------------------------------------------------- # BC's quick'n'dirty makefile - with annotations
# Clear the implicit built in rules
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
.SUFFIXES: # Check devkitpro is installed
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),) ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC) $(error "Use export DEVKITPPC=<path to>devkitPPC and try again")
endif endif
include $(DEVKITPPC)/wii_rules ifeq ($(strip $(DEVKITPRO)),)
$(error "Use export DEVKITPRO=<path to>devkitPRO and try again")
#--------------------------------------------------------------------------------- endif
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed #-------------------------------------------------------------------------------
# SOURCES is a list of directories containing source code # Applicatin will be named after this directory
# INCLUDES is a list of directories containing extra header files #-------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- APP := $(notdir $(CURDIR))
TARGET := $(notdir $(CURDIR)) ELF := $(APP).elf
BUILD := build DOL := $(APP).dol
SOURCES := source source/gfx MAP := $(APP).map
DATA := data
INCLUDES := #-------------------------------------------------------------------------------
# Source code and binary resources
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# options for code generation SRC := $(wildcard *.c)
#--------------------------------------------------------------------------------- SRCOBJ := $(patsubst %.c,%.o,$(SRC))
CFLAGS = -g -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE) RES := $(wildcard *.png)
CXXFLAGS = $(CFLAGS) RESOBJ := $(patsubst %.png,%.o,$(RES))
RESC := $(patsubst %.png,%.c,$(RES))
LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map RESH := $(patsubst %.png,%.h,$(RES))
#--------------------------------------------------------------------------------- OBJ := $(RESOBJ) $(SRCOBJ)
# any extra libraries we wish to link with the project
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz -lfat -lwiiuse -lbte -logc -lm # Include required libraries
#-------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- LIBS := -lgrrlib -lpngu -lpng -ljpeg -lz
# list of directories containing libraries, this must be the top level containing LIBS += -lwiiuse
# include and lib #LIBS += -lmodplay -lasnd
#--------------------------------------------------------------------------------- LIBS += -lbte -logc
LIBDIRS := $(CURDIR)/$(GRRLIB) LIBS += -lm
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # Compilers & utils which we will be using
# rules for different file extensions #-------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- BINDIR := $(DEVKITPPC)/bin
ifneq ($(BUILD),$(notdir $(CURDIR))) PREFIX := $(BINDIR)/powerpc-gekko-
#---------------------------------------------------------------------------------
CC := $(PREFIX)gcc
export OUTPUT := $(CURDIR)/$(TARGET) CXX := $(PREFIX)g++
AR := $(PREFIX)ar
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ AS := $(PREFIX)as
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) LD := $(CC)
OBJCOPY := $(PREFIX)objcopy
export DEPSDIR := $(CURDIR)/$(BUILD)
ELF2DOL := $(BINDIR)/elf2dol
#--------------------------------------------------------------------------------- UPLOAD := $(BINDIR)/wiiload
# automatically build a list of object files for our project
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) # libogc - the main Wii/GC libraries
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) #-------------------------------------------------------------------------------
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) OGC := $(DEVKITPRO)/libogc
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) INCD := $(OGC)/include
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) LIBD := $(OGC)/lib/wii
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C # Wii specific compiler flags
#--------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),) MACHDEP := -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float
export LD := $(CC) CFLAGS := -O2 -Wall $(MACHDEP) -I $(INCD)
else
export LD := $(CXX) #-------------------------------------------------------------------------------
endif # Information for the linker
#-------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \ LDFLAGS = $(MACHDEP) -Wl,-Map,$(MAP)
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ LIBPATHS := -L$(DEVKITPRO)/libogc/lib/wii
$(sFILES:.s=.o) $(SFILES:.S=.o)
#-------------------------------------------------------------------------------
#--------------------------------------------------------------------------------- # Build rules
# build a list of include paths #-------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ # "make all" -> Build the DOL file
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ all : $(DOL)
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC) # "make clean" -> Erase everything made by `make`
clean :
#--------------------------------------------------------------------------------- rm -f $(OBJ) $(RESC) $(RESH) $(ELF) $(DOL) $(MAP)
# build a list of library paths
#--------------------------------------------------------------------------------- # "make run" -> Send the DOL file to the Wii
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ run : $(DOL)
-L$(LIBOGC_LIB) $(UPLOAD) $(DOL)
export OUTPUT := $(CURDIR)/$(TARGET) # The DOL file is built from the ELF file
.PHONY: $(BUILD) clean $(DOL) : $(ELF)
@echo Converting to: $@
#--------------------------------------------------------------------------------- @$(ELF2DOL) $< $@
$(BUILD):
@[ -d $@ ] || mkdir -p $@ # The ELF is built from the OBJects
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile $(ELF) : $(OBJ)
@echo Linking as: $@
#--------------------------------------------------------------------------------- @$(CC) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@
clean:
@echo clean ... # Objects (.o) are made from C files (.c)
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol %.o : %.c
@echo Compiling: $<
#--------------------------------------------------------------------------------- @$(CC) $(CFLAGS) -c $< -o $@
run:
psoload $(TARGET).dol # C files (.c) can be made from PNG images
.PRECIOUS : %.c
#--------------------------------------------------------------------------------- %.c : %.png
reload: @echo Converting resource: $<
psoload -r $(TARGET).dol @./raw2c.exe $< 2>null
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o : %.jpg
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------