1338f490eSJohn B. Wyatt IV# SPDX-License-Identifier: GPL-2.0-only
2338f490eSJohn B. Wyatt IV# Makefile for libcpupower's Python bindings
3338f490eSJohn B. Wyatt IV#
4338f490eSJohn B. Wyatt IV# This Makefile expects you have already run the makefile for cpupower to build
5338f490eSJohn B. Wyatt IV# the .o files in the lib directory for the bindings to be created.
6338f490eSJohn B. Wyatt IV
780e67f18SJohn B. Wyatt IVCC := gcc
880e67f18SJohn B. Wyatt IVHAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi)
980e67f18SJohn B. Wyatt IVHAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi)
10338f490eSJohn B. Wyatt IV
1180e67f18SJohn B. Wyatt IVLIB_DIR := ../../lib
1280e67f18SJohn B. Wyatt IVPY_INCLUDE = $(firstword $(shell python-config --includes))
13338f490eSJohn B. Wyatt IVOBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o)
14*6de02569SJohn B. Wyatt IVINSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
15338f490eSJohn B. Wyatt IV
16338f490eSJohn B. Wyatt IVall: _raw_pylibcpupower.so
17338f490eSJohn B. Wyatt IV
18338f490eSJohn B. Wyatt IV_raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
1980e67f18SJohn B. Wyatt IV	$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
20338f490eSJohn B. Wyatt IV
21338f490eSJohn B. Wyatt IVraw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
22338f490eSJohn B. Wyatt IV	$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)
23338f490eSJohn B. Wyatt IV
24313312c8SMin-Hua Chenraw_pylibcpupower_wrap.c: raw_pylibcpupower.swg
2580e67f18SJohn B. Wyatt IVifeq ($(HAVE_SWIG),0)
2680e67f18SJohn B. Wyatt IV	$(error "swig was not found. Make sure you have it installed and in the PATH to generate the bindings.")
2780e67f18SJohn B. Wyatt IVelse ifeq ($(HAVE_PYCONFIG),0)
2880e67f18SJohn B. Wyatt IV	$(error "python-config was not found. Make sure you have it installed and in the PATH to generate the bindings.")
2980e67f18SJohn B. Wyatt IVendif
30313312c8SMin-Hua Chen	swig -python raw_pylibcpupower.swg
31338f490eSJohn B. Wyatt IV
32*6de02569SJohn B. Wyatt IV# Only installs the Python bindings
33*6de02569SJohn B. Wyatt IVinstall: _raw_pylibcpupower.so
34*6de02569SJohn B. Wyatt IV	install -D _raw_pylibcpupower.so $(INSTALL_DIR)/_raw_pylibcpupower.so
35*6de02569SJohn B. Wyatt IV	install -D raw_pylibcpupower.py $(INSTALL_DIR)/raw_pylibcpupower.py
36*6de02569SJohn B. Wyatt IV
37*6de02569SJohn B. Wyatt IVuninstall:
38*6de02569SJohn B. Wyatt IV	rm -f $(INSTALL_DIR)/_raw_pylibcpupower.so
39*6de02569SJohn B. Wyatt IV	rm -f $(INSTALL_DIR)/raw_pylibcpupower.py
40*6de02569SJohn B. Wyatt IV
41338f490eSJohn B. Wyatt IV# Will only clean the bindings folder; will not clean the actual cpupower folder
42338f490eSJohn B. Wyatt IVclean:
43338f490eSJohn B. Wyatt IV	rm -f raw_pylibcpupower.py raw_pylibcpupower_wrap.c raw_pylibcpupower_wrap.o _raw_pylibcpupower.so
44