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

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

# set some variables
ICONDIR=usr/share/icons
SHAREDIR=usr/share/crystalcursors
WRAPPERDIR=etc/X11/cursors

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	#docbook-to-man debian/crystalcursors.sgml > crystalcursors.1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	[ ! Makefile ] || $(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/crystalcursors.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/crystalcursors/$(ICONDIR)
	find $(CURDIR)/debian/crystalcursors/$(ICONDIR) -type f -exec chmod 644 {} \;
	find $(CURDIR)/debian/crystalcursors/$(ICONDIR) -type d -exec chmod 755 {} \;

	# Don't overwrite system's default xcursor, just provide the directory
	rm -r $(CURDIR)/debian/crystalcursors/$(ICONDIR)/default/*

	# Find *.theme and copy 'em to wrapper-location (see #365072)
	# We have to change the Inherits line in (only) in the wrapper *.themes:
	#  1) find .themes
	#  2) remove lines with "Inherits" and save as tmp
	#  3) write new Inherits-line with name of the directory in /usr/share/icons
	# -- I know this is tricky, but I have not yet found a more elegant way to make
	#    crystalcursors work with debian's update-alternative 
	OLDDIR=`pwd` ;\
	cd $(CURDIR)/debian/crystalcursors/$(ICONDIR); \
	for theme in crystal*; do \
	    grep -v Inherits $(CURDIR)/debian/crystalcursors/$(ICONDIR)/$${theme}/index.theme > tmp ; \
	    echo "Inherits = $${theme}" >> tmp ; \
	    install -m 644 tmp $(CURDIR)/debian/crystalcursors/$(WRAPPERDIR)/$${theme}.theme; \
	    rm tmp; \
	done ; \
	cd $${OLDDIR}

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGELOG
	dh_installdocs
#	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
#	dh_link
#	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
