1# Makefile for Sequoia's Python bindings. 2 3# Configuration. 4PREFIX ?= /usr/local 5DESTDIR ?= 6CFLAGS += -I../../include -I../../../openpgp-ffi/include 7 8# Tools. 9PYTHON ?= python3 10IPYTHON ?= ipython3 11PYTEST ?= pytest-3 12ifeq ($(shell uname -s), Darwin) 13 INSTALL ?= ginstall 14else 15 INSTALL ?= install 16endif 17 18 19CARGO_TARGET_DIR ?= ../../../target 20 21ifneq "$(PYTHON)" "disable" 22PY_VERSION = $(shell $(PYTHON) -c \ 23 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))') 24endif 25 26# Make sure subprocesses pick these up. 27export CFLAGS 28 29all: build 30 31.PHONY: build 32build: .stamp-build 33.stamp-build: sequoia/* ../../include/sequoia/* 34ifneq "$(PYTHON)" "disable" 35 LDFLAGS=-L$(CARGO_TARGET_DIR)/debug $(PYTHON) setup.py build 36 touch $@ 37endif 38 39# Testing and examples. 40.PHONY: test check 41test check: 42ifneq "$(PYTHON)" "disable" 43 LDFLAGS=-L$(CARGO_TARGET_DIR)/debug LD_LIBRARY_PATH=$(CARGO_TARGET_DIR)/debug \ 44 $(PYTHON) setup.py test 45endif 46 47.PHONY: shell 48shell: build 49ifneq "$(PYTHON)" "disable" 50 cp build/*/_sequoia.abi*.so . # XXX can we get setuptools to do that? 51 LDFLAGS=-L$(CARGO_TARGET_DIR)/debug LD_LIBRARY_PATH=$(CARGO_TARGET_DIR)/debug \ 52 $(IPYTHON) -i -c \ 53'from sequoia.prelude import *; ctx = Context()' 54endif 55 56# Installation. 57.PHONY: build-release 58build-release: .stamp-build-release 59.stamp-build-release: 60ifneq "$(PYTHON)" "disable" 61 rm -f .stamp-build 62 $(PYTHON) setup.py clean 63 LDFLAGS=-L$(CARGO_TARGET_DIR)/release \ 64 $(PYTHON) setup.py build 65 touch $@ 66endif 67 68ifneq "$(DESTDIR)" "" 69 root_arg=--root=$(DESTDIR) 70endif 71 72.PHONY: install 73install: build-release 74ifneq "$(PYTHON)" "disable" 75 $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib/python$(PY_VERSION)/site-packages 76 77 LDFLAGS=-L$(CARGO_TARGET_DIR)/release \ 78 $(PYTHON) setup.py install $(root_arg) --prefix=$(PREFIX) 79endif 80 81# Housekeeping. 82.PHONY: clean 83clean: 84ifneq "$(PYTHON)" "disable" 85 $(PYTHON) setup.py clean 86 rm -f _sequoia.*.so 87 rm -f .stamp-build .stamp-build-release 88endif 89