# Dynamic Host Configuration Client manager D-BUS Daemon

VERSION := $(shell awk '/Version:/ { print $$2 }' dhcdbd.spec)
RELEASE := $(shell awk '/Release:/ { print $$2 }' dhcdbd.spec | sed -e 's|%.*$$||g')

CVSROOT ?= ${CVSROOT:-$(shell cat CVS/Root 2>/dev/null)}
CVSTAG  = dhcdbd-$(subst .,_,$(VERSION)-$(RELEASE))

SRPMDIR = $(shell rpm --eval '%{_srcrpmdir}')

all: dhcdbd

dhcdbd:
	$(MAKE) -C src

clean:
	$(MAKE) -C src clean
	-rm -f *.tar.bz2

install: dhcdbd
	mkdir -p $(DESTDIR)/sbin
	mkdir -p $(DESTDIR)/usr/share/dbus-1/services
	mkdir -p $(DESTDIR)/etc/dbus-1/system.d
	install -m 0755 src/dhcdbd $(DESTDIR)/sbin/dhcdbd
	install -m 0644 dhcdbd.conf $(DESTDIR)/etc/dbus-1/system.d/dhcdbd.conf
	install -m 0644 dhcdbd.service $(DESTDIR)/usr/share/dbus-1/services/dhcdbd.service

tag:
	@cvs tag -cRF $(CVSTAG)
	@echo "Tagged as $(CVSTAG)"

archive: tar

tar: tag
	@rm -rf /tmp/dhcdbd
	@rm -rf /tmp/dhcdbd-$(VERSION)
	@tag=`cvs status Makefile|awk ' /Sticky Tag/ { print $$3 } '` 2>/dev/null;\
	[ x"$$tag" = x"(none)" ] && tag=HEAD; \
	[ x"$$TAG" != x ] && tag=$$TAG; \
	cvsroot=`cat CVS/Root` 2>/dev/null; \
	echo "*** Pulling off $$tag from $$cvsroot!"; \
	cd /tmp ; cvs -z3 -Q -d $$cvsroot export -r $$tag dhcdbd || echo "Um... export aborted."
	@mv /tmp/dhcdbd /tmp/dhcdbd-$(VERSION)
	@cd /tmp ; tar --bzip2 -cSpf dhcdbd-$(VERSION).tar.bz2 dhcdbd-$(VERSION)
	@rm -rf /tmp/dhcdbd-$(VERSION)
	@cp /tmp/dhcdbd-$(VERSION).tar.bz2 .
	@rm -f /tmp/dhcdbd-$(VERSION).tar.bz2
	@echo
	@echo "The final archive is in dhcdbd-$(VERSION).tar.bz2"

srpm: tar
	@rpmbuild -ts --nodeps dhcdbd-$(VERSION).tar.bz2 || exit 1
	@rm -f dhcdbd-$(VERSION).tar.bz2

build: src
	@rm -rf /tmp/dhcdbd
	@mkdir /tmp/dhcdbd
	cd /tmp/dhcdbd ; cvs co common ; cd common ; ./cvs-import.sh $(SRPMDIR)/dhcdbd-$(VERSION)-$(RELEASE).src.rpm
	@rm -rf /tmp/dhcdbd
	brew build $(COLLECTION) 'cvs://cvs.devel.redhat.com/cvs/dist?devel/dhcdbd#$(CVSTAG)'
