SAGEFILES := $(basename $(notdir $(wildcard *.sage)))
PYFILES := $(addprefix sagelib/, $(addsuffix .py,$(SAGEFILES)))
.PRECIOUS: $(PYFILES)

.PHONY: pyfiles
pyfiles: sagelib/__init__.py $(PYFILES)

sagelib/__init__.py:
	mkdir -p sagelib
	echo pass > sagelib/__init__.py

# Note: 'sage --preparse' was removed from the sage command line in 10.7, so
# call the preparser through the library instead.
sagelib/%.py: %.sage
	@echo "Parsing $<"
	@sage -c "from sage.repl.preparse import preparse_file; open('$@', 'w').write('# This file was *autogenerated* from the file $<\n' 'from sage.all_cmdline import *   # import sage library\n\n' + preparse_file(open('$<').read()))"

# If we need any submodules, etc.
setup:

run: pyfiles
	sage mayo.sage

test: pyfiles
	sage test_mayo.sage

test-conda: pyfiles
	conda run -n sage sage test_mayo.sage

params-check: pyfiles
	sage parameter_check.sage

vectors: pyfiles
	@echo "Removing vectors folder, if present"
	@rm -rf vectors
	@echo "Creating vectors folder"
	@mkdir -p vectors
	sage test_mayo.sage

kat-test: pyfiles
	sage test_kat.sage

.PHONY: clean
clean:
	rm -rf sagelib *.pyc *.sage.py *.log __pycache__

.PHONY: distclean
distclean: clean
	rm -rf vectors ascii
