Rules.mk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. RULES_MK := y
  40. include 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. $(MAKE) -f $(ROOT)/Rules.mk -C $* build.o
  52. %.o: %.c Makefile
  53. @echo CC $@
  54. $(CC) $(CFLAGS) -c $< -o $@
  55. %.o: %.S Makefile
  56. @echo AS $@
  57. $(CC) $(AFLAGS) -c $< -o $@
  58. %.ld: %.ld.S Makefile
  59. @echo CPP $@
  60. $(CC) -P -E $(AFLAGS) $< -o $@
  61. %.elf: $(OBJS) %.ld Makefile
  62. @echo LD $@
  63. $(CC) $(LDFLAGS) -T$(*F).ld $(OBJS) -o $@
  64. chmod a-x $@
  65. %.hex: %.elf
  66. @echo OBJCOPY $@
  67. $(OBJCOPY) -O ihex $< $@
  68. chmod a-x $@
  69. %.bin: %.elf
  70. @echo OBJCOPY $@
  71. $(OBJCOPY) -O binary $< $@
  72. chmod a-x $@
  73. %.o: $(RPATH)/%.c Makefile
  74. @echo CC $@
  75. $(CC) $(CFLAGS) -c $< -o $@
  76. %.o: $(RPATH)/%.S Makefile
  77. @echo AS $@
  78. $(CC) $(AFLAGS) -c $< -o $@
  79. clean:: $(addprefix _clean_,$(SUBDIRS) $(SUBDIRS-n) $(SUBDIRS-))
  80. rm -f *.orig *.rej *~ *.o *.elf *.hex *.bin *.ld $(DEPS)
  81. _clean_%: FORCE
  82. $(MAKE) -f $(ROOT)/Rules.mk -C $* clean
  83. -include $(DEPS)