# Makefile 
# dbwilson 2/20/90
##########################################
.SUFFIXES: .o .cc .c .yacc .lex
VPATH = /usr/tmp
MACHINE = vax
ROOT = /mit/cdsdev/beta
LIBDIR = -L. -L/usr/athena/lib -L${ROOT}/${MACHINE}lib

LIBS = -lcds -ly -ll \
 ${ROOT}/${MACHINE}lib/ResInd.o \
 ${ROOT}/${MACHINE}lib/TextPlot.o \
 ${ROOT}/${MACHINE}lib/Axis.o \
 -lAt -lCm -lXm -lXt -lX11 -lm

LIBDIR = $(ROOT)/src.lib
INCLUDE = -I. -I/usr/athena/include -I${ROOT}/include/cur \
 $(LIBDIR) $(LIBDIR)/expect $(LIBDIR)/vimage

INCLUDE++ =  -I/mit/gnu/lib/g++-include
MAIN = ${ROOT}/main/main.cc
OBJECTS = *.o
DEVLIB = libcds.a
VER=btest
DBG_DEFS = -DDEBUG -DDEV -g -O -Wall -DVER=\"${VER}\"
THIS_MAKEFILE = Makefile
SRC = `ls|egrep '\.cc$$|\.yacc$$'`
CC = gcc
CPLUS = g++

cds:${OBJECTS}
	${CPLUS} ${DBG_DEFS} ${OBJECTS} -DMAIN=$@_main ${MAIN} ${LIBDIR} ${LIBS} -o /usr/tmp/$@
	@echo ""
	@echo "finished compiling /usr/tmp/cds"
	chmod 777 /usr/tmp/cds
echo:
	@echo ${OBJECTS}

attach:
	attach x11 motifdev gnu atdev motif

devlib: ${OBJECTS}
	cp ${ROOT}/${MACHINE}lib/libcds.a ${DEVLIB}
	ar urv ${DEVLIB} ${OBJECTS}
	ranlib ${DEVLIB}

objs:
	@for file in *.cc; do \
	if [ -f $$file ]; then \
	make `basename $$file .cc`.o; \
	fi; \
	done

.cc.o:
	${CPLUS} -c ${DBG_DEFS} ${INCLUDE} ${INCLUDE++} $*.cc -o $@

.c.o:
	${CC} -c ${DBG_DEFS} ${INCLUDE} $*.c -o $@

.yacc.o:
	yacc $*.yacc
	lex $*.lex
	rm -f $*.cc yy.tmp lex.tmp
	cat y.tab.c | \
	sed -e "s/yyparse() {/int "$*"::yyparse() {/g" \
	    -e "s/# define YYLMAX 200/# define YYLMAX 20000/g"\
	    -e "s/char yytext\[YYLMAX\];//g"\
	    -e "s/extern short yyerrflag;//g" \
	    -e "s/extern int yychar;//g" \
	    -e "s/extern int yyprevious;/static int yyprevious/g" \
	    -e "s/short yyexca/static short yyexca/g" \
	    -e "s/short yyact/static const short yyact/g" \
	    -e "s/short yypact/static const short yypact/g" \
	    -e "s/short yypgo/static const short yypgo/g" \
	    -e "s/short yyr1/static const short yyr1/g" \
	    -e "s/short yyr2/static const short yyr2/g" \
	    -e "s/short yychk/static const short yychk/g" \
	    -e "s/short yydef/static const short yydef/g" \
	    -e "s/int yychar = -1;//g" \
	    -e "s/int yynerrs = 0;//g" \
	    -e "s/short yyerrflag = 0;//g" > yy.tmp

	cat lex.yy.c | \
	sed -e "s/yylex(){/int "$*"::yylex() {/g"\
	    -e "s/# define YYLMAX 200/# define YYLMAX 20000/g"\
	    -e "s/char yytext\[YYLMAX\];//g"\
	    -e "s/int yyvstop\[\]/static int yyvstop\[\]/g" \
	    -e "s/yysvec/"$*"yysvec/g" \
	    -e "s/yybgin/"$*"yybgin/g" \
	    -e "s/struct yywork \*yytop =/static struct yywork \*yytop =/g" \
	    -e "s/int yyleng;//g" \
	    -e "s/int yymorfg;//g" \
            -e "s/int yylineno =1;//g" \
	    -e "s/int yytchar;//g" \
	    -e "s/char yysbuf\[YYLMAX\];//g" \
	    -e "s/char \*yysptr = yysbuf;//g" \
	    -e "s/extern char \*yysptr, yysbuf\[\];//g"\
	    -e "s/extern int yyprevious;/static int yyprevious;/g" \
	    -e "s/int yyprevious =/static int yyprevious =/g" \
	    -e "s/extern char yytext\[\]//g" \
 	    -e "s/yylook(){/int "$*"::yylook(){/g" \
	    -e "s/struct yywork {/static struct yywork {/g" \
	    -e "s/char yymatch/static char yymatch/g" \
	    -e "s/char yyextra/static char yyextra/g" \
	    -e "/yyback(p\, m)/,/unput(c);\n}/ d" > lex.tmp

	cat yy.tmp lex.tmp | \
	sed -e "s/FILE \*yyin ={stdin}, \*yyout ={stdout};//g" \
            -e "s/extern int yylineno;//g" \
		> $*.cc
	rm -f y.tab.c lex.yy.c yy.tmp lex.tmp

	${CPLUS} -c ${DBG_DEFS} ${INCLUDE} ${INCLUDE++} $*.cc -o $@
	rm -f $*.cc


lint:
	lint ${DBG_DEFS} ${INCLUDE} ${SRC}
# stingy old makedepend only allows you ONE kind of suffix to enter with
# the -o flag.  
#
# rip the prev dep list, if any, off the end of this makefile
# and append the special makedepend string
# generate a dep list with .o endings for the object files
# repeatedly filter .o -> .{suffix} to create other 4 
# dependency lists, catting each onto this makefile
depend:
	@echo ${SRC}
	@echo FIGURING DEPENDENCIES `pwd`
	@makedepend -s"# BEGINNING OF DEPENDENCY SECTION "
	@rm -f dep_o
	@echo > dep_o
	@makedepend ${INCLUDE} ${INCLUDE++} -s"# # # # # # #" -fdep_o  ${SRC}
	@echo ADDING DEPENDENCIES `pwd`
	@cat dep_o >> ${THIS_MAKEFILE}
	@rm dep_o dep_o.bak ${THIS_MAKEFILE}.bak
	@echo DONE DEPENDING `pwd`

saber:
	# load ${MAIN} ${INCLUDE} ${INCLUDE++} ${MY_SRC}  ${LIBDIR} ${LIBS}

saber_dbg:
	# load ${MAIN} ${INCLUDE} ${MY_SRC}  ${LIBDIR} ${DBGLIBS}

# BEGINNING OF DEPENDENCY SECTION 

# # # # # # #
