## Copyright (C) 1996 DIMACS Center, Rutgers, The State University of New Jersey
## Author(s): Jonathan Berry

## This software is copyrighted by the DIMACS Center at Rutgers, The State
## University of New Jersey.  IT IS PROVIDED AS IS, AND THE AUTHORS, DIMACS, AND
## RUTGERS, THE STATE UNIVERSITY OF NEW JERSEY  DISCLAIM
## ALL LIABILITY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
## DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
## DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
## POSSIBILITY OF SUCH DAMAGE.

## THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
## IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
## NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
## MODIFICATIONS.

## The authors hereby grant permission to use, copy, modify, distribute,
## and license this software and its documentation for any purpose, provided
## that existing copyright notices are retained in all copies and that this
## notice is included verbatim in any distributions. No written agreement,
## license, or royalty fee is required for any of the authorized uses.
## Modifications to this software may be copyrighted by their authors
## and need not follow the licensing terms described here, provided that
## the new terms are clearly indicated on the first page of each file where
## they apply.

## Last File Update: 31-Jul-1996
## 
SHELL = /bin/sh

############################################################################
## ATTENTION LIBRARY PROGRAMMERS:
##
##  At the bottom of this makefile, there is a detachable, self-contained
##  makefile specially designed for compiling standalone programs using
##  Link's libraries.  It gives you the option of including the GUI or not.
##  You can copy this makefile to an empty directory and use it as is, or
##  copy only the appropriate part.  In either case, search for the string
##  LIBRARY_MAKEFILE in this file and read the directions.
############################################################################
LINK_VERSION     = 1.1

prefix		= @prefix@

OP_SYS		= @OP_SYS@
STK_VERSION     = @STK_VERSION@
VERS-OPT        = -DSTK_VERSION=\"$(STK_VERSION)\"
DFLGS           = -DSTk_CODE -DSUNOS4
TK		= -DUSE_TK

bindir		= $(prefix)/bin
libdir		= $(prefix)/lib/LINK/$(LINK_VERSION)
incdir		= $(libdir)/include
execdir		= $(libdir)/$(OP_SYS)

stkprefix          = @stkprefix@
stklibdir       = @STK_PREFIX@/lib/stk/$(STK_VERSION)/$(OP_SYS)
stkincdir       = @STK_PREFIX@/lib/stk/$(STK_VERSION)/include
#stkincdir	= @STK_PREFIX@/include

STKINCLUDES     = -I$(stkincdir)
STKFLAGS	= $(MACH) $(VERS-OPT) $(DFLGS) \
		  $(TK) -DHAVE_UNISTD_H=1 -DHAVE_SIGACTION=1 -DHAVE_SELECT=1





top_srcdir      = @top_srcdir@
srcdir          = @srcdir@
VPATH           = @srcdir@
LINKBASE        = @srcdir@
LINKINCL        = @LINK_PREFIX@/include

##------------------------------------------------------------------
## got to find flex & bison;  lex and yacc are not good enough
FLEX =   @FLEX@
PARSE = @PARSE@
##------------------------------------------------------------------

TKINCL          = @TK_STK_INCLUDE@
TCLINCL         = @TCL_STK_INCLUDE@
MPINCL         = @MP_STK_INCLUDE@
X11INCL         = @XINCLUDES@ 

MPLIB		= @MP_LIB@/@MP@.a
TKLIB		= @TK_STK_LIB@/libtk.a
TCLLIB		= @TCL_STK_LIB@/libtcl.a

##LIBS =-L$(stklibdir) -L@MP_LIB@ -L@FLEX_LIB@ @X_PRE_LIBS@ @XLIBSW@ @X_EXTRA_LIBS@ -lX11 -ltcl -lfl -lm

