#!/usr/bin/make -f

CC =gcc
CFLAGS =-W -Wall -Wshadow -O2 -g -ffile-prefix-map=$(CURDIR)=.
STRIP =strip
BGINCS =/usr/include/bglibs

ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  STRIP =: nostrip
endif

DIR =$(shell pwd)/debian/ucspi-proxy

patch: deb-checkdir patch-stamp
patch-stamp:
	for i in `ls -1 debian/diff/*.diff || :`; do \
	  patch -p1 <$$i || exit 1; \
	done
	touch patch-stamp

configure: deb-checkdir configure-stamp
configure-stamp: patch-stamp
	for i in conf-*; do \
	  test -e $${i%'{orig}'}'{orig}' || cp -v $$i $$i'{orig}'; \
	done
	echo '/usr/bin' >conf-bin
	echo '$(BGINCS)' >conf-bgincs
	echo '$(CC) $(CFLAGS)' >conf-cc
	echo '$(CC)' >conf-ld
	echo '/usr/share/man' >conf-man
	touch configure-stamp

build: deb-checkdir build-stamp
build-stamp: configure-stamp
	$(MAKE)
	touch build-stamp

clean: deb-checkdir deb-checkuid patch-stamp
	$(MAKE) clean
	for i in `ls *'{orig}' || :`; do mv -vf $$i $${i%'{orig}'}; done
	test ! -e patch-stamp || \
	  for i in `ls -1r debian/diff/*.diff || :`; do patch -p1 -R <$$i; done
	rm -f build-stamp configure-stamp patch-stamp
	rm -rf '$(DIR)'
	rm -f debian/files debian/substvars changelog

install: deb-checkdir deb-checkuid build-stamp
	rm -rf '$(DIR)'
	$(MAKE) install install_prefix='$(DIR)'
	$(STRIP) -R .comment -R .note '$(DIR)'/usr/bin/ucspi-proxy*
	gzip -9n '$(DIR)'/usr/share/man/man1/*.1
	chmod u=rwx,og=rx '$(DIR)' '$(DIR)/usr' '$(DIR)/usr/bin' '$(DIR)/usr/share' '$(DIR)/usr/share/man'
	test -r changelog || ln -s ChangeLog changelog

binary-indep:

binary-arch: deb-checkdir deb-checkuid install ucspi-proxy.deb
	dpkg-shlibdeps '$(DIR)'/usr/bin/*
	dpkg-gencontrol -isp -pucspi-proxy -P'$(DIR)'
	dpkg -b '$(DIR)' ..

binary: binary-indep binary-arch

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

include debian/implicit
