#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/buildflags.mk
sgbdir=debian/sgb
sgbdocdir=debian/sgb-doc
fullsgbdir=$(CURDIR)/$(sgbdir)

%:
	dh $@


# We apply the PROTOTYPES to the package
execute_before_dh_auto_build:
	cp PROTOTYPES/*.ch .
	for i in gb_io gb_graph gb_gates; do mv $${i}.ch $${i}_proto.ch; done
	ctie -c gb_io.ch gb_io.w gb_io_proto.ch gb_io_headers.ch
	ctie -c gb_graph.ch gb_graph.w gb_graph_proto.ch gb_graph_headers.ch gb_graph-bigalloc.ch
	ctie -c gb_gates.ch gb_gates.w gb_gates_proto.ch gb_gates_printf.ch

override_dh_auto_build:
	$(MAKE) -f Makefile.debian CFLAGS='$(CFLAGS) -Wall -D_REENTRANT -I.' VERSION=$(DEB_VERSION_UPSTREAM) tests
	rm -f *.o
	$(MAKE) -f Makefile.debian CFLAGS='$(CFLAGS) -Wall -fPIC -D_REENTRANT -I.' VERSION=$(DEB_VERSION_UPSTREAM) sotests
	$(MAKE) -f Makefile.debian demos
	$(MAKE) -f Makefile.debian doc

override_dh_auto_clean:
	$(MAKE) -f Makefile.debian veryclean
	rm -f $$(cd PROTOTYPES && echo *.ch)
	rm -f gb_io_proto.ch gb_graph_proto.ch gb_gates_proto.ch

override_dh_auto_install-arch:
	$(MAKE) -f Makefile.debian install
	#  We make appropriate links for the dynamic library
	cd $(sgbdir)/usr/lib && mv libgb.so libgb.so.1.$(DEB_VERSION_UPSTREAM) && \
	  ln -s libgb.so.1.$(DEB_VERSION_UPSTREAM) libgb.so.1 && \
	  ln -s libgb.so.1.$(DEB_VERSION_UPSTREAM) libgb.so

override_dh_auto_install-indep:

execute_after_dh_installexamples-indep:
	mv $(sgbdocdir)/usr/share/doc/sgb/examples/Makefile.doc \
	  $(sgbdocdir)/usr/share/doc/sgb/examples/Makefile

override_dh_makeshlibs:
	dh_makeshlibs -a -V 'sgb (>= 1:20010107-2)'
