<commit_before>
# This is not so much a Makefile as a collection of scripts.
# If you are just interested in Javascript only the js
# and test targets are important.

default: test

js:
	@echo "#######################################################"
	@echo "## Set up directories"
	mkdir -p bin
	mkdir -p lib
	@echo "#######################################################"
	@echo "## Generate javascript"
	haxe language/js.hxml # produces lib/daff.js
	@echo "#######################################################"
	@echo "## Make library version"
	cat env/js/fix_exports.js >> lib/daff.js
	cat env/js/table_view.js >> lib/daff.js
	cat env/js/ndjson_table_view.js >> lib/daff.js
	cat env/js/sqlite_database.js >> lib/daff.js
	cat env/js/util.js >> lib/daff.js
	@echo "#######################################################"
	@echo "## Make executable version (just add shebang)"
	echo "#!/usr/bin/env node" > bin/daff.js
	cat lib/daff.js >> bin/daff.js
	chmod u+x bin/daff.js
	@echo "#######################################################"
	@echo "## Check size"
	@wc bin/daff.js

test: js
	./scripts/run_tests.sh

min: js
	uglifyjs lib/daff.js > lib/daff.min.js
	gzip -k -f lib/daff.min.js
	@wc lib/daff.js
	@wc lib/daff.min.js
	@wc lib/daff.min.js.gz

cpp:
	haxe language/cpp.hxml

version:
	grep "\"version\"" package.json | grep -E -o "[.0-9]+" > version.txt
	cat coopy/Coopy.hx | sed "s/VERSION = .*;/VERSION = \"`cat version.txt`\";/" > coopy/Coopy.hx.next
	cmp coopy/Coopy.hx.next coopy/Coopy.hx || cp coopy/Coopy.hx.next coopy/Coopy.hx
	rm -f coopy/Coopy.hx.next version.txt
	@grep "\"version\"" package.json
	@grep "var VERSION" coopy/Coopy.hx

tag:
	# yes I know about npm-version
	@make version
	@make test
	@grep "\"version\"" package.json | grep -E -o "[.0-9]+" | tee version.txt
	@echo "git commit -m \"`cat version.txt`\" -a"
	@echo "git tag -a \"v`cat version.txt`\" -m \"`cat version.txt`\""
	read x
	git commit -m "`cat version.txt`" -a && git tag -a "v`cat version.txt`" -m "`cat version.txt`"

doc:
	haxe -xml doc.xml language/js.hxml
	haxedoc doc.xml -f coopy

cpp_package:
	haxe language/cpp_for_package.hxml

