Rules.mk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. TOOL_PREFIX = arm-none-eabi-
  2. CC = $(TOOL_PREFIX)gcc
  3. OBJCOPY = $(TOOL_PREFIX)objcopy
  4. LD = $(TOOL_PREFIX)ld
  5. PYTHON = python3
  6. ZIP = zip -r
  7. UNZIP = unzip
  8. ifneq ($(VERBOSE),1)
  9. TOOL_PREFIX := @$(TOOL_PREFIX)
  10. endif
  11. FLAGS = -g -Os -nostdlib -std=gnu99 -iquote $(ROOT)/inc
  12. FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement
  13. FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs
  14. FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
  15. FLAGS += -mlittle-endian -mthumb -mfloat-abi=soft
  16. FLAGS += -Wno-unused-value -ffunction-sections
  17. ifeq ($(mcu),stm32f1)
  18. FLAGS += -mcpu=cortex-m3 -DSTM32F1=1 -DMCU=1
  19. stm32f1=y
  20. else ifeq ($(mcu),stm32f7)
  21. FLAGS += -mcpu=cortex-m7 -DSTM32F7=7 -DMCU=7
  22. stm32f7=y
  23. else ifeq ($(mcu),at32f4)
  24. FLAGS += -mcpu=cortex-m4 -DAT32F4=4 -DMCU=4
  25. at32f4=y
  26. endif
  27. ifneq ($(debug),y)
  28. FLAGS += -DNDEBUG
  29. endif
  30. ifeq ($(bootloader),y)
  31. FLAGS += -DBOOTLOADER=1
  32. endif
  33. FLAGS += -MMD -MF .$(@F).d
  34. DEPS = .*.d
  35. FLAGS += $(FLAGS-y)
  36. CFLAGS += $(CFLAGS-y) $(FLAGS) -include decls.h
  37. AFLAGS += $(AFLAGS-y) $(FLAGS) -D__ASSEMBLY__
  38. LDFLAGS += $(LDFLAGS-y) $(FLAGS) -Wl,--gc-sections
  39. SRCDIR := $(shell $(PYTHON) $(ROOT)/scripts/srcdir.py $(CURDIR))
  40. include $(SRCDIR)/Makefile
  41. SUBDIRS += $(SUBDIRS-y)
  42. OBJS += $(OBJS-y) $(patsubst %,%/build.o,$(SUBDIRS))
  43. # Force execution of pattern rules (for which PHONY cannot be directly used).
  44. .PHONY: FORCE
  45. FORCE:
  46. .PHONY: clean
  47. .SECONDARY:
  48. build.o: $(OBJS)
  49. $(LD) -r -o $@ $^
  50. %/build.o: FORCE
  51. +mkdir -p $*
  52. $(MAKE) -f $(ROOT)/Rules.mk -C $* build.o
  53. %.ld: $(SRCDIR)/%.ld.S $(SRCDIR)/Makefile
  54. @echo CPP $@
  55. $(CC) -P -E $(AFLAGS) $< -o $@
  56. %.elf: $(OBJS) %.ld $(SRCDIR)/Makefile
  57. @echo LD $@
  58. $(CC) $(LDFLAGS) -T$(*F).ld $(OBJS) -o $@
  59. chmod a-x $@
  60. %.hex: %.elf
  61. @echo OBJCOPY $@
  62. $(OBJCOPY) -O ihex $< $@
  63. chmod a-x $@
  64. ifneq ($(bootloader),y)
  65. srec_cat ../bootloader/target.hex -Intel $@ -Intel -o $@ -Intel
  66. endif
  67. %.bin: %.elf
  68. @echo OBJCOPY $@
  69. $(OBJCOPY) -O binary $< $@
  70. chmod a-x $@
  71. %.upd: %.bin
  72. $(PYTHON) $(ROOT)/scripts/mk_update.py new $@ \
  73. $< $(mcu)-$(FW_MAJOR).$(FW_MINOR)-$(bootloader)
  74. %.o: $(SRCDIR)/%.c $(SRCDIR)/Makefile
  75. @echo CC $@
  76. $(CC) $(CFLAGS) -c $< -o $@
  77. %.o: $(SRCDIR)/%.S $(SRCDIR)/Makefile
  78. @echo AS $@
  79. $(CC) $(AFLAGS) -c $< -o $@
  80. -include $(DEPS)