#!/usr/bin/make -f

VERSION := $(shell dpkg-parsechangelog|grep ^Version:|sed 's/^Version: //' | sed 's/-.*$$//g')
UPDATE_FILES := libcdcl-dev.links.in libcdcl5.install.in libcdcl5.links.in

export CFLAGS := $(shell dpkg-buildflags --get CFLAGS)
export CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)
# DPKG_EXPORT_BUILDFLAGS = 1
# include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_configure:
	for f in $(UPDATE_FILES) ; do \
	  cat $(CURDIR)/debian/$$f | sed 's/@CDCLVERSION@/$(VERSION)/g' \
	    > $(CURDIR)/debian/`basename $$f .in` ;\
	done
	dh_auto_configure -- --enable-shared --prefix=/usr

override_dh_auto_build:
	dh_auto_build

override_dh_auto_install:
	mkdir -p $(CURDIR)/debian/tmp
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr
	for f in `find $(CURDIR)/debian/tmp/usr/bin/ -type f ! -name "*dclps*" ! -name "cdclcc" ! -name "cdclconfig*"` ;do \
		chrpath -d $$f ;\
	done

override_dh_intall:
	dh_intall

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(CURDIR)/lib/libcdcl.so*
	for f in $(UPDATE_FILES) ; do \
	  rm -f $(CURDIR)/debian/`basename $$f .in` ;\
	done

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=libcdcl-dbg

override_dh_installchangelogs:
	dh_installchangelogs -k HISTORY

