CXXFLAGS=-O3 -s

# test: do-tst

# We don't do nuitka3-t.exe, because it requires /usr/bin/python3.3 and Mint 17 does not include that
go: g++-t clang++-t cython3-t cython3_types_t nuitka3-t.bin # p2m-rust-t p2ms
	./run-them

p2ms: p2m-rust-t p2m-cpp-t p2m-go-t

p2m-cpp-t: p2m/p2m.cpp
	cd p2m && clang++ -ggdb -I${HOME}/src/py2many/py2many -lm p2m.cpp -o p2m
	mv p2m/p2m p2m-cpp-t

p2m.cpp: p2m/p2m.py
	# py2many isn't ready for this yet: https://github.com/adsharma/py2many/issues/302
	cd p2m && /usr/local/cpython-3.9/bin/py2many --cpp=1 p2m.py

p2m-rust-t: p2m/p2m.py
	# py2many isn't ready for this yet: https://github.com/adsharma/py2many/issues/303
	cd p2m && /usr/local/cpython-3.9/bin/py2many --rust=1 p2m.py
	cd p2m && rustc p2m.rs
	mv p2m/p2m p2m-rust-t

p2m-go-t: p2m/p2m.py
	# This fails with p2m.go:4:1: cannot find package "github.com/hgfischer/go-iter" when compiling go to binary
	cd p2m && /usr/local/cpython-3.9/bin/py2many --go=1 p2m.py
	cd p2m && go build p2m.go
	mv p2m/p2m p2m-go-t

do-tst: tst.pyx
	cython --embed=main --warning-extra tst.pyx
	$(CC) -o tst tst.c -I/usr/include/python2.7 -lpython2.7
	./tst

nuitka2-t.bin:
	ln -sf cpython2-t nuitka2-t
	/usr/bin/nuitka --python-version 2.7 nuitka2-t

nuitka3-t.bin:
	ln -sf cpython3-t nuitka3-t
	nuitka3 nuitka3-t

shedskin-t:
	cd shedskin && shedskin shedskin_t.py
	cd shedskin && make
	ln -s shedskin/shedskin_t shedskin-t

cython2_types_t: cython2_types_t.pyx
	cython --embed=main --warning-extra cython2_types_t.pyx
	$(CC) -o cython2_types_t cython2_types_t.c -I/usr/include/python2.7 -lpython2.7 -lm

cython3_types_t: cython3_types_t.pyx
	cython3 --embed=main --warning-extra cython3_types_t.pyx
	$(CC) -o cython3_types_t cython3_types_t.c -I/usr/include/python3.7m -lpython3.7m -lm

cython2-t:
	ln -sf cpython2-t cython2_t.py
	cython --embed cython2_t.py
	$(CC) -o cython2-t cython2_t.c -I/usr/include/python2.7 -lpython2.7

cython3-t:
	ln -sf cpython3-t cython3_t.py
	cython3 --embed cython3_t.py
	$(CC) -o cython3-t cython3_t.c -I/usr/include/python3.7m -lpython3.7m

install-dependencies:
	# The LLVM that comes with Debian 10 is pretty old.  See: https://apt.llvm.org/
	./install-package --deb-packages 'g++ libpcre++-dev python-all-dev libgc-dev cython3 python3-dev nuitka python3-numpy python3-llvmlite python3-numba nuitka rustc clang-format'
	# pip install --user numba
	# pip3 install --user numba
	# --pip-path /where/pip/lives/pip
	# --python-path /where/python/lives/python
	# --module-to-import module_name
	# --pip-package pip-package-name
	# ./install-via-pip --pip-path /usr/bin/pip3 --python-path /usr/bin/python3 --module-to-import numba --pip-package numba

clean:
	rm -f cython2-t cython3-t shedskin-t clang++-t g++-t
	# These are temporaries
	rm -f cython2_t.c cython3_t.c
	rm -f cython2_types_t.c cython3_types_t.c
	rm -f cython2_types_t cython3_types_t
	find . -type l -print0 | xargs -0 rm -fv
	rm -f shedskin/Makefile shedskin/shedskin_t shedskin/shedskin_t.cpp shedskin/shedskin_t.hpp
	rm -f p2m/*.cpp p2m/*.rs p2m/*.go
	rm -f *.bin
	rm -rf nuitka*-t.build
	rm -f tst tst.c