#
# Makefile for error-table routines
#
# Copyright 1987, 1989, 1991 MIT Student Information Processing Board
# For copyright info, see sipb-copying.h.
#
#	$Id: Makefile,v 1.18 1995/02/23 12:16:13 jik Exp $
#	$Locker:  $
#

# If your system doesn't have or need ranlib, then change it to "echo".
RANLIB= 	ranlib
# Change these if you want.
AR=		ar
LD=		ld
CC=		cc

# Uncomment this if your system claims to be mostly or completely POSIX-
# compliant.
POSIX_DEFINES=	-DPOSIX
# Uncomment this if you're on a mostly SYSV system.
SYSV_DEFINES=	-DSYSV
# If you need to add any extra #define's, add them here.
EXTRA_DEFINES=	

# Change this to indicate the level of debugging you want.
CFLAGS=		-O $(DEFINES)

# Change this to be the "lint" program on your system.  If you don't
# want to bother running lint over the libraries, then set it to
# "echo".  Include the arguments that lint requires on your system to
# build a lint library.
#LINT=		lint -uhvpb
LINT=		echo
# Change this to the argument that is used by lint to specify the name
# of the lint library to build.  If you changed LINT to "echo", then
# make this variable empty.
#LINTLIBFLAG=	-C

# If your system requires something other than the "l" library to be
# linked against lex object files, specify it here.  For example, if
# your system uses flex, then specify "-lfl".
LEXLIB=		-ll

# If you are planning on installing the library, then change these to
# where you want to install.  If you want the install to be rooted
# somewhere other than "/", then change DESTDIR to the root of the
# install.
BINDIR=		/usr/bin
INCDIR=		/usr/include
LIBDIR=		/usr/lib
DOCDIR=		/usr/doc
DESTDIR=

# ***
# Don't change anything below here unless you know what you're doing.
# ***

DEFINES=	$(POSIX_DEFINES) $(SYSV_DEFINES) $(EXTRA_DEFINES)
LINTFILES= 	error_msg.c et_name.c init_et.c com_err.c
LIBOBJS= 	error_msg.o et_name.o init_et.o com_err.o
CFILES=		com_err.c compile_et.c error_msg.c et_name.c\
		init_et.c strcasecmp.c test.c
HFILES=		com_err.h compiler.h error_table.h internal.h\
		sipb-copying.h 
MANS=		com_err.3 compile_et.1
YACCS=		error_table.y
LEXS=		et_lex.lex.l
ETS=		test1.et test2.et
FILES=		Makefile PATCHLEVEL README c_e.texinfo.Zu \
		$(CFILES) $(HFILES) $(MANS) $(YACCS) $(LEXS) $(ETS)


#
# what to build...
#
all:	compile_et libcom_err.a comerr.texinfo

lint:	llib-lcom_err.ln

archive:	et.tar

doc:	com_err.dvi

#
# rules
#
.SUFFIXES: .h .c .et .ps .x9700 .mss .dvi .texinfo

.et.c:
	./compile_et $*.et

.et.h:
	./compile_et $*.et

.texinfo.dvi:
	tex $<

.dvi.ps:
	rm -f $@.new
	dvi2ps -r $< > $@.new
	mv $@.new $@


#
# real entries...
#
compile_et:	compile_et.o error_table.o strcasecmp.o
	${CC} ${CFLAGS} -o compile_et compile_et.o error_table.o\
		strcasecmp.o $(LEXLIB)

tags:	TAGS

com_err.ps : com_err.dvi
com_err.dvi: comerr.texinfo

error_table.o: et_lex.lex.c

install: all
	install -c -s compile_et ${DESTDIR}${BINDIR}/compile_et
	install -c -m 444 com_err.h ${DESTDIR}${INCDIR}/com_err.h
	install -c -m 444 sipb-copying.h \
				${DESTDIR}${INCDIR}/sipb-copying.h
	install -c -m 444 libcom_err.a ${DESTDIR}${LIBDIR}/libcom_err.a
	${RANLIB} ${DESTDIR}${LIBDIR}/libcom_err.a
	install -c -m 444 comerr.texinfo ${DESTDIR}${DOCDIR}/comerr.texinfo
	install -c -m 444 com_err.3 ${DESTDIR}/usr/man/man3/com_err.3
	install -c -m 444 compile_et.1 ${DESTDIR}/usr/man/man1/compile_et.1

TAGS:	et_name.c error_msg.c compile_et.c error_table.c \
		lex.yy.c perror.c init_et.c
	etags et_name.c error_msg.c compile_et.c \
		error_table.c perror.c init_et.c

libcom_err.a:	$(LIBOBJS)
	${AR} cruv libcom_err.a $(LIBOBJS)
	${RANLIB} libcom_err.a

libcom_err.o:	$(LIBOBJS)
	${LD} -r -s -o libcom_err.o $(LIBOBJS)
	chmod -x libcom_err.o

llib-lcom_err.ln: $(LINTFILES)
	$(LINT) $(LINTLIBFLAG)com_err $(LINTFILES)

clean:
	rm -f *~ \#* *.bak \
		*.otl *.aux *.toc *.PS *.dvi *.x9700 *.ps \
		*.cp *.fn *.ky *.log *.pg *.tp *.vr \
		*.o libcom_err.a \
		com_err.o compile_et \
		et.ar TAGS y.tab.c lex.yy.c error_table.c \
		et_lex.lex.c \
		test1.h test1.c test2.h test2.c test \
		eddep makedep

patch: $(FILES)
	./makepatch $(FILES)
	mv patch com_err.patch`cat PATCHLEVEL`
	shar com_err.patch`cat PATCHLEVEL` > com_err.patch`cat PATCHLEVEL`.shar

shar: $(FILES)
	makekit -oMANIFEST $(FILES)

tar: $(FILES)
	tar cvf - $(FILES) | compress > com_err.tar.Z

comerr.texinfo: c_e.texinfo.Z
	-rm -f comerr.texinfo
	uncompress < c_e.texinfo.Z > comerr.texinfo

c_e.texinfo.Z: c_e.texinfo.Zu
	-rm -f c_e.texinfo.Z
	uudecode c_e.texinfo.Zu
	chmod +r c_e.texinfo.Z

# for testing
test:	test.o test1.o test2.o libcom_err.a
	${CC} ${CFLAGS} -o test test.o test1.o test2.o libcom_err.a
test.o:	test1.h test2.h
test1.o : test1.c
test1.c : test1.et
test2.o : test2.c
test2.c : test2.et
# 'make depend' code
depend: ${CFILES} et_lex.lex.c
	rm -f eddep makedep
	${CC} -M ${CFLAGS} ${CFILES} | \
	sed 's; ./; ;' | \
	sed -e ':loop' \
	    -e 's/\.\.\/[^ /]*\/\.\./../' \
	    -e 't loop' > makedep
# add a blank line so that if there are no dependencies, ed
# won't report an error (it does on some 
	echo "$$" > eddep
	echo "a" >> eddep
	echo "" >> eddep
	echo "." >> eddep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >> eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ed - Makefile < eddep
	rm eddep makedep
#
# the last line in the makefile should be...
# DO NOT DELETE THIS LINE -- make depend depends on it.
