SRCDIR= ../../..
include $(SRCDIR)/Makefile.global

MAJOR_VERSION=2
MINOR_VERSION=7
PATCHLEVEL=0

CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION) \
	-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
	-DINCLUDE_PATH=\"$(HEADERDIR)\" 

OBJS=preproc.o pgc.o type.o ecpg.o ecpg_keywords.o output.o\
    keywords.o c_keywords.o ../lib/typename.o descriptor.o variable.o

all:: ecpg

ifneq (@SNPRINTF@,)
OBJS+=$(SRCDIR)/backend/port/snprintf.o

$(SRCDIR)/backend/port/snprintf.o:
	$(MAKE) -C $(SRCDIR)/backend/port snprintf.o
endif

# Rule that really do something.
ecpg: $(OBJS)
	$(CC) -o ecpg $(OBJS) $(LEXLIB) $(LDFLAGS)

preproc.c preproc.h: preproc.y
	$(YACC) $(YFLAGS) $<
	mv y.tab.c preproc.c
	mv y.tab.h preproc.h

pgc.c: pgc.l
	$(LEX) $<
	mv lex.yy.c pgc.c

clean:
	rm -f *.o core a.out ecpg$(X) *~ *.output *.tab.c
# And the garbage that might have been left behind by partial build:
	rm -f y.tab.c y.tab.h lex.yy.c
# make clean does not remove preproc.c, preproc.h, pgc.c since we want
# to ship those files in the distribution, for people with inadequate tools.

install: all
	$(INSTALL) $(INSTL_EXE_OPTS) ecpg$(X) $(BINDIR)

uninstall:
	rm -f $(BINDIR)/ecpg

depend dep: preproc.c pgc.c
	$(CC) -MM $(CFLAGS) *.c >depend

ifeq (depend,$(wildcard depend))
include depend
endif
