#!/usr/bin/make -f

STEM = leaflet-image

# generate documentation unless nodoc requested
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
DOCS = README.html README.txt
endif

%:
	dh $@

# optimize JavaScript for browser use
# * include source-map using upstream intermediary
debian/js/%.min.js: %.js
	mkdir --parents debian/js
	uglifyjs --compress --mangle \
		--in-source-map $<.map \
		--source-map $@.map \
		--output $@ -- $<

# pre-compress for browser use
%.gz: %
	pigz --force --keep -11 -- $<
	brotli --force --keep --best -- $<

%.html: %.md
	pandoc --from gfm-raw_html --to html --standalone \
		--metadata title:leaflet-image \
		--output $@ -- $<

%.txt: %.md
	pandoc --from gfm-raw_html --to plain \
		--output $@ -- $<

override_dh_auto_build: $(DOCS) \
 debian/js/$(STEM).min.js.gz

$(STEM).js: index.js
	webpack --config debian/webpack.config.js \
		--output-library leaflet-image \
		--output-filename $@ -- $<

override_dh_installdocs:
	dh_installdocs --all -- $(DOCS)

.SECONDARY:
