summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2017-12-18 00:31:25 -0800
committerDavid Sterba <dsterba@suse.com>2018-02-24 01:37:17 +0100
commit23c01b3c1b0803950657f3f29914cd59f3554a84 (patch)
tree970d902219a7c2a2bddc87ed883154c1dee79a65 /Makefile
parentd51e8b128f598a31933367ca0fa14b6875b34ca0 (diff)
libbtrfsutil: add Python bindings
The C libbtrfsutil library isn't very useful for scripting, so we also want bindings for Python. Writing unit tests in Python is also much easier than doing so in C. Only Python 3 is supported; if someone really wants Python 2 support, they can write their own bindings. This commit is just the scaffolding. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile36
1 files changed, 36 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 7c88460..b70494b 100644
--- a/Makefile
+++ b/Makefile
@@ -154,8 +154,10 @@ endif
ifeq ($(BUILD_VERBOSE),1)
Q =
+ SETUP_PY_Q =
else
Q = @
+ SETUP_PY_Q = -q
endif
ifeq ("$(origin D)", "command line")
@@ -302,6 +304,9 @@ endif
$($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
all: $(progs) $(libs) $(lib_links) $(BUILDDIRS)
+ifeq ($(PYTHON_BINDINGS),1)
+all: libbtrfsutil_python
+endif
$(SUBDIRS): $(BUILDDIRS)
$(BUILDDIRS):
@echo "Making all in $(patsubst build-%,%,$@)"
@@ -349,6 +354,16 @@ testsuite: btrfs-corrupt-block fssum
@echo "Export tests as a package"
$(Q)cd tests && ./export-testsuite.sh
+ifeq ($(PYTHON_BINDINGS),1)
+test-libbtrfsutil: libbtrfsutil_python
+ $(Q)cd libbtrfsutil/python; \
+ LD_LIBRARY_PATH=../.. $(PYTHON) -m unittest discover -v tests
+
+.PHONY: test-libbtrfsutil
+
+test: test-libbtrfsutil
+endif
+
#
# NOTE: For static compiles, you need to have all the required libs
# static equivalent available
@@ -399,6 +414,15 @@ libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so: libbtrfsutil.so.$(libbtrf
@echo " [LN] $@"
$(Q)$(LN_S) -f $< $@
+ifeq ($(PYTHON_BINDINGS),1)
+libbtrfsutil_python: libbtrfsutil.so libbtrfsutil/btrfsutil.h
+ @echo " [PY] libbtrfsutil"
+ $(Q)cd libbtrfsutil/python; \
+ CFLAGS= LDFLAGS= $(PYTHON) setup.py $(SETUP_PY_Q) build_ext -i build
+
+.PHONY: libbtrfsutil_python
+endif
+
# keep intermediate files from the below implicit rules around
.PRECIOUS: $(addsuffix .o,$(progs))
@@ -582,6 +606,10 @@ clean: $(CLEANDIRS)
$(libs) $(lib_links) \
$(progs_static) $(progs_extra) \
libbtrfsutil/*.o libbtrfsutil/*.o.d
+ifeq ($(PYTHON_BINDINGS),1)
+ $(Q)cd libbtrfsutil/python; \
+ $(PYTHON) setup.py $(SETUP_PY_Q) clean -a
+endif
clean-doc:
@echo "Cleaning Documentation"
@@ -617,6 +645,14 @@ ifneq ($(udevdir),)
$(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
endif
+ifeq ($(PYTHON_BINDINGS),1)
+install_python: libbtrfsutil_python
+ $(Q)cd libbtrfsutil/python; \
+ $(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR)) --prefix $(prefix)
+
+.PHONY: install_python
+endif
+
install-static: $(progs_static) $(INSTALLDIRS)
$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
$(INSTALL) $(progs_static) $(DESTDIR)$(bindir)