#!/usr/bin/make -f

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O2 -g -Wall
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_testdir
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess config.guess
	./configure --disable-shared --enable-static \
	  --disable-xyconvert --host=$(DEB_HOST_GNU_TYPE) \
	  --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr \
	  --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info


build: build-stamp

build-stamp:  config.status
	dh_testdir
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 
	-rm -f config.sub config.guess
	[ ! -f Makefile ] || $(MAKE) distclean


	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/fityk.
	$(MAKE) install prefix=$(CURDIR)/debian/fityk/usr
	mkdir -p $(CURDIR)/debian/fityk/usr/share/pixmaps
	cp src/wxgui/img/fityk.xpm $(CURDIR)/debian/fityk/usr/share/pixmaps/
	dh_install fityk.desktop usr/share/applications/
	# Move samples into documentation directory.  Since the shared
	# libraries are not built, do not install the C, lua and python
	# test scripts.  If libfityk is built as a standalone library
	# then the scripts should be installed.
	cp samples/*.dat $(CURDIR)/debian/fityk/usr/share/doc/fityk/samples/
	cp samples/*.fit $(CURDIR)/debian/fityk/usr/share/doc/fityk/samples/
	cp samples/README $(CURDIR)/debian/fityk/usr/share/doc/fityk/samples/
#	Remove static libraries and headers for now
	rm -rf $(CURDIR)/debian/fityk/usr/lib
	rm -rf $(CURDIR)/debian/fityk/usr/include
#	Remove jquery.js and use the Debian packages instead
	rm -rf $(CURDIR)/debian/fityk/usr/share/fityk/html/_static/jquery.js

# 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_installdocs
	dh_installexamples
	dh_installmenu
	dh_installman
	dh_installinfo
	dh_installchangelogs NEWS
	dh_link
	dh_strip
	dh_compress --exclude=.dat --exclude=.fit
	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 
