#!/usr/bin/make -f
# debian/rules file - for Symsolon
# 
# this file is derivated work on GNU hello rules file
#
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified
#

package = symsolon
docdir = debian/tmp/usr/share/doc/$(package)

CC = gcc
CFLAGS = -g -Wall
INSTALL_PROGRAM = install
QMAKE=qmake-qt4

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  INSTALL_PROGRAM += -s
endif

build:
	$(checkdir)
	$(QMAKE)
	$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)"
	touch build

clean:
	$(checkdir)
	rm -f build
	$(QMAKE)
	-$(MAKE) -i distclean
	rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

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

binary-arch:	checkroot build
	$(checkdir)
	rm -rf debian/tmp
	install -d debian/tmp/DEBIAN $(docdir)
	if [ -f debian/postinst ]; then install -m 755 debian/postinst debian/tmp/DEBIAN; fi
	if [ -f debian/prerm ]; then install -m 755 debian/prerm debian/tmp/DEBIAN; fi
	echo "run '$(QMAKE)' now again! -- to list the compiled file in INSTALLS variable!"
	$(QMAKE)
	$(MAKE) INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
		INSTALL_ROOT=$$(pwd)/debian/tmp/usr install
	if [ -d debian/tmp/usr/info ]; then  mv debian/tmp/usr/info debian/tmp/usr/share; fi
	if [ -d debian/tmp/usr/man ]; then  mv debian/tmp/usr/man debian/tmp/usr/share; fi
	if [ -f NEWS ]; then cp -a NEWS $(docdir); fi
	if [ -f debian/copyright ]; then cp -a debian/copyright $(docdir); fi
	if [ -f debian/changelog ]; then cp -a debian/changelog $(docdir)/changelog.Debian; fi
	if [ -f ChangeLog ]; then cp -a ChangeLog $(docdir)/changelog; fi
	if [ -f $(docdir)/changelog ]; then  gzip -9 $(docdir)/changelog; fi
	if [ -f $(docdir)/changelog.Debian ]; then  gzip -9 $(docdir)/changelog.Debian; fi
	if [ -d debian/tmp/usr/share/man ]; then gzip -r9 debian/tmp/usr/share/man; fi
	if [ -d debian/tmp/usr/share/info ]; then gzip -9 debian/tmp/usr/share/info/*; fi
	dpkg-shlibdeps debian/tmp/usr/bin/symsolon
	dpkg-gencontrol -isp
	chown -R root:root debian/tmp
	chmod -R u+w,go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f src/symsolon/main.cpp -a -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test $$(id -u) = 0

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