From b8e386a6bce7abc00c392934ce610cfc18e202f7 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Mon, 24 Aug 2026 21:05:55 +0300 Subject: [PATCH] build: Add warnings-as-errors mode Add a WERROR=y|n build setting that keeps the local default unchanged and exports -Werror for user-space and kernel compilation. Honor the same setting in direct regression kernel builds. --- Makefile | 29 +++++++++++++++++++++++++++-- debian/rules | 11 +++++++++++ scripts/run-regression-tests | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 08bcfc688..d81740cbd 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,26 @@ endif PKG_BUILD_MODE ?= 2release +WERROR ?= n +ifneq ($(words $(strip $(WERROR))),1) +$(error WERROR must be one of: y n (got '$(WERROR)')) +endif +ifneq ($(filter y n,$(strip $(WERROR))),$(strip $(WERROR))) +$(error WERROR must be one of: y n (got '$(WERROR)')) +endif +override WERROR := $(strip $(WERROR)) +export WERROR + +ifeq ($(WERROR),y) +ifeq ($(filter -Werror,$(CFLAGS)),) +override CFLAGS += -Werror +endif +ifeq ($(filter -Werror,$(KCFLAGS)),) +override KCFLAGS += -Werror +endif +export CFLAGS KCFLAGS +endif + OLD_QLA_INI_DIR = qla2x00t OLD_QLA_DIR = $(OLD_QLA_INI_DIR)/qla2x00-target @@ -117,6 +137,9 @@ SCST_SOURCE_FILES = $(shell if [ -e scripts/list-source-files ]; then \ fi) help: + @echo "Build variables:" + @echo " WERROR=y|n : treat warnings as errors (default: n)" + @echo "" @echo " tags : make tags" @echo " cov-build : make coverity build" @echo " shellcheck : check Bash scripts" @@ -478,6 +501,7 @@ docker-rpm: docker-rpm-image $(DOCKER) run --rm \ --user "$$(id -u):$$(id -g)" \ --env HOME=/tmp \ + --env WERROR="$(WERROR)" \ --mount "type=bind,source=$(CURDIR),target=/source,readonly" \ --mount "type=bind,source=$${git_common_dir},target=$${git_common_dir},readonly" \ --mount "type=bind,source=$(DOCKER_RPM_OUTPUT),target=/output" \ @@ -536,8 +560,9 @@ dpkg: ../scst_$(VERSION).orig.tar.gz else \ buildopts+=(-j4); \ fi && \ - DEB_CC_SET="$(CC)" DEB_KVER_SET=$(KVER) DEB_KDIR_SET=$(KDIR) DEB_QLA_DIR_SET=$(QLA_DIR) \ - DEB_QLA_INI_DIR_SET=$(QLA_INI_DIR) DEB_PKG_BUILD_MODE=$(PKG_BUILD_MODE) \ + DEB_CC_SET="$(CC)" DEB_KVER_SET=$(KVER) DEB_KDIR_SET=$(KDIR) \ + DEB_QLA_DIR_SET=$(QLA_DIR) DEB_QLA_INI_DIR_SET=$(QLA_INI_DIR) \ + DEB_PKG_BUILD_MODE=$(PKG_BUILD_MODE) DEB_WERROR_SET="$(WERROR)" \ debuild "$${buildopts[@]}" --lintian-opts --profile debian && \ mkdir -p dpkg && \ for f in "$${output_files[@]}" ../scst_$(VERSION).orig.tar.[gx]z; do\ diff --git a/debian/rules b/debian/rules index 79ab0bdff..41ec4f33e 100755 --- a/debian/rules +++ b/debian/rules @@ -21,6 +21,17 @@ export CC=$(DEB_CC_SET) export QLA_DIR=$(DEB_QLA_DIR_SET) export QLA_INI_DIR=$(DEB_QLA_INI_DIR_SET) export PKG_BUILD_MODE=$(DEB_PKG_BUILD_MODE) +DEB_WERROR_SET?=n +export WERROR=$(DEB_WERROR_SET) +ifeq ($(WERROR),y) +ifeq ($(filter -Werror,$(CFLAGS)),) +override CFLAGS += -Werror +endif +ifeq ($(filter -Werror,$(KCFLAGS)),) +override KCFLAGS += -Werror +endif +export CFLAGS KCFLAGS +endif # Default to building optional modules (override by changing specific ?=m to =n) CONFIG_SCST_LOCAL?=m diff --git a/scripts/run-regression-tests b/scripts/run-regression-tests index 8600cf2a2..e99c6b12f 100755 --- a/scripts/run-regression-tests +++ b/scripts/run-regression-tests @@ -57,6 +57,26 @@ # shellcheck source=./kernel-functions source "$(dirname "$0")/kernel-functions" +readonly WERROR="${WERROR-n}" +case "${WERROR}" in + y|n) ;; + *) + echo "Error: WERROR must be one of: y n (got '${WERROR}')." >&2 + exit 2 + ;; +esac +if [ "${WERROR}" = y ]; then + case " ${CFLAGS:-} " in + *" -Werror "*) ;; + *) CFLAGS="${CFLAGS:+${CFLAGS} }-Werror" ;; + esac + case " ${KCFLAGS:-} " in + *" -Werror "*) ;; + *) KCFLAGS="${KCFLAGS:+${KCFLAGS} }-Werror" ;; + esac + export CFLAGS KCFLAGS +fi + function usage { echo "Usage: $0 [-c ] [-d ] [-h] [-j ] [-k] [-l]" \ "[-p] [-q] ..." @@ -321,6 +341,7 @@ CONFIG_TRACER_MAX_TRACE \ CONFIG_TRACE_BRANCH_PROFILING \ CONFIG_TRACING \ CONFIG_UNWINDER_ORC \ +CONFIG_WERROR \ CONFIG_X86_32 \ CONFIG_X86_X32 \ CONFIG_X86_KERNEL_IBT \