xref: /linux/tools/power/cpupower/bindings/python/Makefile (revision f4b9d3bf44d59ca4489bd8c489539c27c02e5c6a)
1# SPDX-License-Identifier: GPL-2.0-only
2# Makefile for libcpupower's Python bindings
3#
4# This Makefile expects you have already run the makefile for cpupower to build
5# the .o files in the lib directory for the bindings to be created.
6
7CC := gcc
8HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi)
9HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi)
10
11LIB_DIR := ../../lib
12PY_INCLUDE = $(firstword $(shell python-config --includes))
13OBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o)
14INSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
15
16all: _raw_pylibcpupower.so
17
18_raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
19	$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
20
21raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
22	$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)
23
24raw_pylibcpupower_wrap.c: raw_pylibcpupower.swg
25ifeq ($(HAVE_SWIG),0)
26	$(error "swig was not found. Make sure you have it installed and in the PATH to generate the bindings.")
27else ifeq ($(HAVE_PYCONFIG),0)
28	$(error "python-config was not found. Make sure you have it installed and in the PATH to generate the bindings.")
29endif
30	swig -python raw_pylibcpupower.swg
31
32# Only installs the Python bindings
33install: _raw_pylibcpupower.so
34	install -D _raw_pylibcpupower.so $(INSTALL_DIR)/_raw_pylibcpupower.so
35	install -D raw_pylibcpupower.py $(INSTALL_DIR)/raw_pylibcpupower.py
36
37uninstall:
38	rm -f $(INSTALL_DIR)/_raw_pylibcpupower.so
39	rm -f $(INSTALL_DIR)/raw_pylibcpupower.py
40
41# Will only clean the bindings folder; will not clean the actual cpupower folder
42clean:
43	rm -f raw_pylibcpupower.py raw_pylibcpupower_wrap.c raw_pylibcpupower_wrap.o _raw_pylibcpupower.so
44