
VERSION = $(shell cat ../VERSION)

BUILD   = $(shell ../get-build-number.sh)

FULLVER = $(VERSION).$(BUILD)

PYTHON = python3


all: package

package:
	sed -i -e '/version/ d' -e "/description =/ a version=\"$(FULLVER)\"" pyproject.toml
	$(PYTHON) -m build

install:
	$(PYTHON) -m pip install -I .

install-initial:
	$(PYTHON) -m pip install -I '.[build]'

TMP ?= /tmp

ifeq ($(VIRTUAL_ENV),)
venvdir = $(TMP)/venv-uopt
else
venvdir = $(VIRTUAL_ENV)
endif

doc:
	make -C doc html

check-venv:
	if ! test -d $(venvdir); then virtualenv $(venvdir); fi
	bash -c "source $(venvdir)/bin/activate && make check"

package-venv:
	if ! test -d $(venvdir); then virtualenv $(venvdir); fi
	bash -c "source $(venvdir)/bin/activate && make package"

doc-venv:
	if ! test -d $(venvdir); then virtualenv $(venvdir); fi
	bash -c "source $(venvdir)/bin/activate && make -C doc html"

install-venv:
	if ! test -d $(venvdir); then virtualenv $(venvdir); fi
	bash -c "source $(venvdir)/bin/activate && pip install '.[build]'"

install-pkg:
	if ! test -d $(venvdir); then virtualenv $(venvdir); fi
	bash -c "source $(venvdir)/bin/activate && pip install '.[lean]'"

check:
	echo "Checking PY API"
	ls -l
	cd ../tests/py && (pwd)
	cd ../tests/py && (ls -l)
	cd ../tests/py && (readlink -f .)
	cd ../tests/py && (ls -l ./run_tests.sh)
	cd ../tests/py && (PYTHON=python3 ./run_tests.sh)

clean:
	rm -rf build dist uopt.egg-info

uninstall:
	$(PYTHON) -m pip uninstall uopt

init-venv:
	virtualenv $(venvdir)

clean-venv:
	rm -rf $(venvdir)

.PHONY: doc
