Re: [PATCH v2 2/2] pm: cpupower: Makefile: Allow overriding cross-compiling env params

From: Florian Fainelli
Date: Thu Nov 21 2024 - 12:03:07 EST


On 11/21/24 04:40, Peng Fan wrote:
Subject: Re: [PATCH v2 2/2] pm: cpupower: Makefile: Allow overriding
cross-compiling env params

Hi Peng,

On 9/19/2024 5:08 AM, Peng Fan (OSS) wrote:
From: Peng Fan <peng.fan@xxxxxxx>

Allow overriding the cross-comple env parameters to make it easier
for
Yocto users. Then cross-compiler toolchains to build cpupower with
only two steps:
- source (toolchain path)/environment-setup-armv8a-poky-linux
- make

This patch breaks the way that buildroot builds cpupower:

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
git.buildroot.net%2Fbuildroot%2Ftree%2Fpackage%2Flinux-
tools%2Flinux-tool-
cpupower.mk.in&data=05%7C02%7Cpeng.fan%40nxp.com%7C246da9
2d8b6243d138c808dd09e6d644%7C686ea1d3bc2b4c6fa92cd99c5c3
01635%7C0%7C0%7C638677609234547728%7CUnknown%7CTWFpb
GZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJX
aW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdat
a=nL1YUl%2F07Vd8F0GpW7uRqdpZT74avOku1ox9N3%2FFkUg%3D&r
eserved=0

and after enabling verbose it becomes clear as to why, see below:

>>> linux-tools Configuring
>>> linux-tools Building
GIT_DIR=.
PATH="/local/users/fainelli/buildroot-
upstream/output/arm/host/bin:/local/users/fainelli/buildroot-
upstream/output/arm/host/sbin:/projects/firepath/tools/bin:/home/ff
944844/bin:/home/ff944844/.local/bin:/opt/stblinux/bin:/usr/local/sb
in:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ga
mes:/snap/bin:/opt/toolchains/metaware-vctools-0.4.1/bin/"
/usr/bin/make -j97
CROSS=/local/users/fainelli/buildroot-
upstream/output/arm/host/bin/arm-linux-
CPUFREQ_BENCH=false NLS=false LDFLAGS="-L.
-L/local/users/fainelli/buildroot-upstream/output/arm/target/usr/lib"
DEBUG=false V=1 -C
/local/users/fainelli/buildroot-upstream/output/arm/build/linux-
custom/tools
cpupower
mkdir -p power/cpupower && /usr/bin/make subdir=power/cpupower
--no-print-directory -C power/cpupower cc -DVERSION=\"6.12.0\" -
DPACKAGE=\"cpupower\"
-DPACKAGE_BUGREPORT=\"linux-pm@xxxxxxxxxxxxxxx\" -
D_GNU_SOURCE -pipe -Wall -Wchar-subscripts -Wpointer-arith -Wsign-
compare -Wno-pointer-sign -Wdeclaration-after-statement -Wshadow -
Os -fomit-frame-pointer -fPIC -o lib/cpufreq.o -c lib/cpufreq.c

You are building on an ARM host? Or you are cross compiling
with cc is actually arm gcc?

This is cross compiling targeting ARM, which is why CROSS is set to ../arm-linux-



Here we use cc, aka host compiler, rather than $(CROSS)gcc as we
should, so we are no longer cross compiling at all.

I not understand. CROSS was set, but using cc to compile for host?

See below.



The issue is the use of the lazy set if absent for *all* of CC, LD, AR, STRIP,
RANLIB, rather than just for CROSS. The following fixes it for me:

diff --git a/tools/power/cpupower/Makefile
b/tools/power/cpupower/Makefile index
175004ce44b2..96bb1e5f3970 100644
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -87,11 +87,11 @@ INSTALL_SCRIPT = ${INSTALL} -m 644
# to something more interesting, like "arm-linux-". If you want
# to compile vs uClibc, that can be done here as well.
CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
-CC ?= $(CROSS)gcc
-LD ?= $(CROSS)gcc
-AR ?= $(CROSS)ar
-STRIP ?= $(CROSS)strip
-RANLIB ?= $(CROSS)ranlib
+CC = $(CROSS)gcc
+LD = $(CROSS)gcc
+AR = $(CROSS)ar
+STRIP = $(CROSS)strip
+RANLIB = $(CROSS)ranlib

The ? is just allow to override CC/LD/AR.., so in your env,
CC is set, but should not be used for cpupower compling?

Adding debug to show the origin of the CC variable shows the following:

CROSS=/local/users/fainelli/buildroot-upstream/output/arm/host/bin/arm-linux-
CC origin is (default) and value is (cc)
LD origin is (default) and value is (ld)
CC=cc
LD=ld
AR=ar
STRIP=
RANLIB=

See https://www.gnu.org/software/make/manual/html_node/Origin-Function.html#Origin-Function
--
Florian