我正在学习编译器如何工作。我阅读了一篇关于如何使用 Ocamllex 和 Ocamlyacc 从源代码中读取输入、生成标记并生成语法树的教程,以便稍后计算程序的执行。在学习过程中,我不得不经常重新编译代码,因此我决定创建一个 makefile 来自动化这一步。由于我对 Ocaml 和 makefile 都是新手,所以我在努力使 makefile 正常工作。
到目前为止,从我的谷歌研究来看,我可以创建这个 makefile,但我得到的最新错误是“make: *** No rule to make target 'lexer.mli', required 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
我怎样才能为这个任务创建一个合适的makefile?