##########################################################################
## Makefile for standalone programs (both GUI and non-GUI)              ##
##########################################################################
SHELL = /bin/sh
.SUFFIXES : .cpp
##########################################################################
## The sample programs in this 
## example are demo.cpp, demoNoGUI.cpp, and linkUserInit.cpp. 
##
## Directions:
##
## 0.  Search for the text "BEGIN CHANGES" below and set the paths to find
##     the STk and Link libraries and include files.
##
## 1.  To make a demo program that just uses the LINK libraries without any
##     GUI, try:
##
##			make demoNoGUI 
##
## 2.  Run the demoNoGUI command and make sure it works.  The output should
##     be a set containing two elements, each of which appears to be a set 
##     of integers.  The program has constructed and printed an output 
##     representation of two sets of vertices: the set of odd-numbered 
##     vertices and that of even-numbered vertices.
##
## 3.  The GUI version is built by switching the comments in USER_SOURCE and 
##     EXECUTABLE below, then typing:
##
##			make STK_GUI=yes demo
##
##     this creates a program called "demo" that brings up an LINK interface
##     enhanced with the new command   (even-odd-ranks g) where g is a graph.  
##     Try running "demo" and See demo.cpp for details.  
##
## 4.  Replace the demo programs with your source files in USER_SOURCE, 
##     making sure to end each line except the last one with a backslash.  
##
## Any algorithm you wrap into the user interface can easily be added
## the the "Algorithm" menu of each graph window.  Simply make your own
## copy the file $(LINK_BASE)/stklos/graph-menu.stklos and edit it. 
## It will probably not be necessary to learn any Scheme, since you
## should be able to copy the menu entry of an existing algorithm and
## change the name.  If it becomes necessary to make more interesting
## changes, see the STk manual and the Link tutorial.
## If you put your copy of graph-menu.stklos (and any other interface
## files you wish to customize) in the current directory, they will be
## loaded automatically when the application starts.  If, however, you 
## wish to keep your customized interface files in a separate directory, 
## modify the STK_LOAD_PATH environment variable to include that directory 
## before $(LINK_BASE)/stklos.  For example (bash):
##              export STK_LOAD_PATH=/home/joe/my_code:$STK_LOAD_PATH
##########################################################################


##########################################################################
## linklibdir       = the directory where libLINK*.a reside
## linkincdir       = the directory where LINK/basic/*.h reside
##
##                 e.g. if /home/berryj/link/include/LINK/basic/*.h, then
##                      stkindir = /home/berryj/link/include
##
## stklibdir       = the directory where libstk.a, etc. reside
##                   (typically $STK_LIBRARY/Linux* or $STK_LIBRARY/Sun*)
##
## stkincdir       = the directory where stk.h, gmp.h, etc. resize
##                   (typically $STK_LIBRARY/include)
##
## xlibs           = any extra X libraries that must be linked in (other than
##                   -lX11
##########################################################################
########################## BEGIN CHANGES #################################
##########################################################################
stklibdir       = ${STK_LIBRARY}/SunOS-5.6-sun4
stkincdir       = ${STK_LIBRARY}/include
linklibdir      = /home/berryj/public/lib/LINK/1.3
linkincdir      = /home/berryj/public/lib/LINK/1.3/include
xlibs		= -lsocket -lnsl

#USER_SOURCE = \
#		demo.cpp \
#		linkUserInit.cpp	# must edit this file and include it 
				# in this list to augment the GUI

USER_SOURCE = \
		demoNoGUI.cpp  # demoNoGUI.cpp is a sample program
				# using LINK objects, but not the GUI.
#EXECUTABLE = demo
EXECUTABLE = demoNoGUI
##########################################################################
########################## END CHANGES #**################################
##########################################################################

##########################################################################
####################### DO NOT CHANGE BELOW THIS LINE ####################
##########################################################################
USER_OBJ        = ${USER_SOURCE:.cpp=.o}
STK_VERSION     = 3.1.1
VERS-OPT        = -DSTK_VERSION=\"$(STK_VERSION)\"
DFLGS           = -DSTk_CODE -DSUNOS4
TK              = -DUSE_TK
STKFLAGS	= $(MACH) $(VERS-OPT) $(DFLGS) \
		  $(TK) -DUSE_STKLOS -DHAVE_UNISTD_H=1 -DHAVE_SIGACTION=1 \
		  -DHAVE_SELECT=1

LIBS =-L$(stklibdir) -L/usr/local/lib/stk/3.1.1/Linux-2.X-ix86   -L/usr/X11R6/lib  -lstk -lgmp -ltk -levtcl -ltcl $(xlibs) -lX11 -lm -ldl
CC = gcc
CCC = c++
CPPFLAGS = -v -fno-implicit-templates -I$(linkincdir) \
           $(X11INCL)  -I$(stkincdir)
GNUFLAGS = -v $(STKFLAGS) -fno-implicit-templates
##### will need -fPIC -B/usr/bin/ -fno-gnu-linker if dynloading ever used
##### not using it now since I need stklos in -lstk.a
CCFLAGS = 
#### the following replaces COMPILE.cpp, which doesn't seem to be well
#### supported by gnu make.  There should even be the addition:
#### -target $(TARGET_ARCH:-%=%),  but gnu make doesn't support
LINK_COMPILE.cpp = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c -DSTK_GUI
LINK_COMPILE_NO_GUI.cpp = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c
LINK_LINK_STK.cpp = $(LINK_COMPILE.cpp:-c=)
LINK_LINK.cpp = $(LINK_COMPILE_NO_GUI.cpp:-c=)
LINK_LIBS_STK = -lLINKgui -lLINKalganim -lLINKgraph -lLINKbasic
LINK_LIBS = -lLINKalg -lLINKgraph -lLINKbasic
LDLIBS_STK = -L$(linklibdir) $(LIBS) $(LINK_LIBS_STK) $(LINK_LIBS) 
LDLIBS = -L$(linklibdir) $(LINK_LIBS) -lm -ldl
SUFFIXES = .cpp .o
.cpp.o:
	if [ "$(STK_GUI)" = "yes" ]; \
	then \
		$(LINK_COMPILE.cpp) $< -o $@; \
	else \
		$(LINK_COMPILE_NO_GUI.cpp) $< -o $@; \
	fi
$(EXECUTABLE): $(USER_OBJ) 
	if [ "$(STK_GUI)" = "yes" ]; \
	then \
		$(LINK_LINK_STK.cpp) -o $@ $(USER_OBJ) $(LDLIBS_STK); \
	else \
		$(LINK_LINK.cpp) -o $@ $(USER_OBJ) $(LDLIBS); \
	fi; \
	strip $@

clean:
	- rm -f *.o $(EXECUTABLE) demo demoNoGUI
