#------------------------------------------------------------------------
# Imakefile for Xcircuit
# (c) 2000 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 -DHAVE_PUTENV
# for DEC Alpha:
#CCOPTIONS = -Olimit 1000 -taso
# for DEC ULTRIX:
#CCOPTIONS = -Olimit 1000
# for Linux:
#CCOPTIONS = -O2 -m486
# for Solaris:
#CCOPTIONS =
# for HP/UX:
#CCOPTIONS = -Ae -DSVR4
# otherwise try:
#CCOPTIONS = -O2
#
# for debugging purposes uncomment the following line:
CDEBUGFLAGS = -g
STD_INCLUDES = -I. -I/usr/X11R6/include/X11

# The "m4" macro processor is used to generate the man page such that
# the man page reflects the configured options.
M4 = m4

#------------------------------------------------------------------------
# Installation directories:
# Change the following as desired to suit your environment:
#------------------------------------------------------------------------
#
PREFIX = /usr/local
# XCIRCUIT_LIB_DIR = $(PREFIX)/src/xcircuit-2.5.2/lib
XCIRCUIT_LIB_DIR = $(PREFIX)/lib/xcircuit-2.5
XCIRCUIT_BIN_DIR = $(PREFIX)/bin
XCIRCUIT_MAN_DIR = $(PREFIX)/man/man1
XAPPLRESDIR = ${XCIRCUIT_LIB_DIR}/app-defaults

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

#------------------------------------------------------------------------
# Support for background rendering through ghostscript.  Change this
# to the path where gs can be found.
# GS_EXEC= /usr/local/src/gs5.50/obj/gs
GS_EXEC= /usr/bin/gs

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

#------------------------------------------------------------------------
# Support for embedded Python interpreter
# (requires libpython${PYTHON_VERSION}.a)
#
#define HAVE_PYTHON

PYTHON_VERSION=2.1
PYTHON_LIB_DIR=/usr/local/lib
PYTHON_INCLUDE_DIR=/usr/local/include/python${PYTHON_VERSION}

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

# If the compilation fails due to an error not finding
# "u_char" (or "u_short", or "u_long"), uncomment the following
# definition:
#HAVE_UCHAR =
# Otherwise,
HAVE_UCHAR = -DHAVE_U_CHAR

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

# PostScript source files directory
XCIRCUIT_LIBSRC_DIR = ./lib

# Standard library files
#ifdef HAVE_PYTHON
STARTUP_FILE = xcstartup.py
#else
STARTUP_FILE = startup.script
#endif
USER_RC_FILE  = .xcircuitrc
PROLOGUE_FILE = xcircps2.pro
BUILTINS_DEP1 = generic.lps
BUILTINS_DEP2 = analog.lps
BUILTINS_DEP3 = avlsi.lps
BUILTINS_DEP4 = digital.lps
BUILTINS_DEP5 = analoglib2.lps
BUILTINS_DEP6 = ic_templates.lps
BUILTINS_DEP7 = quadparts.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 HAVE_PYTHON
LIBPYTHON= -L${PYTHON_LIB_DIR} -lpython${PYTHON_VERSION} -ldl -lpthread -lutil -ldb
INCLUDES= -I${PYTHON_INCLUDE_DIR}
P_PYTHON= -DHAVE_PYTHON
#else
LIBPYTHON=
INCPYTHON=
P_PYTHON=
#endif

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

DEPLIBS = $(DEPXLIB)
LOCAL_LIBRARIES = $(XWLIB) $(XPMLIB) $(XTOOLLIB) $(XLIB) $(LIBPYTHON) -lm
SRCS = files.c text.c events.c selection.c elements.c libraries.c \
	functions.c formats.c help.c rcfile.c schema.c netlist.c \
	filelist.c menucalls.c fontfile.c parameter.c render.c \
	keybindings.c python.c xcircuit.c
OBJS = files.o text.o events.o selection.o elements.o libraries.o \
	functions.o formats.o help.o rcfile.o schema.o netlist.o \
	filelist.o menucalls.o fontfile.o parameter.o render.o \
	keybindings.o python.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} ${P_PYTHON}

DEFINES = -DBUILTINS_DIR=\"${XCIRCUIT_LIB_DIR}\" \
        -DSTARTUP_FILE=\"${STARTUP_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}\" \
	-DGS_EXEC=\"${GS_EXEC}\" \
	-DPROG_VERSION=${VERSION} \
	-DXAPPLRESDIR=\"${XAPPLRESDIR}\" \
	${CONTEXT_FIX} ${PACKAGES} ${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}/${STARTUP_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}/${BUILTINS_DEP4},${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP5},${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP6},${XCIRCUIT_LIB_DIR})
InstallNonExec(${XCIRCUIT_LIBSRC_DIR}/${BUILTINS_DEP7},${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)
	cp XCircuit.ad $(DESTDIR)${XAPPLRESDIR}

xcircuit.man: xcircuit.1.m4
	$(M4) $(DEFINES) xcircuit.1.m4 > xcircuit.man

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

topclean::
	$(RM) xcircuit menudep *.o *.bak xcircuit.1 core

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

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