# File   : /home/cvs/cvsroot/projects/visualstate/scope/Makefile,v
# Comment: Unix Makefile for SCOPE
# Release: scope-0-15_final
#
#    Copyright (C) 2001-2004 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: FIXME
#
#    make        - builds everything for current platform
#    make scope  - builds scope for linux (only under linux)
#    make scope.exe
#                - builds scope for windows (unfortunately only under 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,
#                  dependency files etc (equivalent to Mosmake realclean)
#    make test   - runs a set of regression tests
#    make stats  - runs a set of statistics over models
#    make fullstats 
#    		 - as above but also run expensive statistics
#
#    make bin-release - build a binary release (linux) for SCOPE (read below)
#    make src-release - build source release for SCOPE (READ below)
#
# Makefile,v 1.2.2.13 2004/05/06 14:21:02 wasowski Exp

# TODO
# esr suggests this piece of code for making releases. Have a go at it
# and try to improve what I have. Also look into release how to and
# try to see what is needed to improve the file names (sec. 7.3)
#
#foobar-$(VERS).tar.gz:
#	@ls $(SRC) | sed s:^:foobar-$(VERS)/: >MANIFEST
#	@(cd ..; ln -s foobar foobar-$(VERS))
#	(cd ..; tar -czvf foobar/foobar-$(VERS).tar.gz `cat foobar/MANIFEST`)
#	@(cd ..; rm foobar-$(VERS))


# general options

# absolute path to the directory containing this makefile

SCOPEROOT :=/home/wasowski/private/work/scope/scope


MOSMLHOME  := /opt/mosml
MOSMLC     := mosmlc
MOSMLFLAGS :=
MOSMLL     := mosmlc 
MOSMLLEX   := mosmllex
MOSMLYAC   := mosmlyac
PERL       := perl
MOSMAKE    := mosmake
TMPFILENAME:= temporary.file
RM         := rm -f
MKDIR      := mkdir
MV         := mv
MAKE       := make
CVS        := cvs
LN         := ln
TOUCH      := touch
FIND       := find
TAR        := tar

# these two are used for scriptin and runing interactive sessions (testing)
# NOTE: lazy assignments on purpose

MOSML      = mosml $(addprefix -I , $(MOSMAKEDIRS)) -quietdec
MOSMLI     = mosml $(addprefix -I , $(MOSMAKEDIRS)) -P full

########## You should not need to change below this line 
########## if you only need to compile.

# scope components
MOSMAKEDIRS := acfg wuddy lib util envspec test/src ./

# this is supposed to tell mosmake (and mosmlc) where to find muddy
MOSMLFLAGS := -I $(SCOPEROOT)/muddy/

# this is supposed to the same for ld
MUDDYHOME := $(SCOPEROOT)/muddy/

# release number

RELEASE := 0-15_final
RELEASEDIR := /tmp/releasing_scope/

# 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-15.txt

# files included in the binary distribution of scope

BINDISTRO := scope wuddy/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 :=

# paths to models (used in testing)

GENERICDIR := ../models/generic/
COMPILABLEDIR := ../models/compilable/

# used to be conditional, but really error prone (did not work on gentoo)
EXEEXT := 

############# END OF OPTIONS #############################################

.PHONY: muddy

SCOPE := scope$(EXEEXT)
include $(MOSMAKE)/Makefile.inc

# hooks to build parts of the project
wuddy      : wuddy/wuddy-fn.uo,smartmade wuddy/wuddy-fn.ui,smartmade
lib        : lib/stub.uo,smartmade
util       : util/stub.uo,smartmade
test_build : test/src/stub.uo,smartmade
envtool    : envspec/envtool.uo,smartmade
envtooli   : envspec/envtooli

# TODO: scope should depend on muddy.so

muddy:
	echo $(MUDDYHOME)
	make MOSMLHOME=\"${MOSMLHOME}\" -C muddy/ 

# TODO: cross compilation stuff does not really work with mosmake
#ifeq ($(OSTYPE),linux-gnu) 
#target: scope
#else 
#target: scope.exe
#	echo $(OSTYPE)
#endif
#
#scope: lib wuddy $(OBJECTS)
#	$(MOSMLL) -standalone $(OBJECTS) -o scope
#
#scope.exe: lib wuddy $(OBJECTS) 
#	$(MOSMLL) -noheader $(OBJECTS) -o $(TMPFILENAME)
#	cat lib/camlrunm.exe $(TMPFILENAME) > scope.exe
#	rm -f $(TMPFILENAME)

scope: muddy MainRun
	mv MainRun scope

# other commands

# depend

dep : depend

mrprop : realclean
	rm -f scope-*-bin.tar.gz scope-*-src.tar.gz

#extended cleaning requirements

clean: scopeclean

scopeclean:
	$(RM) *.err core test_results skas* *.dot MANIFEST

# releasing 

bin-release:
	${RM} -R ${RELEASEDIR} && \
	${MKDIR} -p ${RELEASEDIR} && \
	cd ${RELEASEDIR} && \
	${CVS} export -kv -r scope-${RELEASE} scope-src
	${MAKE} -C ${RELEASEDIR}/scope-src /scope-src SCOPEROOT=\"${RELEASEDIR}/scope-src\" dobinaryrelease
	${MV} ${RELEASEDIR}/scope-${RELEASE}-bin.tar.gz .
	${RM} -R ${RELEASEDIR}

src-release:
	${RM} -R ${RELEASEDIR} && \
	${MKDIR} ${RELEASEDIR} && \
	cd ${RELEASEDIR} && \
	${CVS} export -kv -r scope-${RELEASE} scope-src
	${MAKE} -C ${RELEASEDIR}/scope-src SCOPEROOT=\"${RELEASEDIR}/scope-src/\" dosourcerelease
	${MV} ${RELEASEDIR}/scope-${RELEASE}.tar.gz .
	${RM} -R ${RELEASEDIR}

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)
	${MV} ${RELEASEDIR}/scope-src ${RELEASEDIR}/scope-$(RELEASE)
	cd ${RELEASEDIR} && \
		${FIND} scope-${RELEASE}/ -type f > scope-${RELEASE}/MANIFEST
	cd ${RELEASEDIR} && \
		${TAR} czvf scope-${RELEASE}.tar.gz `cat scope-${RELEASE}/MANIFEST`

# testing 

include test/makefile.inc

