make.mk 2.5 KB

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