# File   : /home/cvs/cvsroot/projects/visualstate/scope/makefile,v
# Comment: Unix Makefile for SCOPE
# Release: scope-0-10
#
#    Copyright (C) 2001-2002 Andrzej Wasowski
#    
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#    
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Usage:
#
#    make        - builds the tool as standalone executable for current platorm
#    make scope  - builds scope for linux (only under linux)
#    make scope.exe
#                - builds scope for windows (both under linux and windows)
#    make clean  - cleans the subtree starting in tool directory (all backups,
#                  intermedate files, anonymized files, etc)
#    make mrprop - as make clean but also removes built executables
#    make test   - runs a set of regression tests
#
#    make stat   - runs a set of statistics over models
#
#    make bin-release - build a binary release (linux) for SCOPE (read below)
#    make src-release - build source release for SCOPE (READ below)
#
# (obsolete) To open a test session in interactive environment issue:
#	$ make
#       $ mosml use.sml
# in scope source directory
#
# WARNING: automatic platform detection is very fragile (and unfortunately
#          make test relies on it).
#
#
# makefile,v 1.105 2002/11/16 00:05:39 wasowski Exp

# release number
 
RELEASE=0-10

# name of release notes (will then be renamed to release-$(RELEASE).txt)
# it is kept here for convenience. This way you do not have to rename
# release notes with every tagged releases (like alphas, betas, etc)

RELEASE_NOTES=release-0-10.txt

MOSMLHOME=/usr/mosml
MOSMLTOOLS=camlrunm $(MOSMLHOME)/tools
MOSMLLIBS=-I . -I lib
MOSMLC=mosmlc -c $(MOSMLLIBS)
MOSMLL=mosmlc $(MOSMLLIBS)
MOSMLLEX=mosmllex
MOSMLYACC=mosmlyac

TMPFILENAME=temporary.file

# files included in the binary distribution of scope

BINDISTRO=scope lib/libmuddy.so doc/LICENSE doc/MANUAL doc/$(RELEASE_NOTES) \
	  CodGenC1_testdrv.c CodGenC1_tinydrv.c CodGenC1_smokedrv.c VSTypes.h \
	  CodGenVS_tinydrv.c                    CodGenVS_smokedrv.c

SRCDISTRO=

# files and modules specifically belonging to CodGenC1

CODGENC1_UNITS=CodGenC1_LR CodGenC1_front CodGenC1_schedule CodGenC1_back_types \
	       CodGenC1_back CodGenC1_dump CodGenC1
CODGENC1_OBJECTS=CodGenC1_LR.uo CodGenC1_front.uo CodGenC1_schedule.uo CodGenC1_back_types.uo\
		 CodGenC1_back.uo CodGenC1_dump.uo CodGenC1.uo

# global list of files and modules

UNITS=UList Cppish Haskellish Say -toplevel MkEnvStruct Typeset -toplevel set-fn \
      Symbol SymbolEnv Err Types Prim Exp vsr Absyn AbsynPrint AbsynLogic Simplifier \
      Normalise JoinTran StaticScope Stat VsrAbsyn Interpr -toplevel codgen-sig CodGen \
      CodeGenC $(CODGENC1_UNITS) -toplevel CodGenCstubs -toplevel CodGenCdrv \
      -toplevel CodGenScope parser lexer parse Semant Unparse Main MainRun

OBJECTS=UList.uo Cppish.uo Haskellish.uo Say.uo MkEnvStruct.uo Typeset.uo set-fn.uo \
	Symbol.uo SymbolEnv.uo Err.uo Types.uo Prim.uo Exp.uo vsr.uo Absyn.uo AbsynPrint.uo \
	Simplifier.uo AbsynLogic.uo Normalise.uo JoinTran.uo StaticScope.uo Stat.uo  \
	VsrAbsyn.uo Interpr.uo codgen-sig.uo CodGen.uo CodGenC.uo \
	$(CODGENC1_OBJECTS) CodGenCstubs.uo CodGenCdrv.uo CodGenScope.uo \
	parser.uo lexer.uo parse.uo Semant.uo Unparse.uo Main.uo MainRun.uo


ifeq ($(OSTYPE),linux-gnu) 
target: scope
else 
target: scope.exe
	echo $(OSTYPE)
endif



scope: lib $(OBJECTS)
	$(MOSMLL) -standalone $(OBJECTS) -o scope

scope.exe: lib $(OBJECTS) 
	$(MOSMLL) -noheader $(OBJECTS) -o $(TMPFILENAME)
	cat lib/camlrunm.exe $(TMPFILENAME) > scope.exe
	rm -f $(TMPFILENAME)

Absyn.uo Absyn.ui: Absyn.sml 
	$(MOSMLC) set-fn.ui binary-set-fn.ui -structure $<

Main.uo Main.ui: Main.sml CodGenC1.ui CodGenCstubs.ui CodGenCdrv.ui CodGenScope.ui
	$(MOSMLC) getopt-sig.ui getopt.ui CodGenC1.ui CodGenCstubs.ui \
		CodGenCdrv.ui CodGenScope.ui Main.sml

