Fix removing USE_LED_STRIP (#12162)
[betaflight.git] / Makefile
blob1dde7cc6efb070f822eb89a19138310ad44bc140
1 ###############################################################################
2 # "THE BEER-WARE LICENSE" (Revision 42):
3 # <msmith@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 # can do whatever you want with this stuff. If we meet some day, and you think
5 # this stuff is worth it, you can buy me a beer in return
6 ###############################################################################
8 # Makefile for building the betaflight firmware.
10 # Invoke this with 'make help' to see the list of supported targets.
12 ###############################################################################
15 # Things that the user might override on the commandline
18 # The target to build, see VALID_TARGETS below
19 TARGET ?= STM32F405
20 BOARD ?=
22 # Compile-time options
23 OPTIONS ?=
25 # compile for External Storage Bootloader support
26 EXST ?= no
28 # compile for target loaded into RAM
29 RAM_BASED ?= no
31 # reserve space for custom defaults
32 CUSTOM_DEFAULTS_EXTENDED ?= no
34 # Debugger optons:
35 # empty - ordinary build with all optimizations enabled
36 # INFO - ordinary build with debug symbols and all optimizations enabled
37 # GDB - debug build with minimum number of optimizations
38 DEBUG ?=
40 # Insert the debugging hardfault debugger
41 # releases should not be built with this flag as it does not disable pwm output
42 DEBUG_HARDFAULTS ?=
44 # Serial port/Device for flashing
45 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /dev/ttyUSB*) no-port-found))
47 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
48 FLASH_SIZE ?=
50 ###############################################################################
51 # Things that need to be maintained as the source changes
54 FORKNAME = betaflight
56 # Working directories
57 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
58 SRC_DIR := $(ROOT)/src/main
59 OBJECT_DIR := $(ROOT)/obj/main
60 BIN_DIR := $(ROOT)/obj
61 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
62 INCLUDE_DIRS := $(SRC_DIR) \
63 $(ROOT)/src/main/target \
64 $(ROOT)/src/main/startup
65 LINKER_DIR := $(ROOT)/src/link
67 ## V : Set verbosity level based on the V= parameter
68 ## V=0 Low
69 ## V=1 High
70 include $(ROOT)/make/build_verbosity.mk
72 # Build tools, so we all share the same versions
73 # import macros common to all supported build systems
74 include $(ROOT)/make/system-id.mk
76 # developer preferences, edit these at will, they'll be gitignored
77 -include $(ROOT)/make/local.mk
79 # pre-build sanity checks
80 include $(ROOT)/make/checks.mk
82 # configure some directories that are relative to wherever ROOT_DIR is located
83 TOOLS_DIR ?= $(ROOT)/tools
84 DL_DIR := $(ROOT)/downloads
86 export RM := rm
88 # import macros that are OS specific
89 include $(ROOT)/make/$(OSFAMILY).mk
91 # include the tools makefile
92 include $(ROOT)/make/tools.mk
94 # default xtal value for F4 targets
95 HSE_VALUE ?= 8000000
97 # used for turning on features like VCP and SDCARD
98 FEATURES =
100 ifneq ($(BOARD),)
101 # silently ignore if the file is not present. Allows for target defaults.
102 -include $(ROOT)/src/main/board/$(BOARD)/board.mk
103 endif
105 include $(ROOT)/make/targets.mk
107 REVISION := norevision
108 ifeq ($(shell git diff --shortstat),)
109 REVISION := $(shell git log -1 --format="%h")
110 endif
112 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
113 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
114 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
116 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
118 # Search path for sources
119 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
120 FATFS_DIR = $(ROOT)/lib/main/FatFS
121 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
123 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
125 LD_FLAGS :=
126 EXTRA_LD_FLAGS :=
129 # Default Tool options - can be overridden in {mcu}.mk files.
131 ifeq ($(DEBUG),GDB)
132 OPTIMISE_DEFAULT := -Og
134 LTO_FLAGS := $(OPTIMISE_DEFAULT)
135 DEBUG_FLAGS = -ggdb3 -gdwarf-5 -DDEBUG
136 else
137 ifeq ($(DEBUG),INFO)
138 DEBUG_FLAGS = -ggdb3
139 endif
140 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
141 OPTIMISE_DEFAULT := -O2
142 OPTIMISE_SPEED := -Ofast
143 OPTIMISE_SIZE := -Os
145 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
146 endif
148 VPATH := $(VPATH):$(ROOT)/make/mcu
149 VPATH := $(VPATH):$(ROOT)/make
151 # start specific includes
152 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
154 # openocd specific includes
155 include $(ROOT)/make/openocd.mk
157 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
158 ifeq ($(TARGET_FLASH_SIZE),)
159 ifneq ($(MCU_FLASH_SIZE),)
160 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
161 else
162 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
163 endif
164 endif
166 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
168 ifneq ($(HSE_VALUE),)
169 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
170 endif
172 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
173 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
175 .DEFAULT_GOAL := hex
177 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
178 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
179 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
180 endif
182 INCLUDE_DIRS := $(INCLUDE_DIRS) \
183 $(ROOT)/lib/main/MAVLink
185 INCLUDE_DIRS := $(INCLUDE_DIRS) \
186 $(TARGET_DIR)
188 VPATH := $(VPATH):$(TARGET_DIR)
190 include $(ROOT)/make/source.mk
192 ###############################################################################
193 # Things that might need changing to use different tools
196 # Find out if ccache is installed on the system
197 CCACHE := ccache
198 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
199 ifneq ($(RESULT),0)
200 CCACHE :=
201 endif
203 # Tool names
204 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
205 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
206 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
207 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
208 OBJDUMP := $(ARM_SDK_PREFIX)objdump
209 READELF := $(ARM_SDK_PREFIX)readelf
210 SIZE := $(ARM_SDK_PREFIX)size
211 DFUSE-PACK := src/utils/dfuse-pack.py
214 # Tool options.
216 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
217 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
218 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
219 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
220 CC_NO_OPTIMISATION :=
223 # Added after GCC version update, remove once the warnings have been fixed
225 TEMPORARY_FLAGS :=
227 EXTRA_WARNING_FLAGS := -Wold-style-definition
229 CFLAGS += $(ARCH_FLAGS) \
230 $(addprefix -D,$(OPTIONS)) \
231 $(addprefix -I,$(INCLUDE_DIRS)) \
232 $(DEBUG_FLAGS) \
233 -std=gnu17 \
234 -Wall -Wextra -Werror -Wpedantic -Wunsafe-loop-optimizations -Wdouble-promotion \
235 $(EXTRA_WARNING_FLAGS) \
236 -ffunction-sections \
237 -fdata-sections \
238 -fno-common \
239 $(TEMPORARY_FLAGS) \
240 $(DEVICE_FLAGS) \
241 -D_GNU_SOURCE \
242 -DUSE_STDPERIPH_DRIVER \
243 -D$(TARGET) \
244 $(TARGET_FLAGS) \
245 -D'__FORKNAME__="$(FORKNAME)"' \
246 -D'__TARGET__="$(TARGET)"' \
247 -D'__REVISION__="$(REVISION)"' \
248 -pipe \
249 -MMD -MP \
250 $(EXTRA_FLAGS)
252 ASFLAGS = $(ARCH_FLAGS) \
253 $(DEBUG_FLAGS) \
254 -x assembler-with-cpp \
255 $(addprefix -I,$(INCLUDE_DIRS)) \
256 -MMD -MP
258 ifeq ($(LD_FLAGS),)
259 LD_FLAGS = -lm \
260 -nostartfiles \
261 --specs=nano.specs \
262 -lc \
263 -lnosys \
264 $(ARCH_FLAGS) \
265 $(LTO_FLAGS) \
266 $(DEBUG_FLAGS) \
267 -static \
268 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
269 -Wl,-L$(LINKER_DIR) \
270 -Wl,--cref \
271 -Wl,--no-wchar-size-warning \
272 -Wl,--print-memory-usage \
273 -T$(LD_SCRIPT) \
274 $(EXTRA_LD_FLAGS)
275 endif
277 ###############################################################################
278 # No user-serviceable parts below
279 ###############################################################################
281 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
282 --std=c99 --inline-suppr --quiet --force \
283 $(addprefix -I,$(INCLUDE_DIRS)) \
284 -I/usr/include -I/usr/include/linux
286 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)
289 # Things we will build
291 TARGET_BIN = $(TARGET_BASENAME).bin
292 TARGET_HEX = $(TARGET_BASENAME).hex
293 TARGET_HEX_REV = $(TARGET_BASENAME)_$(REVISION).hex
294 TARGET_DFU = $(TARGET_BASENAME).dfu
295 TARGET_ZIP = $(TARGET_BASENAME).zip
296 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
297 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
298 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
299 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
300 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
301 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
302 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
304 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
306 TARGET_EF_HASH := $(shell echo -n "$(EXTRA_FLAGS)" | openssl dgst -md5 | awk '{print $$2;}')
307 TARGET_EF_HASH_FILE := $(OBJECT_DIR)/$(TARGET)/.efhash_$(TARGET_EF_HASH)
309 CLEAN_ARTIFACTS := $(TARGET_BIN)
310 CLEAN_ARTIFACTS += $(TARGET_HEX_REV) $(TARGET_HEX)
311 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
312 CLEAN_ARTIFACTS += $(TARGET_LST)
313 CLEAN_ARTIFACTS += $(TARGET_DFU)
315 # Make sure build date and revision is updated on every incremental build
316 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
318 # List of buildable ELF files and their object dependencies.
319 # It would be nice to compute these lists, but that seems to be just beyond make.
321 $(TARGET_LST): $(TARGET_ELF)
322 $(V0) $(OBJDUMP) -S --disassemble $< > $@
324 ifeq ($(EXST),no)
325 $(TARGET_BIN): $(TARGET_ELF)
326 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
327 $(V1) $(OBJCOPY) -O binary $< $@
329 $(TARGET_HEX): $(TARGET_ELF)
330 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
331 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
333 $(TARGET_DFU): $(TARGET_HEX)
334 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
335 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
337 else
338 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
340 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
341 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
342 $(V1) $(OBJCOPY) -O binary $< $@
344 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
345 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
346 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
347 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
348 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
349 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
351 @echo "Generating MD5 hash of binary" "$(STDOUT)"
352 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
354 @echo "Patching MD5 hash into binary" "$(STDOUT)"
355 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
356 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
358 # Note: From the objcopy manual "If you do not specify outfile, objcopy creates a temporary file and destructively renames the result with the name of infile"
359 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
360 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
361 # a) regeneration of $(TARGET_BIN), and
362 # b) the results of $(TARGET_BIN) will not be as expected.
363 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
364 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) -j .exst_hash
365 rm $(TARGET_EXST_ELF).tmp
367 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
368 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
370 # For some currently unknown reason, OBJCOPY, with only input/output files, will generate a file around 2GB for the H730 unless we remove an unused-section
371 # As a workaround drop the ._user_heap_stack section, which is only used during build to show errors if there's not enough space for the heap/stack.
372 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
373 $(V1) @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
374 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --remove-section ._user_heap_stack --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
376 $(V1) $(READELF) -S $(TARGET_EXST_ELF)
377 $(V1) $(READELF) -l $(TARGET_EXST_ELF)
379 $(TARGET_HEX): $(TARGET_BIN)
380 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
382 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
383 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
385 endif
387 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
388 @echo "Linking $(TARGET)" "$(STDOUT)"
389 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
390 $(V1) $(SIZE) $(TARGET_ELF)
392 # Compile
394 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
395 define compile_file
396 echo "%% ($(1)) $<" "$(STDOUT)" && \
397 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
398 endef
400 ifeq ($(DEBUG),GDB)
401 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
402 $(V1) mkdir -p $(dir $@)
403 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
404 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
406 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
408 else
409 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
410 $(V1) mkdir -p $(dir $@)
411 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
412 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
414 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
415 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
417 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
418 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
420 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
424 endif
426 # Assemble
427 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
428 $(V1) mkdir -p $(dir $@)
429 @echo "%% $(notdir $<)" "$(STDOUT)"
430 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
432 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
433 $(V1) mkdir -p $(dir $@)
434 @echo "%% $(notdir $<)" "$(STDOUT)"
435 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
438 ## all : Build all currently built targets
439 all: $(CI_TARGETS)
441 ## all_all : Build all targets (including legacy / unsupported)
442 all_all: $(VALID_TARGETS)
444 $(VALID_TARGETS):
445 $(V0) @echo "Building $@" && \
446 $(MAKE) hex TARGET=$@ && \
447 echo "Building $@ succeeded."
449 $(NOBUILD_TARGETS):
450 $(MAKE) TARGET=$@
452 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
454 ## clean : clean up temporary / machine-generated files
455 clean:
456 @echo "Cleaning $(TARGET)"
457 $(V0) rm -f $(CLEAN_ARTIFACTS)
458 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
459 @echo "Cleaning $(TARGET) succeeded."
461 ## test_clean : clean up temporary / machine-generated files (tests)
462 test-%_clean:
463 $(MAKE) test_clean
465 test_clean:
466 $(V0) cd src/test && $(MAKE) clean || true
468 ## <TARGET>_clean : clean up one specific target (alias for above)
469 $(TARGETS_CLEAN):
470 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
472 ## clean_all : clean all valid targets
473 clean_all: $(TARGETS_CLEAN) test_clean
475 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
477 ## <TARGET>_flash : build and flash a target
478 $(TARGETS_FLASH):
479 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
480 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
481 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
482 else
483 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
484 endif
486 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
487 tty_flash:
488 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
489 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
490 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
492 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
493 dfu_flash:
494 ifneq (no-port-found,$(SERIAL_DEVICE))
495 # potentially this is because the MCU already is in DFU mode, try anyway
496 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
497 $(V0) sleep 1
498 endif
499 $(V0) $(MAKE) $(TARGET_DFU)
500 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
502 st-flash_$(TARGET): $(TARGET_BIN)
503 $(V0) st-flash --reset write $< 0x08000000
505 ## st-flash : flash firmware (.bin) onto flight controller
506 st-flash: st-flash_$(TARGET)
508 ifneq ($(OPENOCD_COMMAND),)
509 openocd-gdb: $(TARGET_ELF)
510 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
511 endif
513 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
515 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
516 $(TARGETS_ZIP):
517 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
518 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
520 zip:
521 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
523 binary:
524 $(V0) $(MAKE) -j $(TARGET_BIN)
526 hex:
527 $(V0) $(MAKE) -j $(TARGET_HEX)
529 TARGETS_REVISION = $(addsuffix _rev,$(VALID_TARGETS))
530 ## <TARGET>_rev : build target and add revision to filename
531 $(TARGETS_REVISION):
532 $(V0) $(MAKE) hex_rev TARGET=$(subst _rev,,$@)
534 hex_rev: hex
535 $(V0) mv -f $(TARGET_HEX) $(TARGET_HEX_REV)
537 all_rev: $(addsuffix _rev,$(CI_TARGETS))
539 unbrick_$(TARGET): $(TARGET_HEX)
540 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
541 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
543 ## unbrick : unbrick flight controller
544 unbrick: unbrick_$(TARGET)
546 ## cppcheck : run static analysis on C source code
547 cppcheck: $(CSOURCES)
548 $(V0) $(CPPCHECK)
550 cppcheck-result.xml: $(CSOURCES)
551 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
553 # mkdirs
554 $(DL_DIR):
555 mkdir -p $@
557 $(TOOLS_DIR):
558 mkdir -p $@
560 ## version : print firmware version
561 version:
562 @echo $(FC_VER)
564 ## help : print this help message and exit
565 help: Makefile make/tools.mk
566 @echo ""
567 @echo "Makefile for the $(FORKNAME) firmware"
568 @echo ""
569 @echo "Usage:"
570 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
571 @echo "Or:"
572 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
573 @echo ""
574 @echo "Valid TARGET values are: $(VALID_TARGETS)"
575 @echo ""
576 @sed -n 's/^## //p' $?
578 ## targets : print a list of all valid target platforms (for consumption by scripts)
579 targets:
580 @echo "Valid targets: $(VALID_TARGETS)"
581 @echo "Built targets: $(CI_TARGETS)"
582 @echo "Default target: $(TARGET)"
584 targets-ci-print:
585 @echo $(CI_TARGETS)
587 ## target-mcu : print the MCU type of the target
588 target-mcu:
589 @echo $(TARGET_MCU)
591 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
592 targets-by-mcu:
593 $(V1) for target in $${TARGETS}; do \
594 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
595 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
596 if [ "$${DO_BUILD}" = 1 ]; then \
597 echo "Building target $${target}..."; \
598 $(MAKE) TARGET=$${target}; \
599 if [ $$? -ne 0 ]; then \
600 echo "Building target $${target} failed, aborting."; \
601 exit 1; \
602 fi; \
603 else \
604 echo -n "$${target} "; \
605 fi; \
606 fi; \
607 done
608 @echo
610 ## targets-f4 : make all F4 targets
611 targets-f4:
612 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
614 targets-f4-print:
615 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
617 targets-ci-f4-print:
618 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
620 ## targets-f7 : make all F7 targets
621 targets-f7:
622 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
624 targets-f7-print:
625 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
627 targets-ci-f7-print:
628 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
630 ## test : run the Betaflight test suite
631 ## junittest : run the Betaflight test suite, producing Junit XML result files.
632 ## test-representative: run a representative subset of the Betaflight test suite (i.e. run all tests, but run each expanded test only for one target)
633 ## test-all: run the Betaflight test suite including all per-target expanded tests
634 test junittest test-all test-representative:
635 $(V0) cd src/test && $(MAKE) $@
637 ## test_help : print the help message for the test suite (including a list of the available tests)
638 test_help:
639 $(V0) cd src/test && $(MAKE) help
641 ## test_versions : print the compiler versions used for the test suite
642 test_versions:
643 $(V0) cd src/test && $(MAKE) versions
645 ## test_% : run test 'test_%' from the test suite
646 test_%:
647 $(V0) cd src/test && $(MAKE) $@
649 $(TARGET_EF_HASH_FILE):
650 $(V1) mkdir -p $(dir $@)
651 $(V0) rm -f $(OBJECT_DIR)/$(TARGET)/.efhash_*
652 @echo "EF HASH -> $(TARGET_EF_HASH_FILE)"
653 $(V1) touch $(TARGET_EF_HASH_FILE)
655 # rebuild everything when makefile changes or the extra flags have changed
656 $(TARGET_OBJS): $(TARGET_EF_HASH_FILE) Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
658 # include auto-generated dependencies
659 -include $(TARGET_DEPS)