xref: /linux/tools/power/cpupower/bindings/python/Makefile (revision c89756bcf406af313d191cfe3709e7c175c5b0cd)
1# SPDX-License-Identifier: GPL-2.0-only
2# Makefile for libcpupower's Python bindings
3#
4# This Makefile expects you have already run `make install-lib` in the lib
5# 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
11PY_INCLUDE = $(firstword $(shell python-config --includes))
12INSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
13
14all: _raw_pylibcpupower.so
15
16_raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
17	$(CC) -shared -lcpupower raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
18
19raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
20	$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)
21
22raw_pylibcpupower_wrap.c: raw_pylibcpupower.swg
23ifeq ($(HAVE_SWIG),0)
24	$(error "swig was not found. Make sure you have it installed and in the PATH to generate the bindings.")
25else ifeq ($(HAVE_PYCONFIG),0)
26	$(error "python-config was not found. Make sure you have it installed and in the PATH to generate the bindings.")
27endif
28	swig -python raw_pylibcpupower.swg
29
30# Only installs the Python bindings
31install: _raw_pylibcpupower.so
32	install -D _raw_pylibcpupower.so $(INSTALL_DIR)/_raw_pylibcpupower.so
33	install -D raw_pylibcpupower.py $(INSTALL_DIR)/raw_pylibcpupower.py
34
35uninstall:
36	rm -f $(INSTALL_DIR)/_raw_pylibcpupower.so
37	rm -f $(INSTALL_DIR)/raw_pylibcpupower.py
38
39# Will only clean the bindings folder; will not clean the actual cpupower folder
40clean:
41	rm -f raw_pylibcpupower.py raw_pylibcpupower_wrap.c raw_pylibcpupower_wrap.o _raw_pylibcpupower.so
42