Rules.mk 2.3 KB

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