| 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 := source |
| 20 |
DATA := data |
| 21 |
INCLUDES := include |
| 22 |
|
| 23 |
#--------------------------------------------------------------------------------- |
| 24 |
# options for code generation |
| 25 |
#--------------------------------------------------------------------------------- |
| 26 |
ARCH := -mthumb -mthumb-interwork |
| 27 |
|
| 28 |
CFLAGS := -g -Wall -O2\ |
| 29 |
-march=armv5te -mtune=arm946e-s \ |
| 30 |
-ffast-math \ |
| 31 |
$(ARCH) |
| 32 |
|
| 33 |
CFLAGS += $(INCLUDE) -DARM9 |
| 34 |
CXXFLAGS := $(CFLAGS) |
| 35 |
|
| 36 |
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s |
| 37 |
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) |
| 38 |
|
| 39 |
#--------------------------------------------------------------------------------- |
| 40 |
# any extra libraries we wish to link with the project |
| 41 |
#--------------------------------------------------------------------------------- |
| 42 |
LIBS := -lfat -lnds9 |
| 43 |
|
| 44 |
|
| 45 |
#--------------------------------------------------------------------------------- |
| 46 |
# list of directories containing libraries, this must be the top level containing |
| 47 |
# include and lib |
| 48 |
#--------------------------------------------------------------------------------- |
| 49 |
LIBDIRS := $(LIBNDS) |
| 50 |
|
| 51 |
#--------------------------------------------------------------------------------- |
| 52 |
# no real need to edit anything past this point unless you need to add additional |
| 53 |
# rules for different file extensions |
| 54 |
#--------------------------------------------------------------------------------- |
| 55 |
ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 56 |
#--------------------------------------------------------------------------------- |
| 57 |
|
| 58 |
export OUTPUT := $(CURDIR)/$(TARGET) |
| 59 |
|
| 60 |
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 61 |
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 62 |
|
| 63 |
export DEPSDIR := $(CURDIR)/$(BUILD) |
| 64 |
|
| 65 |
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 66 |
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 67 |
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 68 |
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 69 |
|
| 70 |
#--------------------------------------------------------------------------------- |
| 71 |
# use CXX for linking C++ projects, CC for standard C |
| 72 |
#--------------------------------------------------------------------------------- |
| 73 |
ifeq ($(strip $(CPPFILES)),) |
| 74 |
#--------------------------------------------------------------------------------- |
| 75 |
export LD := $(CC) |
| 76 |
#--------------------------------------------------------------------------------- |
| 77 |
else |
| 78 |
#--------------------------------------------------------------------------------- |
| 79 |
export LD := $(CXX) |
| 80 |
#--------------------------------------------------------------------------------- |
| 81 |
endif |
| 82 |
#--------------------------------------------------------------------------------- |
| 83 |
|
| 84 |
export OFILES := $(addsuffix .o,$(BINFILES)) \ |
| 85 |
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 86 |
|
| 87 |
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 88 |
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 89 |
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 90 |
-I$(CURDIR)/$(BUILD) |
| 91 |
|
| 92 |
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 93 |
|
| 94 |
.PHONY: $(BUILD) clean |
| 95 |
|
| 96 |
#--------------------------------------------------------------------------------- |
| 97 |
$(BUILD): |
| 98 |
@[ -d $@ ] || mkdir -p $@ |
| 99 |
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 100 |
|
| 101 |
#--------------------------------------------------------------------------------- |
| 102 |
clean: |
| 103 |
@echo clean ... |
| 104 |
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 |
| 105 |
|
| 106 |
|
| 107 |
#--------------------------------------------------------------------------------- |
| 108 |
else |
| 109 |
|
| 110 |
DEPENDS := $(OFILES:.o=.d) |
| 111 |
|
| 112 |
#--------------------------------------------------------------------------------- |
| 113 |
# main targets |
| 114 |
#--------------------------------------------------------------------------------- |
| 115 |
$(OUTPUT).nds : $(OUTPUT).arm9 |
| 116 |
$(OUTPUT).arm9 : $(OUTPUT).elf |
| 117 |
$(OUTPUT).elf : $(OFILES) |
| 118 |
|
| 119 |
#--------------------------------------------------------------------------------- |
| 120 |
%.bin.o : %.bin |
| 121 |
#--------------------------------------------------------------------------------- |
| 122 |
@echo $(notdir $<) |
| 123 |
@$(bin2o) |
| 124 |
|
| 125 |
|
| 126 |
-include $(DEPENDS) |
| 127 |
|
| 128 |
#--------------------------------------------------------------------------------------- |
| 129 |
endif |
| 130 |
#--------------------------------------------------------------------------------------- |