| 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 |
| 20 | DATA := |
| 21 | |
| 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 -fomit-frame-pointer\ |
| 30 | -ffast-math \ |
| 31 | $(ARCH) |
| 32 | |
| 33 | CFLAGS += $(INCLUDE) -DARM9 |
| 34 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions |
| 35 | |
| 36 | ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s |
| 37 | |
| 38 | LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) |
| 39 | |
| 40 | #--------------------------------------------------------------------------------- |
| 41 | # any extra libraries we wish to link with the project |
| 42 | #--------------------------------------------------------------------------------- |
| 43 | LIBS := -lnds9 |
| 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 ARM9BIN := $(TOPDIR)/$(TARGET).arm9 |
| 59 | export ARM9ELF := $(CURDIR)/$(TARGET).arm9.elf |
| 60 | export DEPSDIR := $(CURDIR)/$(BUILD) |
| 61 | |
| 62 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 63 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 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 | -I$(CURDIR)/$(BUILD) |
| 90 | |
| 91 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 92 | |
| 93 | .PHONY: $(BUILD) clean |
| 94 | |
| 95 | #--------------------------------------------------------------------------------- |
| 96 | $(BUILD): |
| 97 | @[ -d $@ ] || mkdir -p $@ |
| 98 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 99 | |
| 100 | #--------------------------------------------------------------------------------- |
| 101 | clean: |
| 102 | @echo clean ... |
| 103 | @rm -fr $(BUILD) *.elf *.nds* *.bin |
| 104 | |
| 105 | |
| 106 | #--------------------------------------------------------------------------------- |
| 107 | else |
| 108 | |
| 109 | #--------------------------------------------------------------------------------- |
| 110 | # main targets |
| 111 | #--------------------------------------------------------------------------------- |
| 112 | $(ARM9BIN) : $(ARM9ELF) |
| 113 | @$(OBJCOPY) -O binary $< $@ |
| 114 | @echo built ... $(notdir $@) |
| 115 | |
| 116 | $(ARM9ELF) : $(OFILES) |
| 117 | @echo linking $(notdir $@) |
| 118 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ |
| 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 $(DEPSDIR)/*.d |
| 129 | |
| 130 | #--------------------------------------------------------------------------------------- |
| 131 | endif |
| 132 | #--------------------------------------------------------------------------------------- |