X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=bindings%2Focaml%2FMakefile.ocaml;h=c8e826f77e995cc8739c4791ca16f77e17c47082;hp=4c65ca8ffc600f59315793a24000ad4614bd284d;hb=f368dadd9425de65fea4283daef5d197e98cc1cd;hpb=ab4456f10a72f3a7c73dac0e95578b9b7e4250b8 diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml index 4c65ca8ffc6..c8e826f77e9 100644 --- a/bindings/ocaml/Makefile.ocaml +++ b/bindings/ocaml/Makefile.ocaml @@ -2,32 +2,31 @@ # # The LLVM Compiler Infrastructure # -# This file was developed by Gordon Henriksen and is distributed under the -# University of Illinois Open Source License. See LICENSE.TXT for details. +# 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 # here rather than in Makefile.rules. # +# 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 -# Find the ocaml stdlib root. /usr/local/lib/ocaml is the default when built -# from source; distros use something like /usr/lib/ocaml/3.10.0. -ifndef OCAML_LIBDIR -OCAML_LIBDIR := $(shell $(OCAMLC) -where) -endif - -# CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its -# includes under its libdir. -CFLAGS += -I$(OCAML_LIBDIR) +# CFLAGS needs to be set before Makefile.rules is included. +CXX.Flags += -I"$(shell $(OCAMLC) -where)" +C.Flags += -I"$(shell $(OCAMLC) -where)" include $(LEVEL)/Makefile.common # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the -# user can override this with OCAML_LIBDIR. +# user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=. PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR) OcamlDir := $(LibDir)/ocaml @@ -39,16 +38,29 @@ endif # Tools OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir) +ifneq ($(ObjectsO),) +OCAMLAFLAGS += $(patsubst %,-cclib %, \ + $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \ + $(shell $(LLVM_CONFIG) --ldflags)) \ + $(UsedLibs)) +else OCAMLAFLAGS += $(patsubst %,-cclib %, \ $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \ - $(UsedLibs) -l$(LIBRARYNAME)) + $(UsedLibs)) +endif + +# -g was introduced in 3.10.0. +#ifneq ($(ENABLE_OPTIMIZED),1) +# OCAMLDEBUGFLAG := -g +#endif -Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) -Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) -Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o) +Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ + -o) -Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o) -Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o) +Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) +Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) # Source files OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml)) @@ -71,11 +83,13 @@ 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)/%) # Installation targets DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa +DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%) ##===- Dependencies -------------------------------------------------------===## @@ -90,13 +104,16 @@ $(ObjDir)/%.ml: $(PROJ_SRC_DIR)/%.ml $(ObjDir)/.dir $(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \ $(OcamlDir)/.dir $(ObjDir)/.dir - $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeader) > $@ + $(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@ + +$(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi) -include $(ObjDir)/$(LIBRARYNAME).ocamldep ##===- Build static library from C sources --------------------------------===## +ifneq ($(ObjectsO),) all-local:: $(LibraryA) clean-local:: clean-a install-local:: install-a @@ -120,6 +137,34 @@ install-a:: $(LibraryA) uninstall-a:: $(Echo) "Uninstalling $(DestA)" -$(Verb) $(RM) -f $(DestA) +endif + + +##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===## + +all-local:: build-deplibs +clean-local:: clean-deplibs +install-local:: install-deplibs +uninstall-local:: uninstall-deplibs + +build-deplibs: $(OutputLibs) + +$(OcamlDir)/%.a: $(LibDir)/%.a + $(Verb) ln -sf $< $@ + +$(OcamlDir)/%.o: $(LibDir)/%.o + $(Verb) ln -sf $< $@ + +clean-deplibs: + $(Verb) rm -f $(OutputLibs) + +install-deplibs: + $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \ + ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \ + done + +uninstall-deplibs: + $(Verb) rm -f $(DestLibs) ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===## @@ -177,9 +222,6 @@ $(OutputCMA): $(LibraryCMA) $(OcamlDir)/.dir $(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" $(Verb) $(Archive.CMA) $@ $(ObjectsCMO) - $(Verb) for i in $(UsedLibNames); do \ - ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \ - done $(ObjDir)/%.cmo: $(ObjDir)/%.ml $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" @@ -192,18 +234,10 @@ install-cma:: $(OutputCMA) $(Echo) "Installing $(BuildMode) $(DestCMA)" $(Verb) $(MKDIR) $(PROJ_libocamldir) $(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)" - $(Verb) for i in $(UsedLibNames); do \ - $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ - ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \ - done uninstall-cma:: $(Echo) "Uninstalling $(DestCMA)" -$(Verb) $(RM) -f $(DestCMA) - $(Verb) for i in $(UsedLibNames); do \ - $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ - $(RM) -f "$(PROJ_libocamldir)/$$i"; \ - done ##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===## @@ -234,7 +268,7 @@ $(ObjDir)/%.cmx: $(ObjDir)/%.ml $(Verb) $(Compile.CMX) $@ $< clean-cmxa:: - $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.o) $(OutputsCMX) + $(Verb) $(RM) -f $(OutputCMXA) $(OutputCMXA:.cmxa=.a) $(OutputsCMX) install-cmxa:: $(OutputCMXA) $(OutputsCMX) $(Verb) $(MKDIR) $(PROJ_libocamldir) @@ -259,6 +293,13 @@ uninstall-cmxa:: endif +##===- Generate documentation ---------------------------------------------===## + +$(ObjDir)/$(LIBRARYNAME).odoc: $(ObjectsCMI) + $(Echo) "Documenting $(notdir $@)" + $(Verb) $(OCAMLDOC) -I $(OcamlDir) -I $(ObjDir) -dump $@ $(OcamlHeaders) + +ocamldoc: $(ObjDir)/$(LIBRARYNAME).odoc ##===- Debugging gunk -----------------------------------------------------===## printvars:: printcamlvars