
# project name
PROJECT	= utempter
# major number of the .so lib
SOMAJOR = 0

SHAREDLIB = lib$(PROJECT).so
SONAME = $(SHAREDLIB).$(SOMAJOR)

CFLAGS = -Wall $(RPM_OPT_FLAGS)

VERSION=$(shell awk '/define version/ { print $$3 }' utempter.spec)
CVSTAG = r$(subst .,-,$(VERSION))

TARGETS = $(PROJECT) utmp $(SHAREDLIB)

all:	$(TARGETS)

clean:
	rm -f *.so utempter utmp *.os

%.os : %.c
	$(CC) -c $(CFLAGS) -fPIC $< -o $@

install:
	mkdir -p $(RPM_BUILD_ROOT)/usr/sbin
	mkdir -p $(RPM_BUILD_ROOT)/$(LIBDIR)
	mkdir -p $(RPM_BUILD_ROOT)/usr/include
	install -m 4755 utempter $(RPM_BUILD_ROOT)/usr/sbin
	install -m 644 utempter.h $(RPM_BUILD_ROOT)/usr/include
	install -m 644 $(SHAREDLIB) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB).$(VERSION)
	ln -sf $(SHAREDLIB).$(VERSION) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB)

$(SHAREDLIB): utmpintf.os
	$(CC) -o $@ -shared -Wl,-soname,$(SONAME) $^ -lc

utmpintf.o: utmpintf.c utempter.h

archive:
	cvs tag -F $(CVSTAG) .
	@rm -rf /tmp/utempter-$(VERSION) /tmp/utempter
	@cd /tmp; cvs export -r$(CVSTAG) utempter
	@mv /tmp/utempter /tmp/utempter-$(VERSION)
	@dir=$$PWD; cd /tmp; tar cvzf $$dir/utempter-$(VERSION).tar.gz utempter-$(VERSION)
	@rm -rf /tmp/utempter-$(VERSION)
	@echo "The archive is in utempter-$(VERSION).tar.gz"
