/**/# Run imake -DUseInstalled -I/usr/lib/X11/config to make a Makefile.
/**/# This is an R5 style Imakefile, so will need the R5 config files to
/**/# to make a Makefile.  It also assume that X11 is installed in /usr/lib.

        SHAR = shar
        COMPRESS = compress
        BTOA = btoa
        SPLIT = split
        CAT = cat
/***** Note: probably want to define this to be something else *****/
        HELPDIR = /usr/doc/spider

/***** Note:  Used to over-ride some declarations in the default Imakefile
              configurations.  If you want to use some of these things, then
              set OverrideDefs to YES below and change the corresponding
              definitions to what you would like them to be below.  Delete
              or comment out those you do not wish to use  *****/
#ifndef OverrideDefs
#define OverrideDefs YES
#endif

#if OverrideDefs

# ifdef ManSuffix
#  undef ManSuffix
#  define ManSuffix 1
# else
#  define ManSuffix 1
# endif
        MANSUFFIX = ManSuffix
        MANDIR = ./man$(MANSUFFIX)
        BINDIR = ./bin
        MKDIRHIER = /usr/bin/X11/mkdirhier

#endif /* OverrideDefs */

/***** Note:  if your OS or libc does not have usleep defined, set this
              to YES.  (SunOS is one that does have usleep in libc) *****/
#ifndef NeedsLocalUsleep
#define NeedsLocalUsleep NO
#endif

/***** Note:  if your OS or libc does not have strdup defined, set this
              to YES.  (SunOS is one that does have strdup in libc) *****/
#ifndef NeedsLocalStrdup
#define NeedsLocalStrdup NO
#endif

/***** Note:  only need XViewHasOlgx when using XView 2.0 or greater *****/
#ifndef XViewHasOlgx
#define XViewHasOlgx YES
#endif

/***** Note:  cannot have CompileXlibOnly, CompileXView, and CompileXAW 
              all be true.  Need to pick one *****/
#ifndef CompileXlibOnly
#define CompileXlibOnly NO
#endif

#ifndef CompileXView
#define CompileXView NO
#endif

#ifndef CompileXAW
#define CompileXAW YES
#endif

#if CompileXlibOnly
# if CompileXView
#  undef CompileXView
# endif
# if CompileXAW
#  undef CompileXAW
# endif
#elif CompileXView
# if CompileXAW
#  undef CompileXAW
# endif
#endif

/***** Note:  cannot have both Round Cards and Small Cards be true *****/
#ifndef RoundCards
#define RoundCards NO
#endif

#ifndef SmallCards
#define SmallCards YES
#endif

#if SmallCards
# if RoundCards
#  undef RoundCards
# endif
#endif

#if CompileXView
/**/# If these are not defined in the site.def file, define them now.
/**/# set up compile time dependencies for XView clients.
        XVTOP = $(XVIEWHOME)
        XVLIBSRC = $(XVTOP)/lib
# if UseInstalled
        DEPXVIEWLIB =
        DEPOLGXLIB =
# else
        DEPXVIEWLIB = $(XVLIBSRC)/libxview.a
#  if XViewNeedsOlgx
        DEPOLGXLIB = $(XVLIBSRC)/libolgx.a
#  else
        DEPOLGXLIB =
#  endif
# endif
        XVIEWLIB = -L$(XVLIBSRC) -lxview
# if XViewNeedsOlgx
        OLGXLIB = -L$(XVLIBSRC) -lolgx
# else
        OLGXLIB =
# endif
#endif /* CompileXView */

        KL_DIST = main.c
#if CompileXlibOnly
# if RoundCards
        DEPLIBS = $(DEPXMULIB) $(DEPXLIB)
        LOCAL_LIBRARIES = $(XMULIB) $(XLIB)
# else
        DEPLIBS = $(DEPXLIB)
        LOCAL_LIBRARIES = $(XLIB)
# endif
        TKOBJS = main.o
 
        TKSRCS = main.c
 
        TKHEADERS = 
 
        TKBITMAPS = 
 
        TKDOCS = 

        TKDEFINES = -DKITLESS
 
        TKINCLUDES = 

        TARGET = spider
#endif /* CompileXlibOnly */

        XVIEW_DIST = xv_ui.c xv_stubs.c xv_ui.h spider.info
#if CompileXView
# if RoundCards
        DEPLIBS = $(DEPXVIEWLIB) $(DEPOLGXLIB) $(DEPXMULIB) $(DEPXLIB)
        LOCAL_LIBRARIES = $(XVIEWLIB) $(OLGXLIB) $(XMULIB) $(XLIB)
# else
        DEPLIBS = $(DEPXVIEWLIB) $(DEPOLGXLIB) $(DEPXLIB)
        LOCAL_LIBRARIES = $(XVIEWLIB) $(OLGXLIB) $(XLIB)
# endif
        TKOBJS = xv_ui.o xv_stubs.o 

        TKSRCS = xv_ui.c xv_stubs.c

        TKHEADERS = xv_ui.h

        TKBITMAPS = 

        TKDOCS = spider.info 

        TKDEFINES = -DXVIEW

        TKINCLUDES = -I$(XVTOP)/include 

        TARGET = spider
