# Declare an OCaml library
LIBRARY = beluga-core
# Declare an OCaml package
PACK    = Core

# Declare the files the package will contain
FILES[] =
        abstract
        apxnorm
        lfcheck
        lfrecon
        check
        context
        convSigma
        coverage
        ctxsub
        debug
        error
        gensym
        holes
        id
        index
	logic
        opsem
        parser
        pragma
        pretty
        prettyext
        reconstruct
        recsgn
        store
        subord
        substitution
        syntax
        synext
        synapx
        synint
        trail
        token
        unify
        version
        whnf
        monitor

# Declare one pseudo target for the package and one for the files it
# contains
.PHONY: lexer src files pack

.DEFAULT: src

clean:
        rm $(filter-proper-targets $(ls R, .))
        rm $(filter %.omc,         $(ls R, .))

src: lexer files pack $(OCamlLibrary $(LIBRARY), $(PACK))

if $(NATIVE_ENABLED)
    pack: $(OCamlPackage $(PACK), $(FILES) lexer)
else
    pack: $(QuietOCamlPackage $(PACK), $(FILES) lexer)

# **NOTE** Because of the way scoping for OCAMLFLAGS works, the pack
# target must come _BEFORE_ the files target, otherwise pack will be
# passed the -for-pack flag as well, which is not what we want

# Use the -for-pack flag for compiling the individual modules
OCAMLFLAGS += -for-pack $(PACK)
files: $(addsuffixes $(if $(BYTE_ENABLED), .cmo) $(if $(NATIVE_ENABLED), .cmx), $(FILES))

# Turn off unused variable warning only for the lexer; needed for
# dummy variables created by ulex / camlp4
OCAMLFLAGS += -w z
lexer: $(addsuffixes $(if $(BYTE_ENABLED), .cmo) $(if $(NATIVE_ENABLED), .cmx), lexer)

version.ml: version.mlp
        section
            stdout = $(fopen version.ml, w)
            fsubst($<)
            case $"%VERSION%%" g
                value <NONE>
            close($(stdout))