SymbolEnv.uo SymbolEnv.ui: SymbolEnv.sml MkEnvStruct.ui Symbol.uo	
	$(MOSMLC) -structure MkEnvStruct.ui Symbol.ui SymbolEnv.sml

MkEnvStruct.ui MkEnvStruct.uo : MkEnvStruct.sml
	$(MOSMLC) -toplevel $<

set-fn.ui set-fn.uo : set-fn.sml
	$(MOSMLC) binary-set-fn.ui ord-set-sig.ui -toplevel $<

codgen-sig.ui codgen-sig.uo : codgen-sig.sml Absyn.ui
	$(MOSMLC) -toplevel $<

CodGenC1.uo : CodGenC1.sml codgen-sig.ui
	$(MOSMLC) codgen-sig.ui -toplevel $<

CodGenCstubs.uo : CodGenCstubs.sml codgen-sig.ui
	$(MOSMLC) codgen-sig.ui -toplevel $<

CodGenCdrv.uo : CodGenCdrv.sml codgen-sig.ui
	$(MOSMLC) codgen-sig.ui -toplevel $<

CodGenScope.uo : CodGenScope.sml codgen-sig.ui
	$(MOSMLC) codgen-sig.ui -toplevel $<

parser.ui: parser.sig
	$(MOSMLC) -liberal parser.sig

parser.sml parser.sig: parser.grm
	$(MOSMLYACC) parser.grm

.SUFFIXES :
.SUFFIXES : .sml .sig .ui .uo .mlp .lex .c .o

.sig.ui:
	$(MOSMLC) $<

.sml.uo:
	$(MOSMLC) $<

.lex.sml:
	$(MOSMLLEX) $<



dep: lexer.sml parser.sml makefile
	rm -f makefile.bak
	mv makefile makefile.bak
	$(MOSMLTOOLS)/cutdeps < makefile.bak > makefile
	$(MOSMLTOOLS)/mosmldep >> makefile

.PHONY:clean bak dobak test_parse dotest_parse mrprop test_results zip tgz \
       test lib debug dobinaryrelease dosourcerelease bin-release src-release

lib:
	make -C lib -f makefile 

zip: scope.exe
	zip -j scope-bin.zip scope.exe doc/LICENSE doc/MANUAL lib/camlrt.dll doc/release-$(RELEASE).txt

bin-release:
	rm -Rf /tmp/releasing_scope && \
	mkdir /tmp/releasing_scope && \
	cd /tmp/releasing_scope && \
	cvs export -kv -rscope-$(RELEASE) scope-src
	make -C /tmp/releasing_scope/scope-src dobinaryrelease
	mv /tmp/releasing_scope/scope-$(RELEASE)-bin.tar.gz .
	rm -Rf /tmp/releasing_scope

src-release:
	rm -Rf /tmp/releasing_scope && \
	mkdir /tmp/releasing_scope && \
	cd /tmp/releasing_scope && \
	cvs export -kv -rscope-$(RELEASE) scope-src
	make -C /tmp/releasing_scope/scope-src dosourcerelease
	mv /tmp/releasing_scope/scope-$(RELEASE)-src.tar.gz .
	rm -Rf /tmp/releasing_scope



dobinaryrelease: $(BINDISTRO)
	mkdir ../scope-$(RELEASE)-bin && \
	cp $^ ../scope-$(RELEASE)-bin/ && \
	cd .. && \
	(mv scope-$(RELEASE)-bin/$(RELEASE_NOTES) scope-$(RELEASE)-bin/release-$(RELEASE).txt || true ) && \
	tar czvf scope-$(RELEASE)-bin.tar.gz scope-$(RELEASE)-bin/ 

dosourcerelease: $(SRCDISTRO)
	mkdir ../scope-$(RELEASE)-src && \
	mkdir ../scope-$(RELEASE)-src/doc && \
	mkdir ../scope-$(RELEASE)-src/lib && \
	mkdir ../scope-$(RELEASE)-src/test && \
	mkdir ../scope-$(RELEASE)-src/model && \
	cp *.* makefile ../scope-$(RELEASE)-src  > /dev/null && \
	cp -R doc ../scope-$(RELEASE)-src/ && \
	cp -R lib ../scope-$(RELEASE)-src/ && \
	cd .. && \
	(mv scope-$(RELEASE)-src/doc/$(RELEASE_NOTES) scope-$(RELEASE)-src/doc/release-$(RELEASE).txt || true) && \
	tar czvf scope-$(RELEASE)-src.tar.gz scope-$(RELEASE)-src/ 


clean: doclean
	make -C test clean 
	make -C lib -f makefile clean
	rm -f parser.sig parser.sml lexer.sml $(TMPFILENAME)
	
mrprop: clean
	make -C test mrprop
	make -C lib mrprop
	rm -f scope scope.exe
	rm -f scope-bin.tar.gz scope-bin.zip

# doclean is a general cleaning procedure 
# called from all makefiles in subtree

doclean:
	rm -f *.err *.ui *.uo *~ core *.bak *.o test_results skas* *.dot

