#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_GOPKG := github.com/google/cadvisor

%:
	dh $@ --buildsystem=golang --with=golang --builddirectory=_build

STATIC_PAGES = \
    pages/static/jquery_min_js.go  \
    pages/static/bootstrap_min_js.go  \
    pages/static/bootstrap_min_css.go    \
    pages/static/bootstrap_theme_min_css.go \

override_dh_clean:
	dh_clean $(STATIC_PAGES)
	## Remove Files-Excluded (when built from checkout or non-DFSG tarball):
	$(RM) -rv `perl -0nE 'say $$1 if m{^Files\-Excluded\:\s*(.*?)(?:\n\n|Files:|Comment:)}sm;' debian/copyright`

override_dh_auto_configure:
	build/assets.sh
	mkdir _build
	if [ -e vendor ]; then \
	  cp -r vendor _build/; \
	fi
	dh_auto_configure

override_dh_auto_test:
	## Tests want `sudo`, disable tests:
	@

override_dh_auto_install:
	dh_auto_install
	## executable-not-elf-or-script:
	chmod -c -R -x+X $(CURDIR)/debian/tmp/usr/share/gocode/src/$(DH_GOPKG)

## STATIC_PAGES: https://github.com/google/cadvisor/issues/879
pages/static/bootstrap_min_css.go:
	printf "package static\n\n" > $@
	printf "const bootstrapCss = \`\n" >>$@
	cat debian/missing-sources/bootstrap.css >>$@
	#cat /usr/share/javascript/bootstrap/css/bootstrap.css >>$@
	printf "\`\n" >>$@

pages/static/bootstrap_theme_min_css.go:
	printf "package static\n\n" > $@
	printf "const bootstrapThemeCss = \`\n" >>$@
	cat debian/missing-sources/bootstrap-theme.css >>$@
	#cat /usr/share/javascript/bootstrap/css/bootstrap-theme.css >>$@
	printf "\`\n" >>$@

pages/static/bootstrap_min_js.go:
	printf "package static\n\n" > $@
	printf "const bootstrapJs = \`\n" >>$@
	cat debian/missing-sources/bootstrap.min.js >>$@
	#cat /usr/share/javascript/bootstrap/js/bootstrap.min.js >>$@
	printf "\`\n" >>$@

pages/static/jquery_min_js.go:
	printf "package static\n\n" > $@
	printf "const jqueryJs = \`\n" >>$@
	cat /usr/share/javascript/jquery/jquery.min.js >>$@
	printf "\`\n" >>$@