## there is some redundancy here.  The reason is that some places might
## not have STk fully installed.  The MPLIB,TKLIB,TCLLIB (and ..INCL) allow
## you to recover.
LIBS =-L$(stklibdir) -L@TK_STK_LIB@ @X_PRE_LIBS@ @XLIBSW@ @X_EXTRA_LIBS@ -lstk $(MPLIB) $(TKLIB) $(TCLLIB) -lXpm -lX11 -lm


### ---------------------Parameters for GNU Compiler---------------------

CC = @CC@
CCC = @CXX@
CPPFLAGS = -I. -I$(LINKINCL) $(X11INCL) -I$(TCLINCL) -I$(TKINCL) \
           -I$(MPINCL) $(STKINCLUDES)
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 libstk.a

DEPENDFLAGS = "-D__GNUC__ -I$(LINKINCL) $(X11INCL) -I$(TCLINCL) $(STKINCLUDES)"


## ------------------Parameters for AT&T Sun Compiler---------------------
##  NOT USED RIGHT NOW
# CCC = CC
# ATTINCL = /usr/lang/SC2.0.1/include/CC_413
# CPPFLAGS = "-I../include -I$(X11INCL) -I$(TCLINCL)"
# DEPENDFLAGS =  "-I$(LINKINCL) -I$(ATTINCL) -I$(TCLINCL)"

CCFLAGS = 
#### the following replaces COMPILE.cc, 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.c = $(CC) $(CCFLAGS) $(CPPFLAGS) -c 
LINK_COMPILE.cc = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c -DSTK_GUI
LINK_COMPILE_NO_GUI.cc = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c

PROGRAM = Link README

$(PROGRAM): autowrap bin stklos standalone test include src
	cd autowrap; $(MAKE) -f Make.autowrap all
	cd bin; $(MAKE) -f Make.bin all
	cd standalone; $(MAKE) -f Make.standalone all
	cd stklos; $(MAKE) -f Make.stklos all
	cd test; $(MAKE) -f Make.tests all
	cd include; $(MAKE) -f Make.incl all
	cd src; $(MAKE) -f Make.src LINK_COMPILE.c="$(LINK_COMPILE.c)" LINK_COMPILE.cc="$(LINK_COMPILE.cc)" GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) LIBS="$(LIBS)" all

libs: src
	- rm src/algorithm/Animation.o   ### GUI stuff must be removed
	cd src; $(MAKE) -f Make.src \
		LINK_COMPILE.cc="$(LINK_COMPILE.c)" \
		LINK_COMPILE.cc="$(LINK_COMPILE_NO_GUI.cc)" \
		GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) \
		LIBS="$(LIBS)" libs
	- rm src/algorithm/Animation.o   ### so next make will put it back

debug:
	cd include; $(MAKE) -f Make.incl all
	cd src; $(MAKE) -f Make.src LINK_COMPILE.c="$(LINK_COMPILE.c)" LINK_COMPILE.cc="$(LINK_COMPILE.cc)" GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) LIBS="$(LIBS)" all

include:
	mkdir include
	mkdir include/LINK
	mkdir include/LINK/algorithm
	mkdir include/LINK/basic
	mkdir include/LINK/generator
	mkdir include/LINK/graph
	mkdir include/LINK/layout
	mkdir include/LINK/stkWrapper
	mkdir include/LINK/userobj
	mkdir include/LINK/wrappers

standalone:
	mkdir standalone

bin:
	mkdir bin

autowrap:
	mkdir autowrap

test:
	mkdir test
	mkdir test/graphs
	mkdir test/algorithm

