make.mk 3.2 KB

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