Makefile 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # Try "make help" first
  2. .DEFAULT_GOAL := sketch
  3. ##
  4. ## Useful paths, constants, etc.
  5. ##
  6. ifeq ($(LIB_MAPLE_HOME),)
  7. SRCROOT := .
  8. else
  9. SRCROOT := $(LIB_MAPLE_HOME)
  10. endif
  11. BUILD_PATH = build
  12. LIBMAPLE_PATH := $(SRCROOT)/libmaple
  13. WIRISH_PATH := $(SRCROOT)/wirish
  14. SUPPORT_PATH := $(SRCROOT)/support
  15. LIBRARIES_PATH := $(SRCROOT)/libraries
  16. # Support files for linker
  17. LDDIR := $(SUPPORT_PATH)/ld
  18. # Support files for this Makefile
  19. MAKEDIR := $(SUPPORT_PATH)/make
  20. BOARD_INCLUDE_DIR := $(MAKEDIR)/board-includes
  21. ##
  22. ## Target-specific configuration. This determines some compiler and
  23. ## linker options/flags.
  24. ##
  25. # Try "make help" for more information on BOARD and MEMORY_TARGET;
  26. # these default to a Maple Flash build.
  27. BOARD ?= maple
  28. MEMORY_TARGET ?= flash
  29. # $(BOARD)- and $(MEMORY_TARGET)-specific configuration
  30. include $(MAKEDIR)/target-config.mk
  31. ##
  32. ## Build rules and useful templates
  33. ##
  34. include $(MAKEDIR)/build-rules.mk
  35. include $(MAKEDIR)/build-templates.mk
  36. ##
  37. ## Compilation flags
  38. ##
  39. # FIXME: the following allows for deprecated include style, e.g.:
  40. # #include "libmaple.h"
  41. # or
  42. # #include "wirish.h"
  43. # It slows compilation noticeably; remove after 1 release.
  44. TARGET_FLAGS += -I$(LIBMAPLE_PATH)/include/libmaple \
  45. -I$(WIRISH_PATH)/include/wirish
  46. TARGET_FLAGS += -I$(LIBRARIES_PATH) # for internal lib. includes, e.g. <Wire/WireBase.h>
  47. GLOBAL_CFLAGS := -Os -g3 -gdwarf-2 -nostdlib \
  48. -ffunction-sections -fdata-sections \
  49. -Wl,--gc-sections $(TARGET_FLAGS)
  50. GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall $(TARGET_FLAGS)
  51. GLOBAL_ASFLAGS := -x assembler-with-cpp $(TARGET_FLAGS)
  52. LDFLAGS = $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS) -mcpu=cortex-m3 -mthumb \
  53. -Xlinker --gc-sections \
  54. -Xassembler --march=armv7-m -Wall
  55. # -Xlinker --print-gc-sections \
  56. ##
  57. ## Set all submodules here
  58. ##
  59. LIBMAPLE_MODULES += $(SRCROOT)/libmaple
  60. LIBMAPLE_MODULES += $(SRCROOT)/libmaple/usb # The USB module is kept separate
  61. LIBMAPLE_MODULES += $(LIBMAPLE_MODULE_SERIES) # STM32 series submodule in libmaple
  62. LIBMAPLE_MODULES += $(SRCROOT)/wirish
  63. # Official libraries:
  64. LIBMAPLE_MODULES += $(SRCROOT)/libraries/Servo
  65. LIBMAPLE_MODULES += $(SRCROOT)/libraries/LiquidCrystal
  66. LIBMAPLE_MODULES += $(SRCROOT)/libraries/Wire
  67. # Experimental libraries:
  68. LIBMAPLE_MODULES += $(SRCROOT)/libraries/FreeRTOS
  69. # User modules:
  70. ifneq ($(USER_MODULES),)
  71. LIBMAPLE_MODULES += $(USER_MODULES)
  72. endif
  73. # Call each module's rules.mk:
  74. $(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m))))
  75. ##
  76. ## Targets
  77. ##
  78. # main target
  79. include $(SRCROOT)/build-targets.mk
  80. .PHONY: install sketch clean help cscope tags ctags ram flash jtag doxygen mrproper list-boards
  81. # Target upload commands
  82. # USB ID for DFU upload -- FIXME: do something smarter with this
  83. BOARD_USB_VENDOR_ID := 1EAF
  84. BOARD_USB_PRODUCT_ID := 0003
  85. UPLOAD_ram := $(SUPPORT_PATH)/scripts/reset.py && \
  86. sleep 1 && \
  87. $(DFU) -a0 -d $(BOARD_USB_VENDOR_ID):$(BOARD_USB_PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R
  88. UPLOAD_flash := $(SUPPORT_PATH)/scripts/reset.py && \
  89. sleep 1 && \
  90. $(DFU) -a1 -d $(BOARD_USB_VENDOR_ID):$(BOARD_USB_PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R
  91. # Conditionally upload to whatever the last build was
  92. install: INSTALL_TARGET = $(shell cat $(BUILD_PATH)/build-type 2>/dev/null)
  93. install: $(BUILD_PATH)/$(BOARD).bin
  94. @echo "Install target:" $(INSTALL_TARGET)
  95. $(UPLOAD_$(INSTALL_TARGET))
  96. # Force a rebuild if the target changed
  97. PREV_BUILD_TYPE = $(shell cat $(BUILD_PATH)/build-type 2>/dev/null)
  98. build-check:
  99. ifneq ($(PREV_BUILD_TYPE), $(MEMORY_TARGET))
  100. $(shell rm -rf $(BUILD_PATH))
  101. endif
  102. sketch: build-check MSG_INFO $(BUILD_PATH)/$(BOARD).bin
  103. clean:
  104. rm -rf build
  105. mrproper: clean
  106. rm -rf doxygen
  107. help:
  108. @echo ""
  109. @echo "Basic usage (BOARD defaults to maple):"
  110. @echo " $$ cp your-main.cpp main.cpp"
  111. @echo " $$ make BOARD=your_board"
  112. @echo " $$ make BOARD=your_board install"
  113. @echo ""
  114. @echo "(Multiple source files? Link with libmaple.a (\`$$ make library')"
  115. @echo "or hack build-targets.mk appropriately.)"
  116. @echo ""
  117. @echo "Important targets:"
  118. @echo " sketch: Compile for BOARD to MEMORY_TARGET (default)."
  119. @echo " install: Compile and upload over USB using Maple bootloader"
  120. @echo ""
  121. @echo "You *must* set BOARD if not compiling for Maple (e.g."
  122. @echo "use BOARD=maple_mini for mini, etc.), and MEMORY_TARGET"
  123. @echo "if not compiling to Flash. Run \`$$ make list-boards' for"
  124. @echo "a list of all boards."
  125. @echo ""
  126. @echo "Valid MEMORY_TARGETs (default=flash):"
  127. @echo " ram: Compile to RAM (doesn't touch Flash)"
  128. @echo " flash: Compile to Flash (for Maple bootloader)"
  129. @echo " jtag: Compile for JTAG/SWD upload (overwrites bootloader)"
  130. @echo ""
  131. @echo "Other targets:"
  132. @echo " clean: Remove all build and object files"
  133. @echo " doxygen: Build Doxygen HTML and XML documentation"
  134. @echo " help: Show this message"
  135. @echo " mrproper: Remove all generated files"
  136. @echo ""
  137. cscope:
  138. rm -rf cscope.*
  139. find . -name '*.[hcS]' -o -name '*.cpp' | xargs cscope -b
  140. tags:
  141. etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
  142. @echo "Made TAGS file for EMACS code browsing"
  143. ctags:
  144. ctags-exuberant -R .
  145. @echo "Made tags file for VIM code browsing"
  146. ram:
  147. @$(MAKE) MEMORY_TARGET=ram --no-print-directory sketch
  148. flash:
  149. @$(MAKE) MEMORY_TARGET=flash --no-print-directory sketch
  150. jtag:
  151. @$(MAKE) MEMORY_TARGET=jtag --no-print-directory sketch
  152. doxygen:
  153. doxygen $(SUPPORT_PATH)/doxygen/Doxyfile
  154. # This output is kind of ugly, but I don't understand make very well.
  155. list-boards:
  156. @echo " $(addsuffix "\\n",$(basename $(notdir $(wildcard $(BOARD_INCLUDE_DIR)/*.mk))))"