# Makefile for
# - parser & tree-builder base modules
# - normalize   -- pretty-printer for HTML files
# - htmlclean	-- clean up HTML files
# - num		-- number H1-H6 headers
# - toc		-- create a ToC of H1-H6
# - count	-- count elements and attributes in a file
# - unent	-- replace entities by character itself (assumes UTF-8)
# - pipe	-- transform HTML or XML to nsgmls-like output
# - xml2asc	-- convert a UTF-8 stream to ASCII with &#nnn; entities
# - asc2xml	-- convert ASCII with &#nnn; entities to UTF-8
#
# Bert Bos <bert@w3.org>
# Created 8 May 1998
# $Id: Makefile,v 1.16 1998/12/18 02:32:12 bbos Exp $

# How to invoke flex
LEX = flex -Cfe
# How to invoke bison
YACC = bison -y
# Flags for bison
YFLAGS = -d
# How to invoke the C compiler
#CC = purify -cache-dir=$(HOME)/Tmp gcc
CC = gcc
# Flags for cc
CFLAGS = -g -Wall# -p -O2
# How to invoke the C preprocessor
CPP = gcc -E
# Libraries
LIBS = 
# Where to install the binaries
BINDIR = $(HOME)/bin

# No configuration needed below here


YACC_SRCS = html.y
LEX_SRCS = scan.l
GPERF_SRCS = dtd.hash unent.hash
COMM_HDRS = api.h export.h
C_SRCS = cexport.c types.c tree.c textwrap.c htmlclean.c num.c toc.c \
	normalize.c count.c pipe.c xmlrecode.c

SRCS = $(YACC_SRCS) $(LEX_SRCS) $(GPERF_SRCS) $(COMM_HDRS) $(C_SRCS)

GEN_SRCS = $(YACC_SRCS:.y=.c) $(LEX_SRCS:.l=.c) $(GPERF_SRCS:.hash=.c)
CFILES = $(C_SRCS) $(GEN_SRCS)
OBJS = $(CFILES:.c=.o)
HDRS = $(CFILES:.c=.e) $(YACC_SRCS:.y=.h)


APPLS = cexport htmlclean num toc normalize count pipe unent xml2asc asc2xml


VERSION := $(shell date +%d-%b-%Y)
PACKAGE = htmlutils-$(VERSION)


SUFFIX	      =	.c:sC .l:sC .y:sC .e:h .h:h
.SUFFIXES:	.e
.c.e: cexport;	./do_export $* $(CFLAGS) -c "$(CPP)"
.y.h:;	$(YACC) $(YFLAGS) $<; mv y.tab.c $*.c; mv y.tab.h $*.h
.y.c:;	$(YACC) $(YFLAGS) $<; mv y.tab.c $*.c; mv y.tab.h $*.h


all: $(APPLS)

install: all
	cp $(APPLS) $(BINDIR)

package: $(PACKAGE).tar.gz

clean:
	-rm -f $(APPLS)
	-rm -f $(OBJS)
	-rm -f $(PACKAGE).tar.gz
	-rm -f *~ *.bak core

veryclean: clean
	-rm -f $(HDRS)
	-rm -f $(GEN_SRCS)

depend: cexport $(SRCS) $(GEN_SRCS) $(HDRS)
	makedepend -- $(CFLAGS) -- $(SRCS)


asc2xml: xmlrecode.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

xml2asc: asc2xml
	ln $< $@

htmlclean: types.o tree.o dtd.o html.o scan.o htmlclean.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

num: types.o html.o scan.o num.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

toc: types.o html.o scan.o dtd.o tree.o toc.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

normalize: types.o html.o scan.o dtd.o tree.o textwrap.o normalize.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

count: types.o html.o scan.o count.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

pipe: types.o html.o scan.o pipe.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

unent: unent.o
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

dtd.c: dtd.hash
	gperf -a -c -C -o -t -p -T -k '1,2,$$' -N lookup_element $< >$@

unent.c: unent.hash
	gperf -a -c -C -o -t -p -k '1,2,$$' -D -N lookup_entity $< >$@

cexport: cexport.c
	$(CC) -O -o $@ $^

