############################################################################ # # Copyright (c) 2015 - 2024 PX4 Development Team. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name PX4 nor the names of its contributors may be # used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ # Enforce the presence of the GIT repository # # We depend on our submodules, so we have to prevent attempts to # compile without it being present. ifeq ($(wildcard .git),) $(error YOU HAVE TO USE GIT TO DOWNLOAD THIS REPOSITORY. ABORTING.) endif # Help # -------------------------------------------------------------------- # Don't be afraid of this makefile, it is just passing # arguments to cmake to allow us to keep the wiki pages etc. # that describe how to build the px4 firmware # the same even when using cmake instead of make. # # Example usage: # # make px4_fmu-v2_default (builds) # make px4_fmu-v2_default upload (builds and uploads) # make px4_fmu-v2_default test (builds and tests) # # This tells cmake to build the nuttx px4_fmu-v2 default config in the # directory build/px4_fmu-v2_default and then call make # in that directory with the target upload. # explicity set default build target all: px4_sitl_default # define a space character to be able to explicitly find it in strings space := $(subst ,, ) define make_list $(shell [ -f .github/workflows/compile_${1}.yml ] && cat .github/workflows/compile_${1}.yml | sed -E 's|[[:space:]]+(.*),|check_\1|g' | grep check_${2}) endef # Parsing # -------------------------------------------------------------------- # assume 1st argument passed is the main target, the # rest are arguments to pass to the makefile generated # by cmake in the subdirectory FIRST_ARG := $(firstword $(MAKECMDGOALS)) ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) # Get -j or --jobs argument as suggested in: # https://stackoverflow.com/a/33616144/8548472 MAKE_PID := $(shell echo $$PPID) j := $(shell ps T | sed -n 's|.*$(MAKE_PID).*$(MAKE).* \(-j\|--jobs\) *\([0-9][0-9]*\).*|\2|p') # Default j for clang-tidy j_clang_tidy := $(or $(j),4) NINJA_BIN := ninja ifndef NO_NINJA_BUILD NINJA_BUILD := $(shell $(NINJA_BIN) --version 2>/dev/null) ifndef NINJA_BUILD NINJA_BIN := ninja-build NINJA_BUILD := $(shell $(NINJA_BIN) --version 2>/dev/null) endif endif ifdef NINJA_BUILD PX4_CMAKE_GENERATOR := Ninja PX4_MAKE := $(NINJA_BIN) ifdef VERBOSE PX4_MAKE_ARGS := -v else PX4_MAKE_ARGS := endif # Only override ninja default if -j is set. ifneq ($(j),) PX4_MAKE_ARGS := $(PX4_MAKE_ARGS) -j$(j) endif else ifdef SYSTEMROOT # Windows PX4_CMAKE_GENERATOR := "MSYS\ Makefiles" else PX4_CMAKE_GENERATOR := "Unix\ Makefiles" endif # For non-ninja builds we default to -j4 j := $(or $(j),4) PX4_MAKE = $(MAKE) PX4_MAKE_ARGS = -j$(j) --no-print-directory endif SRC_DIR := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))") # check if replay env variable is set & set build dir accordingly ifdef replay BUILD_DIR_SUFFIX := _replay else BUILD_DIR_SUFFIX := endif CMAKE_ARGS ?= # additional config parameters passed to cmake ifdef EXTERNAL_MODULES_LOCATION override CMAKE_ARGS += -DEXTERNAL_MODULES_LOCATION:STRING=$(EXTERNAL_MODULES_LOCATION) endif ifdef PX4_CMAKE_BUILD_TYPE override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=${PX4_CMAKE_BUILD_TYPE} else # Address Sanitizer ifdef PX4_ASAN override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=AddressSanitizer endif # Memory Sanitizer ifdef PX4_MSAN override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=MemorySanitizer endif # Thread Sanitizer ifdef PX4_TSAN override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=ThreadSanitizer endif # Undefined Behavior Sanitizer ifdef PX4_UBSAN override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=UndefinedBehaviorSanitizer endif endif # Prefer the interpreter from an active Python virtual environment. # Otherwise leave PYTHON_EXECUTABLE unset and let CMake resolve Python. ifneq ($(strip $(VIRTUAL_ENV)),) PYTHON_EXECUTABLE ?= $(VIRTUAL_ENV)/bin/python endif # Pick up specific Python path if set ifdef PYTHON_EXECUTABLE override CMAKE_ARGS += -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} endif # Functions # -------------------------------------------------------------------- # describe how to build a cmake config define cmake-build # Strip BUILD_DIR_SUFFIX (e.g. _replay, _failsafe_web) from CONFIG so the # board lookup in cmake/px4_config.cmake sees the bare __