#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_build:
	# Compile the WebAssembly code from source
	find . -name "*.wasm" -delete
	wat2wasm src/lib/lz4/lz4-block-codec.wat -o src/lib/lz4/lz4-block-codec.wasm
	wat2wasm src/js/wasm/hntrie.wat -o src/js/wasm/hntrie.wasm
	wat2wasm src/js/wasm/biditrie.wat -o src/js/wasm/biditrie.wasm
	wat2wasm src/lib/publicsuffixlist/wasm/publicsuffixlist.wat -o src/lib/publicsuffixlist/wasm/publicsuffixlist.wasm
	wasm-opt src/lib/lz4/lz4-block-codec.wasm -O4 -o src/lib/lz4/lz4-block-codec.wasm
	# Replace embedded copy of csstree.esm.js with corresponding Debian file from src:node-css-tree
	cp /usr/share/nodejs/css-tree/dist/csstree.esm.js src/lib/csstree/css-tree.js
	# Replace embedded copy of js-beautify with Debian's system library node-js-beautify
	cp /usr/share/nodejs/js-beautify/js/lib/beautifier.min.js src/lib/js-beautify/beautifier.min.js
	# Build the minified asset filters
	cd uAssets && ./tools/make-ublock.sh
	# Build the browser-specific versions of ublock-origin
	./tools/make-firefox.sh
	./tools/make-chromium.sh

override_dh_install:
	dh_install -p ublock-origin-doc
	dh_install -p webext-ublock-origin-firefox -X LICENSE.txt
	dh_install -p webext-ublock-origin-chromium -X LICENSE.txt

override_dh_auto_test:
	# Skip the tests

override_dh_auto_clean:
	./tools/make-clean.sh

override_dh_installchangelogs:
	dh_installchangelogs debian/upstream/changelog.html debian/upstream/changelog

.PHONY: get-orig-changelog
get-orig-changelog:
	amo-changelog -p rst ublock-origin
