source.mk - GaloisInc/betaflight GitHub Wiki

Purpose of this document

This document is meant to describe the purpose of and the content found within source.mk.

source.mk

Source.mk is a makefile fragment found within the top-level make folder. It’s purpose is to collect and organize all the .c source files needed for Betaflight to compile for a given target. The broad strategy of source.mk is to collect large groups of source files into makefile variables. These variables are accessed by the top-level makefile for compilation.

The source files are generally organized into variables by the type of optimization needed. To optimize program execution, Betaflight will optimize certain source files for speed, and other files for size. For example, the variables SPEED_OPTIMISED_SRC and SIZE_OPTIMISED_SRC contain source files that require speed and size optimization, respectively. The COMMON_SRC variable contains all source files that require no optimization. Source files are differentiated by optimization type so that the compiler knows what to do with each file.

It’s important to note too, source.mk receives several source file variables from other locations. For example, the variable MCU_COMMON_SRC gets populated in the MCU.mk file, and TARGET_SRC gets populated in the target-specific .mk file. External source file variables get combined into one greater variable, SRC, towards the bottom of source.mk.