# $Id: Makefile.in,v 1.2 2000/10/09 18:14:21 msw Exp $

srcdir=@srcdir@
VPATH=@srcdir@
prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
mandir=@mandir@

ARCH		= @ARCH@
CC		= @CC@
CFLAGS		= @CFLAGS@
LDFLAGS		= @LDFLAGS@
HOSTCC		= @HOSTCC@
HOSTCFLAGS	= @HOSTCFLAGS@
AR		= @AR@
RANLIB		= @RANLIB@
INSTALL		= @INSTALL_LOCAL@
STRIP		= @STRIP@

PARSERCFLAGS	= @PARSERCFLAGS@

DEFS = -I. -I$(srcdir) -I$(srcdir)/../include -D_GNU_SOURCE @DEFS@ $(EXTRA_DEFS)

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

######################################################################

all: genksyms

genksyms: genksyms.o parse.o lex.o ../util/libutil.a
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

parse.o: parse.c
	$(CC) $(CFLAGS) $(PARSERCFLAGS) $(DEFS) -c -o $@ $<

parse.c parse.h: parse.y
	@echo "expect 6 shift/reduce conflicts and 5 reduce/reduce conflicts."
	bison -o parse.c -dtv $^

lex.o: lex.c
	$(CC) $(CFLAGS) $(PARSERCFLAGS) $(DEFS) -c -o $@ $<

lex.c: lex.l parse.h
	flex -o$@ -d $^

crc32.tab: makecrc32.c
	$(HOSTCC) $(HOSTCFLAGS) -o makecrc32 $^
	./makecrc32 > $@.tmp
	mv $@.tmp $@

keywords.c: keywords.gperf
	gperf -a -C -E -g -H is_reserved_hash -k 1,3,$$ -N is_reserved_word -p -t $^ > $@.tmp
	mv $@.tmp $@

clean:
	rm -f *.o *.tmp parse.output genksyms makecrc32

realclean: clean
	rm -f .depend parse.c parse.h lex.c crc32.tab

	# rm -f keywords.c     gperf is not on all distributions

distclean: realclean
	rm -f Makefile

install install-bin: all
	$(INSTALL) $(STRIP) genksyms $(sbindir)

# auto-generated dependancies are almost redundant once we add all the
# rules to get the generated files built first.
dep depend:

genksyms.o: genksyms.c crc32.tab genksyms.h \
  $(srcdir)/../include/util.h $(srcdir)/../include/version.h
lex.o: lex.c keywords.c genksyms.h parse.c $(srcdir)/../include/util.h
parse.o: parse.c genksyms.h
