#
# $Id: Makefile,v 1.16 1999/01/12 20:25:53 lindig Exp $
# $Name:  $
#


# 
# basic variables and rules for compiling Objective Caml projects
# are imported from the top level to ensure consistency.
#

TOPLEVEL =	.
include 	$(TOPLEVEL)/Makefile.ocaml

#
# Name and version for binaries and tar files
#

NAME =		tony
VERSION =       0.9

# Default target is 'all'

all::		ALWAYS DEPEND
all.opt::	ALWAYS DEPEND

# realclean includes clean'ing

realclean::	clean

# -----------------------------------------------------------------------------
# Important Variables
# -----------------------------------------------------------------------------

#
# enter ML sources generated by some tool below.  These are usually lex
# and yacc generated files.
#

GENERATED = 	xmlparse.ml xmlparse.mli xmlscan.ml this.ml

clean::;	rm -f $(GENERATED)

# Files made in this directory from source files. They make up the
# executable.

CMO = 		error.cmo xml.cmo xmlstate.cmo xmlparse.cmo \
		xmlscan.cmo this.cmo main.cmo

CMX =		$(CMO:.cmo=.cmx)
OBJ =		$(CMO:.cmo=.o)
CMI =		$(CMO:.cmo=.cmi)

# Some cmo files depend on modules from mylib - make sure they are
# there.

$(CMO):		mylib
$(CMX):		mylib.opt

clean::; 	rm -f $(CMO) $(CMX) $(OBJ) $(CMI)

#
# Mylib - this library contains some generic modules. MYLIB conatains
# the path to the directory that holds the library.
#

MYLIB =			./mylib

all     mylib    ::;	cd $(MYLIB) && $(MAKE) all
all.opt mylib.opt::;	cd $(MYLIB) && $(MAKE) all.opt

clean::; 		cd $(MYLIB) && $(MAKE) clean
realclean::;		cd $(MYLIB) && $(MAKE) realclean

#
# Compiler flags used in Makefile.ocaml for compiling
#

INCLUDE =	-I $(MYLIB)
CFLAGS = 	$(INCLUDE)
OFLAGS = 	$(INCLUDE) -unsafe -noassert
OFLAGS = 	$(INCLUDE) 

# -----------------------------------------------------------------------------
# Targets
# -----------------------------------------------------------------------------

all::		$(NAME)
all.opt::	$(NAME).opt


$(NAME):	$(CMO) mylib
		$(CAMLC) $(CFLAGS) -o $@ mylib.cma $(CMO)

$(NAME).opt:	$(CMX) mylib.opt
		$(CAMLOPT) $(OFLAGS) -o $@ mylib.cmxa $(CMX)

realclean::; 	rm -f $(NAME) $(NAME).opt

#
# Gemerate source file with version and name information

this.ml:	this.in
		sed 	-e 's/@this@/$(NAME)-$(VERSION)/'\
			-e 's/@arch@/$(ARCH)/'\
		this.in > $@

# 
# cmo: just make all .cmo files (for interactive use in the toplevel)
#

cmo:		$(CMO)

# -----------------------------------------------------------------
# build a source/binary distribution
# -----------------------------------------------------------------

FILES.BIN:	ALWAYS
		find .							\
			-name CVS 				-prune	\
			-o -name 'Makefile*'			-prune  \
			-o -name '*.o' 				-prune	\
			-o -name '*.cmi' 			-prune	\
			-o -name '*.ml[iyl]'			-prune  \
			-o -name '*.ml'  			-prune  \
			-o -name '*.cmo'			-prune 	\
			-o -name '*.cma'			-prune 	\
			-o -name '*.cmxa'			-prune 	\
			-o -name '*.cmx'			-prune  \
			-o -name '*.in'				-prune  \
			-o -name '*.tar*'			-prune  \
			-o -name '*.tmp*'			-prune  \
			-o -name '*.output'			-prune  \
                        -o -name 'FILES.*'                      -prune  \
                        -o -type f -print | sort | 			\
		sed 	-e 's|^\./|$(NAME)-$(VERSION)/|'  > $@
		
