#
#	Makefile for ss library
#
#	Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology
#    	Developed by the MIT Student Information Processing Board (SIPB).
#    	For copying information, see the file mit-copyright.h in this release.
SHELL=	/bin/sh
CC=	@CC@
INSTALL=@INSTALL@
LEX=	@LEX@
YACC=	@YACC@
RANLIB=	@RANLIB@
LEXLIB=	@LEXLIB@

DEFS=	@DEFS@
LIBS=	@LIBS@
DESTDIR=
BINDIR=
LIBDIR=
INCLUDES= -I. -I../include
ETDIR=../et/

# flags

CFLAGS=	-O

# for the library

LIB=	libss.a
COMERR=	-lcom_err

# with ss_err.o first, ../include/ss_err.h should get rebuilt first too.  shouldn't
# be relying on this, though.
OBJS=	ss_err.o \
	std_rqs.o \
	invocation.o help.o \
	execute_cmd.o listen.o parse.o error.o prompt.o \
	request_tbl.o list_rqs.o pager.o requests.o \
	data.o

SRCS=	invocation.c help.c \
	execute_cmd.c listen.c parse.c error.c prompt.c \
	request_tbl.c list_rqs.c pager.c requests.c \
	data.c

# for mk_cmds program

MKCMDSOBJS=	mk_cmds.o utils.o options.o ct.tab.o cmd_tbl.o

MKCMDSFILES=	mk_cmds.c utils.c options.c ct.y cmd_tbl.l

MKCMDSCSRCS=	mk_cmds.c utils.c options.c ct.tab.c cmd_tbl.c

# include files

HFILES= ss_internal.h copyright.h

# for 'tags' and dependencies

CFILES=	$(SRCS) $(MKCMDSCSRCS) test.c

# for building archives

FILES=	$(SRCS) $(MKCMDSFILES) $(HFILES) \
	std_rqs.ct Makefile.in \
	test.c commands.ct mit-sipb-copyright.h

#
# stuff to build
#

all:	libss.a mk_cmds

install: all
	${INSTALL} -c -s mk_cmds ${DESTDIR}/usr/athena/mk_cmds
	${INSTALL} -c libss.a ${DESTDIR}/usr/athena/lib/libss.a
	${RANLIB} ${DESTDIR}/usr/athena/lib/libss.a
	${INSTALL} -c libss.a ${DESTDIR}/usr/athena/lib/libss_p.a
	${RANLIB} ${DESTDIR}/usr/athena/lib/libss_p.a
	@rm -rf ${DESTDIR}/usr/include/ss
	@mkdir ${DESTDIR}/usr/include/ss
	cp copyright.h ${DESTDIR}/usr/include/ss/mit-sipb-copyright.h

tags:	TAGS

.SUFFIXES:	.ct

$(OBJS) : ../include/com_err.h

.c.o:
	${CC} -c ${CFLAGS} ${INCLUDES} ${DEFS} $*.c

std_rqs.c: mk_cmds std_rqs.ct
	./mk_cmds std_rqs.ct

ss_err.o: ss_err.c
	rm -f ss_err.o
	${CC} -O -c ss_err.c

ss_err.c: ../ets/ss_err.et
	../et/compile_et ../ets/ss_err.et; rm ss_err.h

ct.tab.c ct.tab.h: ct.y
	rm -f ct.tab.* y.*
	${YACC} -d ct.y
	mv -f y.tab.c ct.tab.c
	mv -f y.tab.h ct.tab.h

#
libss.a:	$(OBJS)
	rm -f $@
	ar cruv $@ $(OBJS)
	${RANLIB} $@

libss_p.a:	$(OBJS)
	rm -f $@
	cd profiled;ar cruv ../$@ $(OBJS)
	${RANLIB} $@

libss.o:	$(OBJS)
	ld -r -s -o $@ $(OBJS)
	chmod -x $@

mk_cmds:	$(MKCMDSOBJS)
	$(CC) $(CFLAGS) -o $@ $(MKCMDSOBJS) $(LEXLIB)

TAGS:	$(CFILES)
	-etags $(CFILES)

archives: ss.tar

ss.tar:	$(FILES)
	rm -f $@
	tar crf $@ $(FILES)

test:	test.o commands.o $(LIB)
	${CC} ${CFLAGS} -o test test.o commands.o $(LIB) $(COMERR)

commands.c: mk_cmds commands.ct
	./mk_cmds $*.ct

saber:	${SRCS} ss_err.o std_rqs.o
	saber ${SABEROPTS} ${SRCS} -I../et -G ss_err.o std_rqs.o -lcom_err

clean:	
	rm -f *.o *~ \#* *.bak core \
		../include/ss_err.h ct.tab.c ct.tab.h cmd_tbl.c \
		lex.yy.c y.tab.c \
		libss.a libss_p.a llib-lss.ln mk_cmds \
		ss.ar ss.tar \
		TAGS test

dist:	$(FILES)
	-mkdir ../../dist/source/ss
	cp -p ${FILES} ../../dist/source/ss/
	cp -p Makefile.in ../../dist/source/ss/

invocation.o : invocation.c ss_internal.h ../include/ss.h ../include/ss_err.h
help.o : help.c ss_internal.h ../include/ss.h ../include/ss_err.h
execute_cmd.o : execute_cmd.c ss_internal.h ../include/ss_err.h ../include/ss.h
listen.o : listen.c ss_internal.h ../include/ss.h ../include/ss_err.h
parse.o : parse.c ss_internal.h ../include/ss.h ../include/ss_err.h
error.o : error.c ss_internal.h ../include/ss.h ../include/ss_err.h ../include/com_err.h 
prompt.o : prompt.c ss_internal.h ../include/ss.h ../include/ss_err.h
request_tbl.o : request_tbl.c ss_internal.h ../include/ss.h ../include/ss_err.h 
list_rqs.o : list_rqs.c ss_internal.h ../include/ss.h ../include/ss_err.h
pager.o : pager.c ss_internal.h ../include/ss.h ../include/ss_err.h
requests.o : requests.c ss_internal.h ../include/ss.h ../include/ss_err.h
data.o : data.c ss_internal.h ../include/ss.h ../include/ss_err.h
mk_cmds.o : mk_cmds.c ss_internal.h ../include/ss.h ../include/ss_err.h
utils.o : utils.c ss_internal.h ../include/ss.h ../include/ss_err.h
options.o : options.c ss_internal.h ../include/ss.h ../include/ss_err.h
ct.tab.o : ct.tab.c ss_internal.h ../include/ss.h ../include/ss_err.h
cmd_tbl.o : cmd_tbl.c ss_internal.h ../include/ss.h ../include/ss_err.h
test.o : test.c ../include/ss.h ../include/ss_err.h 
