make.mk 3.0 KB

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