#------------------------------------------------------------------------
# Imakefile for Xcircuit
# (c) 1998 Tim Edwards, Johns Hopkins University
#------------------------------------------------------------------------
#
#------------------------------------------------------------------------
# Compile flags (should not be necessary to uncomment anything unless
# you have a DEC Alpha or if problems are encountered during compilation):
#------------------------------------------------------------------------
#
#CC = cc
# If you wish to compile with GNU cc, uncomment the following:
#CC = gcc
#
# cckr is for SGI only (non-ansi-standard switch):
#CCOPTIONS = -O2 -cckr -Wf,-XNh2000
# for DEC Alpha:
#CCOPTIONS = -Olimit 1000 -taso -D
# for DEC ULTRIX:
#CCOPTIONS = -Olimit 1000
# for Linux:
#CCOPTIONS = -O2 -m486
# otherwise try:
#CCOPTIONS = -O2
#
# for debugging purposes uncomment the following line:
#CDEBUGFLAGS = -g

#------------------------------------------------------------------------
# Installation directories:
# Change the following as desired to suit your environment:
#------------------------------------------------------------------------
#
PREFIX = /usr/local
XCIRCUIT_LIB_DIR = $(PREFIX)/lib/xcircuit
XCIRCUIT_BIN_DIR = $(PREFIX)/bin
XCIRCUIT_MAN_DIR = $(PREFIX)/man/man1

#------------------------------------------------------------------------
# Support for graphics double-buffering (A memory hog, but yields 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

#------------------------------------------------------------------------
#
# System-specific compile-time definitions
#
#------------------------------------------------------------------------

# For DEC Alpha, or if the compilation fails due to an error
# redefining "uchar", uncomment the following definition:
#HAVE_UCHAR = -DHAVE_UCHAR
# Otherwise,
HAVE_UCHAR =

# DEC Alpha, Solaris and other SVR4 systems need the following,
# or if you have compilation errors about "dp->d_name" being
# undefined:
#DIRENT = -DSVR4_DIRENT
# Otherwise,
DIRENT =

# My DECstation (Ultrix) has something funny going on in XLib. . . if there
# is a compile-time error "ld: Undefined: XUniqueContext *** Error code 1"
# then enable the following definition:
#CONTEXT_FIX = -DUniqueContextProblem
# Otherwise,
CONTEXT_FIX =

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

# Version number
VERSION = 1.7

# PostScript source files directory
XCIRCUIT_LIBSRC_DIR = ./psfiles

# 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
SIGNAL_LIB    = signal.lps
MUSIC_LIB     = musiclib.lps

# Xw library
XWLIB = -L./Xw -lxcXw

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

PACKAGES = ${P_LGF}

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} \
		    ${HAVE_UCHAR}

#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)
DependTarget()

install::
InstallProgram(xcircuit, ${XCIRCUIT_BIN_DIR})
#ifdef SCHEMA
	(cd ${XCIRCUIT_BIN_DIR}; ln -sf xcircuit ${SCHEMPROG})
#endif
	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})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${SIGNAL_LIB},	${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${MUSIC_LIB},	${XCIRCUIT_LIB_DIR})
InstallAppDefaults(XCircuit)

install.man::
InstallManPage(xcircuit, ${XCIRCUIT_MAN_DIR})

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)
