Re: OCaml: problems compiling

From: Pierre Weis (weis@pauillac.inria.fr)
Date: Tue Jul 22 1997 - 18:25:11 MET DST


From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <199707221625.SAA19307@pauillac.inria.fr>
Subject: Re: OCaml: problems compiling
In-Reply-To: <199707221550.LAA21532@apollonius.mitre.org> from "Joshua D. Guttman" at "Jul 22, 97 11:50:29 am"
To: guttman@mitre.org
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 ``types.ml'' and ``main.ml''. 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.

Usage:
-- 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 lexer.ml

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

GENERATED = $(LEXGENERATED) $(YACCGENERATED)

# Caml sources
SOURCES = types.ml main.ml $(GENERATED)
# 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)

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

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

.ml.cmo:
        $(CAMLC) -c $<

.mli.cmi:
        $(CAMLC) -c $<

.mll.ml:
        $(CAMLLEX) $<

.mly.ml:
        $(CAMLYACC) $<

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

# Dependencies
depend: $(SOURCES) $(GENERATED) $(LEXSOURCES) $(YACCSOURCES)
        $(CAMLDEP) *.mli *.ml > .depend

include .depend

=============================================================

Hope this help,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/



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