123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- #---------------------------------------------------------------------------------
- # Clear the implicit built in rules
- #---------------------------------------------------------------------------------
- .SUFFIXES:
- #---------------------------------------------------------------------------------
- ifeq ($(strip $(DEVKITARM)),)
- $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
- endif
- LIBGBA := $(DEVKITPRO)/libgba
- #---------------------------------------------------------------------------------
- # path to tools - this can be deleted if you set the path in windows
- #---------------------------------------------------------------------------------
- export PATH := $(DEVKITARM)/bin:$(PATH)
- #---------------------------------------------------------------------------------
- # the prefix on the compiler executables
- #---------------------------------------------------------------------------------
- PREFIX := arm-eabi-
- export CC := $(PREFIX)gcc
- export CXX := $(PREFIX)g++
- export AS := $(PREFIX)as
- export AR := $(PREFIX)ar
- export OBJCOPY := $(PREFIX)objcopy
- define adjustdepends
- cp $(DEPSDIR)/$*.d $(DEPSDIR)/$*.P;
- sed -e 's/#.*//' -e 's/^[^:]*: \+//' -e 's/^ *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $(DEPSDIR)/$*.P >> $(DEPSDIR)/$*.d;
- rm $(DEPSDIR)/$*.P
- endef
- #---------------------------------------------------------------------------------
- %.a:
- #---------------------------------------------------------------------------------
- @echo "### " $(notdir $@)
- rm -f $@
- $(AR) -rc $@ $^
- #---------------------------------------------------------------------------------
- %.o: %.cpp
- @echo "### " $(notdir $<)
- $(CXX) -MMD -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@
- $(adjustdepends)
- #---------------------------------------------------------------------------------
- %.o: %.c
- @echo "### " $(notdir $<)
- $(CC) -MMD -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@
- $(adjustdepends)
- #---------------------------------------------------------------------------------
- %.o: %.s
- @echo $(notdir $<)
- $(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
- $(adjustdepends)
- #---------------------------------------------------------------------------------
- %.o: %.S
- @echo $(notdir $<)
- $(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
- $(adjustdepends)
- #---------------------------------------------------------------------------------
- # canned command sequence for binary data
- #---------------------------------------------------------------------------------
- define bin2o
- bin2s $< | $(AS) $(ARCH) -o $(@)
- echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
- echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
- echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
- endef
- #---------------------------------------------------------------------------------
- %.gba: %.elf
- $(OBJCOPY) -O binary $< $@
- @echo built ... $(notdir $@)
- @gbafix $@
- #---------------------------------------------------------------------------------
- %_mb.elf:
- @echo "### linking multiboot"
- $(LD) -specs=gba_mb.specs $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
- #---------------------------------------------------------------------------------
- %.elf:
- @echo "### linking cartridge"
- $(LD) $(LDFLAGS) -specs=gba.specs $(OFILES) $(LIBPATHS) $(LIBS) -o $@
- #---------------------------------------------------------------------------------
- # TARGET is the name of the output, if this ends with _mb generates a multiboot image
- # BUILD is the directory where object files & intermediate files will be placed
- # SOURCES is a list of directories containing source code
- # INCLUDES is a list of directories containing extra header files
- #---------------------------------------------------------------------------------
- TARGET := supertux
- BUILD := build
- SOURCES := src data
- INCLUDES :=
- #---------------------------------------------------------------------------------
- # options for code generation
- #---------------------------------------------------------------------------------
- ARCH := -mthumb -mthumb-interwork
- CFLAGS := -g -Wall -O3\
- -mcpu=arm7tdmi -mtune=arm7tdmi\
- -fomit-frame-pointer\
- -ffast-math \
- $(ARCH)
- CFLAGS += $(INCLUDE)
- CXXFLAGS := -g -Wall -O3\
- -mcpu=arm7tdmi -mtune=arm7tdmi\
- -fomit-frame-pointer\
- -ffast-math \
- $(ARCH)
- CXXFLAGS += $(INCLUDE)
- ASFLAGS := $(ARCH)
- LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map
- #---------------------------------------------------------------------------------
- # path to tools - this can be deleted if you set the path in windows
- #---------------------------------------------------------------------------------
- export PATH := $(DEVKITARM)/bin:$(PATH)
- #---------------------------------------------------------------------------------
- # any extra libraries we wish to link with the project
- #---------------------------------------------------------------------------------
- LIBS := -lgba -lm
- #---------------------------------------------------------------------------------
- # list of directories containing libraries, this must be the top level containing
- # include and lib
- #---------------------------------------------------------------------------------
- LIBDIRS := $(LIBGBA)
- #---------------------------------------------------------------------------------
- # no real need to edit anything past this point unless you need to add additional
- # rules for different file extensions
- #---------------------------------------------------------------------------------
- ifneq ($(BUILD),$(notdir $(CURDIR)))
- #---------------------------------------------------------------------------------
- export OUTPUT := $(CURDIR)/$(TARGET)
- export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
- export PATH := $(DEVKITARM)/bin:$(PATH)
- export DEPSDIR := $(CURDIR)/$(BUILD)
- #---------------------------------------------------------------------------------
- # automatically build a list of object files for our project
- #---------------------------------------------------------------------------------
- CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
- CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
- SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
- RAWFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.raw)))
- #---------------------------------------------------------------------------------
- # use CXX for linking C++ projects, CC for standard C
- #---------------------------------------------------------------------------------
- ifeq ($(strip $(CPPFILES)),)
- #---------------------------------------------------------------------------------
- export LD := $(CC)
- #---------------------------------------------------------------------------------
- else
- #---------------------------------------------------------------------------------
- export LD := $(CXX)
- #---------------------------------------------------------------------------------
- endif
- #---------------------------------------------------------------------------------
- export OFILES := $(RAWFILES:.raw=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
- #---------------------------------------------------------------------------------
- # build a list of include paths
- #---------------------------------------------------------------------------------
- export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
- $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
- -I$(CURDIR)/$(BUILD)
- #---------------------------------------------------------------------------------
- # build a list of library paths
- #---------------------------------------------------------------------------------
- export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
- .PHONY: $(BUILD) clean
- #---------------------------------------------------------------------------------
- $(BUILD):
- @[ -d $@ ] || mkdir -p $@
- make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
- all : $(BUILD)
- #---------------------------------------------------------------------------------
- clean:
- rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
- #---------------------------------------------------------------------------------
- else
- DEPENDS := $(OFILES:.o=.d)
- #---------------------------------------------------------------------------------
- # main targets
- #---------------------------------------------------------------------------------
- $(OUTPUT).gba : $(OUTPUT).elf
- $(OUTPUT).elf : $(OFILES)
- %.o : %.raw
- @echo $(notdir $<)
- @$(bin2o)
- -include $(DEPENDS)
- #---------------------------------------------------------------------------------
- endif
- #---------------------------------------------------------------------------------
|