FILES.SRC:	ALWAYS
		find .  -follow						\
			-name CVS 				-prune	\
			-o -name '*.a' 				-prune	\
			-o -name '*.o' 				-prune	\
			-o -name '*.cmi' 			-prune	\
			-o -name '*.cmo'			-prune 	\
			-o -name '*.cma'			-prune 	\
			-o -name '*.cmxa'			-prune 	\
			-o -name '*.cmx'			-prune  \
			-o -name '*.tar*'			-prune  \
			-o -name '*.tmp*'			-prune  \
			-o -name '*.sig'			-prune  \
			-o -name '*.output'			-prune  \
                        -o -name 'FILES.*'                      -prune  \
			-o -name '$(NAME)'                      -prune  \
                        -o -name '$(NAME).opt'                  -prune  \
		     	-o -type f -print				\
			| sort | 			\
		sed 	-e 's|^\./|$(NAME)-$(VERSION)/|'  > $@

                        

DIST =          $(NAME)-$(VERSION).tar.gz

dist:           $(DIST)

$(DIST):	FILES.SRC
		ln -s . $(NAME)-$(VERSION) 
		tar cvhf - `cat FILES.SRC` | gzip > $@
		rm -f $(NAME)-$(VERSION)
		rm -f FILES.SRC 

# 
# -----------------------------------------------------------------------------
# phony targets
# -----------------------------------------------------------------------------

# all code created by generators must be there before dependencies
# are calculated!

depend:		DEPEND ALWAYS

DEPEND:		$(GENERATED)
		$(CAMLDEP) $(INCLUDE) *.mli *.ml > DEPEND

tags:		ALWAYS
		mltags *.mli $(MYLIB)/*.mli *.ml $(MYLIB)/*.ml

clean::;	rm -f tags

#
# dummy target
#

ALWAYS:

# -----------------------------------------------------------------------------
# dependencies - include manually if your make does not support include
# -----------------------------------------------------------------------------

-include DEPEND

#
# $Log: Makefile,v $
# Revision 1.16  1999/01/12 20:25:53  lindig
#
#
# * New branch: the element data type models a list explicitly.
#
# Revision 1.15  1999/01/10 19:47:26  lindig
#
#
# Typo fixed, new target 'tags' in Makefile.
#
# Revision 1.14  1999/01/10 14:06:39  lindig
#
# The internal representation of character data has changed (see the xml
# data type).  Data is now stored in so called chunks.  At pretty
# printing time chunks are split into words and whitespace.  In previous
# version was this done while parsing and thus the character data
# representation was much more fragmented.
#
# The lexer combinators from the mylib library have changed.  Saving
# results while scanning is now more flexbible because a function is
# passed to the save fuction which can transform the scanned string.
#
# Revision 1.13  1999/01/07 18:42:15  lindig
#
#
#
#   Input without an encoding declaration no longer has an encoding "-"
#   in its output.
#
#   Identifier part of declarations are no longer changed to lowercase.
#
#   Pretty printed declarations now contain fewer spaces.
#
# Revision 1.12  1999/01/03 19:27:29  lindig
#
# New version 0.7.
#
# Revision 1.11  1999/01/01 16:53:45  lindig
#
# Copyright statement added.
#
# Revision 1.10  1998/12/14 19:08:12  lindig
#
#
# * Just a test of $Name:  $ keyword expansion
#
# Revision 1.9  1998/12/14 18:51:34  lindig
# * target "all" now depends on DEPENDS. This will create depenencies
#   first when Tony is checked out from CVS.
#
# Revision 1.8  1998/12/14 18:35:31  lindig
#
#
# * scanstate renamed to xmlstate
#
# Revision 1.7  1998/12/14 17:46:06  lindig
#
#
# * Makefiles improved
#
# Revision 1.6  1998/12/13 19:19:09  lindig
#
#
# Makefile and README refined for possible release. make all now should
# properly compile mylib first.
#
#


