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
bindir=${exec_prefix}/bin

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

CPPFLAGS=@CPPFLAGS@
CFLAGS=@CFLAGS@
ALL_CFLAGS=${CFLAGS} -I${top_srcdir}/h -I${BUILDTOP}/h @X_CFLAGS@ ${CPPFLAGS}
LDFLAGS=-L${BUILDTOP}/lib @LDFLAGS@
LIBS=-lzephyr -lss -lreadline -lhistory -lcurses @LIBS@ -lcom_err

OBJS=	zctl.o zctl_cmds.o

all: zctl

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

zctl_cmds.c: zctl_cmds.ct
	mk_cmds ${srcdir}/zctl_cmds.ct

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

check:

install: zctl
	${INSTALL} -m 755 -s zctl ${DESTDIR}${bindir}
	${INSTALL} -m 644 ${srcdir}/zctl.1 ${DESTDIR}${mandir}/man1

clean:
	rm -f ${OBJS} zctl_cmds.c zctl

${OBJS}: ${top_srcdir}/h/sysdep.h ${BUILDTOP}/h/config.h
${OBJS}: ${BUILDTOP}/h/zephyr/zephyr.h ${BUILDTOP}/h/zephyr/zephyr_err.h

.PHONY: all check install clean

