##########################################################################
## 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)
##
## xlibdir         = the directory containing the X11 libraries
## xlibs           = any extra X libraries that must be linked in (other than
##                   -lX11
##########################################################################
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
########################## BEGIN CHANGES #################################
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##########################################################################
##### Set your STK_LIBRARY environment variable to hold the path to
##### the directory above that containing STk-3.1.1's libstk.a.  For example, 
##### if libstk.a is in the directory 
#####           /cs/berryj/public/lib/stk/3.1.1/SunOS-5.5-sun4
##### then you must set STK_LIBRARY to be 
#####           /cs/berryj/public/lib/stk/3.1.1
##########################################################################
##########################################################################
##### Set your STK_LOAD_PATH environment variable to hold the path to
##### the directory containing Link's .stklos files.  For example, if
##### if graph-menu.stklos is in the directory 
#####           /cs/berryj/public/lib/LINK/1.3/stklos
##### then you must set STK_LIBRARY to be 
#####           /cs/berryj/public/lib/LINK/1.3/stklos
##########################################################################
##### Change the paths below to find the libraries and include files
##########################################################################
stklibdir       = ${STK_LIBRARY}/Linux-2.X-ix86/Libs
stkincdir       = ${STK_LIBRARY}/include
linklibdir      = /usr/local/lib/LINK/1.4    
linkincdir      = /usr/local/lib/LINK/1.4/include
xlibdir		= /usr/X11R6/lib
xlibs		= 

USER_SOURCE = \
linkUserInit.cpp \
demo.cpp 

#demoNoGUI.cpp

EXECUTABLE = demo
##########################################################################
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
########################## END CHANGES #**################################
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
##########################################################################

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

LIBS =-L$(stklibdir) -L$(linklibdir) -L$(xlibdir) -lstk -lgmp -ltk -levtcl -ltcl $(xlibs) -lX11 -lm -ldl
CC = gcc
CCC = c++
CPPFLAGS = -g -v -I$(linkincdir) \
           $(X11INCL)  -I$(stkincdir)

#### 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) $(STKFLAGS) -c 
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) $< ; \
	else \
		$(LINK_COMPILE_NO_GUI.cpp) $< ; \
	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
