Add iterm relax cutoff to msp (#8678)
[betaflight.git] / Makefile
blobdaf4aaf65e86febe7bd8eb7703b23541f7ab85f0
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 # compile for target loaded into RAM
31 RAM_BASED ?= no
33 # Debugger optons:
34 # empty - ordinary build with all optimizations enabled
35 # RELWITHDEBINFO - ordinary build with debug symbols and all optimizations enabled
36 # GDB - debug build with minimum number of optimizations
37 DEBUG ?=
39 # Insert the debugging hardfault debugger
40 # releases should not be built with this flag as it does not disable pwm output
41 DEBUG_HARDFAULTS ?=
43 # Serial port/Device for flashing
44 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /dev/ttyUSB*) no-port-found))
46 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
47 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 # configure some directories that are relative to wherever ROOT_DIR is located
80 ifndef TOOLS_DIR
81 TOOLS_DIR := $(ROOT)/tools
82 endif
83 BUILD_DIR := $(ROOT)/build
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 # used to disable features based on flash space shortage (larger number => more features disabled)
101 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
102 FEATURE_CUT_LEVEL =
104 # The list of targets to build for 'pre-push'
105 PRE_PUSH_TARGET_LIST ?= OMNIBUSF4 STM32F405 SPRACINGF7DUAL STM32F7X2 SITL test-representative
107 include $(ROOT)/make/targets.mk
109 REVISION := $(shell git log -1 --format="%h")
111 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
112 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
113 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
115 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
117 # Search path for sources
118 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
119 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
120 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
121 FATFS_DIR = $(ROOT)/lib/main/FatFS
122 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
124 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
126 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 -DDEBUG
136 else
137 ifeq ($(DEBUG),INFO)
138 DEBUG_FLAGS = -ggdb3
139 endif
140 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
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 ($(FLASH_SIZE),)
159 ifneq ($(TARGET_FLASH),)
160 FLASH_SIZE := $(TARGET_FLASH)
161 else
162 $(error FLASH_SIZE not configured for target $(TARGET))
163 endif
164 endif
166 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
168 ifneq ($(HSE_VALUE),)
169 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
170 endif
172 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
173 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
174 else ifneq ($(FEATURE_CUT_LEVEL),)
175 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
176 endif
178 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
179 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
181 ifeq ($(OPBL),yes)
182 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
183 .DEFAULT_GOAL := binary
184 else
185 .DEFAULT_GOAL := hex
186 endif
188 INCLUDE_DIRS := $(INCLUDE_DIRS) \
189 $(ROOT)/lib/main/MAVLink
191 INCLUDE_DIRS := $(INCLUDE_DIRS) \
192 $(TARGET_DIR)
194 VPATH := $(VPATH):$(TARGET_DIR)
196 include $(ROOT)/make/source.mk
198 ###############################################################################
199 # Things that might need changing to use different tools
202 # Find out if ccache is installed on the system
203 CCACHE := ccache
204 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
205 ifneq ($(RESULT),0)
206 CCACHE :=
207 endif
209 # Tool names
210 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
211 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
212 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
213 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
214 OBJDUMP := $(ARM_SDK_PREFIX)objdump
215 SIZE := $(ARM_SDK_PREFIX)size
218 # Tool options.
220 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
221 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
222 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
223 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
224 CC_NO_OPTIMISATION :=
226 CFLAGS += $(ARCH_FLAGS) \
227 $(addprefix -D,$(OPTIONS)) \
228 $(addprefix -I,$(INCLUDE_DIRS)) \
229 $(DEBUG_FLAGS) \
230 -std=gnu11 \
231 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
232 -ffunction-sections \
233 -fdata-sections \
234 -fno-common \
235 -pedantic \
236 $(DEVICE_FLAGS) \
237 -D_GNU_SOURCE \
238 -DUSE_STDPERIPH_DRIVER \
239 -D$(TARGET) \
240 $(TARGET_FLAGS) \
241 -D'__FORKNAME__="$(FORKNAME)"' \
242 -D'__TARGET__="$(TARGET)"' \
243 -D'__REVISION__="$(REVISION)"' \
244 -save-temps=obj \
245 -MMD -MP \
246 $(EXTRA_FLAGS)
248 ASFLAGS = $(ARCH_FLAGS) \
249 $(DEBUG_FLAGS) \
250 -x assembler-with-cpp \
251 $(addprefix -I,$(INCLUDE_DIRS)) \
252 -MMD -MP
254 ifeq ($(LD_FLAGS),)
255 LD_FLAGS = -lm \
256 -nostartfiles \
257 --specs=nano.specs \
258 -lc \
259 -lnosys \
260 $(ARCH_FLAGS) \
261 $(LTO_FLAGS) \
262 $(DEBUG_FLAGS) \
263 -static \
264 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
265 -Wl,-L$(LINKER_DIR) \
266 -Wl,--cref \
267 -Wl,--no-wchar-size-warning \
268 -Wl,--print-memory-usage \
269 -T$(LD_SCRIPT)
270 endif
272 ###############################################################################
273 # No user-serviceable parts below
274 ###############################################################################
276 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
277 --std=c99 --inline-suppr --quiet --force \
278 $(addprefix -I,$(INCLUDE_DIRS)) \
279 -I/usr/include -I/usr/include/linux
282 # Things we will build
284 TARGET_S19 = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).s19
285 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
286 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
287 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
288 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
289 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
290 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
291 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
292 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
293 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
295 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
297 CLEAN_ARTIFACTS := $(TARGET_BIN)
298 CLEAN_ARTIFACTS += $(TARGET_HEX)
299 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
300 CLEAN_ARTIFACTS += $(TARGET_LST)
302 # Make sure build date and revision is updated on every incremental build
303 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
305 # List of buildable ELF files and their object dependencies.
306 # It would be nice to compute these lists, but that seems to be just beyond make.
308 $(TARGET_LST): $(TARGET_ELF)
309 $(V0) $(OBJDUMP) -S --disassemble $< > $@
312 $(TARGET_S19): $(TARGET_ELF)
313 @echo "Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
314 $(V1) $(OBJCOPY) --output-target=srec $(TARGET_S19)
316 ifeq ($(EXST),no)
317 $(TARGET_BIN): $(TARGET_ELF)
318 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
319 $(V1) $(OBJCOPY) -O binary $< $@
321 $(TARGET_HEX): $(TARGET_ELF)
322 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
323 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
325 else
326 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
328 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
329 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
330 $(V1) $(OBJCOPY) -O binary $< $@
332 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
333 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
334 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
335 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
336 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
337 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
339 @echo "Generating MD5 hash of binary" "$(STDOUT)"
340 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
342 @echo "Patching MD5 hash into binary" "$(STDOUT)"
343 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
344 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
346 @echo "Patching MD5 hash into exst elf" "$(STDOUT)"
347 $(OBJCOPY) $(TARGET_ELF) --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
348 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
349 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
351 $(TARGET_HEX): $(TARGET_BIN)
352 @echo "Creating EXST HEX from patched EXST ELF $(TARGET_HEX)" "$(STDOUT)"
353 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $(TARGET_EXST_ELF) $@
355 endif
357 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
358 @echo "Linking $(TARGET)" "$(STDOUT)"
359 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
360 $(V1) $(SIZE) $(TARGET_ELF)
362 # Compile
364 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
365 define compile_file
366 echo "%% ($(1)) $<" "$(STDOUT)" && \
367 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
368 endef
370 ifeq ($(DEBUG),GDB)
371 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
372 $(V1) mkdir -p $(dir $@)
373 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
374 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
376 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
378 else
379 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
380 $(V1) mkdir -p $(dir $@)
381 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
382 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
384 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
385 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
387 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
388 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
390 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
394 endif
396 # Assemble
397 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
398 $(V1) mkdir -p $(dir $@)
399 @echo "%% $(notdir $<)" "$(STDOUT)"
400 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
402 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
403 $(V1) mkdir -p $(dir $@)
404 @echo "%% $(notdir $<)" "$(STDOUT)"
405 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
408 ## all : Build all targets (excluding unsupported)
409 all: $(SUPPORTED_TARGETS)
411 ## all_with_unsupported : Build all targets (including unsupported)
412 all_with_unsupported: $(VALID_TARGETS)
414 ## unsupported : Build unsupported targets
415 unsupported: $(UNSUPPORTED_TARGETS)
417 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
418 pre-push:
419 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
421 ## official : Build all official (travis) targets
422 official: $(OFFICIAL_TARGETS)
424 ## targets-group-1 : build some targets
425 targets-group-1: $(GROUP_1_TARGETS)
427 ## targets-group-2 : build some targets
428 targets-group-2: $(GROUP_2_TARGETS)
430 ## targets-group-3 : build some targets
431 targets-group-3: $(GROUP_3_TARGETS)
433 ## targets-group-3 : build some targets
434 targets-group-4: $(GROUP_4_TARGETS)
436 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
437 targets-group-rest: $(GROUP_OTHER_TARGETS)
439 $(VALID_TARGETS):
440 $(V0) @echo "Building $@" && \
441 $(MAKE) binary hex TARGET=$@ && \
442 echo "Building $@ succeeded."
444 $(NOBUILD_TARGETS):
445 $(MAKE) TARGET=$@
447 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
449 ## clean : clean up temporary / machine-generated files
450 clean:
451 @echo "Cleaning $(TARGET)"
452 $(V0) rm -f $(CLEAN_ARTIFACTS)
453 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
454 @echo "Cleaning $(TARGET) succeeded."
456 ## test_clean : clean up temporary / machine-generated files (tests)
457 test-%_clean:
458 $(MAKE) test_clean
460 test_clean:
461 $(V0) cd src/test && $(MAKE) clean || true
463 ## <TARGET>_clean : clean up one specific target (alias for above)
464 $(TARGETS_CLEAN):
465 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
467 ## clean_all : clean all valid targets
468 clean_all: $(TARGETS_CLEAN) test_clean
470 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS) )
472 ## <TARGET>_flash : build and flash a target
473 $(TARGETS_FLASH):
474 $(V0) $(MAKE) binary hex TARGET=$(subst _flash,,$@)
475 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
476 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
477 else
478 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
479 endif
481 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
482 tty_flash:
483 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
484 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
485 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
487 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
488 dfu_flash:
489 ifneq (no-port-found,$(SERIAL_DEVICE))
490 # potentially this is because the MCU already is in DFU mode, try anyway
491 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
492 $(V0) sleep 1
493 endif
494 $(V0) dfu-util -a 0 -D $(TARGET_BIN) -s 0x08000000:leave
496 st-flash_$(TARGET): $(TARGET_BIN)
497 $(V0) st-flash --reset write $< 0x08000000
499 ## st-flash : flash firmware (.bin) onto flight controller
500 st-flash: st-flash_$(TARGET)
502 ifneq ($(OPENOCD_COMMAND),)
503 openocd-gdb: $(TARGET_ELF)
504 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
505 endif
507 binary:
508 $(V0) $(MAKE) -j $(TARGET_BIN)
510 srec:
511 $(V0) $(MAKE) -j $(TARGET_S19)
513 hex:
514 $(V0) $(MAKE) -j $(TARGET_HEX)
516 unbrick_$(TARGET): $(TARGET_HEX)
517 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
518 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
520 ## unbrick : unbrick flight controller
521 unbrick: unbrick_$(TARGET)
523 ## cppcheck : run static analysis on C source code
524 cppcheck: $(CSOURCES)
525 $(V0) $(CPPCHECK)
527 cppcheck-result.xml: $(CSOURCES)
528 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
530 # mkdirs
531 $(DL_DIR):
532 mkdir -p $@
534 $(TOOLS_DIR):
535 mkdir -p $@
537 $(BUILD_DIR):
538 mkdir -p $@
540 ## version : print firmware version
541 version:
542 @echo $(FC_VER)
544 ## help : print this help message and exit
545 help: Makefile make/tools.mk
546 @echo ""
547 @echo "Makefile for the $(FORKNAME) firmware"
548 @echo ""
549 @echo "Usage:"
550 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
551 @echo "Or:"
552 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
553 @echo ""
554 @echo "Valid TARGET values are: $(VALID_TARGETS)"
555 @echo ""
556 @sed -n 's/^## //p' $?
558 ## targets : print a list of all valid target platforms (for consumption by scripts)
559 targets:
560 @echo "Valid targets: $(VALID_TARGETS)"
561 @echo "Supported targets: $(SUPPORTED_TARGETS)"
562 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
563 @echo "Target: $(TARGET)"
564 @echo "Base target: $(BASE_TARGET)"
565 @echo "targets-group-1: $(GROUP_1_TARGETS)"
566 @echo "targets-group-2: $(GROUP_2_TARGETS)"
567 @echo "targets-group-3: $(GROUP_3_TARGETS)"
568 @echo "targets-group-4: $(GROUP_4_TARGETS)"
569 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
571 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
572 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
573 @echo "targets-group-3: $(words $(GROUP_3_TARGETS)) targets"
574 @echo "targets-group-4: $(words $(GROUP_4_TARGETS)) targets"
575 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
576 @echo "total in all groups $(words $(SUPPORTED_TARGETS)) targets"
578 ## target-mcu : print the MCU type of the target
579 target-mcu:
580 @echo $(TARGET_MCU)
582 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
583 targets-by-mcu:
584 $(V1) for target in $(VALID_TARGETS); do \
585 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
586 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
587 if [ "$${DO_BUILD}" = 1 ]; then \
588 echo "Building target $${target}..."; \
589 $(MAKE) TARGET=$${target}; \
590 if [ $$? -ne 0 ]; then \
591 echo "Building target $${target} failed, aborting."; \
592 exit 1; \
593 fi; \
594 else \
595 echo -n "$${target} "; \
596 fi; \
597 fi; \
598 done
599 @echo
601 ## targets-f3 : make all F3 targets
602 targets-f3:
603 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 DO_BUILD=1
605 targets-f3-print:
606 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3
608 ## targets-f4 : make all F4 targets
609 targets-f4:
610 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 DO_BUILD=1
612 targets-f4-print:
613 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4
615 ## targets-f7 : make all F7 targets
616 targets-f7:
617 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 DO_BUILD=1
619 targets-f7-print:
620 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7
622 ## test : run the Betaflight test suite
623 ## junittest : run the Betaflight test suite, producing Junit XML result files.
624 ## 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)
625 ## test-all: run the Betaflight test suite including all per-target expanded tests
626 test junittest test-all test-representative:
627 $(V0) cd src/test && $(MAKE) $@
629 ## test_help : print the help message for the test suite (including a list of the available tests)
630 test_help:
631 $(V0) cd src/test && $(MAKE) help
633 ## test_% : run test 'test_%' from the test suite
634 test_%:
635 $(V0) cd src/test && $(MAKE) $@
638 check-target-independence:
639 $(V1) for test_target in $(VALID_TARGETS); do \
640 FOUND=$$(grep -rE "\W$${test_target}(\W.*)?$$" src/main | grep -vE "(//)|(/\*).*\W$${test_target}(\W.*)?$$" | grep -vE "^src/main/target"); \
641 if [ "$${FOUND}" != "" ]; then \
642 echo "Target dependencies for target '$${test_target}' found:"; \
643 echo "$${FOUND}"; \
644 exit 1; \
645 fi; \
646 done
648 check-fastram-usage-correctness:
649 $(V1) NON_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM_ZERO_INIT\W.*=.*" src/main/ | grep -Ev "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
650 if [ "$${NON_TRIVIALLY_INITIALIZED}" != "" ]; then \
651 echo "Non-trivially initialized FAST_RAM_ZERO_INIT variables found, use FAST_RAM instead:"; \
652 echo "$${NON_TRIVIALLY_INITIALIZED}"; \
653 exit 1; \
654 fi; \
655 TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -v "="); \
656 EXPLICITLY_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -E "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
657 if [ "$${TRIVIALLY_INITIALIZED}$${EXPLICITLY_TRIVIALLY_INITIALIZED}" != "" ]; then \
658 echo "Trivially initialized FAST_RAM variables found, use FAST_RAM_ZERO_INIT instead to save FLASH:"; \
659 echo "$${TRIVIALLY_INITIALIZED}\n$${EXPLICITLY_TRIVIALLY_INITIALIZED}"; \
660 exit 1; \
663 check-platform-included:
664 $(V1) PLATFORM_NOT_INCLUDED=$$(find src/main -type d -name target -prune -o -type f -name \*.c -exec grep -L "^#include \"platform.h\"" {} \;); \
665 if [ "$$(echo $${PLATFORM_NOT_INCLUDED} | grep -v -e '^$$' | wc -l)" -ne 0 ]; then \
666 echo "The following compilation units do not include the required target specific configuration provided by 'platform.h':"; \
667 echo "$${PLATFORM_NOT_INCLUDED}"; \
668 exit 1; \
671 # rebuild everything when makefile changes
672 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
674 # include auto-generated dependencies
675 -include $(TARGET_DEPS)