$(PACKAGE).tar.gz: depend Makefile do_export *.1 README*
	-rm -rf $(PACKAGE)
	mkdir $(PACKAGE)
	ln README* $(SRCS) $(GEN_SRCS) $(HDRS) Makefile do_export *.1 $(PACKAGE)
	tar cf - $(PACKAGE) | gzip >$@
	rm -rf $(PACKAGE)

$(HDRS):: cexport

# DO NOT DELETE

html.o: /usr/include/assert.h /usr/include/stdio.h
html.o: /usr/include/sys/feature_tests.h /usr/include/stdlib.h
html.o: /usr/include/ctype.h export.h types.e tree.e api.h
scan.o: /usr/include/assert.h /usr/include/string.h
scan.o: /usr/include/sys/feature_tests.h /usr/include/stdlib.h
scan.o: /usr/include/ctype.h export.h types.e html.h
dtd.o: /usr/include/string.h /usr/include/sys/feature_tests.h
dtd.o: /usr/include/stdlib.h /usr/include/assert.h export.h types.e
unent.o: /usr/include/string.h /usr/include/sys/feature_tests.h
unent.o: /usr/include/stdio.h /usr/include/ctype.h
cexport.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
cexport.o: /usr/include/string.h /usr/include/ctype.h /usr/include/stdlib.h
types.o: /usr/include/ctype.h /usr/include/sys/feature_tests.h export.h
tree.o: /usr/include/assert.h /usr/include/stdlib.h
tree.o: /usr/include/sys/feature_tests.h /usr/include/string.h
tree.o: /usr/include/stdio.h export.h types.e dtd.e
textwrap.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
textwrap.o: /usr/include/ctype.h /usr/include/assert.h export.h types.e
htmlclean.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h export.h
htmlclean.o: types.e tree.e html.e scan.e api.h
num.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
num.o: /usr/include/unistd.h /usr/include/sys/types.h
num.o: /usr/include/sys/isa_defs.h /usr/include/sys/machtypes.h
num.o: /usr/include/sys/select.h /usr/include/sys/time.h
num.o: /usr/include/sys/time.h /usr/include/sys/unistd.h /usr/include/ctype.h
num.o: /usr/include/string.h /usr/include/stdlib.h /usr/include/assert.h
num.o: export.h types.e html.e scan.e api.h
toc.o: /usr/include/assert.h /usr/include/ctype.h
toc.o: /usr/include/sys/feature_tests.h /usr/include/stdlib.h
toc.o: /usr/include/stdio.h /usr/include/sys/time.h /usr/include/string.h
toc.o: export.h types.e tree.e html.e scan.e
normalize.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
normalize.o: /usr/include/ctype.h /usr/include/stdlib.h /usr/include/unistd.h
normalize.o: /usr/include/sys/types.h /usr/include/sys/isa_defs.h
normalize.o: /usr/include/sys/machtypes.h /usr/include/sys/select.h
normalize.o: /usr/include/sys/time.h /usr/include/sys/time.h
normalize.o: /usr/include/sys/unistd.h /usr/include/assert.h export.h types.e
normalize.o: tree.e html.e scan.e api.h textwrap.e
count.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
count.o: /usr/include/unistd.h /usr/include/sys/types.h
count.o: /usr/include/sys/isa_defs.h /usr/include/sys/machtypes.h
count.o: /usr/include/sys/select.h /usr/include/sys/time.h
count.o: /usr/include/sys/time.h /usr/include/sys/unistd.h
count.o: /usr/include/ctype.h /usr/include/string.h /usr/include/stdlib.h
count.o: /usr/include/assert.h export.h types.e html.e scan.e api.h
pipe.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
pipe.o: /usr/include/unistd.h /usr/include/sys/types.h
pipe.o: /usr/include/sys/isa_defs.h /usr/include/sys/machtypes.h
pipe.o: /usr/include/sys/select.h /usr/include/sys/time.h
pipe.o: /usr/include/sys/time.h /usr/include/sys/unistd.h
pipe.o: /usr/include/ctype.h /usr/include/string.h /usr/include/stdlib.h
pipe.o: /usr/include/assert.h export.h types.e html.e scan.e api.h
xmlrecode.o: /usr/include/stdio.h /usr/include/sys/feature_tests.h
xmlrecode.o: /usr/include/string.h /usr/include/ctype.h
