# 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')

TAG = 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:
	@git tag $(TAG)
	@echo "Tagged as $(TAG)"

archive: tag
	@git checkout -b dhcdbd-$(VERSION) $(TAG)
	@git checkout -f dhcdbd-$(VERSION)
	@rm -rf dhcdbd-$(VERSION)
	@mkdir -p dhcdbd-$(VERSION)
	@cp -a COPYING ChangeLog Makefile README TODO dhcdbd.conf dhcdbd.init \
		dhcdbd.service dhcdbd.spec include src dhcdbd-$(VERSION)
	@tar --bzip2 -cSpf dhcdbd-$(VERSION).tar.bz2 dhcdbd-$(VERSION)
	@rm -rf dhcdbd-$(VERSION)
	@git checkout -f master
	@echo
	@echo "The final archive is in dhcdbd-$(VERSION).tar.bz2"
