make.mk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # ---------------------------------------
  2. # Common make definition for all examples
  3. # ---------------------------------------
  4. # Build directory
  5. BUILD := _build/$(BOARD)
  6. PROJECT := $(notdir $(CURDIR))
  7. BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
  8. # Handy check parameter function
  9. check_defined = \
  10. $(strip $(foreach 1,$1, \
  11. $(call __check_defined,$1,$(strip $(value 2)))))
  12. __check_defined = \
  13. $(if $(value $1),, \
  14. $(error Undefined make flag: $1$(if $2, ($2))))
  15. #-------------- Select the board to build for. ------------
  16. # Board without family
  17. ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),)
  18. BOARD_PATH := hw/bsp/$(BOARD)
  19. FAMILY :=
  20. endif
  21. # Board within family
  22. ifeq ($(BOARD_PATH),)
  23. BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD)))
  24. FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH)))
  25. FAMILY_PATH = hw/bsp/$(FAMILY)
  26. endif
  27. ifeq ($(BOARD_PATH),)
  28. $(info You must provide a BOARD parameter with 'BOARD=')
  29. $(error Invalid BOARD specified)
  30. endif
  31. ifeq ($(FAMILY),)
  32. include $(TOP)/hw/bsp/$(BOARD)/board.mk
  33. else
  34. # Include Family and Board specific defs
  35. include $(TOP)/$(FAMILY_PATH)/family.mk
  36. SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
  37. endif
  38. # Fetch submodules depended by family
  39. fetch_submodule_if_empty = $(if $(wildcard $(TOP)/$1/*),,$(info $(shell git -C $(TOP) submodule update --init $1)))
  40. ifdef DEPS_SUBMODULES
  41. $(foreach s,$(DEPS_SUBMODULES),$(call fetch_submodule_if_empty,$(s)))
  42. endif
  43. #-------------- Cross Compiler ------------
  44. # Can be set by board, default to ARM GCC
  45. CROSS_COMPILE ?= arm-none-eabi-
  46. # Allow for -Os to be changed by board makefiles in case -Os is not allowed
  47. CFLAGS_OPTIMIZED ?= -Os
  48. CC = $(CROSS_COMPILE)gcc
  49. CXX = $(CROSS_COMPILE)g++
  50. GDB = $(CROSS_COMPILE)gdb
  51. OBJCOPY = $(CROSS_COMPILE)objcopy
  52. SIZE = $(CROSS_COMPILE)size
  53. MKDIR = mkdir
  54. ifeq ($(CMDEXE),1)
  55. CP = copy
  56. RM = del
  57. PYTHON = python
  58. else
  59. SED = sed
  60. CP = cp
  61. RM = rm
  62. PYTHON = python3
  63. endif
  64. #-------------- Source files and compiler flags --------------
  65. # Include all source C in family & board folder
  66. SRC_C += hw/bsp/board.c
  67. SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
  68. INC += $(TOP)/$(FAMILY_PATH)
  69. # Compiler Flags
  70. CFLAGS += \
  71. -ggdb \
  72. -fdata-sections \
  73. -ffunction-sections \
  74. -fsingle-precision-constant \
  75. -fno-strict-aliasing \
  76. -Wdouble-promotion \
  77. -Wstrict-prototypes \
  78. -Wstrict-overflow \
  79. -Wall \
  80. -Wextra \
  81. -Werror \
  82. -Wfatal-errors \
  83. -Werror-implicit-function-declaration \
  84. -Wfloat-equal \
  85. -Wundef \
  86. -Wshadow \
  87. -Wwrite-strings \
  88. -Wsign-compare \
  89. -Wmissing-format-attribute \
  90. -Wunreachable-code \
  91. -Wcast-align \
  92. -Wcast-function-type \
  93. -Wcast-qual \
  94. -Wnull-dereference
  95. # Debugging/Optimization
  96. ifeq ($(DEBUG), 1)
  97. CFLAGS += -Og
  98. else
  99. CFLAGS += $(CFLAGS_OPTIMIZED)
  100. endif
  101. # Log level is mapped to TUSB DEBUG option
  102. ifneq ($(LOG),)
  103. CMAKE_DEFSYM += -DLOG=$(LOG)
  104. CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
  105. endif
  106. # Logger: default is uart, can be set to rtt or swo
  107. ifneq ($(LOGGER),)
  108. CMAKE_DEFSYM += -DLOGGER=$(LOGGER)
  109. endif
  110. ifeq ($(LOGGER),rtt)
  111. CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
  112. RTT_SRC = lib/SEGGER_RTT
  113. INC += $(TOP)/$(RTT_SRC)/RTT
  114. SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
  115. else ifeq ($(LOGGER),swo)
  116. CFLAGS += -DLOGGER_SWO
  117. endif