# $Id: Makefile,v 1.5 1995/10/12 20:26:28 connolly Exp $
#
# Makefile for Basic SGML scanner
#

PACKAGE = sgml-lex
RELEASE = 19951012

# Tools not included in this directory:
#
# Perl (tested with perl4.036 and perl5.001)
PERL = perl
# flex (tested with flex 2.4.7)
FLEX = flex
# rm
RM = rm
# Tar (gnu tar)
GNUTAR = tar

#
# Config options
#
CFLAGS = $(CDEBUGFLAGS) -Wall
# not too stable yet... @#
CDEBUGFLAGS = -g

LFLAGS=-p -s -t -8
# -p -> report performance statistics
# -s -> no "default rule"
# -t -> write to stdout rather than lex.yy.c
# -8 -> 8-bit clean scanner

OBJS = sgml_lex.o sgml_dumpevent.o
LIB = libsgml_lex.a
BUILD = *.o *.a sgml_lex
DERIVED = sgml.c sgml_lex_actions.c sgml_lex_tables.c test.expected lex-test.sgm

ORIGINALS = Makefile \
	sgml-lex.html \
	sgml.l \
	sgml_lex.h sgml_lex.c \
	sgml_dumpevent.c \
	grab-pre.pl excerpt.pl

PYTHON_SUPPORT=	sgml_lexmodule.c \
	sgmllib.py

# main target/product is sgml_lex library
$(LIB): sgml_lex.o sgml_dumpevent.o
	$(AR) cq $@ $(OBJS)


test: sgml_lex lex-test.sgm test.expected
	./sgml_lex <lex-test.sgm >test.output
	diff test.expected test.output

# Test driver
sgml_lex: main.o $(LIB)
	$(CC) -o $@ main.o $(LIB)

main.o: main.c sgml_lex.h

sgml_dumpevent.o: sgml_lex.h sgml_dumpevent.c

sgml_lex.o: sgml.c sgml_lex_actions.c sgml_lex_tables.c sgml_lex.h


#
# You shouldn't generally have to build these...
#
sgml.c: sgml.l
	$(FLEX) $(LFLAGS) sgml.l >$@ || rm $@

sgml_lex_tables.c: sgml.c excerpt.pl
	$(PERL) excerpt.pl tables sgml.c >$@ || rm $@

sgml_lex_actions.c: sgml.c excerpt.pl
	$(PERL) excerpt.pl actions sgml.c >$@ || rm $@

lex-test.sgm: sgml-lex.html grab-pre.pl
	$(PERL) grab-pre.pl sgml-lex.html >$@

test.expected: sgml_lex lex-test.sgm
	./sgml_lex <lex-test.sgm >test.expected

$(PACKAGE)-$(RELEASE).tar.gz: $(ORIGINALS) $(DERIVED)
	$(GNUTAR) czvf $@ $(ORIGINALS) $(DERIVED)

dist: $(PACKAGE)-$(RELEASE).tar.gz

clean:
	$(RM) -f $(BUILD) *~

clobber: clean
	$(RM) -f $(DERIVED)
