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

Peng Fan (OSS) posted 2 patches 2 months, 1 week ago
[PATCH v2 2/2] pm: cpupower: Makefile: Allow overriding cross-compiling env params
Posted by Peng Fan (OSS) 2 months, 1 week ago
From: Peng Fan <peng.fan@nxp.com>

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

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 tools/power/cpupower/Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile
index 6c02f401069e..e2a48af6fa2a 100644
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -86,12 +86,12 @@ INSTALL_SCRIPT = ${INSTALL} -m 644
 # If you are running a cross compiler, you may want to set this
 # 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
+CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
+CC ?= $(CROSS)gcc
+LD ?= $(CROSS)gcc
+AR ?= $(CROSS)ar
+STRIP ?= $(CROSS)strip
+RANLIB ?= $(CROSS)ranlib
 HOSTCC = gcc
 MKDIR = mkdir
 

-- 
2.37.1
Re: [PATCH v2 2/2] pm: cpupower: Makefile: Allow overriding cross-compiling env params
Posted by Florian Fainelli 1 week, 1 day ago
Hi Peng,

On 9/19/2024 5:08 AM, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> 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://git.buildroot.net/buildroot/tree/package/linux-tools/linux-tool-cpupower.mk.in

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/ff944844/bin:/home/ff944844/.local/bin:/opt/stblinux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/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@vger.kernel.org\" -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

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

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
  HOSTCC = gcc
  MKDIR = mkdir

-- 
Florian