#------------------------------------------------------------------------
# Imakefile for Xcircuit
#------------------------------------------------------------------------

# CC = gcc
CC = cc

# Compile flags

# cckr is for SGI only (non-ansi-standard switch):
CCOPTIONS = -O2 -cckr -Wf,-XNh2000
# CCOPTIONS = -O2 -cckr -Wf,-XNh2000

# for DECstations:
#CCOPTIONS = -Olimit 1000
# for Linux:
#CCOPTIONS = -O2 -m486
# otherwise (Sun, gcc, etc.):
#CCOPTIONS = -O2

# Solaris and other SVR4 systems need the following:
#DIRENT = -DSVR4_DIRENT
# Systems with at least some BSD compatibility may use this:
DIRENT =

# for debugging purposes use -g:
# CDEBUGFLAGS = -g
CDEBUGFLAGS =

#------------------------------------------------------------------------
# Change the following to suit your environment:

# XCIRCUIT_LIB_DIR =  /home/cad/lib/xcircuit
XCIRCUIT_LIB_DIR = /usr/local/lib/xcircuit
XCIRCUIT_BIN_DIR = /usr/local/bin
XCIRCUIT_MAN_DIR = /usr/local/man/cat1
XCIRCUIT_LIBSRC_DIR = ./psfiles

#------------------------------------------------------------------------
# Support for graphics double-buffering (A real memory hog, but fastest
# graphics rendering).
#------------------------------------------------------------------------

DO_BUFFER= -DDOUBLEBUFFER
# DO_BUFFER=

#------------------------------------------------------------------------
# Support for reading various file formats
# (other than Xcircuit PostScript)
#
#   MAKE_LGF	Support for Caltech tools' "analog" simulator .lgf
#		file format.	
#------------------------------------------------------------------------

#define MAKE_LGF

#------------------------------------------------------------------------
# My DECstation has something funny going on in XLib. . . if there is
# a compile-time error "ld: Undefined: XUniqueContext *** Error code 1"
# then uncomment the following line:
#CONTEXT_FIX = -DUniqueContextProblem
CONTEXT_FIX =

#------------------------------------------------------------------------
# You should not need to change anything after this line unless you have
# Xw already compiled on your system and want to use it instead of the
# built-in Xw package.
#------------------------------------------------------------------------

XWLIB = -L./Xw -lxcXw

#------------------------------------------------------------------------
# You should not need to change anything after this line
#------------------------------------------------------------------------

# Standard library files
BUILTINS_FILE = builtins.lps
USER_RC_FILE  = .xcircuitrc
PROLOGUE_FILE = xcircps.pro
BUILTINS_DEP1 = analog.lps
BUILTINS_DEP2 = avlsi.lps
BUILTINS_DEP3 = digital.lps
LGF_LIB       = lgf.lps

# Version number
VERSION = 1.6

DEPLIBS = $(DEPXLIB)
LOCAL_LIBRARIES = $(XWLIB) $(XTOOLLIB) $(XLIB) -lm
SRCS = files.c text.c events.c selection.c elements.c libraries.c \
	functions.c formats.c rcfile.c xcircuit.c
OBJS = files.o text.o events.o selection.o elements.o libraries.o \
	functions.o formats.o rcfile.o xcircuit.o

#ifdef MAKE_LGF
P_LGF = -DLGF
#else
P_LGF =
#endif
#ifdef SCHEMA
P_SCHEM = -DSCHEMA
#else
P_SCHEM =
#endif

PACKAGES = ${P_LGF} ${P_SCHEMA}

DEFINES = -DBUILTINS_DIR=\"${XCIRCUIT_LIB_DIR}\" \
        -DBUILTINS_FILE=\"${BUILTINS_FILE}\" \
	-DUSER_RC_FILE=\"${USER_RC_FILE}\" \
        -DPROLOGUE_DIR=\"${XCIRCUIT_LIB_DIR}\" \
        -DPROLOGUE_FILE=\"${PROLOGUE_FILE}\" \
        -DLGF_LIB=\"${LGF_LIB}\" \
	-DVERSION=\"${VERSION}\" ${CONTEXT_FIX} ${PACKAGES} \
	${DIRENT} ${DO_BUFFER}

#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'
   AllTarget(libxcXw.a)

#ifdef MakeNsubdirMakefiles
   MakeNsubdirMakefiles()
#endif

MakeMakeSubdirs(Xw, libxcXw.a)
MakeSubdirs(Xw)
DependSubdirs(Xw)

AllTarget(menudep)

menudep: menudep.o
	$(CC) -o menudep menudep.o

AllTarget(xcircuit)

xcircuit.c: menudep.h

menudep.h: menudep
	./menudep

xcircuit: $(OBJS) $(DEPLIBS)
	RemoveTargetProgram($@)
	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) \
		$(EXTRA_LOAD_FLAGS)
InstallProgram(xcircuit, ${XCIRCUIT_BIN_DIR})
InstallManPage(xcircuit, ${XCIRCUIT_MAN_DIR})
DependTarget()

install::
	MakeDir(${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_FILE}, ${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${PROLOGUE_FILE}, ${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP1}, ${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP2}, ${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP3}, ${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${LGF_LIB}, ${XCIRCUIT_LIB_DIR})
InstallAppDefaults(XCircuit)

clean::
	$(RM) xcircuit menudep *.o *.bak core
	(cd ./Xw; $(RM) *.o *.bak core)

veryclean::
	$(RM) xcircuit *.o *.bak Makefile menudep menudep.h core
	(cd ./Xw; $(RM) *.o *.a *.bak Makefile core)
