#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

PACKAGE=gabedit
INSTALL=/usr/bin/install

GTKLIB        = `pkg-config --libs gtk+-2.0 gtkglext-1.0 pangox`
GTKCFLAGS     = `pkg-config --cflags gtk+-2.0 gtkglext-1.0 pangox`
OGLLIB        = -lGL -lGLU
OGLCFLAGS     = -I/usr/include
LIBPTHREAD    = -lpthread
OMPLIB        = -lgomp
OMPCFLAGS     = -DENABLE_OMP -fopenmp
DRAWGEOMGL    = -DDRAWGEOMGL

CC            = gcc -g
COMMONCFLAGS  = -Wall

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

COMMONCFLAGS += -DENABLE_DEPRECATED

LDFLAGS      += -Wl,--as-needed

build: build-stamp
build-stamp:
	dh_testdir
	$(MAKE) external_gl2ps=1 \
	        GTKLIB="$(GTKLIB)" \
		GTKCFLAGS="$(GTKCFLAGS)" \
		OGLLIB="$(OGLLIB)" \
	        OGLCFLAGS="$(OGLCFLAGS)" \
		LIBPTHREAD="$(LIBPTHREAD)" \
		OMPLIB="$(OMPLIB)" \
		OMPCFLAGS="$(OMPCFLAGS)" \
		DRAWGEOMGL="$(DRAWGEOMGL)" \
		COMMONCFLAGS="$(COMMONCFLAGS) $(OMPCFLAGS) $(DRAWGEOMGL)" \
		CC="$(CC)"
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	$(MAKE) clean
	dh_clean build-stamp

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	for size in 16 24 32 48 ; do \
		$(INSTALL) -m 644 icons/Gabedit$${size}.png \
		    $(CURDIR)/debian/$(PACKAGE)/usr/share/icons/hicolor/$${size}x$${size}/apps/gabedit.png ; \
	done

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	# fix permissions to be 0644
	chmod 644 $(CURDIR)/debian/$(PACKAGE)/usr/share/doc/$(PACKAGE)/examples/*
	dh_installman
	dh_installmenu
	dh_installmime
	dh_link
	dh_strip
	dh_compress $(CURDIR)/debian/$(PACKAGE)/usr/share/doc/$(PACKAGE)/examples/exampleGeoConv.gab
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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