# SccsId = "@(#)Makefile 4.7 (TU-Delft) 07/27/92"
########################################################################
## the env vars
## CACDSRCHOME  path to cacdsrc home
## NELSISHOME   path to nelsis home
## ARCHITECTURE
## HOSTNAME
## defined automagically
## IF etdisrc entered correctly e.g set home=~cacdsrc;newgrp etdisrc

## ARCHITECTURE DEPENDENT DEFINES ############################################
CONFIGDIR=$(CACDSRCHOME)/CONFIG
include $(CONFIGDIR)/M.$(ARCHITECTURE)

SHELL=/bin/sh

#ICDPATH        =       $(NELSISHOME)
ICDPATH         =       $(CACDSRCHOME)/DEVWSPC/$(ARCHITECTURE)

BIN= $(ICDPATH)/bin
LIB= $(ICDPATH)/lib
LIBPROC= $(LIB)/process
LIBINCL= $(LIB)/include
# ESE = -DESE

OCFLAGS=
DFLAGS= -D$(OSTYPE) 
IFLAGS= -I$(LIBINCL)
# For NCF_RELEASE >= 400, use -DFUNCVIEW with cpp !
# Unfortunately, we cannot switch in the code on NCF_RELEASE
# since the C pre-processor does not include 'dmi(ncl).h' due to -DNOSYSINCL
CPP_FLAGS= -DNOSYSINCL $(DFLAGS) $(ESE) $(IFLAGS)
CFLAGS= $(OCFLAGS) $(DFLAGS) $(ESE) $(IFLAGS)
LDFLAGS= 
OLIBS= -ll -lm -ll
YFLAGS= -d
CPP = cpre.cpp

DMLIB= $(LIB)/libddm.a 
ESELIB=$(LIB)/libese.a
FMTLIBS=$(LIB)/libcirfmt.a

TARGET=csls
TARGET_OLD=sls_mkdb
TARGETB=putspice
ESETARGET=eseputsls
ESETARGETB=eseputspice

# Some of the source files are .cls files.  These files must be
# converted to .c files by means of a class pre-processor (cpre).
# When all .c files are available and up to date, but 'make' wants 
# to run the pre-processor though (e.g. because all file dates are equal),
# you should first execute :  $ make doTouch (see below)

SRCL= lex.l spilex.l
SRCY= parse.y spipar.y
SRC0= dict.h mkdbincl.h mkdbdefs.h netelem.h ntwdefs.h odb.h\
      queue.h slserr.h stack.h xelem.h sys_incl.h
SRC1= sig_init.c dbopen.c dbaccess.c
SRC2= main.cls neteqv.cls init_ntw.cls class.cls simple.cls\
      end_ntw.cls to_db.cls slserr.cls util.cls bifunc.cls dffunc.cls
SRC3= diction.cls queue.cls stack.cls ntwdefs.cls netelem.cls xelem.cls
SRCS= $(SRCL) $(SRCY) $(SRC0) $(SRC1) $(SRC2) $(SRC3)

CSRCL= lex.c spilex.c
CSRCY= parse.c spipar.c
CSRC2= main.c main.sp.c neteqv.c init_ntw.c class.c simple.c\
       end_ntw.c to_db.c slserr.c util.c bifunc.c dffunc.c
CSRCS= $(CSRCL) $(CSRCY) $(SRC1) $(CSRC2)

OBJ1= sig_init.o dbopen.o dbaccess.o
OBJ2= neteqv.o init_ntw.o class.o simple.o\
      end_ntw.o to_db.o slserr.o util.o bifunc.o dffunc.o
OBJ3= lex.o
OBJ4= parse.o main.o
OBJS= $(OBJ1) $(OBJ2) $(OBJ3) $(OBJ4)

OBJ3B= spilex.o
OBJ4B= spipar.o main.sp.o
OBJSB= $(OBJ1) $(OBJ2) $(OBJ3B) $(OBJ4B)

