diff options
author | Erick Tryzelaar <idadesub@users.sourceforge.net> | 2010-03-08 19:32:27 +0000 |
---|---|---|
committer | Erick Tryzelaar <idadesub@users.sourceforge.net> | 2010-03-08 19:32:27 +0000 |
commit | 49457b81589c6a3ef384caa8fdf1463ad2ada7c7 (patch) | |
tree | 8500bcc1ba0067ff7816b083d8b5a535be6ee50d /bindings | |
parent | 9ef76b9985a0c408e126affa049698c413ad8664 (diff) |
Add OCaml tutorial to the examples.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97966 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/ocaml/Makefile.ocaml | 123 |
1 files changed, 95 insertions, 28 deletions
diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml index 4e5de80264..1cff422c28 100644 --- a/bindings/ocaml/Makefile.ocaml +++ b/bindings/ocaml/Makefile.ocaml @@ -66,35 +66,64 @@ Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) +ifdef OCAMLOPT +Archive.EXE := $(strip $(OCAMLOPT) -cc $(CXX) $(OCAMLCFLAGS) $(UsedOcamLibs:%=%.cmxa) $(OCAMLDEBUGFLAG) -o) +else +Archive.EXE := $(strip $(OCAMLC) -cc $(CXX) $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG:%=%.cma) -o) +endif + # Source files OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml)) -OcamlHeaders1 := $(OcamlSources1:.ml=.mli) +OcamlHeaders1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.mli)) + +OcamlSources2 := $(filter-out $(ExcludeSources),$(OcamlSources1)) +OcamlHeaders2 := $(filter-out $(ExcludeHeaders),$(OcamlHeaders1)) -OcamlSources := $(OcamlSources1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%) -OcamlHeaders := $(OcamlHeaders1:$(PROJ_SRC_DIR)/%=$(ObjDir)/%) +OcamlSources := $(OcamlSources2:$(PROJ_SRC_DIR)/%=$(ObjDir)/%) +OcamlHeaders := $(OcamlHeaders2:$(PROJ_SRC_DIR)/%=$(ObjDir)/%) # Intermediate files -LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma -LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa ObjectsCMI := $(OcamlSources:%.ml=%.cmi) ObjectsCMO := $(OcamlSources:%.ml=%.cmo) ObjectsCMX := $(OcamlSources:%.ml=%.cmx) +ifdef LIBRARYNAME +LibraryCMA := $(ObjDir)/$(LIBRARYNAME).cma +LibraryCMXA := $(ObjDir)/$(LIBRARYNAME).cmxa +endif + +ifdef TOOLNAME +ToolEXE := $(ObjDir)/$(TOOLNAME)$(EXEEXT) +endif + # Output files # The .cmo files are the only intermediates; all others are to be installed. -LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a -OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma) -OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa) OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi) OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx) OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%) +ifdef LIBRARYNAME +LibraryA := $(OcamlDir)/lib$(LIBRARYNAME).a +OutputCMA := $(LibraryCMA:$(ObjDir)/%.cma=$(OcamlDir)/%.cma) +OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa) +endif + +ifdef TOOLNAME +ifdef EXAMPLE_TOOL +OutputEXE := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT) +else +OutputEXE := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT) +endif +endif + # Installation targets +DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%) + +ifdef LIBRARYNAME DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa -DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%) - +endif ##===- Dependencies -------------------------------------------------------===## # Copy the sources into the intermediate directory because older ocamlc doesn't @@ -106,18 +135,27 @@ $(ObjDir)/%.mli: $(PROJ_SRC_DIR)/%.mli $(ObjDir)/.dir $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir $(Verb) $(CP) -f $< $@ +$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi) + +ifdef LIBRARYNAME $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \ $(OcamlDir)/.dir $(ObjDir)/.dir $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ -$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi) - -include $(ObjDir)/$(LIBRARYNAME).ocamldep +endif + +ifdef TOOLNAME +$(ObjDir)/$(TOOLNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \ + $(OcamlDir)/.dir $(ObjDir)/.dir + $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ +-include $(ObjDir)/$(TOOLNAME).ocamldep +endif ##===- Build static library from C sources --------------------------------===## -ifneq ($(ObjectsO),) +ifdef LibraryA all-local:: $(LibraryA) clean-local:: clean-a install-local:: install-a @@ -160,7 +198,7 @@ $(OcamlDir)/%.o: $(LibDir)/%.o $(Verb) ln -sf $< $@ clean-deplibs: - $(Verb) rm -f $(OutputLibs) + $(Verb) $(RM) -f $(OutputLibs) install-deplibs: $(Verb) $(MKDIR) $(PROJ_libocamldir) @@ -169,11 +207,12 @@ install-deplibs: done uninstall-deplibs: - $(Verb) rm -f $(DestLibs) + $(Verb) $(RM) -f $(DestLibs) ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===## +ifneq ($(OcamlHeaders),) all-local:: build-cmis clean-local:: clean-cmis install-local:: install-cmis @@ -212,10 +251,16 @@ uninstall-cmis:: $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ $(RM) -f "$(PROJ_libocamldir)/$$i"; \ done +endif ##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===## +$(ObjDir)/%.cmo: $(ObjDir)/%.ml + $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" + $(Verb) $(Compile.CMO) $@ $< + +ifdef LIBRARYNAME all-local:: $(OutputCMA) clean-local:: clean-cma install-local:: install-cma @@ -228,10 +273,6 @@ $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" $(Verb) $(Archive.CMA) $@ $(ObjectsCMO) -$(ObjDir)/%.cmo: $(ObjDir)/%.ml - $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" - $(Verb) $(Compile.CMO) $@ $< - clean-cma:: $(Verb) $(RM) -f $(OutputCMA) $(UsedLibNames:%=$(OcamlDir)/%) @@ -243,7 +284,7 @@ install-cma:: $(OutputCMA) uninstall-cma:: $(Echo) "Uninstalling $(DestCMA)" -$(Verb) $(RM) -f $(DestCMA) - +endif ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===## @@ -251,6 +292,14 @@ uninstall-cma:: # If unavailable, 'configure' will not define OCAMLOPT in Makefile.config. ifdef OCAMLOPT +$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx + $(Verb) $(CP) -f $< $@ + +$(ObjDir)/%.cmx: $(ObjDir)/%.ml + $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build" + $(Verb) $(Compile.CMX) $@ $< + +ifdef LIBRARYNAME all-local:: $(OutputCMXA) $(OutputsCMX) clean-local:: clean-cmxa install-local:: install-cmxa @@ -260,18 +309,11 @@ $(OutputCMXA): $(LibraryCMXA) $(Verb) $(CP) -f $< $@ $(Verb) $(CP) -f $(<:.cmxa=.a) $(@:.cmxa=.a) -$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx - $(Verb) $(CP) -f $< $@ - $(LibraryCMXA): $(ObjectsCMX) $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX) $(Verb) $(RM) -f $(@:.cmxa=.o) -$(ObjDir)/%.cmx: $(ObjDir)/%.ml - $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build" - $(Verb) $(Compile.CMX) $@ $< - clean-cmxa:: $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.a) $(OutputsCMX) @@ -295,7 +337,27 @@ uninstall-cmxa:: $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ $(RM) -f $(PROJ_libocamldir)/$$i; \ done +endif +endif + +##===- Build executables --------------------------------------------------===## + +ifdef TOOLNAME +all-local:: $(OutputEXE) +clean-local:: clean-exe + +$(OutputEXE): $(ToolEXE) $(OcamlDir)/.dir + $(Verb) $(CP) -f $< $@ +ifndef OCAMLOPT +$(ToolEXE): $(ObjectsCMO) $(OcamlDir)/.dir + $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" + $(Verb) $(Archive.EXE) $@ $< +else +$(ToolEXE): $(ObjectsCMX) $(OcamlDir)/.dir + $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" + $(Verb) $(Archive.EXE) $@ $< +endif endif ##===- Generate documentation ---------------------------------------------===## @@ -325,7 +387,10 @@ printcamlvars:: $(Echo) "LibraryCMA : " '$(LibraryCMA)' $(Echo) "LibraryCMXA : " '$(LibraryCMXA)' $(Echo) "OcamlSources1: " '$(OcamlSources1)' + $(Echo) "OcamlSources2: " '$(OcamlSources2)' $(Echo) "OcamlSources : " '$(OcamlSources)' + $(Echo) "OcamlHeaders1: " '$(OcamlHeaders1)' + $(Echo) "OcamlHeaders2: " '$(OcamlHeaders2)' $(Echo) "OcamlHeaders : " '$(OcamlHeaders)' $(Echo) "ObjectsCMI : " '$(ObjectsCMI)' $(Echo) "ObjectsCMO : " '$(ObjectsCMO)' @@ -340,4 +405,6 @@ printcamlvars:: .PHONY: printcamlvars build-cmis \ clean-a clean-cmis clean-cma clean-cmxa \ install-a install-cmis install-cma install-cmxa \ - uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa + install-exe \ + uninstall-a uninstall-cmis uninstall-cma uninstall-cmxa \ + uninstall-exe |