X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=bindings%2Focaml%2FMakefile.ocaml;h=7b26caf6bb633bb5cf97476593ba1f34434508e3;hp=9ca9fb742a9dc3ce2e032e7f8ccbd545f70df6b4;hb=693bfa58d388fa7d8d185ab77f251c3ee0f44b02;hpb=a15dc035a6d4153bece7a067e037e5d6f5d58b16 diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml index 9ca9fb742a9..7b26caf6bb6 100644 --- a/bindings/ocaml/Makefile.ocaml +++ b/bindings/ocaml/Makefile.ocaml @@ -1,20 +1,20 @@ -##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===## -# +##===- bindings/ocaml/Makefile.ocaml -----------------------*- Makefile -*-===## +# # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. -# +# ##===----------------------------------------------------------------------===## -# -# An ocaml library is a unique project type in the context of LLVM, so rules are +# +# An OCaml library is a unique project type in the context of LLVM, so rules are # here rather than in Makefile.rules. -# -# Reference materials on installing ocaml libraries: -# +# +# Reference materials on installing OCaml libraries: +# # https://fedoraproject.org/wiki/Packaging/OCaml # http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt -# +# ##===----------------------------------------------------------------------===## include $(LEVEL)/Makefile.config @@ -23,6 +23,10 @@ include $(LEVEL)/Makefile.config CXX.Flags += -I"$(shell $(OCAMLC) -where)" C.Flags += -I"$(shell $(OCAMLC) -where)" +ifeq ($(ENABLE_SHARED),1) +LINK_COMPONENTS := all +endif + include $(LEVEL)/Makefile.common # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the @@ -31,13 +35,28 @@ PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR) OcamlDir := $(LibDir)/ocaml # Info from llvm-config and similar +ifndef IS_CLEANING_TARGET ifdef UsedComponents -UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents)) +UsedLibs = $(shell $(LLVM_CONFIG) --libs --system-libs $(UsedComponents)) UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents)) endif +endif + +# How do we link OCaml executables with LLVM? +# 1) If this is a --enable-shared build, build stub libraries. This also allows +# to use LLVM from toplevels. +# 2) If this is a --disable-shared build, embed ocamlc options for building +# a custom runtime and a static executable. It is not possible to use LLVM +# from toplevels. +ifneq ($(ObjectsO),) +ifeq ($(ENABLE_SHARED),1) +OCAMLSTUBS := 1 +endif +endif # Tools -OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir) +OCAMLCFLAGS += -I $(ObjDir) -I $(OcamlDir) +ifndef IS_CLEANING_TARGET ifneq ($(ObjectsO),) OCAMLAFLAGS += $(patsubst %,-cclib %, \ $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \ @@ -48,49 +67,113 @@ OCAMLAFLAGS += $(patsubst %,-cclib %, \ $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \ $(UsedLibs)) endif - -# -g was introduced in 3.10.0. -#ifneq ($(ENABLE_OPTIMIZED),1) -# OCAMLDEBUGFLAG := -g -#endif +endif + +ifneq ($(ENABLE_OPTIMIZED),1) + OCAMLDEBUGFLAG := -g +endif Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) + +ifdef OCAMLSTUBS +# Avoid the need for LD_LIBRARY_PATH +ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW)) +ifneq ($(HOST_OS),Darwin) +OCAMLRPATH := $(RPATH) -Wl,'$(SharedLibDir)' +endif +endif +endif + +ifdef OCAMLSTUBS +Archive.CMA := $(strip $(OCAMLC) -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \ + -o) +else Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ -o) +endif -Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +ifdef OCAMLSTUBS +Archive.CMXA := $(strip $(OCAMLOPT) -a $(patsubst %,-cclib %, \ + $(LLVMLibsOptions) -l$(LIBRARYNAME) \ + -L$(SharedLibDir) $(OCAMLRPATH)) \ + $(OCAMLDEBUGFLAG) -o) +else Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) +endif + +ifdef OCAMLOPT +Archive.EXE := $(strip $(OCAMLOPT) -cc $(CXX) $(OCAMLCFLAGS) $(UsedOcamlLibs:%=%.cmxa) $(OCAMLDEBUGFLAG) -o) +else +Archive.EXE := $(strip $(OCAMLC) -cc $(CXX) $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG:%=%.cma) -o) +endif # Source files +ifndef OcamlSources1 OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml)) -OcamlHeaders1 := $(OcamlSources1:.ml=.mli) +endif + +ifndef OcamlHeaders1 +OcamlHeaders1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.mli)) +endif + +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 OCAMLSTUBS +SharedLib := $(OcamlDir)/dll$(LIBRARYNAME)$(SHLIBEXT) +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 +ifdef OCAMLSTUBS +DestSharedLib := $(PROJ_libocamldir)/dll$(LIBRARYNAME)$(SHLIBEXT) +endif ##===- Dependencies -------------------------------------------------------===## # Copy the sources into the intermediate directory because older ocamlc doesn't @@ -102,18 +185,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 @@ -132,7 +224,7 @@ install-a:: $(LibraryA) $(Echo) "Installing $(BuildMode) $(DestA)" $(Verb) $(MKDIR) $(PROJ_libocamldir) $(Verb) $(INSTALL) $(LibraryA) $(DestA) - $(Verb) + $(Verb) uninstall-a:: $(Echo) "Uninstalling $(DestA)" @@ -140,6 +232,34 @@ uninstall-a:: endif +##===- Build stub library from C sources ----------------------------------===## + +ifdef SharedLib +all-local:: $(SharedLib) +clean-local:: clean-shared +install-local:: install-shared +uninstall-local:: uninstall-shared + +$(SharedLib): $(ObjectsO) $(OcamlDir)/.dir + $(Echo) "Building $(BuildMode) $(notdir $@)" + $(Verb) $(Link) $(SharedLinkOptions) $(OCAMLRPATH) $(LLVMLibsOptions) \ + -o $@ $(ObjectsO) + +clean-shared:: + -$(Verb) $(RM) -f $(SharedLib) + +install-shared:: $(SharedLib) + $(Echo) "Installing $(BuildMode) $(DestSharedLib)" + $(Verb) $(MKDIR) $(PROJ_libocamldir) + $(Verb) $(INSTALL) $(SharedLib) $(DestSharedLib) + $(Verb) + +uninstall-shared:: + $(Echo) "Uninstalling $(DestSharedLib)" + -$(Verb) $(RM) -f $(DestSharedLib) +endif + + ##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===## all-local:: build-deplibs @@ -156,19 +276,21 @@ $(OcamlDir)/%.o: $(LibDir)/%.o $(Verb) ln -sf $< $@ clean-deplibs: - $(Verb) rm -f $(OutputLibs) + $(Verb) $(RM) -f $(OutputLibs) install-deplibs: + $(Verb) $(MKDIR) $(PROJ_libocamldir) $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \ ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \ 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 @@ -189,14 +311,14 @@ clean-cmis:: # Also install the .mli's (headers) as documentation. install-cmis: $(OutputsCMI) $(OcamlHeaders) $(Verb) $(MKDIR) $(PROJ_libocamldir) - $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \ - $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ - $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ - done $(Verb) for i in $(OcamlHeaders:$(ObjDir)/%=%); do \ $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ $(DataInstall) $(ObjDir)/$$i "$(PROJ_libocamldir)/$$i"; \ done + $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \ + $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ + $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ + done uninstall-cmis:: $(Verb) for i in $(OutputsCMI:$(OcamlDir)/%=%); do \ @@ -207,10 +329,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 @@ -223,10 +351,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)/%) @@ -238,7 +362,7 @@ install-cma:: $(OutputCMA) uninstall-cma:: $(Echo) "Uninstalling $(DestCMA)" -$(Verb) $(RM) -f $(DestCMA) - +endif ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===## @@ -246,6 +370,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 @@ -255,18 +387,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) @@ -290,14 +415,34 @@ 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) $@ $(ObjectsCMO) +else +$(ToolEXE): $(ObjectsCMX) $(OcamlDir)/.dir + $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" + $(Verb) $(Archive.EXE) $@ $(ObjectsCMX) +endif endif ##===- Generate documentation ---------------------------------------------===## $(ObjDir)/$(LIBRARYNAME).odoc: $(ObjectsCMI) $(Echo) "Documenting $(notdir $@)" - $(Verb) $(OCAMLDOC) -I $(OcamlDir) -I $(ObjDir) -dump $@ $(OcamlHeaders) + $(Verb) $(OCAMLDOC) -I $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders) ocamldoc: $(ObjDir)/$(LIBRARYNAME).odoc @@ -319,8 +464,12 @@ printcamlvars:: $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)' $(Echo) "LibraryCMA : " '$(LibraryCMA)' $(Echo) "LibraryCMXA : " '$(LibraryCMXA)' + $(Echo) "SharedLib : " '$(SharedLib)' $(Echo) "OcamlSources1: " '$(OcamlSources1)' + $(Echo) "OcamlSources2: " '$(OcamlSources2)' $(Echo) "OcamlSources : " '$(OcamlSources)' + $(Echo) "OcamlHeaders1: " '$(OcamlHeaders1)' + $(Echo) "OcamlHeaders2: " '$(OcamlHeaders2)' $(Echo) "OcamlHeaders : " '$(OcamlHeaders)' $(Echo) "ObjectsCMI : " '$(ObjectsCMI)' $(Echo) "ObjectsCMO : " '$(ObjectsCMO)' @@ -329,10 +478,13 @@ printcamlvars:: $(Echo) "DestA : " '$(DestA)' $(Echo) "DestCMA : " '$(DestCMA)' $(Echo) "DestCMXA : " '$(DestCMXA)' + $(Echo) "DestSharedLib: " '$(DestSharedLib)' $(Echo) "UsedLibs : " '$(UsedLibs)' $(Echo) "UsedLibNames : " '$(UsedLibNames)' .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