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
21 # Compile-time options
24 # compile for OpenPilot BootLoader support
27 # compile for External Storage Bootloader support
30 # compile for target loaded into RAM
33 # reserve space for custom defaults
34 CUSTOM_DEFAULTS_EXTENDED ?
= no
37 # empty - ordinary build with all optimizations enabled
38 # INFO - ordinary build with debug symbols and all optimizations enabled
39 # GDB - debug build with minimum number of optimizations
42 # Insert the debugging hardfault debugger
43 # releases should not be built with this flag as it does not disable pwm output
46 # Serial port/Device for flashing
47 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyACM
*) $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
))
49 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
52 # Release file naming (no revision to be present if this is 'yes')
55 ###############################################################################
56 # Things that need to be maintained as the source changes
62 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
63 SRC_DIR
:= $(ROOT
)/src
/main
64 OBJECT_DIR
:= $(ROOT
)/obj
/main
65 BIN_DIR
:= $(ROOT
)/obj
66 CMSIS_DIR
:= $(ROOT
)/lib
/main
/CMSIS
67 INCLUDE_DIRS
:= $(SRC_DIR
) \
68 $(ROOT
)/src
/main
/target \
69 $(ROOT
)/src
/main
/startup
70 LINKER_DIR
:= $(ROOT
)/src
/link
72 ## V : Set verbosity level based on the V= parameter
75 include $(ROOT
)/make
/build_verbosity.mk
77 # Build tools, so we all share the same versions
78 # import macros common to all supported build systems
79 include $(ROOT
)/make
/system-id.mk
81 # developer preferences, edit these at will, they'll be gitignored
82 -include $(ROOT
)/make
/local.mk
84 # pre-build sanity checks
85 include $(ROOT
)/make
/checks.mk
87 # configure some directories that are relative to wherever ROOT_DIR is located
88 TOOLS_DIR ?
= $(ROOT
)/tools
89 DL_DIR
:= $(ROOT
)/downloads
93 # import macros that are OS specific
94 include $(ROOT
)/make
/$(OSFAMILY
).mk
96 # include the tools makefile
97 include $(ROOT
)/make
/tools.mk
99 # default xtal value for F4 targets
102 # used for turning on features like VCP and SDCARD
105 # used to disable features based on flash space shortage (larger number => more features disabled)
106 FEATURE_CUT_LEVEL_SUPPLIED
:= $(FEATURE_CUT_LEVEL
)
109 # The list of targets to build for 'pre-push'
110 ifeq ($(OSFAMILY
), macosx
)
111 # SITL is not buildable on MacOS
112 PRE_PUSH_TARGET_LIST ?
= $(UNIFIED_TARGETS
) STM32F4DISCOVERY_DEBUG test-representative
114 PRE_PUSH_TARGET_LIST ?
= $(UNIFIED_TARGETS
) SITL STM32F4DISCOVERY_DEBUG test-representative
117 include $(ROOT
)/make
/targets.mk
119 REVISION
:= norevision
120 ifeq ($(shell git diff
--shortstat
),)
121 REVISION
:= $(shell git log
-1 --format
="%h")
124 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
125 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
126 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
128 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
130 # Search path for sources
131 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
132 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
133 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
134 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
135 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
137 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
143 # Default Tool options - can be overridden in {mcu}.mk files.
146 OPTIMISE_DEFAULT
:= -Og
148 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
149 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
154 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
155 OPTIMISE_DEFAULT
:= -O2
156 OPTIMISE_SPEED
:= -Ofast
159 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
162 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
163 VPATH
:= $(VPATH
):$(ROOT
)/make
165 # start specific includes
166 include $(ROOT
)/make
/mcu
/$(TARGET_MCU
).mk
168 # openocd specific includes
169 include $(ROOT
)/make
/openocd.mk
171 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
172 ifeq ($(TARGET_FLASH_SIZE
),)
173 ifneq ($(MCU_FLASH_SIZE
),)
174 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
176 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
180 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
182 ifneq ($(HSE_VALUE
),)
183 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
186 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED
),)
187 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL_SUPPLIED
)
188 else ifneq ($(FEATURE_CUT_LEVEL
),)
189 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL
)
192 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
193 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
196 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
197 .DEFAULT_GOAL
:= binary
202 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
203 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
204 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
207 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
208 $(ROOT
)/lib
/main
/MAVLink
210 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
213 VPATH
:= $(VPATH
):$(TARGET_DIR
)
215 include $(ROOT
)/make
/source.mk
217 ###############################################################################
218 # Things that might need changing to use different tools
221 # Find out if ccache is installed on the system
223 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
229 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
230 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
231 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
232 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
233 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
234 READELF
:= $(ARM_SDK_PREFIX
)readelf
235 SIZE
:= $(ARM_SDK_PREFIX
)size
236 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
241 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
242 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
243 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
244 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
245 CC_NO_OPTIMISATION
:=
248 # Added after GCC version update, remove once the warnings have been fixed
252 CFLAGS
+= $(ARCH_FLAGS
) \
253 $(addprefix -D
,$(OPTIONS
)) \
254 $(addprefix -I
,$(INCLUDE_DIRS
)) \
257 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
258 -ffunction-sections \
265 -DUSE_STDPERIPH_DRIVER \
268 -D
'__FORKNAME__="$(FORKNAME)"' \
269 -D
'__TARGET__="$(TARGET)"' \
270 -D
'__REVISION__="$(REVISION)"' \
275 ASFLAGS
= $(ARCH_FLAGS
) \
277 -x assembler-with-cpp \
278 $(addprefix -I
,$(INCLUDE_DIRS
)) \
291 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
292 -Wl
,-L
$(LINKER_DIR
) \
294 -Wl
,--no-wchar-size-warning \
295 -Wl
,--print-memory-usage \
300 ###############################################################################
301 # No user-serviceable parts below
302 ###############################################################################
304 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
305 --std
=c99
--inline-suppr
--quiet
--force \
306 $(addprefix -I
,$(INCLUDE_DIRS
)) \
307 -I
/usr
/include -I
/usr
/include/linux
309 TARGET_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)
311 # Things we will distribute (variable name, includes revision by default)
313 ifeq ($(RELEASE
),yes
)
314 TARGET_DISTRIBUTION_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)
316 TARGET_DISTRIBUTION_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)_
$(REVISION
)
319 TARGET_DIST_S19
= $(TARGET_DISTRIBUTION_BASENAME
).s19
320 TARGET_DIST_BIN
= $(TARGET_DISTRIBUTION_BASENAME
).bin
321 TARGET_DIST_HEX
= $(TARGET_DISTRIBUTION_BASENAME
).hex
322 TARGET_DIST_DFU
= $(TARGET_DISTRIBUTION_BASENAME
).dfu
323 TARGET_DIST_ZIP
= $(TARGET_DISTRIBUTION_BASENAME
).zip
326 # Things we will build (consistent name, regardless of revision)
328 TARGET_BIN
= $(TARGET_BASENAME
).bin
329 TARGET_HEX
= $(TARGET_BASENAME
).hex
330 TARGET_DFU
= $(TARGET_BASENAME
).dfu
331 TARGET_ZIP
= $(TARGET_BASENAME
).zip
332 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
333 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_EXST.elf
334 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_UNPATCHED.bin
335 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).lst
336 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
337 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
338 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
340 TARGET_EXST_HASH_SECTION_FILE
= $(OBJECT_DIR
)/$(TARGET
)/exst_hash_section.bin
342 CLEAN_ARTIFACTS
:= $(TARGET_S19
) $(TARGET_DIST_S19
)
343 CLEAN_ARTIFACTS
:= $(TARGET_BIN
) $(TARGET_DIST_BIN
)
344 CLEAN_ARTIFACTS
+= $(TARGET_HEX
) $(TARGET_DIST_HEX
)
345 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
346 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
347 CLEAN_ARTIFACTS
+= $(TARGET_DFU
) $(TARGET_DIST_DFU
)
348 CLEAN_ARTIFACTS
+= $(TARGET_ZIP
) $(TARGET_DIST_ZIP
)
350 # Make sure build date and revision is updated on every incremental build
351 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(SRC
)
353 # List of buildable ELF files and their object dependencies.
354 # It would be nice to compute these lists, but that seems to be just beyond make.
356 $(TARGET_LST
): $(TARGET_ELF
)
357 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
360 $(TARGET_BIN
): $(TARGET_ELF
)
361 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
362 $(V1
) $(OBJCOPY
) -O binary
$< $@
364 $(TARGET_HEX
): $(TARGET_ELF
)
365 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
366 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
368 $(TARGET_DFU
): $(TARGET_HEX
)
369 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
370 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
373 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
375 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
376 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
377 $(V1
) $(OBJCOPY
) -O binary
$< $@
379 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
380 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
381 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
382 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
383 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
384 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
386 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
387 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
389 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
390 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
391 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
393 # 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"
394 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
395 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
396 # a) regeneration of $(TARGET_BIN), and
397 # b) the results of $(TARGET_BIN) will not be as expected.
398 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
399 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
400 rm $(TARGET_EXST_ELF
).tmp
402 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
403 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
405 # 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
406 # 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.
407 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
408 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
409 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --remove-section ._user_heap_stack
--update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
411 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
412 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
414 $(TARGET_HEX
): $(TARGET_BIN
)
415 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
417 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
418 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
422 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
423 @echo
"Linking $(TARGET)" "$(STDOUT)"
424 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
425 $(V1
) $(SIZE
) $(TARGET_ELF
)
429 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
431 echo
"%% ($(1)) $<" "$(STDOUT)" && \
432 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
436 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
437 $(V1
) mkdir
-p
$(dir $@
)
438 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
439 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
441 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
444 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
445 $(V1
) mkdir
-p
$(dir $@
)
446 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
447 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
449 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
450 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
452 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
453 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
455 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
462 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
463 $(V1
) mkdir
-p
$(dir $@
)
464 @echo
"%% $(notdir $<)" "$(STDOUT)"
465 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
467 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
468 $(V1
) mkdir
-p
$(dir $@
)
469 @echo
"%% $(notdir $<)" "$(STDOUT)"
470 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
474 $(TARGET_DIST_S19
): $(TARGET_S19
)
475 @echo
"Creating distribution srec/S19 $(TARGET_DIST_S19)" "$(STDOUT)"
476 $(V1
) cp
$(TARGET_S19
) $(TARGET_DIST_S19
)
478 $(TARGET_DIST_BIN
): $(TARGET_BIN
)
479 @echo
"Creating distribution bin $(TARGET_DIST_BIN)" "$(STDOUT)"
480 $(V1
) cp
$(TARGET_BIN
) $(TARGET_DIST_BIN
)
482 $(TARGET_DIST_HEX
): $(TARGET_HEX
)
483 @echo
"Creating distribution hex $(TARGET_DIST_HEX)" "$(STDOUT)"
484 $(V1
) cp
$(TARGET_HEX
) $(TARGET_DIST_HEX
)
486 $(TARGET_DIST_DFU
): $(TARGET_DFU
)
487 @echo
"Creating distribution dfu $(TARGET_DIST_DFU)" "$(STDOUT)"
488 $(V1
) cp
$(TARGET_DFU
) $(TARGET_DIST_DFU
)
490 $(TARGET_DIST_ZIP
): $(TARGET_ZIP
)
491 @echo
"Creating distribution zip $(TARGET_DIST_ZIP)" "$(STDOUT)"
492 $(V1
) cp
$(TARGET_ZIP
) $(TARGET_DIST_ZIP
)
494 ## all : Build all currently built targets
497 ## all_all : Build all targets (including legacy / unsupported)
498 all_all
: $(VALID_TARGETS
)
500 ## unified : build all Unified Targets
501 unified
: $(UNIFIED_TARGETS
)
503 ## unified_zip : build all Unified Targets as zip files (for posting on GitHub)
504 unified_zip
: $(addsuffix _clean
,$(UNIFIED_TARGETS
)) $(addsuffix _zip
,$(UNIFIED_TARGETS
))
506 ## legacy : Build legacy targets
507 legacy
: $(LEGACY_TARGETS
)
509 ## unsupported : Build unsupported targets
510 unsupported
: $(UNSUPPORTED_TARGETS
)
512 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
514 $(MAKE
) $(addsuffix _clean
,$(PRE_PUSH_TARGET_LIST
)) $(PRE_PUSH_TARGET_LIST
) EXTRA_FLAGS
=-Werror
516 ## targets-group-1 : build some targets
517 targets-group-1
: $(GROUP_1_TARGETS
)
519 ## targets-group-2 : build some targets
520 targets-group-2
: $(GROUP_2_TARGETS
)
522 ## targets-group-rest: build the rest of the targets (not listed in the other groups)
523 targets-group-rest
: $(GROUP_OTHER_TARGETS
)
526 $(V0
) @echo
"Building $@" && \
527 $(MAKE
) hex TARGET
=$@
&& \
528 echo
"Building $@ succeeded."
533 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
))
535 ## clean : clean up temporary / machine-generated files
537 @echo
"Cleaning $(TARGET)"
538 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
539 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
540 @echo
"Cleaning $(TARGET) succeeded."
542 ## test_clean : clean up temporary / machine-generated files (tests)
547 $(V0
) cd src
/test && $(MAKE
) clean || true
549 ## <TARGET>_clean : clean up one specific target (alias for above)
551 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
553 ## clean_all : clean all valid targets
554 clean_all
: $(TARGETS_CLEAN
) test_clean
556 TARGETS_FLASH
= $(addsuffix _flash
,$(VALID_TARGETS
))
558 ## <TARGET>_flash : build and flash a target
560 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
561 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
562 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
564 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
567 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
569 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
570 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
571 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
573 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
575 ifneq (no-port-found
,$(SERIAL_DEVICE
))
576 # potentially this is because the MCU already is in DFU mode, try anyway
577 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
580 $(V0
) $(MAKE
) $(TARGET_DFU
)
581 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
583 st-flash_
$(TARGET
): $(TARGET_BIN
)
584 $(V0
) st-flash
--reset write
$< 0x08000000
586 ## st-flash : flash firmware (.bin) onto flight controller
587 st-flash
: st-flash_
$(TARGET
)
589 ifneq ($(OPENOCD_COMMAND
),)
590 openocd-gdb
: $(TARGET_ELF
)
591 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
594 TARGETS_ZIP
= $(addsuffix _zip
,$(VALID_TARGETS
))
596 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
598 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
599 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
602 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_DIST_HEX
)
605 $(V0
) $(MAKE
) -j
$(TARGET_DIST_BIN
)
608 $(V0
) $(MAKE
) -j
$(TARGET_DIST_S19
)
611 $(V0
) $(MAKE
) -j
$(TARGET_DIST_HEX
)
613 unbrick_
$(TARGET
): $(TARGET_HEX
)
614 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
615 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
617 ## unbrick : unbrick flight controller
618 unbrick
: unbrick_
$(TARGET
)
620 ## cppcheck : run static analysis on C source code
621 cppcheck
: $(CSOURCES
)
624 cppcheck-result.xml
: $(CSOURCES
)
625 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
634 ## version : print firmware version
638 ## help : print this help message and exit
639 help
: Makefile make
/tools.mk
641 @echo
"Makefile for the $(FORKNAME) firmware"
644 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
646 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
648 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
650 @sed
-n
's/^## //p' $?
652 ## targets : print a list of all valid target platforms (for consumption by scripts)
654 @echo
"Valid targets: $(VALID_TARGETS)"
655 @echo
"Built targets: $(CI_TARGETS)"
656 @echo
"Unified targets: $(UNIFIED_TARGETS)"
657 @echo
"Legacy targets: $(LEGACY_TARGETS)"
658 @echo
"Unsupported targets: $(UNSUPPORTED_TARGETS)"
659 @echo
"Default target: $(TARGET)"
660 @echo
"targets-group-1: $(GROUP_1_TARGETS)"
661 @echo
"targets-group-2: $(GROUP_2_TARGETS)"
662 @echo
"targets-group-rest: $(GROUP_OTHER_TARGETS)"
664 @echo
"targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
665 @echo
"targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
666 @echo
"targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
667 @echo
"total in all groups $(words $(CI_TARGETS)) targets"
669 ## target-mcu : print the MCU type of the target
673 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
675 $(V1
) for target in
$${TARGETS}; do \
676 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
677 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
678 if
[ "$${DO_BUILD}" = 1 ]; then \
679 echo
"Building target $${target}..."; \
680 $(MAKE
) TARGET
=$${target}; \
681 if
[ $$?
-ne
0 ]; then \
682 echo
"Building target $${target} failed, aborting."; \
686 echo
-n
"$${target} "; \
692 ## targets-f4 : make all F4 targets
694 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
697 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)"
700 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(CI_TARGETS)"
702 ## targets-f7 : make all F7 targets
704 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
707 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)"
710 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(CI_TARGETS)"
712 ## test : run the Betaflight test suite
713 ## junittest : run the Betaflight test suite, producing Junit XML result files.
714 ## 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)
715 ## test-all: run the Betaflight test suite including all per-target expanded tests
716 test junittest test-all test-representative
:
717 $(V0
) cd src
/test && $(MAKE
) $@
719 ## test_help : print the help message for the test suite (including a list of the available tests)
721 $(V0
) cd src
/test && $(MAKE
) help
723 ## test_versions : print the compiler versions used for the test suite
725 $(V0
) cd src
/test && $(MAKE
) versions
727 ## test_% : run test 'test_%' from the test suite
729 $(V0
) cd src
/test && $(MAKE
) $@
732 # rebuild everything when makefile changes
733 $(TARGET_OBJS
): Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*)
735 # include auto-generated dependencies
736 -include $(TARGET_DEPS
)