php:
	haxe language/php.hxml
	find php_bin/lib/coopy -iname "*View.*.php" -exec sed -i 's/function hashSet(/function hashSet(\&/' {} \;
	cp env/php/*.class.php php_bin/lib/coopy/
	cp scripts/example.php php_bin/
	@echo 'Output in php_bin, run "php php_bin/index.php" for an example utility'
	@echo 'or try "php php_bin/example.php" for an example of using daff as a library'


java:
	haxe language/java.hxml
	cp scripts/JavaTableView.java java_bin/src/coopy
	cp scripts/Example.java java_bin
	echo "src/coopy/JavaTableView.java" >> java_bin/cmd
	cd java_bin && javac -sourcepath src -d obj -g:none "@cmd"
	cd java_bin && rm *.jar
	cd java_bin/obj && jar cvfm ../daff.jar ../manifest .
	cd java_bin && javac -cp daff.jar Example.java
	@echo 'Output in java_bin, run "java -jar java_bin/daff.jar" for help'
	@echo 'Run example with "java -cp java_bin/daff.jar:java_bin Example"'

cs:
	haxe language/cs.hxml
	@echo 'Output in cs_bin, do something like "gmcs -recurse:*.cs -main:coopy.Coopy -out:coopyhx.exe" in that directory'

py:
	rm -rf python_bin
	mkdir -p python_bin
	haxe language/py_util.hxml
	sed -i "1i#!/usr/bin/env python" python_bin/daff.py
	sed -i "s|.*Coopy.main.*||" python_bin/daff.py
	cat scripts/python_table_view.py >> python_bin/daff.py
	echo "if __name__ == '__main__':" >> python_bin/daff.py
	echo "\tCoopy.main()" >> python_bin/daff.py
	sed -i 's/Sys.stdout().writeString/python_lib_Sys.stdout.write/' python_bin/daff.py # fix utf-8
	cp scripts/example.py python_bin/
	@echo 'Output in python_bin, run "python3 python_bin/daff.py" for an example utility'
	@echo 'or try "python3 python_bin/example.py" for an example of using daff as a library'
<commit_msg>tweak utf8 output for python build, see #31<commit_after>
# This is not so much a Makefile as a collection of scripts.
# If you are just interested in Javascript only the js
# and test targets are important.

default: test

js:
	@echo "#######################################################"
	@echo "## Set up directories"
	mkdir -p bin
	mkdir -p lib
	@echo "#######################################################"
	@echo "## Generate javascript"
	haxe language/js.hxml # produces lib/daff.js
	@echo "#######################################################"
	@echo "## Make library version"
	cat env/js/fix_exports.js >> lib/daff.js
	cat env/js/table_view.js >> lib/daff.js
	cat env/js/ndjson_table_view.js >> lib/daff.js
	cat env/js/sqlite_database.js >> lib/daff.js
	cat env/js/util.js >> lib/daff.js
	@echo "#######################################################"
	@echo "## Make executable version (just add shebang)"
	echo "#!/usr/bin/env node" > bin/daff.js
	cat lib/daff.js >> bin/daff.js
	chmod u+x bin/daff.js
	@echo "#######################################################"
	@echo "## Check size"
	@wc bin/daff.js

test: js
	./scripts/run_tests.sh

min: js
	uglifyjs lib/daff.js > lib/daff.min.js
	gzip -k -f lib/daff.min.js
	@wc lib/daff.js
	@wc lib/daff.min.js
	@wc lib/daff.min.js.gz

cpp:
	haxe language/cpp.hxml

version:
	grep "\"version\"" package.json | grep -E -o "[.0-9]+" > version.txt
	cat coopy/Coopy.hx | sed "s/VERSION = .*;/VERSION = \"`cat version.txt`\";/" > coopy/Coopy.hx.next
	cmp coopy/Coopy.hx.next coopy/Coopy.hx || cp coopy/Coopy.hx.next coopy/Coopy.hx
	rm -f coopy/Coopy.hx.next version.txt
	@grep "\"version\"" package.json
	@grep "var VERSION" coopy/Coopy.hx

tag:
	# yes I know about npm-version
	@make version
	@make test
	@grep "\"version\"" package.json | grep -E -o "[.0-9]+" | tee version.txt
	@echo "git commit -m \"`cat version.txt`\" -a"
	@echo "git tag -a \"v`cat version.txt`\" -m \"`cat version.txt`\""
	read x
	git commit -m "`cat version.txt`" -a && git tag -a "v`cat version.txt`" -m "`cat version.txt`"

doc:
	haxe -xml doc.xml language/js.hxml
	haxedoc doc.xml -f coopy

cpp_package:
	haxe language/cpp_for_package.hxml

php:
	haxe language/php.hxml
	find php_bin/lib/coopy -iname "*View.*.php" -exec sed -i 's/function hashSet(/function hashSet(\&/' {} \;
	cp env/php/*.class.php php_bin/lib/coopy/
	cp scripts/example.php php_bin/
	@echo 'Output in php_bin, run "php php_bin/index.php" for an example utility'
	@echo 'or try "php php_bin/example.php" for an example of using daff as a library'


java:
	haxe language/java.hxml
	cp scripts/JavaTableView.java java_bin/src/coopy
	cp scripts/Example.java java_bin
	echo "src/coopy/JavaTableView.java" >> java_bin/cmd
	cd java_bin && javac -sourcepath src -d obj -g:none "@cmd"
	cd java_bin && rm *.jar
	cd java_bin/obj && jar cvfm ../daff.jar ../manifest .
	cd java_bin && javac -cp daff.jar Example.java
	@echo 'Output in java_bin, run "java -jar java_bin/daff.jar" for help'
	@echo 'Run example with "java -cp java_bin/daff.jar:java_bin Example"'

cs:
	haxe language/cs.hxml
	@echo 'Output in cs_bin, do something like "gmcs -recurse:*.cs -main:coopy.Coopy -out:coopyhx.exe" in that directory'

py:
	rm -rf python_bin
	mkdir -p python_bin
	haxe language/py_util.hxml
	sed -i "1i#!/usr/bin/env python" python_bin/daff.py
	sed -i "s|.*Coopy.main.*||" python_bin/daff.py
	cat scripts/python_table_view.py >> python_bin/daff.py
	echo "if __name__ == '__main__':" >> python_bin/daff.py
	echo "\tCoopy.main()" >> python_bin/daff.py
	sed -i 's/Sys.stdout().writeString(txt)/(python_lib_Sys.stdout.buffer if hasattr(python_lib_Sys.stdout,"buffer") else python_lib_Sys.stdout).write(txt.encode("utf-8", "strict"))/' python_bin/daff.py # fix utf-8
	cp scripts/example.py python_bin/
	@echo 'Output in python_bin, run "python3 python_bin/daff.py" for an example utility'
	@echo 'or try "python3 python_bin/example.py" for an example of using daff as a library'

{'fraction_non_alphanumeric': 0.21163000128650455, 'fraction_numerical': 0.0025730091341824263, 'mean_word_length': 3.8709273182957395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '268575', 'n_tokens_mistral': 3062, 'n_tokens_neox': 2984, 'n_words': 794}