bak: 	
	make clean
	make -C .. -f scope/makefile dobak
	
dobak:
	rm -f scope-bin.tar.gz scope-src.tar.gz
	tar czvf scope-src.tar.gz scope/


# test calls

test_parser:	
	make -C test test_parser

test: target 
	make -C test

stats: target
	@make -C test stats
fullstats: target
	@make -C test fullstats

debug: target
	make -C test use

### DO NOT DELETE THIS LINE
CodGenCdrv.uo: Absyn.uo CodGenC.uo Cppish.uo 
JoinTran.uo: Absyn.uo 
Exp.uo: Prim.uo Symbol.ui 
CodGenC1_back_types.uo: CodGen.uo 
lexer.uo: parser.ui vsr.uo Err.ui 
parser.ui: Types.ui vsr.uo 
parser.uo: parser.ui Types.ui vsr.uo Symbol.ui Err.ui 
CodGenCstubs.uo: Absyn.uo CodGenC.uo Cppish.uo 
CodGenC1_back.uo: CodGenC1_LR.uo CodGenC1_back_types.uo UList.ui Absyn.uo \
    CodGenC.uo Symbol.ui Err.ui 
CodGenC1_front.uo: Stat.uo SymbolEnv.uo CodGenC1_LR.uo Types.ui \
    StaticScope.uo UList.ui Haskellish.ui Absyn.uo Symbol.ui Normalise.ui \
    Say.ui 
CodGenC1_LR.uo: CodGen.uo Types.ui StaticScope.uo UList.ui Symbol.ui Exp.uo 
CodGenC1_dump.uo: CodGenC.uo Cppish.uo Err.ui CodGenC1_back.uo 
CodGenC1_schedule.uo: CodGenC1_LR.uo Haskellish.ui Err.ui Say.ui 
vsr.uo: Types.ui Prim.uo Symbol.ui 
parse.uo: parse.ui Symbol.ui Err.ui Say.ui lexer.uo parser.ui 
parse.ui: vsr.uo 
codgen-sig.uo: Absyn.uo 
VsrAbsyn.uo: VsrAbsyn.ui SymbolEnv.uo vsr.uo Absyn.uo Haskellish.ui \
    Symbol.ui Err.ui Say.ui 
VsrAbsyn.ui: vsr.uo Absyn.uo 
Unparse.uo: Unparse.ui Types.ui vsr.uo Typeset.ui CodGenC.uo Symbol.ui \
    Say.ui 
Unparse.ui: vsr.uo 
UList.uo: UList.ui 
Typeset.uo: Typeset.ui 
Types.uo: Types.ui Haskellish.ui Err.ui 
SymbolEnv.uo: Symbol.ui 
Symbol.uo: Symbol.ui 
StaticScope.uo: AbsynPrint.uo Typeset.ui Haskellish.ui Absyn.uo Symbol.ui \
    Simplifier.uo Err.ui Say.ui AbsynLogic.ui 
Stat.uo: StaticScope.uo Absyn.uo Haskellish.ui Err.ui Say.ui 
Simplifier.uo: Haskellish.ui Absyn.uo Symbol.ui Err.ui 
Semant.uo: Semant.ui Absyn.uo 
Semant.ui: Absyn.uo 
Say.uo: Say.ui 
PPSymbol.uo: Symbol.ui 
Normalise.uo: Normalise.ui Haskellish.ui Absyn.uo Symbol.ui Err.ui Say.ui 
Normalise.ui: Absyn.uo 
MainRun.uo: Main.uo 
Main.uo: Stat.uo CodGenScope.uo Haskellish.ui Absyn.uo CodGenC.uo Symbol.ui \
    CodGenCstubs.uo VsrAbsyn.ui CodGenC1.uo Unparse.ui CodGenCdrv.uo Err.ui \
    Say.ui parse.ui AbsynLogic.ui 
Interpr.uo: SymbolEnv.uo Types.ui Prim.uo Absyn.uo Haskellish.ui Err.ui 
Haskellish.uo: Haskellish.ui 
Err.uo: Err.ui Say.ui 
CodGenC1.uo: CodGenC1_dump.uo Types.ui CodGenC1_front.uo Haskellish.ui \
    Absyn.uo CodGenC.uo CodGenC1_schedule.uo Err.ui CodGenC1_back.uo Say.ui 
CodGenC.uo: CodGen.uo SymbolEnv.uo Types.ui Typeset.ui Haskellish.ui \
    Absyn.uo 
CodGen.uo: Cppish.uo 
AbsynPrint.uo: Typeset.ui Haskellish.ui Absyn.uo Symbol.ui Err.ui Say.ui 
AbsynLogic.uo: AbsynLogic.ui SymbolEnv.uo AbsynPrint.uo Typeset.ui \
    Haskellish.ui Absyn.uo Symbol.ui Err.ui Say.ui 
AbsynLogic.ui: Absyn.uo 
Absyn.uo: SymbolEnv.uo Types.ui Haskellish.ui Symbol.ui Err.ui Exp.uo 