src:
	mkdir src
	mkdir src/algorithm
	mkdir src/algorithm/manualSTkWrappers
	mkdir src/basic
	mkdir src/basic/linkTemplates
	mkdir src/basic/STkTemplates
	mkdir src/basic/autogenSTkMethods
	mkdir src/basic/manualSTkMethods
	mkdir src/generator
	mkdir src/generator/manualSTkWrappers
	mkdir src/graph
	mkdir src/graph/linkTemplates
	mkdir src/graph/STkTemplates
	mkdir src/graph/autogenSTkMethods
	mkdir src/graph/manualSTkMethods
	mkdir src/layout
	mkdir src/layout/manualSTkWrappers
	mkdir src/stkWrapper
	mkdir src/userobj
	mkdir src/userobj/linkTemplates
	mkdir src/userobj/STkTemplates
	mkdir src/userobj/autogenSTkMethods
	mkdir src/userobj/manualSTkMethods
	mkdir src/wrappers

stklos:
	mkdir stklos
	mkdir stklos/lessons

clean:
	- rm -f config.* Makefile 
	cd autowrap; make -f Make.autowrap clean
	cd bin; make -f Make.bin clean
	cd src; make -f Make.src clean

install:
	if [ ! -d $(execdir) ]; \
	then \
		mkdir -p $(execdir); \
	fi
	if [ ! -d $(bindir) ]; \
	then \
		mkdir -p $(bindir); \
	fi
	if [ ! -d $(libdir) ]; \
	then \
		mkdir -p $(libdir); \
	fi
	if [ ! -d $(incdir) ]; \
	then \
		mkdir -p $(incdir); \
	fi
	- rm -f $(execdir)/Link
	- mv @LINK_PREFIX@/src/Link $(execdir)/Link-$(LINK_VERSION)
	- strip $(execdir)/Link-$(LINK_VERSION)
	- ln -s $(execdir)/Link-$(LINK_VERSION) $(bindir)/Link 
	- cp -R @LINK_PREFIX@/include/LINK $(incdir)
	- mv @LINK_PREFIX@/src/*.a $(libdir)

depend:
	cd src; $(MAKE) -f Make.src DEPENDFLAGS=$(DEPENDFLAGS) depend


##########################################################################
## ATTENTION LIBRARY PROGRAMMERS:  LIBRARY_MAKEFILE
##########################################################################
## In order to use this makefile to compile your Link applications,
## add your source files to USER_SOURCE, making sure to end each line
## except the last one with a backslack.  (Replace demo.cc with your
## files).  NOTE:  this makefile links your program with all of the
## Link libraries (layouts, generators, algorithms, graph, and basic).  
## If executable size is a problem for you, edit the LINK_LIBS macro
## below.
##
## The directory $(LINK_PREFIX)/standalone contains the example which this
## makefile is currently set up to build.  The sample programs in this 
## example are demo.cc, demoNoGUI.cc, and linkUserInit.cc.  Try copying 
## this Makefile and those files to an empty directory. Then you can type 
##
##			make demoNoGUI 
##
## to build the first demo.  The GUI
## version is built by switching the comments in USER_SOURCE and 
## EXECUTABLE below and typing 
##
##			make -D STK_GUI=yes demo
##
## 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_PREFIX)/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 GUI part of the Link manual.
## 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_PREFIX)/stklos.
##########################################################################
#USER_SOURCE = \
#		demo.cc \
#		linkUserInit.cc	# must edit this file and include it 
#				# in this list to augment the GUI
#
USER_SOURCE = \
		demoNoGUI.cc  # demoNoGUI.cc is a sample program
				# using LINK objects, but not the GUI.
## ******************************************************************

## ******************************************************************
## Name your executable file below.
## ******************************************************************
#EXECUTABLE = demo
EXECUTABLE = demoNoGUI
## ******************************************************************

## ******************************************************************
## make -D STK_GUI=yes demo      makes the system with your additions
##
## make demoNoGUI                makes the system with your additions
##				 (assuming you've uncommented the 
##				 appropriate macros above)
## ******************************************************************


######################################################################
###################NO NEED TO CHANGE ANYTHING BELOW THIS POINT########
######################################################################
USER_OBJ = ${USER_SOURCE:.cc=.o}

OP_SYS          = @OP_SYS@
STK_VERSION         = @STK_VERSION@
VERS-OPT        = -DSTK_VERSION=\"$(STK_VERSION)\"
DFLGS           = -DSTk_CODE -DSUNOS4
TK              = -DUSE_TK



stkprefix          = @stkprefix@
stklibdir       = @STK_PREFIX@/lib/stk/$(STK_VERSION)/$(OP_SYS)
stkincdir       = @STK_PREFIX@/lib/stk/$(STK_VERSION)/include
linklibdir      = @LINK_PREFIX@/src

STKINCLUDES     = -I$(stkincdir)
STKFLAGS	= $(MACH) $(VERS-OPT) $(DFLGS) \
		  $(TK) -DHAVE_UNISTD_H=1 -DHAVE_SIGACTION=1 -DHAVE_SELECT=1

LINKINCL        = @LINK_PREFIX@/include

FLEX =   flex
PARSE = bison

## these are only here to handle nonstandard STk installations
## ***********************************************************
TKINCL          = @TK_STK_INCLUDE@
TCLINCL         = @TCL_STK_INCLUDE@
MPINCL         = @MP_STK_INCLUDE@
X11INCL         = @XINCLUDES@

MPLIB           = @MP_LIB@/@MP@.a
TKLIB           = @TK_STK_LIB@/libtk.a
TCLLIB          = @TCL_STK_LIB@/libtcl.a
## ***********************************************************

## there is some redundancy here.  The reason is that some places might
## not have STk fully installed.  The MPLIB,TKLIB,TCLLIB (and ..INCL) allow
## you to recover.
##LIBS =-L$(stklibdir) -L$(linklibdir) -L@TK_STK_LIB@  @X_PRE_LIBS@ @XLIBSW@ @X_EXTRA_LIBS@ -lXpm -lX11 -lstk -lgmp -ltk -ltcl  -lm
LIBS =-L$(stklibdir) -L@TK_STK_LIB@ @X_PRE_LIBS@ @XLIBSW@ @X_EXTRA_LIBS@ -lstk $(MPLIB) $(TKLIB) $(TCLLIB) -lXpm -lX11 -lm

CC = gcc
CCC = c++
CPPFLAGS = -I. -I$(LINKINCL) $(X11INCL) -I$(TCLINCL) -I$(TKINCL) \
           -I$(MPINCL) $(STKINCLUDES)
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.cc, 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.cc = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c -DSTK_GUI
LINK_COMPILE_NO_GUI.cc = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c

LINK_LINK_STK.cc = $(LINK_COMPILE.cc:-c=)
LINK_LINK.cc = $(LINK_COMPILE_NO_GUI.cc:-c=)

LINK_LIBS_STK = -lwrappers -llayoutstk -lgenstk -lalgstk -luserobjstk -lgraphstk -lbasicstk -lstkWrapper 

LINK_LIBS = -llayout -lgen -lalg -luserobj -lgraph -lbasic

LDLIBS_STK = $(LIBS) $(LINK_LIBS_STK) $(LINK_LIBS) 
LDLIBS = -L$(linklibdir) $(LINK_LIBS) -lm

SUFFIXES = .cc .o

.cc.o:
	if [ "$(STK_GUI)" = "yes" ]; \
	then \
		$(LINK_COMPILE.cc) $< -o $@; \
	else \
		$(LINK_COMPILE_NO_GUI.cc) $< -o $@; \
	fi

$(EXECUTABLE): $(USER_OBJ) 
	if [ "$(STK_GUI)" = "yes" ]; \
	then \
		$(LINK_LINK_STK.cc) -o $@ $(USER_OBJ) $(LDLIBS_STK); \
	else \
		$(LINK_LINK.cc) -o $@ $(USER_OBJ) $(LDLIBS); \
	fi; \
	strip $@

# can uncomment this if you detach the standalone makefile in the second
# half of this file
#clean:
#	- rm -f *.o $(EXECUTABLE)
