#!/usr/bin/make -f

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

# These definitions can be removed once #842092 is fixed
debRreposname   := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}' | sed 's/r-\([a-z]\+\)-.*/\1/')
awkString       := "'/^(Package|Bundle):/ {print $$2 }'"
cranNameOrig    := $(shell awk "$(awkString)" DESCRIPTION)
cranName        := $(shell echo "$(cranNameOrig)" | tr A-Z a-z)
package         := r-$(debRreposname)-$(cranName)
debRdir         := usr/lib/R/site-library
debRlib         := $(CURDIR)/debian/$(package)/$(debRdir)

%:
	dh $@ --buildsystem R

override_dh_install:
	dh_install
	echo DEBUG rm -vf $(debRlib)/$(cranNameOrig)/NEWS
	rm -vf $(debRlib)/$(cranNameOrig)/NEWS
	# sed -i 's/#include "yaml.h"/#include <yaml.h>/' src/r-ext.h
	# FIXME no match?
	# grep -v --fixed-strings -e '  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>' -e '  <script src="http://yihui.name/knitr/js/docco-resize.js"></script>' $(debRlib)/$(cranNameOrig)/doc/highr-internals.html > $(debRlib)/$(cranNameOrig)/doc/highr-internals.html,
	# grep -v --fixed-strings -e '  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>' $(debRlib)/$(cranNameOrig)/doc/highr-internals.html >$(debRlib)/$(cranNameOrig)/doc/highr-internals.html,
	grep -v --fixed-strings -e '  <script src=\"https://code.jquery.com/jquery-2.1.1.min.js\"></script>' $(debRlib)/$(cranNameOrig)/doc/highr-internals.html >$(debRlib)/$(cranNameOrig)/doc/highr-internals.html,
	mv $(debRlib)/$(cranNameOrig)/doc/highr-internals.html, $(debRlib)/$(cranNameOrig)/doc/highr-internals.html

# --line-regexp
#     usr/lib/R/site-library/highr/doc/highr-internals.html You may use
#      libjs-jquery package. (https://code.jquery.com/jquery-2.1.1.min.js)
#    inst/doc/highr-custom.html , highr-internals.html :
#     <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
#     <script src="http://yihui.name/knitr/js/docco-resize.js"></script>
