Makefile 4.6 KB

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