Re: [PATCH v3 03/30] tools: lib: thermal: Initialize CFLAGS before including Makefile.include

From: Ian Rogers

Date: Mon Mar 09 2026 - 11:16:30 EST


On Sun, Mar 8, 2026 at 9:46 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> Initialize CFLAGS to the default value before including
> tools/scripts/Makefile.include.
>
> Defer appending EXTRA_CFLAGS to CFLAGS until after including
> Makefile.include, as it may extend EXTRA_CFLAGS in the future.
>
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> tools/lib/thermal/Makefile | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/tools/lib/thermal/Makefile b/tools/lib/thermal/Makefile
> index 41aa7a324ff4d76351b89d7d7cf382df3fc14052..50efa97163fc089455161d6b81db13aa0ae41af6 100644
> --- a/tools/lib/thermal/Makefile
> +++ b/tools/lib/thermal/Makefile
> @@ -23,6 +23,14 @@ INSTALL = install
> DESTDIR ?=
> DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
>
> +# Defer assigning EXTRA_CFLAGS to CFLAGS until after including
> +# tools/scripts/Makefile.include, as it may add flags to EXTRA_CFLAGS.
> +ifdef EXTRA_CFLAGS
> + CFLAGS :=
> +else
> + CFLAGS := -g -Wall
> +endif
> +
> include $(srctree)/tools/scripts/Makefile.include
> include $(srctree)/tools/scripts/Makefile.arch
>
> @@ -39,13 +47,6 @@ libdir = $(prefix)/$(libdir_relative)
> libdir_SQ = $(subst ','\'',$(libdir))
> libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
>
> -# Set compile option CFLAGS
> -ifdef EXTRA_CFLAGS
> - CFLAGS := $(EXTRA_CFLAGS)
> -else
> - CFLAGS := -g -Wall
> -endif
> -
> NL3_CFLAGS = $(shell pkg-config --cflags libnl-3.0 2>/dev/null)
> ifeq ($(NL3_CFLAGS),)
> NL3_CFLAGS = -I/usr/include/libnl3
> @@ -60,6 +61,7 @@ INCLUDES = \
> -I$(srctree)/tools/include/uapi
>
> # Append required CFLAGS
> +override CFLAGS += $(EXTRA_CFLAGS)
> override CFLAGS += $(EXTRA_WARNINGS)
> override CFLAGS += -Werror -Wall
> override CFLAGS += -fPIC

The change lgtm. Running this patch through an AI review showed that
what looks like a typo, CFLAGS becoming CFGLAS, is located below:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/thermal/Makefile#n62
```
# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS)
override CFLAGS += -Werror -Wall
override CFLAGS += -fPIC
override CFLAGS += $(NL3_CFLAGS)
override CFLAGS += $(INCLUDES)
override CFLAGS += -fvisibility=hidden
override CFGLAS += -Wl,-L.
override CFGLAS += -Wl,-lthermal
```

Thanks,
Ian

> --
> 2.34.1
>