25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

179 satır
5.4 KiB

  1. ##
  2. ## This file is part of the libopencm3 project.
  3. ##
  4. ## This library is free software: you can redistribute it and/or modify
  5. ## it under the terms of the GNU Lesser General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## This library is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU Lesser General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU Lesser General Public License
  15. ## along with this library. If not, see <http://www.gnu.org/licenses/>.
  16. ##
  17. # This version of rules.mk expects the following to be defined before
  18. # inclusion..
  19. ### REQUIRED ###
  20. # OPENCM3_DIR - duh
  21. # OPENCM3_LIB - the basename, eg: opencm3_stm32f4
  22. # OPENCM3_DEFS - the target define eg: -DSTM32F4
  23. # ARCH_FLAGS - eg, -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
  24. # (ie, the full set of cpu arch flags, _none_ are defined in this file)
  25. # PROJECT - will be the basename of the output elf, eg usb-gadget0-stm32f4disco
  26. # CFILES - basenames only, eg main.c blah.c
  27. # LDSCRIPT - full path, eg ../../examples/stm32/f4/stm32f4-discovery/stm32f4-discovery.ld
  28. #
  29. ### OPTIONAL ###
  30. # INCLUDES - fully formed -I paths, if you want extra, eg -I../shared
  31. # BUILD_DIR - defaults to bin, should set this if you are building multiarch
  32. # OPT - full -O flag, defaults to -Os
  33. # CSTD - defaults -std=c99
  34. # CXXSTD - no default.
  35. # OOCD_INTERFACE - eg stlink-v2
  36. # OOCD_TARGET - eg stm32f4x
  37. # both only used if you use the "make flash" target.
  38. # OOCD_FILE - eg my.openocd.cfg
  39. # This overrides interface/target above, and is used as just -f FILE
  40. ### TODO/FIXME/notes ###
  41. # No support for stylecheck.
  42. # No support for BMP/texane/random flash methods, no plans either
  43. # No support for magically finding the library.
  44. # C++ hasn't been actually tested with this..... sorry bout that. ;)
  45. # Second expansion/secondary not set, add this if you need them.
  46. BUILD_DIR ?= bin
  47. OPT ?= -Os
  48. CSTD ?= -std=c99
  49. # Be silent per default, but 'make V=1' will show all compiler calls.
  50. # If you're insane, V=99 will print out all sorts of things.
  51. V?=0
  52. ifeq ($(V),0)
  53. Q := @
  54. NULL := 2>/dev/null
  55. endif
  56. # Tool paths.
  57. PREFIX ?= arm-none-eabi-
  58. CC = $(PREFIX)gcc
  59. LD = $(PREFIX)gcc
  60. OBJCOPY = $(PREFIX)objcopy
  61. OBJDUMP = $(PREFIX)objdump
  62. OOCD ?= openocd
  63. OPENCM3_INC = $(OPENCM3_DIR)/include
  64. # Inclusion of library header files
  65. INCLUDES += $(patsubst %,-I%, . $(OPENCM3_INC) )
  66. OBJS = $(CFILES:%.c=$(BUILD_DIR)/%.o)
  67. GENERATED_BINS = $(PROJECT).elf $(PROJECT).bin $(PROJECT).map $(PROJECT).list $(PROJECT).lss
  68. TGT_CPPFLAGS += -MD
  69. TGT_CPPFLAGS += -Wall -Wundef $(INCLUDES)
  70. TGT_CPPFLAGS += $(INCLUDES) $(OPENCM3_DEFS)
  71. TGT_CFLAGS += $(OPT) $(CSTD) -ggdb3
  72. TGT_CFLAGS += $(ARCH_FLAGS)
  73. TGT_CFLAGS += -fno-common
  74. TGT_CFLAGS += -ffunction-sections -fdata-sections
  75. TGT_CFLAGS += -Wextra -Wshadow -Wno-unused-variable -Wimplicit-function-declaration
  76. TGT_CFLAGS += -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes
  77. TGT_CXXFLAGS += $(OPT) $(CXXSTD) -ggdb3
  78. TGT_CXXFLAGS += $(ARCH_FLAGS)
  79. TGT_CXXFLAGS += -fno-common
  80. TGT_CXXFLAGS += -ffunction-sections -fdata-sections
  81. TGT_CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++
  82. TGT_LDFLAGS += -T$(LDSCRIPT) -L$(OPENCM3_DIR)/lib -nostartfiles
  83. TGT_LDFLAGS += $(ARCH_FLAGS)
  84. TGT_LDFLAGS += -specs=nano.specs
  85. TGT_LDFLAGS += -Wl,--gc-sections
  86. # OPTIONAL
  87. #TGT_LDFLAGS += -Wl,-Map=$(PROJECT).map
  88. ifeq ($(V),99)
  89. TGT_LDFLAGS += -Wl,--print-gc-sections
  90. endif
  91. # Linker script generator fills this in for us.
  92. ifeq (,$(DEVICE))
  93. LDLIBS += -l$(OPENCM3_LIB)
  94. endif
  95. # nosys is only in newer gcc-arm-embedded...
  96. #LDLIBS += -specs=nosys.specs
  97. LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
  98. # Burn in legacy hell fortran modula pascal yacc idontevenwat
  99. .SUFFIXES:
  100. .SUFFIXES: .c .h .o .cxx .elf .bin .list .lss
  101. # Bad make, never *ever* try to get a file out of source control by yourself.
  102. %: %,v
  103. %: RCS/%,v
  104. %: RCS/%
  105. %: s.%
  106. %: SCCS/s.%
  107. all: $(PROJECT).elf $(PROJECT).bin
  108. flash: $(PROJECT).flash
  109. # error if not using linker script generator
  110. ifeq (,$(DEVICE))
  111. $(LDSCRIPT):
  112. ifeq (,$(wildcard $(LDSCRIPT)))
  113. $(error Unable to find specified linker script: $(LDSCRIPT))
  114. endif
  115. endif
  116. # Need a special rule to have a bin dir
  117. $(BUILD_DIR)/%.o: %.c
  118. @printf " CC\t$<\n"
  119. @mkdir -p $(dir $@)
  120. $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $@ -c $<
  121. $(BUILD_DIR)/%.o: %.cxx
  122. @printf " CXX\t$<\n"
  123. @mkdir -p $(dir $@)
  124. $(Q)$(CC) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $@ -c $<
  125. $(PROJECT).elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
  126. @printf " LD\t$@\n"
  127. $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
  128. %.bin: %.elf
  129. @printf " OBJCOPY\t$@\n"
  130. $(Q)$(OBJCOPY) -O binary $< $@
  131. %.lss: %.elf
  132. $(OBJDUMP) -h -S $< > $@
  133. %.list: %.elf
  134. $(OBJDUMP) -S $< > $@
  135. %.flash: %.elf
  136. @printf " FLASH\t$<\n"
  137. ifeq (,$(OOCD_FILE))
  138. $(Q)(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
  139. $(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
  140. -f target/$(OOCD_TARGET).cfg \
  141. -c "program $(realpath $(*).elf) verify reset exit" \
  142. $(NULL)
  143. else
  144. $(Q)(echo "halt; program $(realpath $(*).elf) verify reset" | nc -4 localhost 4444 2>/dev/null) || \
  145. $(Q)$(OOCD) -f $(OOCD_FILE) \
  146. -c "program $(realpath $(*).elf) verify reset exit" \
  147. $(NULL)
  148. endif
  149. clean:
  150. rm -rf $(BUILD_DIR) $(GENERATED_BINS)
  151. .PHONY: all clean flash
  152. -include $(OBJS:.o=.d)