I am learning how to compilers work. I read a tutorial on how to use Ocamllex and Ocamlyacc to read an input from a source code, generate the tokens and generate a syntatic tree in order to compute the execution of the program later. I had to recompile the code often while I was on the learning process and I decided to create a makefile to automatize this step. Since I am new to both Ocaml and makefiles I am struggling quite a bit to make the makefile work.
From my google research so far I could create this makefile, but the latest error I got was "make: *** No rule to make target 'lexer.mli', needed by 'depend'. Stop.".
# 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 = $(GENERATED) calc.ml
# Caml object files to link
OBJS = lexer.cmo parser.cmo calc.cmo
# Name of executable file to generate
EXEC = calc
# 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
How can I create a proper makefile for this task?