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

# Verbose mode
export DH_VERBOSE=1

# This should really not be necessary: make dh_ruby act like the rest
# of the debian build tools…
export DH_RUBY_USE_DH_AUTO_INSTALL_DESTDIR=1

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

override_dh_auto_build:
	# This should really not be necessary: create gem, extract metadata, remove gem…
	#   (dh_ruby will otherwise try to build everything in "ext/*")
	rake create_gem
	tar -O -x -f pkg/puppet-*.gem metadata.gz | gunzip -c > metadata.yml
	# This should really not be necessary: copy "sbin" binaries into "bin"…
	#   (dh_ruby does not support "sbindir", only "bindir")
	rake prepare_gem
	dh_auto_build -O--buildsystem=ruby

override_dh_installinit:
	dh_installinit -ppuppetmaster
	dh_installinit --name=puppetqd
	dh_installinit -ppuppet --error-handler=true -- defaults 21

override_dh_install:
	dh_install -O--buildsystem=ruby
	mv debian/puppetmaster-passenger/usr/share/puppetmaster-passenger/apache2.conf \
	  debian/puppetmaster-passenger/usr/share/puppetmaster-passenger/apache2.site.conf.tmpl
	# BEGIN 2.7.14 tarball: everything is executable
	chmod 644 debian/puppet-el/usr/share/emacs/site-lisp/puppet-mode.el
	chmod 644 debian/puppetmaster-common/etc/puppet/auth.conf
	chmod 644 debian/puppetmaster-passenger/usr/share/puppet/rack/puppetmasterd/config.ru
	chmod 644 debian/puppetmaster-passenger/usr/share/puppetmaster-passenger/apache2.site.conf.tmpl
	chmod 644 debian/vim-puppet/usr/share/vim/addons/ftdetect/puppet.vim
	chmod 644 debian/vim-puppet/usr/share/vim/addons/syntax/puppet.vim
	chmod 755 debian/puppet-common/etc/puppet/etckeeper-commit-post
	chmod 755 debian/puppet-common/etc/puppet/etckeeper-commit-pre
	# END 2.7.14 tarball: everything is executable

override_dh_installlogcheck:
	ln ext/logcheck/puppet debian/puppet-common.logcheck.ignore.server
	dh_installlogcheck -O--buildsystem=ruby

override_dh_installexamples:
	dh_installexamples -O--buildsystem=ruby
	find debian/puppet-common/usr/share/doc/puppet-common/examples -type f -print0 | \
	  xargs -r -0 chmod 644
