#
# Toplevel 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 15:07
#


VERSION		= 2.2

SHELL		= /bin/sh
CP		= /bin/cp
RANLIB 		= @RANLIB@
MACHINE		= @MACHINE@
MP		= @MP@.a

prefix 		= @prefix@
libdir 		= $(prefix)/lib/stk/$(VERSION)
execdir 	= $(libdir)/$(MACHINE)
mandir 		= $(libdir)/man
incdir		= $(libdir)/include
bindir 		= $(prefix)/bin


all: start tcl tk mp src snow stklos ext stop 
	
start:
	@date > .start-date
	@/bin/rm -f config.make
	@echo "# Common startup for all Makefiles"		>  config.make
	@echo "VERSION		= $(VERSION)"			>> config.make
	@echo "SHELL		= $(SHELL)"			>> config.make
	@echo "prefix		= $(prefix)"			>> config.make
	@echo "libdir 		= $(libdir)"			>> config.make
	@echo "execdir	 	= $(execdir)"			>> config.make
	@echo "incdir 		= $(incdir)"			>> config.make
	@echo "bindir 		= $(bindir)"			>> config.make
	@echo "mandir 		= $(mandir)"			>> config.make
	@echo "VERS-OPT		= -DSTK_VERSION=\\\"$(VERSION)\\\"">> config.make
	@echo "MACHINE 		= -DMACHINE=\\\"$(MACHINE)\\\""	>> config.make
	@echo "CC		= @CC@"				>> config.make
	@echo "STKCFLAGS	= @STKCFLAGS@"			>> config.make
	@echo "STKLDFLAGS	= @STKLDFLAGS@"			>> config.make
	@echo "CP		= $(CP)"			>> config.make
	@echo "RANLIB		= @RANLIB@"			>> config.make
	@echo "STRIP		= @STRIP@"			>> config.make
	@echo "XINCLUDES	= @XINCLUDES@"			>> config.make
	@echo "XLIBSW		= @XLIBSW@"			>> config.make
	@echo "MP		= @MP@"				>> config.make
	@echo "DFLGS		= @DFLGS@"			>> config.make
	@echo "EOBJ		= @EOBJ@"			>> config.make
	@echo "EXTRA_OBJ	= @EXTRA_OBJ@"			>> config.make
	@echo "DYNLOAD		= @DYNLOAD@"			>> config.make
	@echo "RANLIB		= @RANLIB@"			>> config.make
	@echo "SH_CCFLAGS	= @SH_CCFLAGS@"			>> config.make
	@echo "SH_LDFLAGS	= @SH_LDFLAGS@"			>> config.make
	@echo "SH_LOADER	= @SH_LOADER@"			>> config.make
	@echo "SH_SUFFIX	= @SH_SUFFIX@"			>> config.make
	@echo "LIB_MALLOC	= @LIB_MALLOC@"			>> config.make
	@echo "LIB_DLD		= @LIB_DLD@"			>> config.make
		
	@echo "STK_LIBRARY	= $(libdir)"			>> config.make


stop:
	@echo -n "Make started at "
	@cat .start-date
	@/bin/rm .start-date
	@echo -n "Make completed at "
	@date

tcl:
	(cd Tcl; $(MAKE) libtcl.a)
tk:	 
	(cd Tk; $(MAKE) libtk.a)
mp:	 
	(cd Mp; $(MAKE) $(MP))
src:	 
	(cd Src; $(MAKE) stk TK="-DUSE_TK")
snow:	 
	(cd Snow; $(MAKE) snow TK="-DNO_TK")
stklos:	 
	(cd STklos; $(MAKE) stklos)	
ext:	 
	(cd Extensions; $(MAKE) all)
doc:	 
	(cd Doc; $(MAKE) all)
dvi:	 
	(cd Doc; $(MAKE) dvi)



widget-demo:
	/bin/sh -c "(cd Demos; STK_LIBRARY=../Lib ../Src/stk-bin -f widget.stk)"

install: clean-before
	(cd Tcl;     	$(MAKE) install)
	(cd Tk;      	$(MAKE) install)
	(cd Mp;		$(MAKE) install)
	(cd Src;     	$(MAKE) install.stk)
	(cd Snow;     	$(MAKE) install.snow)
	(cd Lib;     	$(MAKE) install)
	(cd STklos;  	$(MAKE) install)
	(cd Extensions; $(MAKE) install)
	(cd Demos;   	$(MAKE) install)
	@echo ""
	@echo "Installation completed."

install.libs:
	(cd Tcl;     	$(MAKE) install.libs)
	(cd Tk;      	$(MAKE) install.libs)
	(cd Mp;		$(MAKE) install.libs)
	(cd Src;     	$(MAKE) install.stk.libs)
	(cd Snow;     	$(MAKE) install.snow.libs)
	@echo ""
	@echo "Full installation completed."


clean-before:
	@if [ -d $(prefix)/lib/stk ]; \
	then \
	  echo "*** WARNING:"; \
	  echo "*** A previous version of STk has already been installed in"; \
	  echo "*** directory '$(prefix)/lib/stk'. It is not a problem since"; \
	  echo "*** several versions can coexist now in this directory"; \
	  echo "*** However, if you are short in place, or if you don't use "; \
	  echo "*** a multi architecture file system, cleaning may be a good"; \
	  echo "*** thing to do."; \
	  echo "***" ; \
	  echo "*** Should I clean this directory before starting installation"; \
 	  echo -n "*** of STk-$(VERSION) file? [no] " ; \
	  read a; \
	  case $$a in \
	    y*|Y*) /bin/rm -rf $(prefix)/lib/stk;; \
	    *) echo "No cleaning!";;  \
	  esac; \
	fi
	 
install.man:
	(cd Doc;	$(MAKE) install.man)
	(cd Tk;		$(MAKE) install.man)
clean:
	(cd Tcl;    	$(MAKE) clean)
	(cd Tk;     	$(MAKE) clean)
	(cd Mp;     	$(MAKE) clean)
	(cd Src;    	$(MAKE) clean)
	(cd Snow;    	$(MAKE) clean)
	(cd STklos; 	$(MAKE) clean)
	(cd Extensions; $(MAKE) clean)
	/bin/rm -f core *~ Makefile config.*
