#!/usr/bin/make -f

export DH_RUBY_GEMSPEC = debian/backports.gemspec
export DH_RUBY_IGNORE_TESTS = ruby2.3

%:
	dh $@ --buildsystem=ruby --with ruby

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.rdoc -O--buildsystem=ruby

override_dh_auto_configure:
	dh_auto_configure -O--buildsystem=ruby
	ruby -Ilib -e ' \
		require "backports/version"; \
		spec = Gem::Specification.load(ENV["DH_RUBY_GEMSPEC"]); \
		if spec.version.to_s != Backports::VERSION; \
			$$stderr.puts "Static gemspec is outdated. Run: debian/rules clean"; \
			exit 1; \
		end \
		'

override_dh_clean:
	dh_clean -O--buildsystem=ruby
	# Let's create a static version of the gemspec as we don't build with git
	if [ -d .git ]; then \
		ruby -rrubygems -e ' \
			spec = Gem::Specification.load("backports.gemspec"); \
			spec.files.delete_if { |p| p.start_with? "debian/" }; \
			File.write(ENV["DH_RUBY_GEMSPEC"], spec.to_ruby); \
			'; \
	fi
