Add dynamic distance formatting for OSD elements
[betaflight.git] / Makefile
blob2d80ad7738751657eb2792d6f46cb1c85dcc9496
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 ?= OMNIBUSF4
21 # Compile-time options
22 OPTIONS ?=
24 # compile for OpenPilot BootLoader support
25 OPBL ?= no
27 # compile for External Storage Bootloader support
28 EXST ?= no
30 # Debugger optons:
31 # empty - ordinary build with all optimizations enabled
32 # RELWITHDEBINFO - ordinary build with debug symbols and all optimizations enabled
33 # GDB - debug build with minimum number of optimizations
34 DEBUG ?=
36 # Insert the debugging hardfault debugger
37 # releases should not be built with this flag as it does not disable pwm output
38 DEBUG_HARDFAULTS ?=
40 # Serial port/Device for flashing
41 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /dev/ttyUSB*) no-port-found))
43 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
44 FLASH_SIZE ?=
47 ###############################################################################
48 # Things that need to be maintained as the source changes
51 FORKNAME = betaflight
53 # Working directories
54 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
55 SRC_DIR := $(ROOT)/src/main
56 OBJECT_DIR := $(ROOT)/obj/main
57 BIN_DIR := $(ROOT)/obj
58 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
59 INCLUDE_DIRS := $(SRC_DIR) \
60 $(ROOT)/src/main/target \
61 $(ROOT)/src/main/startup
62 LINKER_DIR := $(ROOT)/src/link
64 ## V : Set verbosity level based on the V= parameter
65 ## V=0 Low
66 ## V=1 High
67 include $(ROOT)/make/build_verbosity.mk
69 # Build tools, so we all share the same versions
70 # import macros common to all supported build systems
71 include $(ROOT)/make/system-id.mk
73 # developer preferences, edit these at will, they'll be gitignored
74 -include $(ROOT)/make/local.mk
76 # configure some directories that are relative to wherever ROOT_DIR is located
77 ifndef TOOLS_DIR
78 TOOLS_DIR := $(ROOT)/tools
79 endif
80 BUILD_DIR := $(ROOT)/build
81 DL_DIR := $(ROOT)/downloads
83 export RM := rm
85 # import macros that are OS specific
86 include $(ROOT)/make/$(OSFAMILY).mk
88 # include the tools makefile
89 include $(ROOT)/make/tools.mk
91 # default xtal value for F4 targets
92 HSE_VALUE ?= 8000000
94 # used for turning on features like VCP and SDCARD
95 FEATURES =
97 # used to disable features based on flash space shortage (larger number => more features disabled)
98 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
99 FEATURE_CUT_LEVEL =
101 # The list of targets to build for 'pre-push'
102 PRE_PUSH_TARGET_LIST ?= OMNIBUSF4 STM32F405 SPRACINGF7DUAL STM32F7X2 SITL test-representative
104 include $(ROOT)/make/targets.mk
106 REVISION := $(shell git log -1 --format="%h")
108 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
109 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
110 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
112 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
114 # Search path for sources
115 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
116 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
117 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
118 FATFS_DIR = $(ROOT)/lib/main/FatFS
119 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
121 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
123 LD_FLAGS :=
126 # Default Tool options - can be overridden in {mcu}.mk files.
128 ifeq ($(DEBUG),GDB)
129 OPTIMISE_DEFAULT := -Og
131 LTO_FLAGS := $(OPTIMISE_DEFAULT)
132 DEBUG_FLAGS = -ggdb3 -DDEBUG
133 else
134 ifeq ($(DEBUG),INFO)
135 DEBUG_FLAGS = -ggdb3
136 endif
137 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
138 OPTIMISE_DEFAULT := -O2
139 OPTIMISE_SPEED := -Ofast
140 OPTIMISE_SIZE := -Os
142 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
143 endif
145 VPATH := $(VPATH):$(ROOT)/make/mcu
146 VPATH := $(VPATH):$(ROOT)/make
148 # start specific includes
149 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
151 # openocd specific includes
152 include $(ROOT)/make/openocd.mk
154 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
155 ifeq ($(FLASH_SIZE),)
156 ifneq ($(TARGET_FLASH),)
157 FLASH_SIZE := $(TARGET_FLASH)
158 else
159 $(error FLASH_SIZE not configured for target $(TARGET))
160 endif
161 endif
163 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
165 ifneq ($(HSE_VALUE),)
166 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
167 endif
169 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
170 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
171 else ifneq ($(FEATURE_CUT_LEVEL),)
172 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
173 endif
175 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
176 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
178 ifeq ($(OPBL),yes)
179 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
180 .DEFAULT_GOAL := binary
181 else
182 .DEFAULT_GOAL := hex
183 endif
185 INCLUDE_DIRS := $(INCLUDE_DIRS) \
186 $(ROOT)/lib/main/MAVLink
188 INCLUDE_DIRS := $(INCLUDE_DIRS) \
189 $(TARGET_DIR)
191 VPATH := $(VPATH):$(TARGET_DIR)
193 include $(ROOT)/make/source.mk
195 ###############################################################################
196 # Things that might need changing to use different tools
199 # Find out if ccache is installed on the system
200 CCACHE := ccache
201 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
202 ifneq ($(RESULT),0)
203 CCACHE :=
204 endif
206 # Tool names
207 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
208 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
209 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
210 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
211 OBJDUMP := $(ARM_SDK_PREFIX)objdump
212 SIZE := $(ARM_SDK_PREFIX)size
215 # Tool options.
217 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
218 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
219 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
220 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
221 CC_NO_OPTIMISATION :=
223 CFLAGS += $(ARCH_FLAGS) \
224 $(addprefix -D,$(OPTIONS)) \
225 $(addprefix -I,$(INCLUDE_DIRS)) \
226 $(DEBUG_FLAGS) \
227 -std=gnu11 \
228 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
229 -ffunction-sections \
230 -fdata-sections \
231 -fno-common \
232 -pedantic \
233 $(DEVICE_FLAGS) \
234 -D_GNU_SOURCE \
235 -DUSE_STDPERIPH_DRIVER \
236 -D$(TARGET) \
237 $(TARGET_FLAGS) \
238 -D'__FORKNAME__="$(FORKNAME)"' \
239 -D'__TARGET__="$(TARGET)"' \
240 -D'__REVISION__="$(REVISION)"' \
241 -save-temps=obj \
242 -MMD -MP \
243 $(EXTRA_FLAGS)
245 ASFLAGS = $(ARCH_FLAGS) \
246 $(DEBUG_FLAGS) \
247 -x assembler-with-cpp \
248 $(addprefix -I,$(INCLUDE_DIRS)) \
249 -MMD -MP
251 ifeq ($(LD_FLAGS),)
252 LD_FLAGS = -lm \
253 -nostartfiles \
254 --specs=nano.specs \
255 -lc \
256 -lnosys \
257 $(ARCH_FLAGS) \
258 $(LTO_FLAGS) \
259 $(DEBUG_FLAGS) \
260 -static \
261 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
262 -Wl,-L$(LINKER_DIR) \
263 -Wl,--cref \
264 -Wl,--no-wchar-size-warning \
265 -Wl,--print-memory-usage \
266 -T$(LD_SCRIPT)
267 endif
269 ###############################################################################
270 # No user-serviceable parts below
271 ###############################################################################
273 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
274 --std=c99 --inline-suppr --quiet --force \
275 $(addprefix -I,$(INCLUDE_DIRS)) \
276 -I/usr/include -I/usr/include/linux
279 # Things we will build
281 TARGET_S19 = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).s19
282 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
283 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
284 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
285 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
286 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
287 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
288 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
289 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
290 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
292 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
294 CLEAN_ARTIFACTS := $(TARGET_BIN)
295 CLEAN_ARTIFACTS += $(TARGET_HEX)
296 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
297 CLEAN_ARTIFACTS += $(TARGET_LST)
299 # Make sure build date and revision is updated on every incremental build
300 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
302 # List of buildable ELF files and their object dependencies.
303 # It would be nice to compute these lists, but that seems to be just beyond make.
305 $(TARGET_LST): $(TARGET_ELF)
306 $(V0) $(OBJDUMP) -S --disassemble $< > $@
309 $(TARGET_S19): $(TARGET_ELF)
310 @echo "Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
311 $(V1) $(OBJCOPY) --output-target=srec $(TARGET_S19)
313 ifeq ($(EXST),no)
314 $(TARGET_BIN): $(TARGET_ELF)
315 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
316 $(V1) $(OBJCOPY) -O binary $< $@
318 $(TARGET_HEX): $(TARGET_ELF)
319 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
320 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
322 else
323 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
325 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
326 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
327 $(V1) $(OBJCOPY) -O binary $< $@
329 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
330 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
331 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
332 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
333 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
334 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
336 @echo "Generating MD5 hash of binary" "$(STDOUT)"
337 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
339 @echo "Patching MD5 hash into binary" "$(STDOUT)"
340 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
341 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
343 @echo "Patching MD5 hash into exst elf" "$(STDOUT)"
344 $(OBJCOPY) $(TARGET_ELF) --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
345 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
346 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
348 $(TARGET_HEX): $(TARGET_BIN)
349 @echo "Creating EXST HEX from patched EXST ELF $(TARGET_HEX)" "$(STDOUT)"
350 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $(TARGET_EXST_ELF) $@
352 endif
354 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
355 @echo "Linking $(TARGET)" "$(STDOUT)"
356 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
357 $(V1) $(SIZE) $(TARGET_ELF)
359 # Compile
361 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
362 define compile_file
363 echo "%% ($(1)) $<" "$(STDOUT)" && \
364 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
365 endef
367 ifeq ($(DEBUG),GDB)
368 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
369 $(V1) mkdir -p $(dir $@)
370 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
371 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
373 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
375 else
376 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
377 $(V1) mkdir -p $(dir $@)
378 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
379 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
381 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
382 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
384 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
385 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
387 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
391 endif
393 # Assemble
394 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
395 $(V1) mkdir -p $(dir $@)
396 @echo "%% $(notdir $<)" "$(STDOUT)"
397 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
399 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
400 $(V1) mkdir -p $(dir $@)
401 @echo "%% $(notdir $<)" "$(STDOUT)"
402 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
405 ## all : Build all targets (excluding unsupported)
406 all: $(SUPPORTED_TARGETS)
408 ## all_with_unsupported : Build all targets (including unsupported)
409 all_with_unsupported: $(VALID_TARGETS)
411 ## unsupported : Build unsupported targets
412 unsupported: $(UNSUPPORTED_TARGETS)
414 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
415 pre-push:
416 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
418 ## official : Build all official (travis) targets
419 official: $(OFFICIAL_TARGETS)
421 ## targets-group-1 : build some targets
422 targets-group-1: $(GROUP_1_TARGETS)
424 ## targets-group-2 : build some targets
425 targets-group-2: $(GROUP_2_TARGETS)
427 ## targets-group-3 : build some targets
428 targets-group-3: $(GROUP_3_TARGETS)
430 ## targets-group-3 : build some targets
431 targets-group-4: $(GROUP_4_TARGETS)
433 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
434 targets-group-rest: $(GROUP_OTHER_TARGETS)
436 $(VALID_TARGETS):
437 $(V0) @echo "Building $@" && \
438 $(MAKE) binary hex TARGET=$@ && \
439 echo "Building $@ succeeded."
441 $(NOBUILD_TARGETS):
442 $(MAKE) TARGET=$@
444 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
446 ## clean : clean up temporary / machine-generated files
447 clean:
448 @echo "Cleaning $(TARGET)"
449 $(V0) rm -f $(CLEAN_ARTIFACTS)
450 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
451 @echo "Cleaning $(TARGET) succeeded."
453 ## test_clean : clean up temporary / machine-generated files (tests)
454 test-%_clean:
455 $(MAKE) test_clean
457 test_clean:
458 $(V0) cd src/test && $(MAKE) clean || true
460 ## <TARGET>_clean : clean up one specific target (alias for above)
461 $(TARGETS_CLEAN):
462 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
464 ## clean_all : clean all valid targets
465 clean_all: $(TARGETS_CLEAN) test_clean
467 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS) )
469 ## <TARGET>_flash : build and flash a target
470 $(TARGETS_FLASH):
471 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
472 $(V0) $(MAKE) -j hex TARGET=$(subst _flash,,$@)
473 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
474 else
475 $(V0) $(MAKE) -j binary TARGET=$(subst _flash,,$@)
476 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
477 endif
479 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
480 tty_flash:
481 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
482 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
483 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
485 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
486 dfu_flash:
487 ifneq (no-port-found,$(SERIAL_DEVICE))
488 # potentially this is because the MCU already is in DFU mode, try anyway
489 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
490 $(V0) sleep 1
491 endif
492 $(V0) dfu-util -a 0 -D $(TARGET_BIN) -s 0x08000000:leave
494 st-flash_$(TARGET): $(TARGET_BIN)
495 $(V0) st-flash --reset write $< 0x08000000
497 ## st-flash : flash firmware (.bin) onto flight controller
498 st-flash: st-flash_$(TARGET)
500 ifneq ($(OPENOCD_COMMAND),)
501 openocd-gdb: $(TARGET_ELF)
502 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
503 endif
505 binary:
506 $(V0) $(MAKE) -j $(TARGET_BIN)
508 srec:
509 $(V0) $(MAKE) -j $(TARGET_S19)
511 hex:
512 $(V0) $(MAKE) -j $(TARGET_HEX)
514 unbrick_$(TARGET): $(TARGET_HEX)
515 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
516 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
518 ## unbrick : unbrick flight controller
519 unbrick: unbrick_$(TARGET)
521 ## cppcheck : run static analysis on C source code
522 cppcheck: $(CSOURCES)
523 $(V0) $(CPPCHECK)
525 cppcheck-result.xml: $(CSOURCES)
526 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
528 # mkdirs
529 $(DL_DIR):
530 mkdir -p $@
532 $(TOOLS_DIR):
533 mkdir -p $@
535 $(BUILD_DIR):
536 mkdir -p $@
538 ## version : print firmware version
539 version:
540 @echo $(FC_VER)
542 ## help : print this help message and exit
543 help: Makefile make/tools.mk
544 @echo ""
545 @echo "Makefile for the $(FORKNAME) firmware"
546 @echo ""
547 @echo "Usage:"
548 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
549 @echo "Or:"
550 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
551 @echo ""
552 @echo "Valid TARGET values are: $(VALID_TARGETS)"
553 @echo ""
554 @sed -n 's/^## //p' $?
556 ## targets : print a list of all valid target platforms (for consumption by scripts)
557 targets:
558 @echo "Valid targets: $(VALID_TARGETS)"
559 @echo "Supported targets: $(SUPPORTED_TARGETS)"
560 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
561 @echo "Target: $(TARGET)"
562 @echo "Base target: $(BASE_TARGET)"
563 @echo "targets-group-1: $(GROUP_1_TARGETS)"
564 @echo "targets-group-2: $(GROUP_2_TARGETS)"
565 @echo "targets-group-3: $(GROUP_3_TARGETS)"
566 @echo "targets-group-4: $(GROUP_4_TARGETS)"
567 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
569 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
570 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
571 @echo "targets-group-3: $(words $(GROUP_3_TARGETS)) targets"
572 @echo "targets-group-4: $(words $(GROUP_4_TARGETS)) targets"
573 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
574 @echo "total in all groups $(words $(SUPPORTED_TARGETS)) targets"
576 ## target-mcu : print the MCU type of the target
577 target-mcu:
578 @echo $(TARGET_MCU)
580 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
581 targets-by-mcu:
582 $(V1) for target in $(VALID_TARGETS); do \
583 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
584 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
585 if [ "$${DO_BUILD}" = 1 ]; then \
586 echo "Building target $${target}..."; \
587 $(MAKE) TARGET=$${target}; \
588 if [ $$? -ne 0 ]; then \
589 echo "Building target $${target} failed, aborting."; \
590 exit 1; \
591 fi; \
592 else \
593 echo -n "$${target} "; \
594 fi; \
595 fi; \
596 done
597 @echo
599 ## targets-f3 : make all F3 targets
600 targets-f3:
601 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 DO_BUILD=1
603 targets-f3-print:
604 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3
606 ## targets-f4 : make all F4 targets
607 targets-f4:
608 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 DO_BUILD=1
610 targets-f4-print:
611 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4
613 ## targets-f7 : make all F7 targets
614 targets-f7:
615 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 DO_BUILD=1
617 targets-f7-print:
618 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7
620 ## test : run the Betaflight test suite
621 ## junittest : run the Betaflight test suite, producing Junit XML result files.
622 ## 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)
623 ## test-all: run the Betaflight test suite including all per-target expanded tests
624 test junittest test-all test-representative:
625 $(V0) cd src/test && $(MAKE) $@
627 ## test_help : print the help message for the test suite (including a list of the available tests)
628 test_help:
629 $(V0) cd src/test && $(MAKE) help
631 ## test_% : run test 'test_%' from the test suite
632 test_%:
633 $(V0) cd src/test && $(MAKE) $@
636 check-target-independence:
637 $(V1) for test_target in $(VALID_TARGETS); do \
638 FOUND=$$(grep -rE "\W$${test_target}(\W.*)?$$" src/main | grep -vE "(//)|(/\*).*\W$${test_target}(\W.*)?$$" | grep -vE "^src/main/target"); \
639 if [ "$${FOUND}" != "" ]; then \
640 echo "Target dependencies for target '$${test_target}' found:"; \
641 echo "$${FOUND}"; \
642 exit 1; \
643 fi; \
644 done
646 check-fastram-usage-correctness:
647 $(V1) NON_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM_ZERO_INIT\W.*=.*" src/main/ | grep -Ev "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
648 if [ "$${NON_TRIVIALLY_INITIALIZED}" != "" ]; then \
649 echo "Non-trivially initialized FAST_RAM_ZERO_INIT variables found, use FAST_RAM instead:"; \
650 echo "$${NON_TRIVIALLY_INITIALIZED}"; \
651 exit 1; \
652 fi; \
653 TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -v "="); \
654 EXPLICITLY_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -E "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
655 if [ "$${TRIVIALLY_INITIALIZED}$${EXPLICITLY_TRIVIALLY_INITIALIZED}" != "" ]; then \
656 echo "Trivially initialized FAST_RAM variables found, use FAST_RAM_ZERO_INIT instead to save FLASH:"; \
657 echo "$${TRIVIALLY_INITIALIZED}\n$${EXPLICITLY_TRIVIALLY_INITIALIZED}"; \
658 exit 1; \
661 check-platform-included:
662 $(V1) PLATFORM_NOT_INCLUDED=$$(find src/main -type d -name target -prune -o -type f -name \*.c -exec grep -L "^#include \"platform.h\"" {} \;); \
663 if [ "$$(echo $${PLATFORM_NOT_INCLUDED} | grep -v -e '^$$' | wc -l)" -ne 0 ]; then \
664 echo "The following compilation units do not include the required target specific configuration provided by 'platform.h':"; \
665 echo "$${PLATFORM_NOT_INCLUDED}"; \
666 exit 1; \
669 # rebuild everything when makefile changes
670 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
672 # include auto-generated dependencies
673 -include $(TARGET_DEPS)