python_version=3.7

# This is only used when using the 'make-install' rule.  python3 setup.py ignores it.
install_dir=/usr/local/lib/python$(python_version)/dist-packages

go: \
	py_treap.py
	python${python_version} setup.py build

py_treap.py: ../m4_treap.m4
	m4 -Dpy=1 < ../m4_treap.m4 > py_treap.py

install:
	python${python_version} setup.py install

make-install:
	install -d $(install_dir)
	install -m 644 treap.py $(install_dir)
	install -m 644 nest.py $(install_dir)

clean:
	rm -f *.pyc *.so *.o core py_treap.py MANIFEST
	rm -rf build dist
	rm -rf __pycache__
	rm -rf treap.egg-info

veryclean: clean
	rm -f *.c

publish: clean py_treap.py
	python setup.py sdist
	twine upload dist/*

test-publish: clean py_treap.py
	python3 setup.py sdist bdist_wheel
	twine upload --repository-url https://test.pypi.org/legacy/ dist/*