1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

Fix SITL for MacOS M1 (#14284)

* Fix SITL for MacOS M1

* move macos m1 SITL fix into SITL.mk and extract warnings flags from cflags into WARNING_FLAGS varible

* add back -Werror

* add warning about potencial issues with PG on SITL builds for MacOS apple silicon

* removed override and added CFLAGS_DISABLED and OPTIMISATION_DISABLED

* change OPTIMISATION_DISABLED to OPTIMISATIONS_DISABLED and also use it for CC_DEBUG_OPTIMISATION

* fix building useless hex

* copy instead of move

* clean new artifacts from SITL

* fix clean

* fix issue where in SITL_STATIC will build properly

* building static does not seem to work on macos

* building static does not seem to work on macos

* building static is not possible on macos

* fix issue where make TARGET=SITL still builds hex

* Move everything to CFLAGS_DISABLED and use else if chaning

* add SITL to CI_TARGETS

* add rev to SITL

* add changes suggested by ledvinap

* Update Makefile

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>

* Update src/platform/SIMULATOR/mk/SITL.mk

* Add EXE_TARGET_REVISION

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
This commit is contained in:
Thisas 2025-04-11 22:13:09 +04:00 committed by GitHub
parent 21dec1d764
commit 38007f8b59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 11 deletions

View file

@ -15,7 +15,7 @@
# Things that the user might override on the commandline
#
# The target to build, see BASE_TARGETS below
# The target to build, see BASE_TARGETS/EXE_TARGETS below
TARGET ?=
CONFIG ?=
@ -47,6 +47,9 @@ SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /
# Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
FLASH_SIZE ?=
# Disabled build flags
CFLAGS_DISABLED :=
###############################################################################
# Things that need to be maintained as the source changes
#
@ -87,9 +90,12 @@ MAKE_PARALLEL = $(if $(filter -j%, $(MAKEFLAGS)),$(EMPTY),-j$(DEFAULT_PAR
# pre-build sanity checks
include $(MAKE_SCRIPT_DIR)/checks.mk
# list of targets that are executed on host (using exe as goal)
EXE_TARGETS := SITL
# basic target list
PLATFORMS := $(sort $(notdir $(patsubst /%,%, $(wildcard $(PLATFORM_DIR)/*))))
BASE_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/target.mk)))))
BASE_TARGETS := $(filter-out $(EXE_TARGETS),$(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/target.mk))))))
# configure some directories that are relative to wherever ROOT_DIR is located
TOOLS_DIR ?= $(ROOT)/tools
@ -128,7 +134,7 @@ HSE_VALUE ?= 8000000
CI_EXCLUDED_TARGETS := $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(PLATFORM_DIR)/*/target/*/.exclude)))))
CI_COMMON_TARGETS := STM32F4DISCOVERY CRAZYBEEF4SX1280 CRAZYBEEF4FR MATEKF405TE AIRBOTG4AIO TBS_LUCID_FC IFLIGHT_BLITZ_F722 NUCLEOF446 SPRACINGH7EXTREME SPRACINGH7RF
CI_TARGETS := $(filter-out $(CI_EXCLUDED_TARGETS), $(BASE_TARGETS)) $(filter $(CI_COMMON_TARGETS), $(BASE_CONFIGS))
CI_TARGETS := $(filter-out $(CI_EXCLUDED_TARGETS), $(BASE_TARGETS) $(EXE_TARGETS)) $(filter $(CI_COMMON_TARGETS), $(BASE_CONFIGS))
PREVIEW_TARGETS := MATEKF411 AIKONF4V2 AIRBOTG4AIO ZEEZF7V3 FOXEERF745V4_AIO KAKUTEH7 TBS_LUCID_FC SITL SPRACINGH7EXTREME SPRACINGH7RF
TARGET_PLATFORM := $(notdir $(patsubst %/,%,$(subst target/$(TARGET)/,, $(dir $(wildcard $(PLATFORM_DIR)/*/target/$(TARGET)/target.mk)))))
@ -224,10 +230,12 @@ include $(MAKE_SCRIPT_DIR)/openocd.mk
ifeq ($(CONFIG),)
ifeq ($(TARGET),)
.DEFAULT_GOAL := all
else ifneq ($(filter $(TARGET),$(EXE_TARGETS)),)
.DEFAULT_GOAL := exe
else
.DEFAULT_GOAL := hex
endif
else
else # ifeq ($(CONFIG),)
.DEFAULT_GOAL := hex
endif
@ -281,6 +289,12 @@ CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
CC_NO_OPTIMISATION :=
CC_DEBUG_OPTIMISATION := $(filter-out $(CFLAGS_DISABLED), $(CC_DEBUG_OPTIMISATION))
CC_DEFAULT_OPTIMISATION := $(filter-out $(CFLAGS_DISABLED), $(CC_DEFAULT_OPTIMISATION))
CC_SPEED_OPTIMISATION := $(filter-out $(CFLAGS_DISABLED), $(CC_SPEED_OPTIMISATION))
CC_SIZE_OPTIMISATION := $(filter-out $(CFLAGS_DISABLED), $(CC_SIZE_OPTIMISATION))
CC_NO_OPTIMISATION := $(filter-out $(CFLAGS_DISABLED), $(CC_NO_OPTIMISATION))
#
# Added after GCC version update, remove once the warnings have been fixed
#
@ -311,6 +325,8 @@ CFLAGS += $(ARCH_FLAGS) \
-MMD -MP \
$(EXTRA_FLAGS)
CFLAGS := $(filter-out $(CFLAGS_DISABLED), $(CFLAGS))
ASFLAGS = $(ARCH_FLAGS) \
$(DEBUG_FLAGS) \
-x assembler-with-cpp \
@ -361,6 +377,7 @@ TARGET_FULLNAME = $(FORKNAME)_$(FC_VER)_$(TARGET_NAME)
#
TARGET_BIN = $(BIN_DIR)/$(TARGET_FULLNAME).bin
TARGET_HEX = $(BIN_DIR)/$(TARGET_FULLNAME).hex
TARGET_EXE = $(BIN_DIR)/$(TARGET_FULLNAME)
TARGET_DFU = $(BIN_DIR)/$(TARGET_FULLNAME).dfu
TARGET_ZIP = $(BIN_DIR)/$(TARGET_FULLNAME).zip
TARGET_OBJ_DIR = $(OBJECT_DIR)/$(TARGET_NAME)
@ -462,6 +479,10 @@ $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
$(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
$(V1) $(SIZE) $(TARGET_ELF)
$(TARGET_EXE): $(TARGET_ELF)
@echo Copy $< to $@ "$(STDOUT)"
$(V1) cp $< $@
# Compile
## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
@ -512,7 +533,6 @@ $(TARGET_OBJ_DIR)/%.o: %.S
@echo "%% $(notdir $<)" "$(STDOUT)"
$(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
## all : Build all currently built targets
all: $(CI_TARGETS)
@ -521,7 +541,12 @@ $(BASE_TARGETS):
$(MAKE) hex TARGET=$@ && \
echo "Building $@ succeeded."
TARGETS_CLEAN = $(addsuffix _clean,$(BASE_TARGETS))
$(EXE_TARGETS):
$(V0) @echo "Building executable target $@" && \
$(MAKE) exe TARGET=$@ && \
echo "Building $@ succeeded."
TARGETS_CLEAN = $(addsuffix _clean,$(BASE_TARGETS) $(EXE_TARGETS))
CONFIGS_CLEAN = $(addsuffix _clean,$(BASE_CONFIGS))
@ -610,11 +635,19 @@ binary:
hex:
$(V0) $(MAKE) $(MAKE_PARALLEL) $(TARGET_HEX)
.phony: exe
exe: $(TARGET_EXE)
TARGETS_REVISION = $(addsuffix _rev,$(BASE_TARGETS))
## <TARGET>_rev : build target and add revision to filename
$(TARGETS_REVISION):
$(V0) $(MAKE) hex REV=yes TARGET=$(subst _rev,,$@)
EXE_TARGETS_REVISION = $(addsuffix _rev,$(EXE_TARGETS))
## <EXE_TARGET>_rev : build executable target and add revision to filename
$(EXE_TARGETS_REVISION):
$(V0) $(MAKE) exe REV=yes TARGET=$(subst _rev,,$@)
all_rev: $(addsuffix _rev,$(CI_TARGETS))
unbrick_$(TARGET): $(TARGET_HEX)
@ -654,7 +687,7 @@ help: Makefile mk/tools.mk
@echo "To populate configuration targets:"
@echo " make configs"
@echo ""
@echo "Valid TARGET values are: $(BASE_TARGETS)"
@echo "Valid TARGET values are: $(EXE_TARGETS) $(BASE_TARGETS)"
@echo ""
@sed -n 's/^## //p' $?
@ -662,6 +695,7 @@ help: Makefile mk/tools.mk
targets:
@echo "Platforms: $(PLATFORMS)"
@echo "Valid targets: $(BASE_TARGETS)"
@echo "Executable targets: $(EXE_TARGETS)"
@echo "Built targets: $(CI_TARGETS)"
@echo "Default target: $(TARGET)"
@echo "CI common targets: $(CI_COMMON_TARGETS)"

View file

@ -30,11 +30,11 @@ MCU_EXCLUDES = \
TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
LIBS = -lm -lpthread -lc -lrt
# overriden on Apple silicon macosx
LD_FLAGS := \
-lm \
-lpthread \
-lc \
-lrt \
$(LIBS) \
$(ARCH_FLAGS) \
$(LTO_FLAGS) \
$(DEBUG_FLAGS) \
@ -56,3 +56,20 @@ OPTIMISE_SIZE := -Os
LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
endif
ifneq ($(filter macosx-arm%,$(OSFAMILY)-$(ARCHFAMILY)),)
CFLAGS_DISABLED := -Werror -Wunsafe-loop-optimizations -fuse-linker-plugin
ifneq ($(filter SITL_STATIC,$(OPTIONS)),)
$(error Static builds are not supported on MacOS)
endif
# This removes the linker script for MacOS apple silicon builds and may cause issues with PG.
LD_FLAGS := \
$(filter-out -lrt, $(LIBS)) \
$(ARCH_FLAGS) \
$(LTO_FLAGS) \
$(DEBUG_FLAGS) \
-Wl,-map,$(TARGET_MAP)
endif