#
#  RLDev: RealLive-compatible development toolkit
#  Copyright (C) 2004-2006 Haeleth
#  Revised 2009-2011 by Richard 23
#
#  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.
#

OCAMLFLAGS = -warn-error Asxyz -cc $(if $(equal $(CXX),gcc),g++,$(CXX))
USE_OCAMLFIND = true

if $(defined-env DEBUG)
  echo "Debug mode"
  NATIVE_ENABLED = false
  BYTE_ENABLED = true
  OCAMLFLAGS += -g -custom
  export

if $(not $(defined-env VERBOSE))
  OMakeFlags(-S --progress)
  export

if $(not $(file-exists ../bin))
  mkdir ../bin

EXEDIR = $(dir ../bin)

.INCLUDE: config.inc
  if $(not $(file-exists config.inc))
    ./configure

OCAMLLEX += -q

# Generate a description of the parsing tables and a report on conflicts resulting 
# from ambiguities in the grammar. The description is put in file grammar.output.

OCAMLYACC += -v

.PHONY: all clean distclean

# build libraries
.SUBDIRS: common

OCAMLINCLUDES += $(dir common)
INCLUDES += $(dir common)
OCAML_LIBS = $(file $(addprefix common/,optpp rlcmp rlkfn appconfig))
OCAML_CLIBS = $(file common/rlprims)

# build programs

OCAMLPACKS = bigarray unix extlib ulex

PROGRAMS = rlc kprl
if $(ENABLE_VACONV)
  PROGRAMS += vaconv
  export
if $(ENABLE_RLXML)
  PROGRAMS += rlxml
  export
if $(file-exists cvtkpacres)
  # If you don't use Kpac, you won't miss this utility.  
  # If you do need to convert Kpac resources, let me know and I'll send you a 
  # version with CvtKpacRes included.
  PROGRAMS += cvtkpacres
  export

version_file = $(file VERSION)

.SUBDIRS: $(PROGRAMS) docsrc

clean:
  $(RM) *.omc

distclean: clean
  $(RM) $(add-wrapper $(EXEDIR)/,$(EXE),$(PROGRAMS)) common/config.cfg config.inc

.DEFAULT: all
