|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +.SUFFIXES: |
| 3 | +#--------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +ifeq ($(strip $(DEVKITARM)),) |
| 6 | +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") |
| 7 | +endif |
| 8 | + |
| 9 | +include $(DEVKITARM)/ds_rules |
| 10 | + |
| 11 | +#--------------------------------------------------------------------------------- |
| 12 | +# TARGET is the name of the output |
| 13 | +# BUILD is the directory where object files & intermediate files will be placed |
| 14 | +# SOURCES is a list of directories containing source code |
| 15 | +# INCLUDES is a list of directories containing extra header files |
| 16 | +#--------------------------------------------------------------------------------- |
| 17 | +TARGET := $(shell basename $(CURDIR)) |
| 18 | +BUILD := build |
| 19 | +SOURCES := gfx source data |
| 20 | +INCLUDES := include build |
| 21 | + |
| 22 | +#--------------------------------------------------------------------------------- |
| 23 | +# options for code generation |
| 24 | +#--------------------------------------------------------------------------------- |
| 25 | +ARCH := -marm -mthumb-interwork |
| 26 | + |
| 27 | +CFLAGS := -g -Wall -O2\ |
| 28 | + -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ |
| 29 | + -ffast-math \ |
| 30 | + $(ARCH) |
| 31 | + |
| 32 | +CFLAGS += $(INCLUDE) -DARM9 |
| 33 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions |
| 34 | + |
| 35 | +ASFLAGS := -g $(ARCH) |
| 36 | +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) |
| 37 | + |
| 38 | +#--------------------------------------------------------------------------------- |
| 39 | +# any extra libraries we wish to link with the project |
| 40 | +#--------------------------------------------------------------------------------- |
| 41 | +LIBS := -lnds9 |
| 42 | + |
| 43 | + |
| 44 | +#--------------------------------------------------------------------------------- |
| 45 | +# list of directories containing libraries, this must be the top level containing |
| 46 | +# include and lib |
| 47 | +#--------------------------------------------------------------------------------- |
| 48 | +LIBDIRS := $(LIBNDS) |
| 49 | + |
| 50 | +#--------------------------------------------------------------------------------- |
| 51 | +# no real need to edit anything past this point unless you need to add additional |
| 52 | +# rules for different file extensions |
| 53 | +#--------------------------------------------------------------------------------- |
| 54 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 55 | +#--------------------------------------------------------------------------------- |
| 56 | + |
| 57 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 58 | + |
| 59 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) |
| 60 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 61 | + |
| 62 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 63 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 64 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 65 | +BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin))) |
| 66 | + |
| 67 | +#--------------------------------------------------------------------------------- |
| 68 | +# use CXX for linking C++ projects, CC for standard C |
| 69 | +#--------------------------------------------------------------------------------- |
| 70 | +ifeq ($(strip $(CPPFILES)),) |
| 71 | +#--------------------------------------------------------------------------------- |
| 72 | + export LD := $(CC) |
| 73 | +#--------------------------------------------------------------------------------- |
| 74 | +else |
| 75 | +#--------------------------------------------------------------------------------- |
| 76 | + export LD := $(CXX) |
| 77 | +#--------------------------------------------------------------------------------- |
| 78 | +endif |
| 79 | +#--------------------------------------------------------------------------------- |
| 80 | + |
| 81 | +export OFILES := $(BINFILES:.bin=.o) \ |
| 82 | + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 83 | + |
| 84 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 85 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 86 | + -I$(CURDIR)/$(BUILD) |
| 87 | + |
| 88 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 89 | + |
| 90 | +.PHONY: $(BUILD) clean |
| 91 | + |
| 92 | +#--------------------------------------------------------------------------------- |
| 93 | +$(BUILD): |
| 94 | + @[ -d $@ ] || mkdir -p $@ |
| 95 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 96 | + |
| 97 | +#--------------------------------------------------------------------------------- |
| 98 | +clean: |
| 99 | + @echo clean ... |
| 100 | + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).ds.gba |
| 101 | + |
| 102 | + |
| 103 | +#--------------------------------------------------------------------------------- |
| 104 | +else |
| 105 | + |
| 106 | +DEPENDS := $(OFILES:.o=.d) |
| 107 | + |
| 108 | +#--------------------------------------------------------------------------------- |
| 109 | +# main targets |
| 110 | +#--------------------------------------------------------------------------------- |
| 111 | +$(OUTPUT).nds : $(OUTPUT).elf |
| 112 | +$(OUTPUT).elf : $(OFILES) |
| 113 | + |
| 114 | +#--------------------------------------------------------------------------------- |
| 115 | +%.o : %.bin |
| 116 | +#--------------------------------------------------------------------------------- |
| 117 | + @echo $(notdir $<) |
| 118 | + $(bin2o) |
| 119 | + |
| 120 | + |
| 121 | +-include $(DEPENDS) |
| 122 | + |
| 123 | +#--------------------------------------------------------------------------------------- |
| 124 | +endif |
| 125 | +#--------------------------------------------------------------------------------------- |
0 commit comments