##############################################################################
# The Harmony Project
# harmony@lists.seas.upenn.edu                                 
##############################################################################
# Copyright (C) 2007 J. Nathan Foster and Benjamin C. Pierce
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
##############################################################################
# /src/OMakefile
# Boomerang build                   
# $Id: OMakefile 4607 2009-08-03 16:53:28Z ddavi $
##############################################################################

##############################################################################
# Library configuration

OCAMLPACKS += num str unix

OCAML_LIBS += $(UBASEDIR)/ubase $(HBASEDIR)/hbase
OCAMLINCLUDES += $(UBASEDIR) $(HBASEDIR)

OCAMLYACC = ocamlyacc -v

##############################################################################
# Main results

RESULT = boomerang
RESULTS = boomerang.cmxa $(RESULT)$(EXE)

.DEFAULT: $(BINDIR)/$(RESULT)$(EXE)

##############################################################################
# Sources

BOOMERANG_BASE_SOURCES[] = \
   amapblist.mli amapblist.ml \
   intmapa.mli intmapa.ml \
   btag.mli btag.ml \
   bannot.mli bannot.ml \
   bcost.mli bcost.ml \
   bstring.mli bstring.ml \
   barx.mli barx.ml \
   balign.mli balign.ml \
   berror.mli berror.ml \
   brx.mli brx.ml erx.mli erx.ml \
   blenses.mli blenses.ml \
   bident.mli bident.ml \
   bvalue.mli bvalue.ml \
   bsyntax.mli bsyntax.ml \
   bprint.mli bprint.ml \
   bsubst.mli bsubst.ml \
   bparser.mly blexer.mll \
   benv.mli benv.ml \
   bakery.ml bregistry.ml bcheck.ml binterp.ml bdriver.ml \
   bdiff3.mli bdiff3.ml \
   bsync.mli bsync.ml \
   toplevel.ml

GENERATED_SOURCES = bparser.mly bparser.ml bparser.mli blexer.mll blexer.ml

BOOMERANG_LENS_SOURCES[] = \
  prelude.ml

BOOMERANG_LIBRARY_SOURCES[] =
    $(addprefix $(SRCDIR)/, $(BOOMERANG_BASE_SOURCES))
    $(addprefix $(LENSESDIR)/, $(BOOMERANG_LENS_SOURCES))

BOOMERANG_LIBRARY_SOURCES = $(file $(BOOMERANG_LIBRARY_SOURCES))

BOOMERANG_SOURCES = $(BOOMERANG_LIBRARY_SOURCES) boomerang.ml

OCamlLibrary($(RESULT), $(rootname $(BOOMERANG_LIBRARY_SOURCES)))
OCamlProgram($(RESULT), $(rootname $(BOOMERANG_SOURCES)))

$(BINDIR)/$(RESULT)$(EXE): $(RESULT)$(EXE)
	if $(not $(file-exists $(BINDIR)))
		mkdir $(BINDIR)
	cp $< $@

##############################################################################
# Miscellaneous

clean:
	$(CLEAN) $(RESULTS) $(GENERATED_SOURCES) bakery.ml

NOBAKE=0

# If we are installing Boomerang somewhere, then we need to build a real
# bakery.ml embedding all the .boom files we might need.  But if we're
# only going to run things in place, we can skip this step and avoid
# recompiling Boomerang whenever .boom files change in the examples.
if $(equal $(NOBAKE), 1)
  bakery.ml: $(TOOLSDIR)/baker$(EXE)
    ./$< ".boom" > $@
else 
  bakery.ml: $(TOOLSDIR)/baker$(EXE) $(BOOMFILES)
    $< ".boom" $(LENSESDIR) $(EXAMPLESDIR) > $@