#endif /* CompileXView */

        XAW_DIST = xaw_ui.c xaw_stubs.c xaw_ui.h
#if CompileXAW
        DEPLIBS = XawClientDepLibs
        LOCAL_LIBRARIES = XawClientLibs

        TKOBJS = xaw_ui.o xaw_stubs.o

        TKSRCS = xaw_ui.c xaw_stubs.c

        TKHEADERS = xaw_ui.h

        TKBITMAPS = 

        TKDOCS =

        TKDEFINES = -DXAW 

        TKINCLUDES = 

        TARGET = spider
#endif /* CompileXAW */

BASE_OBJS = gfx.o spider.o events.o windows.o movelog.o util.o version.o
OBJS = $(BASE_OBJS) $(TKOBJS)

BASE_SRCS = gfx.c spider.c events.c windows.c movelog.c util.c version.c
SRCS =  $(BASE_SRCS) $(TKSRCS)

BASE_HEADERS = globals.h defs.h assert.h copyright.h
HEADERS = $(BASE_HEADERS) $(TKHEADERS)

BASE_BITMAPS = rank.bm suit.bm face.bm spider.bm cards.bm.aa cards.bm.ab
BITMAPS = $(BASE_BITMAPS) $(TKBITMAPS)

BASE_DOCS = doc.intro doc.rules doc.controls doc.examples doc.misc doc.summary 
DOCS =        $(BASE_DOCS) $(TKDOCS)

MISC = Imakefile Makefile.sunpro README spider.man

ALL_SRCS = $(MISC) $(BASE_SRCS) $(BASE_HEADERS) $(BASE_BITMAPS) $(BASE_DOCS) \
        $(XVIEW_DIST) $(XAW_DIST) $(KL_DIST)

#if NeedsLocalUsleep
# if NeedsLocalStrdup
UTILDEFS = -DLOCAL_USLEEP -DLOCAL_STRDUP
# else
UTILDEFS = -DLOCAL_USLEEP
# endif
#else
# if NeedsLocalStrdup
UTILDEFS = -DLOCAL_STRDUP
# else
UTILDEFS = 
# endif
#endif

#if SmallCards
DEFINES = $(TKDEFINES) -DSMALL_CARDS -DHELPDIR="\"$(HELPDIR)\"" $(UTILDEFS)
#else 
# if RoundCards
DEFINES = $(TKDEFINES) -DROUND_CARDS -DHELPDIR="\"$(HELPDIR)\"" $(UTILDEFS)
# else
DEFINES = $(TKDEFINES) -DHELPDIR="\"$(HELPDIR)\"" $(UTILDEFS)
# endif
#endif

INCLUDES = -I. $(TKINCLUDES)

CPPFLAGS = 

all:: $(TARGET)

#if SmallCards
all:: 
	-@if [ ! -f cards.bm ]; then cat cards.bm.aa cards.bm.ab > cards.bm; fi
#endif
#if OverrideDefs
MakeDirectories(install,$(BINDIR))
MakeDirectories(install.man, $(MANDIR))
#endif

ComplexProgramTarget($(TARGET))

#ifdef SparcArchitecture
/**/# SunOS4.0.3 sparc optimizer slimes this file
util.o:	util.c
	$(CC) $(CPPFLAGS) $(DEFINES) $(INCLUDES) -c util.c
#endif

version.o:	version.c
	$(CC) -DDATE="\"`date`\"" -c version.c 

MakeDirectories(install.doc,$(HELPDIR))
InstallMultipleDest(install.doc,$(DOCS),$(HELPDIR))
	
World::  
	@echo ""
	@echo "Begin build of the $(TARGET) application for the"
#if CompileXView
	@echo "XView toolkit version."
#else
# if CompileXlibOnly
	@echo "Xlib only, no toolkit version."
# else
#  if CompileXAW
	@echo "Athena Widget toolkit version."
#  endif
# endif
#endif
#if SmallCards
	@echo "Using cards with small bitmaps for a low resolution display."
#else 
# if RoundCards
	@echo "Using cards with normal bitmaps and optional rounded edges."
# else
	@echo "Using cards with normal bitmaps."
# endif
#endif
	@echo ""
	@date
	@echo ""
	$(MAKE) $(MFLAGS) clean
	$(MAKE) $(MFLAGS) depend
	$(MAKE) $(MFLAGS)
	@echo ""
	@date
	@echo ""
	@echo "Begin installation... "
	$(MAKE) $(MFLAGS) -k install
	$(MAKE) $(MFLAGS) -k install.doc
	$(MAKE) $(MFLAGS) -k install.man
	@echo ""
	@date
	@echo ""
	@echo "Installation complete...now type 'make clean'"

clean::
	$(RM) spider.shar spider.a spider.a.a?a cards.bm

shar::
	$(SHAR) $(ALL_SRCS) > spider.shar

dist::	shar
	$(RM) spider.shar.Z
	$(COMPRESS) spider.shar
	$(CAT) spider.shar.Z | $(BTOA) > spider.a
	$(SPLIT) spider.a spider.a.

