# Makefile for GPDD1
# 	"make " to make the executable: "gpdd_sens.exe".
# 	"make lib" to make the library:   "libgpdd_sens.a".
#
# Input to the simulator is a standard Spice netlist "filename.sp".
#
# Author:	Guoyong SHI (c)
# First Created:	04-06-2004
# Last  Revised:	09-17-2010; 
# 

ROOTDIR	= /d/EDA/GRASS
HOME = $(ROOTDIR)/GPDD1
BACKUP	= $(HOME)/backup

BDDBASE = $(ROOTDIR)/BDDbase
BINDIR = $(ROOTDIR)/netlists/bin
TESTDIR = $(HOME)/testckt

PCCTS	= $(ROOTDIR)/pccts
ANTLR_H	= $(PCCTS)/h
BIN		= $(PCCTS)/bin

ANTLR	= $(BIN)/antlr
DLG		= $(BIN)/dlg

CC = g++

AFLAGS	= -CC
DFLAGS	= -C2 -i -CC

DEFINE	= -DNTRACE 
LIBS = -L$(BDDBASE)
CFLAGS	= -g $(DEFINE) -I. -I$(ANTLR_H) -I$(BDDBASE) 
# must put the -D flags before -I flags to make the -D flags effective!
LFLAGS	= -O6 

PROJECT = GPDD1
TARGET	= gpdd1
LIBGRASS = libgpdd.a

MAINC = main.cpp 
MAINO = main.o 

SRCS = \
	   ToGraph.cpp \
       Subgraph.cpp \
       GPDDnode.cpp \
       GPDD.cpp \
       Analysis_AC.cpp \
       complex.cpp  \
       utility.cpp


HEADERS = class_id.h option.h \
		  Analysis_AC.h \
		  Subgraph.h ToGraph.h \
		  GPDDnode.h GPDD.h \
		  gpdd_global.h gpdd_struct.h \
          complex.h \
		  utility.h

OBJS = $(SRCS:.cpp=.o) 

# Parser related source files:
SRCPAR = netgram.cpp netparser.cpp \
	   $(ANTLR_H)/AParser.cpp $(ANTLR_H)/ATokenBuffer.cpp \
	   $(ANTLR_H)/DLexerBase.cpp DLGLexer.cpp

# Parser related object files:
OBJPAR = netgram.o netparser.o \
	   AParser.o ATokenBuffer.o DLexerBase.o DLGLexer.o

.cpp.o:
	$(CC) $(CFLAGS) -c $<
.cc.o:
	$(CC) $(CFLAGS) -c $<

# Grammar file for pccts
GRM	= netgram.g		

# Files generated by "antlr":
ANTLR_SPAWN = netgram.cpp netparser.cpp netparser.h \
				tokens.h parser.dlg
DLG_SPAWN   = DLGLexer.cpp DLGLexer.h


all: $(TARGET) 


$(TARGET) : $(MAINO) $(OBJS) $(OBJPAR) $(BDDBASE)/libbdd.a
	@echo -n Linking $(TARGET) ...
	@echo
	$(CC) $(LFLAGS) -o $@ $(MAINO) $(OBJS) $(OBJPAR) \
			$(LIBS) -lbdd -lm 
	@echo [$(TARGET).exe] done
	cp $(TARGET) $(TESTDIR)/$(TARGET).exe


lib : $(OBJS) $(OBJPAR) 
	@echo -n Creating $(PROJECT) library ...
	@echo
	ar rv $(LIBGRASS) $(OBJS) $(OBJPAR) 
	@echo [$(LIBGRASS)] done

# <antlr> and <dlg> generate *.h and *.cpp files

$(ANTLR_SPAWN) : $(GRM)
	$(ANTLR) $(AFLAGS) $(GRM)

$(DLG_SPAWN) : parser.dlg
	$(DLG) $(DFLAGS) parser.dlg

netgram.o : tokens.h DLGLexer.h netgram.cpp 
	$(CC) -c $(CFLAGS) -o $@ netgram.cpp
netparser.o : tokens.h DLGLexer.h netparser.cpp
	$(CC) -c $(CFLAGS) -o $@ netparser.cpp

# The following three dependencies are standard

AParser.o : $(ANTLR_H)/AParser.cpp
	$(CC) -c $(CFLAGS) -o AParser.o $(ANTLR_H)/AParser.cpp
ATokenBuffer.o : $(ANTLR_H)/ATokenBuffer.cpp
	$(CC) -c $(CFLAGS) -o ATokenBuffer.o $(ANTLR_H)/ATokenBuffer.cpp
DLexerBase.o : $(ANTLR_H)/DLexerBase.cpp
	$(CC) -c $(CFLAGS) -o DLexerBase.o $(ANTLR_H)/DLexerBase.cpp

#-----------------------------------------------------------------------

clean:
	rm -f *.o
	rm -f netgram.cpp
	rm -f $(TARGET).exe

backup:
	cp $(SRCS) $(HEADERS) $(BACKUP)

