make.mk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # ---------------------------------------
  2. # Common make definition for all examples
  3. # ---------------------------------------
  4. # Build directory
  5. BUILD = _build/build-$(BOARD)
  6. # Handy check parameter function
  7. check_defined = \
  8. $(strip $(foreach 1,$1, \
  9. $(call __check_defined,$1,$(strip $(value 2)))))
  10. __check_defined = \
  11. $(if $(value $1),, \
  12. $(error Undefined make flag: $1$(if $2, ($2))))
  13. #-------------- Select the board to build for. ------------
  14. #BOARD_LIST = $(sort $(subst /.,,$(subst $(TOP)/hw/bsp/,,$(wildcard $(TOP)/hw/bsp/*/.))))
  15. #ifeq ($(filter $(BOARD),$(BOARD_LIST)),)
  16. # $(info You must provide a BOARD parameter with 'BOARD=', supported boards are:)
  17. # $(foreach b,$(BOARD_LIST),$(info - $(b)))
  18. # $(error Invalid BOARD specified)
  19. #endif
  20. # Board without family
  21. BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/$(BOARD)))
  22. FAMILY :=
  23. # Board within family
  24. ifeq ($(BOARD_PATH),)
  25. BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD)))
  26. FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH)))
  27. FAMILY_PATH = hw/bsp/$(FAMILY)
  28. endif
  29. ifeq ($(BOARD_PATH),)
  30. $(error Invalid BOARD specified)
  31. endif
  32. ifeq ($(FAMILY),)
  33. include $(TOP)/hw/bsp/$(BOARD)/board.mk
  34. else
  35. # Include Family and Board specific defs
  36. include $(TOP)/$(FAMILY_PATH)/family.mk
  37. SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
  38. endif
  39. #-------------- Cross Compiler ------------
  40. # Can be set by board, default to ARM GCC
  41. CROSS_COMPILE ?= arm-none-eabi-
  42. CC = $(CROSS_COMPILE)gcc
  43. CXX = $(CROSS_COMPILE)g++
  44. OBJCOPY = $(CROSS_COMPILE)objcopy
  45. SIZE = $(CROSS_COMPILE)size
  46. MKDIR = mkdir
  47. SED = sed
  48. CP = cp
  49. RM = rm
  50. #-------------- Source files and compiler flags --------------
  51. # Include all source C in family & board folder
  52. SRC_C += hw/bsp/board.c
  53. SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
  54. # Compiler Flags
  55. CFLAGS += \
  56. -ggdb \
  57. -fdata-sections \
  58. -ffunction-sections \
  59. -fsingle-precision-constant \
  60. -fno-strict-aliasing \
  61. -Wdouble-promotion \
  62. -Wstrict-prototypes \
  63. -Wall \
  64. -Wextra \
  65. -Werror \
  66. -Wfatal-errors \
  67. -Werror-implicit-function-declaration \
  68. -Wfloat-equal \
  69. -Wundef \
  70. -Wshadow \
  71. -Wwrite-strings \
  72. -Wsign-compare \
  73. -Wmissing-format-attribute \
  74. -Wunreachable-code \
  75. -Wcast-align
  76. # Debugging/Optimization
  77. ifeq ($(DEBUG), 1)
  78. CFLAGS += -Og
  79. else
  80. CFLAGS += -Os
  81. endif
  82. # Log level is mapped to TUSB DEBUG option
  83. ifneq ($(LOG),)
  84. CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
  85. endif
  86. # Logger: default is uart, can be set to rtt or swo
  87. ifeq ($(LOGGER),rtt)
  88. RTT_SRC = lib/SEGGER_RTT
  89. CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
  90. INC += $(TOP)/$(RTT_SRC)/RTT
  91. SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
  92. else ifeq ($(LOGGER),swo)
  93. CFLAGS += -DLOGGER_SWO
  94. endif