# # This Makefile can build both a bytecode and a native executable. It # also has the "make top" target that runs the "ocaml" interpreter # with the bytecode objects loaded in the correct order (as specified # by the $(OCAML_ML) macro below). # # OCaml does not automatically keep the .depend file up to date. So, # you must remember to run "make depend" manually as required. # # A summary of the top-level targets for this Makefile follows: # # make all -- Build bytecode and native executables. # make depend -- Generate dependencies. # make top -- Run "ocaml" with all objects loaded in the top-level. # EXEC = hello OCAMLC = ocamlc OCAMLOPT = ocamlopt OCAMLDEP = ocamldep # Build the byte code executable for debugging and the native # executable for performance. INCLUDES = OCAML_CFLAGS = -g $(INCLUDES) OCAMLOPT_CFLAGS = -unsafe -inline 99999 -ccopt -O2 $(INCLUDES) OCAML_LDFLAGS = OCAMLOPT_LDFLAGS = # OCaml *.mli interface files. OCAML_MLI = hello.mli \ goodbye.mli # OCaml *.ml implementation files. Do not include main.ml here. # Order is important because the order listed below is the same order # the resulting objects will be passed into $(OCAMLC) or $(OCAMLOPT). OCAML_ML = hello.ml \ goodbye.ml # Generate the object files. OCAML_CMI = $(OCAML_MLI:.mli=.cmi) # Compiled interface files. OCAML_CMO = $(OCAML_ML:.ml=.cmo) # Compiled bytecode objects. OCAML_CMX = $(OCAML_ML:.ml=.cmx) # Compiled ocaml native objects. OCAML_O = $(OCAML_ML:.ml=.o) # Compiled linker native objects. # Build both the bytecode and the native executable. all: $(EXEC)_bytecode $(EXEC)_native @echo "Done." $(EXEC)_bytecode: $(OCAML_CMI) $(OCAML_CMO) main.cmo $(OCAMLC) $(OCAML_CFLAGS) -o $@ $(OCAML_LDFLAGS) $(OCAML_CMO) main.cmo $(EXEC)_native: $(OCAML_CMI) $(OCAML_CMX) main.cmx $(OCAMLOPT) $(OCAMLOPT_CFLAGS) -o $@ $(OCAMLOPT_LDFLAGS) $(OCAML_CMX) main.cmx # Start "ocaml" with all the objects (except "main") loaded into the top-level. top: $(EXEC)_bytecode $(EXEC)_native rlwrap ocaml $(INCLUDES) $(OCAML_LDFLAGS) $(OCAML_CMO) clean: -$(RM) $(EXEC)_bytecode $(EXEC)_native .depend -$(RM) main.cmi main.cmo main.cmx main.o -$(RM) $(OCAML_CMI) $(OCAML_CMO) $(OCAML_CMX) $(OCAML_O) .PHONY: all clean top ######################################################################## # Custom OCaml Rules ######################################################################## .SUFFIXES: .mli .ml .cmi .cmo .cmx .p.cmx .mli.cmi: $(OCAMLC) $(OCAML_CFLAGS) -c $< .ml.cmo: $(OCAMLC) $(OCAML_CFLAGS) -c $< .ml.cmx: $(OCAMLOPT) $(OCAMLOPT_CFLAGS) -c $< .ml.p.cmx: $(OCAMLOPT) $(OCAMLOPT_CFLAGS) -p -c -o $*.p.cmx $< ######################################################################## # Dependencies ######################################################################## depend: $(OCAMLDEP) $(OCAML_MLI) $(OCAML_ML) main.ml > .depend -include .depend