# Use ocamlfind to manage library linking
USE_OCAMLFIND = true

# Set up the ocamlfind flags
OCAMLFINDFLAGS = -syntax camlp4o

# The ocamlfind packages we use
OCAMLPACKS[] =
        camlp4
        extlib
        oUnit
        ulex
        dynlink
        unix

# Compile with debugging options?  This enables:
#
# 1. Pattern match failure warnings
# 2. Profiling information in compiled code (-p)

# DEBUG = true

OCAMLFLAGS += $(if $(DEBUG), -w Ae  -warn-error Ap-37 \
                           , -w Aep -warn-error A-37)

OCAMLFLAGS += $(if $(RELEASE), -warn-error a)

# 3. Debugging information in byte-compiled code (-g)  (It is never useful to turn this off. -jd)
OCAMLFLAGS += -g

# Flags to pass to the native-code compiler
# Explanation:
#       -noassert       (turn off assertions)
#       -inline 100     (aggressive inlining)
OCAMLOPTFLAGS  = -noassert -inline 100
OCAMLOPTFLAGS += $(if $(DEBUG), -p)

# Declare a phony clean target
.PHONY: clean beluga beli

# Map the src dir onto the build dir
vmount(-l, src, .build)
mkdir -p .build/core
mkdir -p .build/beluga
mkdir -p .build/beli

if $(not $(RELEASE))
  vmount(-l, sasybel/src, .build/sasybel)
  mkdir -p .build/sasybel
  export

# Include the fake .build subdirectory
.SUBDIRS: .build $(if $(not $(RELEASE)), .build/sasybel)

.DEFAULT: .PHONY/src/.DEFAULT :effects: build
        mkdir -p bin
        ln-or-cp .build/beluga/beluga.$(if $(NATIVE_ENABLED), opt, run) bin/beluga
        ln-or-cp .build/beli/beli.$(if $(NATIVE_ENABLED), opt, run) bin/beli
        if $(not $(RELEASE))
          ln-or-cp .build/sasybel/sasybel.$(if $(NATIVE_ENABLED), opt, run) bin/sasybel
          export

clean: .PHONY/src/clean
        rm $(filter-proper-targets $(ls R, .))
        rm $(filter %.omc,         $(ls R, .))
        rm -rf bin
