rules.mk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #
  2. # Common make definition for all examples
  3. #
  4. # libc
  5. LIBS += -lgcc -lm -lnosys
  6. ifneq ($(BOARD), spresense)
  7. LIBS += -lc
  8. endif
  9. # TinyUSB Stack source
  10. SRC_C += \
  11. src/tusb.c \
  12. src/common/tusb_fifo.c \
  13. src/device/usbd.c \
  14. src/device/usbd_control.c \
  15. src/class/msc/msc_device.c \
  16. src/class/cdc/cdc_device.c \
  17. src/class/hid/hid_device.c \
  18. src/class/midi/midi_device.c \
  19. src/class/usbtmc/usbtmc_device.c \
  20. src/class/vendor/vendor_device.c \
  21. src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c
  22. # TinyUSB stack include
  23. INC += $(TOP)/src
  24. #
  25. CFLAGS += $(addprefix -I,$(INC))
  26. LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs
  27. ASFLAGS += $(CFLAGS)
  28. # Assembly files can be name with upper case .S, convert it to .s
  29. SRC_S := $(SRC_S:.S=.s)
  30. # Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
  31. # assembly file should be placed first in linking order
  32. OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=.o))
  33. OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
  34. # Verbose mode
  35. ifeq ("$(V)","1")
  36. $(info CFLAGS $(CFLAGS) ) $(info )
  37. $(info LDFLAGS $(LDFLAGS)) $(info )
  38. $(info ASFLAGS $(ASFLAGS)) $(info )
  39. endif
  40. # Set all as default goal
  41. .DEFAULT_GOAL := all
  42. all: $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/$(BOARD)-firmware.hex size
  43. uf2: $(BUILD)/$(BOARD)-firmware.uf2
  44. OBJ_DIRS = $(sort $(dir $(OBJ)))
  45. $(OBJ): | $(OBJ_DIRS)
  46. $(OBJ_DIRS):
  47. @$(MKDIR) -p $@
  48. $(BUILD)/$(BOARD)-firmware.elf: $(OBJ)
  49. @echo LINK $@
  50. @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
  51. $(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf
  52. @echo CREATE $@
  53. @$(OBJCOPY) -O binary $^ $@
  54. $(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf
  55. @echo CREATE $@
  56. @$(OBJCOPY) -O ihex $^ $@
  57. UF2_FAMILY ?= 0x00
  58. $(BUILD)/$(BOARD)-firmware.uf2: $(BUILD)/$(BOARD)-firmware.hex
  59. @echo CREATE $@
  60. $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^
  61. # We set vpath to point to the top of the tree so that the source files
  62. # can be located. By following this scheme, it allows a single build rule
  63. # to be used to compile all .c files.
  64. vpath %.c . $(TOP)
  65. $(BUILD)/obj/%.o: %.c
  66. @echo CC $(notdir $@)
  67. @$(CC) $(CFLAGS) -c -MD -o $@ $<
  68. @# The following fixes the dependency file.
  69. @# See http://make.paulandlesley.org/autodep.html for details.
  70. @# Regex adjusted from the above to play better with Windows paths, etc.
  71. @$(CP) $(@:.o=.d) $(@:.o=.P); \
  72. $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
  73. -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
  74. $(RM) $(@:.o=.d)
  75. # ASM sources lower case .s
  76. vpath %.s . $(TOP)
  77. $(BUILD)/obj/%.o: %.s
  78. @echo AS $(notdir $@)
  79. @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
  80. # ASM sources upper case .S
  81. vpath %.S . $(TOP)
  82. $(BUILD)/obj/%.o: %.S
  83. @echo AS $(notdir $@)
  84. @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
  85. size: $(BUILD)/$(BOARD)-firmware.elf
  86. -@echo ''
  87. @$(SIZE) $<
  88. -@echo ''
  89. clean:
  90. rm -rf $(BUILD)
  91. # Flash binary using Jlink
  92. ifeq ($(OS),Windows_NT)
  93. JLINKEXE = JLink.exe
  94. else
  95. JLINKEXE = JLinkExe
  96. endif
  97. # Flash using jlink
  98. flash-jlink: $(BUILD)/$(BOARD)-firmware.hex
  99. @echo halt > $(BUILD)/$(BOARD).jlink
  100. @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
  101. @echo r >> $(BUILD)/$(BOARD).jlink
  102. @echo go >> $(BUILD)/$(BOARD).jlink
  103. @echo exit >> $(BUILD)/$(BOARD).jlink
  104. $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink