## The SCUQ Library 
## ----------------
## SCUQ = class library for the evaluation Sclar- and Complex-valued Uncertain
##        Quantities
##
## This is the main creation script, the following targets are implemented
##
## all:    Builds docs and runs tests
## clean:  Removes temporary files
## doc:    Builds Sphinx HTML documentation
## backup: Create a backup
## dist:   Create a distribution package (includes sources only).
## test:   Run pytest tests.
## legacy-test: Run the legacy unittest self-test.
## legacy-doc: Build historical Doxygen docs.

# Files that are deleted by invoking clean
TMP_FILES=doc.log src/scuq/*.pyc src/scuq/*.pyo doc/html doc/latex Examples/*.pyc \
	  Examples/*.pyo *.log doc/sphinx/_build

# Files and directories that are important for backups
IMP_FILES=doc doc.cfg Examples scuq make_latex.sh \
	  Makefile AUTHORS

# The souce files 
SOURCES=src/scuq/arithmetic.py src/scuq/cucomponents.py src/scuq/__init__.py \
	src/scuq/operators.py src/scuq/qexceptions.py src/scuq/quantities.py \
	src/scuq/si.py src/scuq/testcases.py src/scuq/units.py
DOCS_SOURCES=doc/sphinx/conf.py doc/sphinx/index.rst doc/sphinx/getting-started.rst \
	doc/sphinx/api/index.rst doc/sphinx/api/arithmetic.rst \
	doc/sphinx/api/operators.rst doc/sphinx/api/qexceptions.rst \
	doc/sphinx/api/quantities.rst doc/sphinx/api/units.rst \
	doc/sphinx/api/si.rst doc/sphinx/api/ucomponents.rst \
	doc/sphinx/api/cucomponents.rst
SPHINX_BUILD=doc/sphinx/_build
PYTHON ?= python

all: doc test

clean: 
	rm -rf $(TMP_FILES)

## Documentation related targets (Sphinx)

$(SPHINX_BUILD)/html/index.html: $(DOCS_SOURCES) $(SOURCES)
	PYTHONPATH=src $(PYTHON) -m sphinx -b html doc/sphinx $(SPHINX_BUILD)/html

doc: $(SPHINX_BUILD)/html/index.html

docs-html: $(SPHINX_BUILD)/html/index.html

docs-linkcheck: $(DOCS_SOURCES) $(SOURCES)
	PYTHONPATH=src $(PYTHON) -m sphinx -b linkcheck doc/sphinx $(SPHINX_BUILD)/linkcheck

docs-strict: $(DOCS_SOURCES) $(SOURCES)
	PYTHONPATH=src $(PYTHON) -m sphinx -W -b html doc/sphinx $(SPHINX_BUILD)/strict-html

docs-coverage: $(DOCS_SOURCES) $(SOURCES)
	PYTHONPATH=src $(PYTHON) -m sphinx -b coverage doc/sphinx $(SPHINX_BUILD)/coverage

docs-clean:
	rm -rf $(SPHINX_BUILD)

# Historical Doxygen pipeline (legacy only)
legacy-doc:
	doxygen doc.cfg
	sh ./make_latex.sh

## Backups

backup: clean
	tar cvjf `date +"%Y%m%d"`_backup.tar.bz2 $(IMP_FILES)

## Distribution related info
dist: clean
	tar cvjf `date +"%Y%m%d"`_dist.tar.bz2 $(SOURCES)
	
test: $(SOURCES)
	PYTHONPATH=src python -m pytest -q

legacy-test: $(SOURCES)
	PYTHONPATH=src SCUQ_RUN_LEGACY_SELFTEST=1 python -m pytest -q test/test_legacy_selftest.py

	
#strip_cvs:
#	rm -rf CVS .cvsignore doc/CVS doc/.cvsignore Examples/CVS \
#	           Examples/.cvsignore scuq/CVS 
