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