Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ######################################
  2. # Makefile by CubeMX2Makefile.py
  3. ######################################
  4. ######################################
  5. # target
  6. ######################################
  7. TARGET = blink
  8. ######################################
  9. # building variables
  10. ######################################
  11. # debug build?
  12. DEBUG = 1
  13. # optimization
  14. OPT = -O0
  15. #######################################
  16. # pathes
  17. #######################################
  18. # Build path
  19. BUILD_DIR = build
  20. ######################################
  21. # source
  22. ######################################
  23. C_SOURCES = \
  24. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c \
  25. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c \
  26. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c \
  27. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c \
  28. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c \
  29. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c \
  30. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c \
  31. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c \
  32. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c \
  33. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c \
  34. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c \
  35. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c \
  36. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c \
  37. Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c \
  38. Src/main.c \
  39. Src/stm32f0xx_it.c \
  40. Src/system_stm32f0xx.c \
  41. Src/stm32f0xx_hal_msp.c
  42. ASM_SOURCES = \
  43. startup/startup_stm32f030x6.s
  44. #######################################
  45. # binaries
  46. #######################################
  47. CC = arm-none-eabi-gcc
  48. AS = arm-none-eabi-gcc -x assembler-with-cpp
  49. CP = arm-none-eabi-objcopy
  50. AR = arm-none-eabi-ar
  51. SZ = arm-none-eabi-size
  52. HEX = $(CP) -O ihex
  53. BIN = $(CP) -O binary -S
  54. #######################################
  55. # CFLAGS
  56. #######################################
  57. # macros for gcc
  58. AS_DEFS =
  59. C_DEFS = -D__weak="__attribute__((weak))" -D__packed="__attribute__((__packed__))" -DUSE_HAL_DRIVER -DSTM32F030x6 -D__weak="__attribute__((weak))" -D__packed="__attribute__((__packed__))" -DUSE_HAL_DRIVER -DSTM32F030x6
  60. # includes for gcc
  61. AS_INCLUDES =
  62. C_INCLUDES = -IInc
  63. C_INCLUDES += -IDrivers/CMSIS/Device/ST/STM32F0xx/Include
  64. C_INCLUDES += -IDrivers/CMSIS/Include
  65. C_INCLUDES += -IDrivers/STM32F0xx_HAL_Driver/Inc
  66. C_INCLUDES += -IDrivers/STM32F0xx_HAL_Driver/Inc/Legacy
  67. # compile gcc flags
  68. ASFLAGS = -mthumb -mcpu=cortex-m0 $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  69. CFLAGS = -mthumb -mcpu=cortex-m0 $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  70. ifeq ($(DEBUG), 1)
  71. CFLAGS += -g -gdwarf-2
  72. endif
  73. # Generate dependency information
  74. CFLAGS += -std=c99 -MD -MP -MF .dep/$(@F).d
  75. #######################################
  76. # LDFLAGS
  77. #######################################
  78. # link script
  79. LDSCRIPT = STM32F030F4Px_FLASH.ld
  80. # libraries
  81. LIBS = -lc -lm -lnosys
  82. LIBDIR =
  83. LDFLAGS = -mthumb -mcpu=cortex-m0 -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  84. # default action: build all
  85. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  86. #######################################
  87. # build the application
  88. #######################################
  89. # list of objects
  90. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  91. vpath %.c $(sort $(dir $(C_SOURCES)))
  92. # list of ASM program objects
  93. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  94. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  95. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  96. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  97. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  98. $(AS) -c $(CFLAGS) $< -o $@
  99. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  100. $(CC) $(OBJECTS) $(LDFLAGS) -o $@
  101. $(SZ) $@
  102. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  103. $(HEX) $< $@
  104. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  105. $(BIN) $< $@
  106. $(BUILD_DIR):
  107. mkdir -p $@
  108. #######################################
  109. # clean up
  110. #######################################
  111. clean:
  112. -rm -fR .dep $(BUILD_DIR)
  113. #######################################
  114. # dependencies
  115. #######################################
  116. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  117. .PHONY: clean all
  118. # *** EOF ***