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 8# CFLAGS ?= 9LDFLAGS ?= -lcpupower 10HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi) 11HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi) 12 13PY_INCLUDE ?= $(firstword $(shell python-config --includes)) 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 $(LDFLAGS) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so 20 21raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c 22 $(CC) $(CFLAGS) $(PY_INCLUDE) -fPIC -c raw_pylibcpupower_wrap.c 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