#!/usr/bin/make -f
#
# rules for RSCDS
#

package=rscds
newname=davical
dt=debian/$(package)

build: inc htdocs debian
	$(checkdir)
	make
	touch build

clean:
	$(checkdir)
	make clean
	rm -f build
	-rm -rf $(dt) debian/files* core debian/substvars debian/html

binary-indep: checkroot build
	$(checkdir)
	-rm -rf $(dt)
	dh_clean -k
	# dh_installdebconf
	install -d $(dt) $(dt)/DEBIAN $(dt)/etc/$(newname) \
		$(dt)/usr/share/$(package) $(dt)/usr/share/doc/$(package)
	cp -a htdocs $(dt)/usr/share/$(package)
	cp -a dba $(dt)/usr/share/$(package)
	cp -a inc $(dt)/usr/share/$(package)
	cp -a locale $(dt)/usr/share/$(package)
	dh_installdocs
	# Install the sample configuration files into the docs/examples directory
	mkdir $(dt)/usr/share/doc/$(package)/examples
	cp config/example-config.php $(dt)/usr/share/doc/$(package)/examples/${newname}-conf.php
	cp config/example-administration.yml $(dt)/usr/share/doc/$(package)/examples/administration.yml
	cp config/debug-config.php $(dt)/usr/share/doc/$(package)/examples
	cp config/other-config.php $(dt)/usr/share/doc/$(package)/examples
	dh_installchangelogs
	dh_fixperms
	# install -m 1777 -d $(dt)/var/lib/$(package)/attachments
	dh_installdeb
	dpkg-gencontrol -P$(dt)
	dpkg --build $(dt) ..

binary-arch: checkroot build
	$(checkdir)
# There are no architecture-dependent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

define checkdir
	test -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot
