#------------------------------------------------------------------------
# Imakefile for Xcircuit
# (c) 1999 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
STD_INCLUDES = -I. -I/usr/X11R6/include/X11

#------------------------------------------------------------------------
# Installation directories:
# Change the following as desired to suit your environment:
#------------------------------------------------------------------------
#
PREFIX = /usr/local
# XCIRCUIT_LIB_DIR = $(PREFIX)/src/xcircuit-2.0b1/psfiles
XCIRCUIT_LIB_DIR = $(PREFIX)/lib/xcircuit-2.0
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 pixmap icon using xpm
#define HAVE_XPM

#------------------------------------------------------------------------
# Window manager bug workaround---If you don't like xcircuit grabbing kbd
# focus whenever the pointer crosses the window, delete this definition.
#define INPUT_FOCUS

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

#------------------------------------------------------------------------
# Support for schematic capture
#
#define SCHEMA

SCHEMFLAG = -schem

#------------------------------------------------------------------------
#
# 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 = 2.0

# PostScript source files directory
XCIRCUIT_LIBSRC_DIR = ./psfiles

# Standard library files
BUILTINS_FILE = builtins.lps
USER_RC_FILE  = .xcircuitrc
PROLOGUE_FILE = xcircps2.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

#ifdef HAVE_XPM
XPM_ICON = -DHAVE_XPM
XPMLIB = -lXpm
#else
XPM_ICON =
XPMLIB =
#endif

#ifdef INPUT_FOCUS
FOCUS_FIX = -DINPUT_FOCUS
#else
FOCUS_FIX =
#endif

DEPLIBS = $(DEPXLIB)
LOCAL_LIBRARIES = $(XWLIB) $(XPMLIB) $(XTOOLLIB) $(XLIB) -lm
SRCS = files.c text.c events.c selection.c elements.c libraries.c \
	functions.c formats.c rcfile.c help.c schema.c netlist.c \
	filelist.c menucalls.c fontfile.c parameter.c xcircuit.c
OBJS = files.o text.o events.o selection.o elements.o libraries.o \
	functions.o formats.o rcfile.o help.o schema.o netlist.o \
	filelist.o menucalls.o fontfile.o parameter.o xcircuit.o

#ifdef MAKE_LGF
P_LGF = -DLGF
#else
P_LGF =
#endif

#ifdef SCHEMA
P_SCHEMA = -DSCHEMA
#else
P_SCHEMA =
#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}\" \
	-DSCHEM_PROG=\"${SCHEMPROG}\" \
	-DSCHEM_FLAG=\"${SCHEMFLAG}\" \
	-DVERSION=\"${VERSION}\" ${CONTEXT_FIX} \
		    ${PACKAGES} ${DIRENT} ${DO_BUFFER} \
		    ${HAVE_UCHAR} ${XPM_ICON} ${FOCUS_FIX}

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

help.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})
	MakeDir($(DESTDIR)${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})
	MakeDir($(DESTDIR)${XCIRCUIT_LIB_DIR}/fonts)
	(cd ${XCIRCUIT_LIBSRC_DIR}/fonts; cp *.lps $(DESTDIR)${XCIRCUIT_LIB_DIR}/fonts) 
	(cd ${XCIRCUIT_LIBSRC_DIR}/fonts; cp *.xfe $(DESTDIR)${XCIRCUIT_LIB_DIR}/fonts) 
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)
