.PHONY: all test clean c python3 clojure
ROUNDS = 100000

all: python3 c clojure

c: a.out

python3: __pycache__

clojure: target/uberjar

target/uberjar:
	cd prime.clj; lein uberjar

__pycache__:
	py3compile -V 3.0- prime.py

a.out:
	gcc --std=c99 -Wall -lm -O3 prime.c

clean:
	- rm -fr a.out __pycache__
	cd prime.clj; lein clean

test: all
	@ time -f "%C : %E seconds" ./a.out $(ROUNDS) > /dev/null
	@ time -f "%C : %E seconds" java -jar prime.clj/target/uberjar/*-standalone.jar $(ROUNDS) > /dev/null
	@ [ -n "$$(which python)" ] && time -f "%C : %E seconds" ./prime.py $(ROUNDS) > /dev/null
	@ [ -n "$$(which python3)" ] && time -f "%C : %E seconds" python3 prime.py $(ROUNDS) > /dev/null
	@ [ -n "$$(which pypy)" ] && time -f "%C : %E seconds" pypy  prime.py $(ROUNDS) > /dev/null
	@ [ -n "$$(which lua)" ] && time -f "%C : %E seconds" ./prime.lua $(ROUNDS) > /dev/null
	@ [ -n "$$(which luajit)" ] && time -f "%C : %E seconds" luajit prime.lua $(ROUNDS) > /dev/null
	@ [ -n "$$(which php)" ] && time -f "%C : %E seconds" ./prime.php $(ROUNDS) > /dev/null
	@ [ -n "$$(which php7.0)" ] && time -f "%C : %E seconds" php7.0 prime.php $(ROUNDS) > /dev/null
	@ [ -n "$$(which ruby)" ] && time -f "%C : %E seconds" ./prime.rb $(ROUNDS) > /dev/null
	@ [ -n "$$(which node)" ] && time -f "%C : %E seconds" ./prime.js $(ROUNDS) > /dev/null
	@ [ -x /usr/bin/awk ] && time -f "%C : %E seconds" ./prime.awk $(ROUNDS) > /dev/null