.SUFFIXES: .cls
.cls.c:
	-$(CPP) $(CPP_FLAGS) $< | cpre -z > tmp
	cat sys_incl.h tmp > $@

$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) $(CFLAGS) $(OBJS) $(FMTLIBS) $(DMLIB) $(OLIBS) -o $(TARGET)
	rm -f tmp

$(TARGETB): $(OBJSB)
	$(CC) $(LDFLAGS) $(CFLAGS) $(OBJSB) $(FMTLIBS) $(DMLIB) $(OLIBS) -o $(TARGETB)
	rm -f tmp

$(ESETARGET): $(OBJS)
	$(CC) $(LDFLAGS) $(CFLAGS) $(OBJS) $(FMTLIBS) $(DMLIB) $(ESELIB) $(OLIBS) -o $@
	rm -f tmp

$(ESETARGETB): $(OBJSB)
	$(CC) $(LDFLAGS) $(CFLAGS) $(OBJSB) $(FMTLIBS) $(DMLIB) $(ESELIB) $(OLIBS) -o $@
	rm -f tmp

ese: $(ESETARGET) $(ESETARGETB)

csrc: $(CSRCS)
	rm -f tmp

lex.o: parse.cls

spilex.o: spipar.cls

parse.cls: parse.y
	$(YACC) $(YFLAGS) parse.y
	mv y.tab.c parse.cls
	mv y.tab.h parse.h

parse.c: parse.cls
	-$(CPP) $(CPP_FLAGS) parse.cls | cpre -z > tmp
	cat sys_incl.h tmp > parse.c

spipar.cls: spipar.y
	$(YACC) $(YFLAGS) spipar.y
	mv y.tab.c spipar.cls
	mv y.tab.h spipar.h

spipar.c: spipar.cls
	-$(CPP) $(CPP_FLAGS) spipar.cls | cpre -z > tmp
	cat sys_incl.h tmp > spipar.c

main.sp.c: main.cls $(SRC0)
	-$(CPP) -DSPICE $(CPP_FLAGS) main.cls | cpre -z > tmp
	cat sys_incl.h tmp > $@

main.sp.o: main.sp.c $(SRC0)
	cc -c -DSPICE $(CFLAGS) main.sp.c

install: $(TARGET) $(TARGETB)
	cp $(TARGET) $(BIN); rm -f $(TARGET)
	rm -f $(BIN)/$(TARGET_OLD)
	ln $(BIN)/$(TARGET) $(BIN)/$(TARGET_OLD)
	cp $(TARGETB) $(BIN); rm -f $(TARGETB)

eseinstall: $(ESETARGET) $(ESETARGETB)
	cp $(ESETARGET) $(BIN)/putsls; rm -f $(ESETARGET)
	cp $(ESETARGETB) $(BIN)/putspice; rm -f $(ESETARGETB)

doTouch:
	chmod u+w parse.cls
	touch parse.cls
	sleep 2
	chmod u+w $(CSRCL) $(CSRCY) $(CSRC2)
	touch $(CSRCL) $(CSRCY) $(CSRC2)
	sleep 2

clean:
	/bin/rm -f $(OBJS) $(OBJ3B) $(OBJ4B) $(TARGET) $(CSRCL) core tmp y.tab.c lex.yy.c

cleanrest:
# be sure you can make them again! (you must have a class preprocessor)
	/bin/rm -f $(CSRCY) $(CSRC2) parse.cls y.tab.h

LINT: $(SRC0) $(CSRCS)
	lint $(CFLAGS) $(CSRCS) > LINT

$(OBJS): $(SRC0)
class.c: $(SRC3)
$(CSRCY): $(SRC0) $(SRC3)
$(CSRC2): $(SRC0) $(SRC3)

$(SRCS):
	-@[ $(TESTLINK) $@ ] || ln -s $(SOURCEDIR)/$@ .; \
	cd $(SOURCEDIR) ; [ -f $@ ] || get -s SCCS/s.$@;

#EOF
