#
# Makefile for STk
# 
# Copyright (C) 1993,1994,1995 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
# 
# Permission to use, copy, and/or distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that both the above copyright notice and this permission notice appear in
# all copies and derived works.  Fees for distribution or use of this
# software or derived works may only be charged with express written
# permission of the copyright holder.  
# This software is provided ``as is'' without express or implied warranty.
#
#           Author: Erick Gallesio [eg@unice.fr]
#    Creation date: ??-Sep-1993 ??:??
# Last file update: 16-Jul-1995 11:16
#

include ../config.make

CFLAGS		= $(STKCFLAGS) $(VERS-OPT) $(MACHINE) $(DYNLOAD) $(TK) $(DFLGS) \
		  $(OPTS) @DEFS@ \
		  -I. -I../Tk -I../Tcl -I../Mp $(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 dummy.o

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

TKLIB		= ../Tk/libtk.a
TCLLIB		= ../Tcl/libtcl.a 
MPLIB		= ../Mp/$(MP).a
LIBS    	= @LIBS@ $(LIB_DLD) $(LIB_MALLOC)

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

default: 
	@echo "You must specify 'stk' or 'snow'"

stk:
	$(MAKE) stk-bin TK="-DUSE_TK"

snow:
	$(MAKE) snow-bin TK="-DNO_TK"
	
dev: 
	$(MAKE) dev-bin TK="-DUSE_TK"

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

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

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

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

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

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

$(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 $(bindir) ] ; then mkdir -p $(bindir); fi
	sed -e "s=@libdir@=$(libdir)=" < run-stk.in > $(bindir)/stk-$(VERSION)
	/bin/rm -f $(bindir)/stk
	ln $(bindir)/stk-$(VERSION) $(bindir)/stk
	chmod 0755 $(bindir)/stk-$(VERSION) $(bindir)/stk
	-if [ ! -d $(execdir) ] ; then mkdir -p $(execdir); fi
	$(CP) stk-bin $(execdir)
	$(STRIP) $(execdir)/stk-bin

install.stk.libs:
	-if [ ! -d $(execdir) ] ; then mkdir -p $(execdir); fi
	$(CP) libstk.a $(execdir)
	$(RANLIB) $(execdir)/libstk.a
	-if [ ! -d $(incdir) ] ; then mkdir -p $(incdir); fi
	$(CP) stk.h $(incdir)

install.snow: snow
	-if [ ! -d $(bindir) ] ; then mkdir -p $(bindir); fi
	sed -e "s=@libdir@=$(libdir)="    < run-snow.in > $(bindir)/snow-$(VERSION)
	/bin/rm -f $(bindir)/snow
	ln $(bindir)/snow-$(VERSION) $(bindir)/snow
	chmod 0755 $(bindir)/snow-$(VERSION) $(bindir)/snow
	-if [ ! -d $(execdir) ] ; then mkdir -p $(execdir); fi
	$(CP) snow-bin $(execdir)
	$(STRIP) $(execdir)/snow-bin

install.snow.libs:
	-if [ ! -d $(execdir) ] ; then mkdir -p $(execdir); fi
	$(CP) libsnow.a $(execdir)
	$(RANLIB) $(execdir)/libsnow.a	

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