python_version=3.11

go: test

rolling_checksum_pyx_mod.pyx: ../rolling_checksum_mod.m4
	m4 -Dpyx=1 < ../rolling_checksum_mod.m4 > rolling_checksum_pyx_mod.pyx

rolling_checksum_pyx_mod.c: rolling_checksum_pyx_mod.pyx
	/usr/local/cpython-3.11/bin/python3 -m cython -a rolling_checksum_pyx_mod.pyx

rolling_checksum_pyx_mod.o: rolling_checksum_pyx_mod.c
	gcc -O3 -c -fPIC -I /usr/local/cpython-$(python_version)/include/python$(python_version) rolling_checksum_pyx_mod.c

rolling_checksum_pyx_mod.so: rolling_checksum_pyx_mod.o
	gcc -O3 -shared rolling_checksum_pyx_mod.o -o rolling_checksum_pyx_mod.so

rcm-input-data:
	../gen-rcm-input-data > rcm-input-data

test: rolling_checksum_pyx_mod.so rcm-input-data
	python3 ../test-rolling_checksum_mod --cython
	
publish: clean rolling_checksum_pyx_mod.pyx
	/usr/local/cpython-3.11/bin/python3 setup.py sdist bdist_wheel
	twine upload dist/*.tar.gz

test-publish: clean rolling_checksum_pyx_mod.pyx
	/usr/local/cpython-3.11/bin/python3 setup.py sdist bdist_wheel
	twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*.tar.gz

clean:
	rm -rf build dist rolling_checksum_pyx_mod.egg-info
	rm -f rolling_checksum_pyx_mod.c rolling_checksum_pyx_mod.pyx rolling_checksum_pyx_mod.html
	rm -f rcm-input-data