PROG=		dumpdesc
SRCDIR=		${PICOPB_TOP}/test/dumpdesc

SRCS+=		descriptor.pb.c
SRCS+=		main.c
SRCS+=		pb_dump.c

CLEANFILES+=	descriptor.pb.c
CLEANFILES+=	descriptor.pb.h

CPPFLAGS+=	-I${SRCDIR}
CPPFLAGS+=	-I${.OBJDIR}
CPPFLAGS+=	-I${PICOPB_TOP}/lib/libpicopb

LDADD+=		${LIBPICOPB}
DPADD+=		${LIBPICOPB}

WARNS=		6

MKMAN=		no
MKLINT=		no

.include <bsd.prog.mk>

.PHONY: regress
regress: check-pb
regress: check-txt

CLEANFILES+=	descriptor.pb
check-pb: .PHONY descriptor.pb descriptor.pb-good
	cmp ${.ALLSRC}

CLEANFILES+=	descriptor.txt
check-txt: .PHONY descriptor.txt descriptor.txt-good
	diff -u ${.ALLSRC}

.SUFFIXES: .pb
.SUFFIXES: .pb-good
.SUFFIXES: .pb.c
.SUFFIXES: .pb.h
.SUFFIXES: .proto
.SUFFIXES: .txt
.SUFFIXES: .txt-good

# XXX Some explicit dependencies are necessary to get things moving...
main.d: descriptor.pb.h
descriptor.pb.c: descriptor.proto
descriptor.pb.d: descriptor.pb.h

.proto.pb.c: ${PICOPBC}
	${PICOPBC} -c $@.tmp -H $*.pb.h $< && mv -f $@.tmp $@
.proto.pb.h: ${PICOPBC}
	${PICOPBC} -h $@.tmp -G $*.pb.h $< && mv -f $@.tmp $@

# XXX If ${PROG} is in ${.CURDIR} rather than in ${.OBJDIR}, this won't
# get the right pathname.  ${.ALLSRC} contains the right pathname, but
# it also contains the implied source, not just ${PROG}.  What to do?
# Actually, ${.ALLSRC} doesn't contain the right pathname: we need to
# use ./ if there is no separate objdir, since . won't be in $PATH.
# For now, we'll just assume nobody tries to build with a separate
# objdir and then run tests with no separate objdir, and work out the
# story with cross-compiling and running tests on the target later.
.pb-good.txt: ${PROG}
	${.OBJDIR}/${PROG} -t < $< > $@.tmp && mv -f $@.tmp $@
.pb-good.pb: ${PROG}
	${.OBJDIR}/${PROG} -b < $< > $@.tmp && mv -f $@.tmp $@

.PATH: ${SRCDIR}
