SHELL = /bin/sh

prefix=@prefix@
exec_prefix=@exec_prefix@
datadir=@datadir@
sysconfdir=@sysconfdir@
sbindir=@sbindir@
lsbindir=@lsbindir@

includedir=${prefix}/include
mandir=${prefix}/man
libdir=${exec_prefix}/lib

srcdir=@srcdir@
top_srcdir=@top_srcdir@
BUILDTOP=..
VPATH=@srcdir@
CC=@CC@
INSTALL=@INSTALL@

CPPFLAGS=@CPPFLAGS@
CFLAGS=@CFLAGS@
ALL_CFLAGS=${CFLAGS} -DSYSCONFDIR=\"${sysconfdir}\" -I${top_srcdir}/h \
	-I${BUILDTOP}/h -I. ${CPPFLAGS}
LDFLAGS=-L${BUILDTOP}/lib @LDFLAGS@
LIBS=-lzephyr @LIBS@ -lcom_err

OBJS=	zsrv_err.o access.o acl_files.o bdump.o class.o client.o common.o \
	dispatch.o kopt.o kstuff.o main.o server.o subscr.o timer.o uloc.o \
	zstring.o realm.o version.o

all: zephyrd

zephyrd: ${OBJS} ${BUILDTOP}/lib/libzephyr.a
	${CC} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}

zsrv_err.c zsrv_err.h: zsrv_err.et
	compile_et ${srcdir}/zsrv_err.et

version.o: version.h

version.h: always
	sh ${srcdir}/new_vers.sh

.c.o:
	${CC} -c ${ALL_CFLAGS} $<

check:

# No dependency on zephyrd, to avoid rebuilding version.o.
install:
	${INSTALL} -m 755 -s zephyrd ${DESTDIR}${sbindir}
	${INSTALL} -m 644 ${srcdir}/zephyrd.8 ${DESTDIR}${mandir}/man8
	${INSTALL} -m 644 ${srcdir}/default.subscriptions \
		${DESTDIR}${sysconfdir}/zephyr

clean:
	rm -f ${OBJS} zephyrd zsrv_err.[ch]

always:

${OBJS}: zserver.h zsrv_err.h timer.h zsrv_conf.h zstring.h access.h acl.h
${OBJS}: ${top_srcdir}/h/internal.h ${top_srcdir}/h/sysdep.h
${OBJS}: ${BUILDTOP}/h/config.h ${BUILDTOP}/h/zephyr/zephyr.h
${OBJS}: ${BUILDTOP}/h/zephyr/zephyr_err.h

.PHONY: all check install clean always

