Skip to contentSkip to conversation

pm:cpupower: Add error warning when SWIG is not installed

PATCH Applied John B. Wyatt IV 2 participants 3 messages Sep 6, 2024 – Sep 12, 2024 CPU power monitoring

lore
Share & tools
lore

John B. Wyatt IV

author maintainer
#0 lore raw

PATCH 1/1 pm:cpupower: Add error warning when SWIG is not installed

Add error message to better explain to the user when SWIG and python-config is missing from the path. Makefile was cleaned up and unneeded elements were removed.

---
 tools/power/cpupower/bindings/python/Makefile | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
tools/power/cpupower/bindings/python/Makefile +11 -9
index d0418f902795..dc09c5b66ead 100644
@@ -4,26 +4,28 @@
 # This Makefile expects you have already run the makefile for cpupower to build
 # the .o files in the lib directory for the bindings to be created.
 
-CC=gcc
-
-LIB_DIR = ../../lib
-BIND_DIR = .
-PY_INCLUDE := $(firstword $(shell python-config --includes))
-#PY_INCLUDE = $(shell python-config --includes | awk '{ print $1 }')
+CC := gcc
+HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi)
+HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi)
 
+LIB_DIR := ../../lib
+PY_INCLUDE = $(firstword $(shell python-config --includes))
 OBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o)
-OBJECTS_BIND = $(wildcard $(BIND_DIR)/*.o)
 
 all: _raw_pylibcpupower.so
 
 _raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
-	$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so # raw_pylibcpupower_wrap.o
-#	$(CC) -shared $(OBJECTS_BIND) $(OBJECTS_LIB) -o _raw_pylibcpupower.so # raw_pylibcpupower_wrap.o
+	$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
 
 raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
 	$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)
 
 raw_pylibcpupower_wrap.c: raw_pylibcpupower.i
+ifeq ($(HAVE_SWIG),0)
+	$(error "swig was not found. Make sure you have it installed and in the PATH to generate the bindings.")
+else ifeq ($(HAVE_PYCONFIG),0)
+	$(error "python-config was not found. Make sure you have it installed and in the PATH to generate the bindings.")
+endif
 	swig -python raw_pylibcpupower.i
 
 # Will only clean the bindings folder; will not clean the actual cpupower folder
Signature · 1 line
2.46.0
maintainer Applied
#1 lore raw
Quoted 8 lines · John B. Wyatt IV

Add error message to better explain to the user when SWIG and python-config is missing from the path. Makefile was cleaned up and unneeded elements were removed.

Thank you. You don't need 1/1 in the prefix for single patches.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/?h=cpupowe
for Linux 6.12-rc1

thanks,
-- Shuah

author maintainer
#2 lore raw
Quoted 6 lines · Shuah Khan
Quoted 4 lines · John B. Wyatt IV

Add error message to better explain to the user when SWIG and python-config is missing from the path. Makefile was cleaned up and unneeded elements were removed.

Quoted 8 lines
Quoted 3 lines

Thank you. You don't need 1/1 in the prefix for single patches.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/?h=cpupowe
for Linux 6.12-rc1

You are welcome and thank you for the guidance on improving my make skills.

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat