#
# Makefile for STk
# 
# Copyright © 1993-1999 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
# 
# Permission to use, copy, modify, distribute,and license this
# software and its documentation for any purpose is hereby granted,
# 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.
# This software is provided ``AS IS'' without express or implied
# warranty.
#
#           Author: Erick Gallesio [eg@unice.fr]
#    Creation date: ??-Sep-1993 ??:??
# Last file update:  3-Sep-1999 20:17 (eg)
#

include ../config.make

CFLAGS		= $(STKCFLAGS) $(MACHINE) $(DYNLOAD) $(TK) $(DFLGS) \
		  $(OPTS) @DEFS@ \
		  -I. -I../Tk/generic -I../Tk/$(FLAVOR) -I../Tcl -I../Mp \
		  -I../Stack $(XINCLUDES)
#
# Add here your object ('.o') files
#
USER_OBJ	= 

#
# Scheme interpreter objects
#
SOBJ 		= stk.o slib.o primitives.o boolean.o char.o str.o vector.o\
	  	  gc.o port.o  number.o list.o symbol.o\
		  read.o print.o eval.o env.o macros.o syntax.o \
		  cont.o io.o sport.o promise.o error.o proc.o keyword.o \
		  dump.o address.o dynload.o unix.o toplevel.o argv.o \
		  extend.o signal.o trace.o module.o dummy.o \
		  stklos.o vport.o console.o

TCLOBJ		= tcl-lib.o tcl-util.o tcl-glue.o tcl-obj.o
TKOBJ		= tk-main.o tk-glue.o tk-util.o

TKLIB		= ../Tk/$(FLAVOR)/libtk.a
TCLLIB		= ../Tcl/libtcl.a
EVTCLLIB	= ../Tcl/libevtcl.a
MPLIB		= ../Mp/$(MP).a
STACKLIB	= ../Stack/libstack.a
LIBS    	= @LIBS@ $(LIB_DLD) $(LIB_MALLOC)

ALLIBS	 = $(MPLIB) $(STACKLIB) $(TKLIB) $(TCLLIB) $(EVTCLLIB)
SALLLIBS = $(MPLIB) $(STACKLIB) $(TCLLIB) 

default: 
	@echo "You must specify 'STk' or 'Snow'"

STk:
	make stk TK="-DUSE_TK"

Snow:
	make snow TK="-DNO_TK"

dev: 
	make dev-bin TK="-DUSE_TK"

tags:
	etags *.[ch] ../Tcl/*.[ch] ../Tk/*.[ch]

stk: 	userinit.o libstk.a $(ALLIBS)
	/bin/rm -f stk
	$(CC) $(STKLDFLAGS) $(CFLAGS) -o stk userinit.o libstk.a $(ALLIBS) \
	      $(XLIBSW) $(LIBS)

snow: 	userinit.o libsnow.a $(SALLIBS)
	/bin/rm -f snow
	$(CC) $(STKLDFLAGS) $(CFLAGS) -o snow userinit.o libsnow.a $(SALLLIBS)\
	      @SNOW_LIBS@ $(LIBS) 

dev-bin: userinit.o $(SOBJ) $(USEROBJ) $(TCLOBJ) $(TKOBJ) $(EOBJ) $(ETKOBJ) $(SALLIBS)
	/bin/rm -f stk
	$(CC) $(STKLDFLAGS) $(CFLAGS) -o stk userinit.o $(SOBJ) $(TCLOBJ) \
	      $(TKOBJ) $(EOBJ) $(ETKOBJ) $(ALLIBS) $(XLIBSW) $(LIBS)

libstk.a: $(SOBJ) $(TCLOBJ) $(TCLOBJ) $(TKOBJ) $(ETKOBJ) $(EOBJ)
	/bin/rm -f libstk.a
	ar rc libstk.a $(SOBJ) $(TKOBJ) $(TCLOBJ) $(ETKOBJ) $(EOBJ)
	$(RANLIB) libstk.a

libsnow.a: $(SOBJ) $(TCLOBJ) $(EOBJ)
	/bin/rm -f libsnow.a
	ar rc libsnow.a $(SOBJ) $(TCLOBJ) $(EOBJ)
	$(RANLIB) libsnow.a

etags:
	etags *.[ch] ../Tcl/*.[ch] ../Tk/generic/*.[ch] ../Tk/unix/*.[ch]

$(MPLIB):
	(cd ../Mp; make $(MP).a)

$(TKLIB): 
	(cd ../Tk; make $(TKLIB))

$(TCLLIB):
	(cd ../Tk; make $(TKLIB))

install:
	@echo "You must specify 'install.stk' or "install.snow'"

install.stk: stk
	-if [ ! -d $(root)$(bindir) ] ; then mkdir -p $(root)$(bindir); fi
	/bin/rm -f $(root)$(bindir)/stk $(root)$(bindir)/stk-$(VERSION) 
	ln -s $(execdir)/stk $(root)$(bindir)/stk-$(VERSION) 
	ln -s $(execdir)/stk $(root)$(bindir)/stk 
	-if [ ! -d $(root)$(execdir) ] ; then mkdir -p $(root)$(execdir); fi
	$(CP) stk $(root)$(execdir)
	chmod 0755 $(root)$(execdir)/stk

install.stk.libs:
	-if [ ! -d $(root)$(ardir) ] ; then mkdir -p $(root)$(ardir); fi
	$(CP) libstk.a $(root)$(ardir)
	$(RANLIB) $(root)$(ardir)/libstk.a
	-if [ ! -d $(root)$(incdir) ] ; then mkdir -p $(root)$(incdir); fi
	$(CP) stk.h stkvers.h tk-glue.h tcl-glue.h $(root)$(incdir)

install.snow: snow
	-if [ ! -d $(root)$(bindir) ] ; then mkdir -p $(root)$(bindir); fi
	/bin/rm -f $(root)$(bindir)/snow-$(VERSION) $(root)$(bindir)/snow
	ln -s $(execdir)/snow $(root)$(bindir)/snow-$(VERSION) 
	ln -s $(execdir)/snow $(root)$(bindir)/snow 
	-if [ ! -d $(root)$(execdir) ] ; then mkdir -p $(root)$(execdir); fi
	$(CP) snow $(root)$(execdir)
	chmod 0755 $(root)$(execdir)/snow

install.snow.libs:
	-if [ ! -d $(root)$(ardir) ] ; then mkdir -p $(root)$(ardir); fi
	$(CP) libsnow.a $(root)$(ardir)
	$(RANLIB) $(root)$(ardir)/libsnow.a	
	-if [ ! -d $(root)$(incdir) ] ; then mkdir -p $(root)$(incdir); fi
	$(CP) stk.h stkvers.h tcl-glue.h $(root)$(incdir)


clean: 
	@/bin/rm -f  core *.o core config.* Makefile \
		     stk  libstk.a  stk  run-stk \
		     snow libsnow.a snow run-snow
