Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
OCaml: problems compiling
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <weis@p...>
Subject: Re: OCaml: problems compiling
> 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) $<

# 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,,