make.mk 2.2 KB

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