Re: OCaml: problems compiling

From: Pierre Weis (
Date: Tue Jul 22 1997 - 18:25:11 MET DST

From: Pierre Weis <>
Message-Id: <>
Subject: Re: OCaml: problems compiling
In-Reply-To: <> from "Joshua D. Guttman" at "Jul 22, 97 11:50:29 am"
Date: Tue, 22 Jul 1997 18:25:11 +0200 (MET DST)

> Is there some convenient way to set up a makefile so that it will
> ensure that foo.cmi is generated (or re-generated) before foo.cmo or
> foo.cmx?
> Not being a magician of `make', I didn't see an easy way to express
> the conditional on there existing a foo.mli file. Of course, in the
> ideal case one would actually see whether it was possible to make
> foo.mli, e.g. from foo.mly.
> Thanks.
> Josh

Well, I'm not a magician of ``make'', but I use the following
(oversimplified) Makefile template for O'Caml. I hope it could be
useful, as a first attempt to automatize your recompilations.

As an example, the template is ready to use, if we suppose that you
want to produce executable file ``exc'', from (Caml lex) lexer source
definition ``lexer.mll'', parser source definition ``parser.mly'', and
O'Caml source files ``'' and ``''. It should not be too
difficult to modify it to fit your needs.

If Makefiles are new to you, note that the lines of rule
bodies must start with a tab character (not 8 blank spaces!).

Note also that this Makefile will handle dependancies between O'Caml
files, provided that you create a dummy file ``.depend'' the first
time you use it.

-- just type make to recompile what have to be recompiled
-- type make clean, then make to rebuild the application from scratch.

# The Caml compilers. You may have to add various -I options.

CAMLC = ocamlc
CAMLDEP = ocamldep
CAMLLEX = ocamllex
CAMLYACC = ocamlyacc

# Lex stuff
LEXSOURCES = lexer.mll
LEXGENERATED = lexer.mli

# Yacc stuff
YACCSOURCES = parser.mly
YACCGENERATED = parser.mli


# Caml sources
# Caml object files to link
OBJS = types.cmo lexer.cmo parser.cmo main.cmo

# Name of executable file to generate
EXEC = exc

# This part should be generic
# Don't forget to create (touch) the file ./.depend at first use.

# Building the world
all: depend $(EXEC)

        $(CAMLC) $(OBJS) -o $(EXEC)

.SUFFIXES: .ml .mli .cmo .cmi .cmx
.SUFFIXES: .mll .mly

        $(CAMLC) -c $<

        $(CAMLC) -c $<
        $(CAMLLEX) $<
        $(CAMLYACC) $<

# Clean up
        rm -f *.cm[io] *.cmx *~ .*~ #*#
        rm -f $(GENERATED)
        rm -f $(EXEC)

# Dependencies
        $(CAMLDEP) *.mli *.ml > .depend

include .depend


Hope this help,

Pierre Weis

INRIA, Projet Cristal,,

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:11 MET