PREFIX=/usr/local

LIB_NAME = utmphelper
LIB_VERS = 1
LIB_FULL = lib$(LIB_NAME).so.$(LIB_VERS)
LIB_OBJS = utmp.o
PUTUTMP_NAME = pututmp
PUTUTMP_OBJS = pututmp.o
CFLAGS = -g -O2 -Wall -W -Werror -Wshadow -Wwrite-strings
CFLAGS += -Wbad-function-cast -Wcast-qual -Wcast-align
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
# CFLAGS += -Wconversion
PUTUTMP=$(PREFIX)/lib/$(PUTUTMP_NAME)
CPPFLAGS = -DPUTUTMP=\"$(PUTUTMP)\"

all: $(LIB_FULL) $(PUTUTMP_NAME)

clean: 
	rm -f ./*.o ./*.so*

dist-clean: clean
	rm -f $(PUTUTMP_NAME) ./*~ ./*% ./*.bak ./\#*\# core

install: all
	install -d $(PREFIX)/lib $(PREFIX)/include
	install -d $(PREFIX)/man/man3 $(PREFIX)/man/man8
	install -s -m 04755 $(PUTUTMP_NAME) $(PREFIX)/lib
	install -s $(LIB_FULL) $(PREFIX)/lib
	install pututmp.h $(PREFIX)/include
	install pututline_helper.3 $(PREFIX)/man/man3
	install pututmp.8 $(PREFIX)/man/man8
	ln -nsf $(LIB_FULL) $(PREFIX)/lib/lib$(LIB_NAME).so
	ldconfig

$(LIB_FULL): $(LIB_OBJS)
	$(LINK.c) -shared -o $@ $(LIB_OBJS)

$(PUTUTMP_NAME): $(PUTUTMP_OBJS)
	$(LINK.c) -o $@ $(PUTUTMP_OBJS)

pututmp.o: pututmp_internal.h
