xref: /spdk/python/Makefile (revision 952532af6688423ac8aab3367c4a3ab13b87842a)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2023 Intel Corporation.
3#  Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES
4#  All rights reserved.
5#
6
7SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
8include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
9
10setup_cmd = pip install --prefix=$(CONFIG_PREFIX)
11ifneq ($(DESTDIR),)
12setup_cmd += --root $(DESTDIR)
13endif
14
15pylibdir := $(abspath $(shell python3 -c "import sysconfig; print(sysconfig.get_paths()['purelib'])"))
16ifneq ($(CONFIG_PREFIX),)
17# Consider different scenarios where purelib can be located:
18#
19# - /usr/lib/python*/site-packages
20# - /usr/local/lib/python*/site-packages
21# - /foo/bar/lib/python*/site-packages
22#
23# The latter here can be a result of using interpreter from within a venv
24# located at custom location - see how we handle PEP668 under ubuntu in
25# pkgdep/ubuntu.sh for instance.
26#
27# So the common part here is:
28#   *lib/python*/site-packages
29#
30# So we cut the path to get the prefix (whatever it may be) and then we nuke
31# it from the main path. So the corner case would look like so:
32#
33# pylibdir := /foo/bar/lib/python*/site-packages
34# pylibprefix := /foo/bar
35# pylibdir := $(CONFIG_PREFIX)/lib/python*/site-packages
36#
37# FIXME: I couldn't get patsubst to do the heavy lifting here, hence fallback
38# to shell.
39pylibprefix := $(shell a=$(pylibdir); echo $${a%/lib*})
40pylibdir := $(CONFIG_PREFIX)$(pylibdir:$(pylibprefix)%=%)
41endif
42
43all:
44
45clean:
46
47install: rpc spdkcli
48	$(Q)$(setup_cmd) $(SPDK_ROOT_DIR)/python
49	rm -rf $(SPDK_ROOT_DIR)/python/spdk.egg-info
50
51$(SPDK_ROOT_DIR)/build/bin/spdk_rpc:
52	cp $(SPDK_ROOT_DIR)/scripts/rpc.py $(SPDK_ROOT_DIR)/build/bin/spdk_rpc
53	chmod +x $(SPDK_ROOT_DIR)/build/bin/spdk_rpc
54
55$(SPDK_ROOT_DIR)/build/bin/spdk_cli:
56	cp $(SPDK_ROOT_DIR)/scripts/spdkcli.py $(SPDK_ROOT_DIR)/build/bin/spdk_cli
57	chmod +x $(SPDK_ROOT_DIR)/build/bin/spdk_cli
58
59rpc: $(SPDK_ROOT_DIR)/build/bin/spdk_rpc
60	$(INSTALL_APP)
61
62spdkcli: $(SPDK_ROOT_DIR)/build/bin/spdk_cli
63	$(INSTALL_APP)
64
65uninstall:
66	$(Q)rm -rf $(DESTDIR)/$(pylibdir)/spdk*
67	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk_rpc
68	$(Q)rm -f $(DESTDIR)/$(bindir)/spdk_cli
69
70.PHONY: all clean install uninstall
71