## 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: 7-Aug-1997
## 
SHELL = /bin/sh

.SUFFIXES : .cpp
############################################################################
## ATTENTION LIBRARY PROGRAMMERS:
##
##  see $LINK_BASE/standalone/Makefile for instructions regarding 
##  programming with LINK's libraries.
############################################################################
LINK_VERSION     = 1.4
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
stklosdir	= $(libdir)/stklos
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) -DUSE_STKLOS -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
TCLEVLIB	= @TCL_STK_LIB@/libevtcl.a
##LIBS =-L$(stklibdir) -L@MP_LIB@ -L@FLEX_LIB@ @X_PRE_LIBS@ @XLIBSW@ @X_EXTRA_LIBS@ -lX11 -ltcl -lfl -lm -ldl
## 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) $(TCLEVLIB) $(TCLLIB) -lX11 -lm -ldl
### ---------------------Parameters for GNU Compiler---------------------
CC = @CC@
CCC = @CXX@
CPPFLAGS = -I.  \
            -I$(LINKINCL) $(X11INCL) -I$(TCLINCL) -I$(TKINCL) \
           -I$(MPINCL) $(STKINCLUDES)
GNUFLAGS = -v $(STKFLAGS)  
##### 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 = 


THIS_DIR=	Config.mk.linux-eg Config.mk.solaris-eg TO_DO BUGS \
                configure.in Makefile.in CHANGELOG COPYRIGHTS GUI_QUICKREF \
                INSTALL README
#### 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.c = $(CC) $(CCFLAGS) $(CPPFLAGS) -c 
LINK_COMPILE.cpp = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c -DSTK_GUI
LINK_COMPILE_NO_GUI.cpp = $(CCC) $(CCFLAGS) $(CPPFLAGS) -c
PROGRAM = Link 
$(PROGRAM): $(THIS_DIR) autowrap bin stklos standalone test include src 
	cd autowrap; $(MAKE) -f Make.autowrap .SUFFIXES="$(.SUFFIXES)" all
	cd bin; $(MAKE) -f Make.bin 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.cpp="$(LINK_COMPILE.cpp)" GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) LIBS="$(LIBS)" all
	- rm src/algorithm/Animation.o   ### GUI stuff must be removed
	cd src; $(MAKE) -f Make.src \
		LINK_COMPILE.cpp="$(LINK_COMPILE.c)" \
		LINK_COMPILE.cpp="$(LINK_COMPILE_NO_GUI.cpp)" \
		GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) \
		LIBS="$(LIBS)" libalg
	- 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.cpp="$(LINK_COMPILE.cpp)" 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

win32-init:
	cd autowrap; $(MAKE) -f Make.autowrap .SUFFIXES="$(.SUFFIXES)" all
	cd src; $(MAKE) -f Make.src LINK_COMPILE.c="$(LINK_COMPILE.c)" LINK_COMPILE.cpp="$(LINK_COMPILE.cpp)" GNUFLAGS="$(GNUFLAGS)" FLEX=$(FLEX) PARSE=$(PARSE) LIBS="$(LIBS)" win32-init

clean:
	cd standalone; rm -rf *.o core demoNoGUI demo Make.standalone
	cd src; make -f Make.src clean
	cd autowrap; make -f Make.autowrap clean
	cd bin; make -f Make.bin clean
	- rm -f config.* Makefile 
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
	if [ ! -d $(stklosdir) ]; \
	then \
		mkdir -p $(stklosdir); \
	fi
	- rm -f $(execdir)/Link
	- rm -f $(bindir)/Link
	- cp @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)
	- cp -R @LINK_PREFIX@/stklos/* $(stklosdir)
	- cp @LINK_PREFIX@/src/*.a $(libdir)
depend:
	cd src; $(MAKE) -f Make.src DEPENDFLAGS=$(DEPENDFLAGS) depend
