#!/usr/bin/make -f

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

CC=gcc
ifneq (,$(findstring diet,$(DEB_BUILD_OPTIONS)))
  CC =diet -v -Os gcc -nostdinc
endif

DIR =$(shell pwd)/debian/freecdb

build: deb-checkdir build-stamp
build-stamp: 
	$(MAKE) CC='$(CC)'
	$(MAKE) check
	touch build-stamp

clean: deb-checkdir deb-checkuid
	$(MAKE) clean
	rm -f build-stamp
	rm -rf '$(DIR)'
	rm -f debian/files debian/substvars

install: deb-checkdir deb-checkuid build-stamp
	rm -rf '$(DIR)'
	install -d -m0755 '$(DIR)'/usr/bin
	install -m0755 cdbdump cdbget cdbmake cdbstats '$(DIR)'/usr/bin/
	$(STRIP) -R .comment -R .note '$(DIR)'/usr/bin/*
	# man pages
	install -d -m0755 '$(DIR)'/usr/share/man/man1
	install -m0644 cdbdump.1 cdbget.1 cdbmake.1 cdbstats.1 \
	  '$(DIR)'/usr/share/man/man1/
	gzip -9 '$(DIR)'/usr/share/man/man1/*.1

binary-indep:

binary-arch: install freecdb.deb
	test '$(CC)' != 'gcc' || dpkg-shlibdeps '$(DIR)'/usr/bin/*
	dpkg-gencontrol -isp -pfreecdb -P'$(DIR)'
	dpkg -b '$(DIR)' ..

binary: binary-indep binary-arch

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

include debian/implicit
