From 0908d49c22775d20a88f595845b515f669d528f7 Mon Sep 17 00:00:00 2001 From: Gordon Henriksen Date: Tue, 18 Sep 2007 12:26:17 +0000 Subject: [PATCH] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42090 91177308-0d34-0410-b5e6-96231b3b80d8 --- Makefile.config.in | 2 + bindings/ocaml/Makefile.ocaml | 265 ++++++++++++++++++++++++++++++++++ test/Makefile | 13 +- 3 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 bindings/ocaml/Makefile.ocaml diff --git a/Makefile.config.in b/Makefile.config.in index 4ab98bc1ec4..a550eaea553 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -156,6 +156,8 @@ ETAGS := @ETAGS@ ETAGSFLAGS := @ETAGSFLAGS@ GROFF := @GROFF@ GZIP := @GZIP@ +OCAMLC := @OCAMLC@ +OCAMLOPT := @OCAMLOPT@ POD2HTML := @POD2HTML@ POD2MAN := @POD2MAN@ RUNTEST := @RUNTEST@ diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml new file mode 100644 index 00000000000..3141cbd068e --- /dev/null +++ b/bindings/ocaml/Makefile.ocaml @@ -0,0 +1,265 @@ +##===- tools/ml/Makefile -----------------------------------*- Makefile -*-===## +# +# 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. +# +##===----------------------------------------------------------------------===## +# +# An ocaml library is a unique project type in the context of LLVM, so rules are +# here rather than in Makefile.rules. +# +##===----------------------------------------------------------------------===## + +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) + +include $(LEVEL)/Makefile.common + +# Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the +# user can override this with OCAML_LIBDIR. +PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR) +OcamlDir := $(LibDir)/ocaml + +# Info from llvm-config and similar +ifdef UsedComponents +UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents)) +UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents)) +endif + +# Tools +OCAMLCFLAGS += -I $(OcamlDir) +OCAMLAFLAGS += $(patsubst %,-cclib %, \ + $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \ + $(UsedLibs) -l$(LIBRARYNAME)) + +Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) +Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o) +Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o) + +Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o) +Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o) + +# Source files +OcamlSources := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml)) +OcamlHeaders := $(OcamlSources:.ml=.mli) + +# Output and intermediate files +# The .cmo files are the only intermediates; all others get installed. +BareLibraryA := lib$(LIBRARYNAME).a +LibraryA := $(OcamlDir)/$(BareLibraryA) +LibraryCMA := $(OcamlDir)/$(LIBRARYNAME).cma +LibraryCMXA := $(OcamlDir)/$(LIBRARYNAME).cmxa +ObjectsCMI := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmi) +ObjectsCMO := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(ObjDir)/%.cmo) +ObjectsCMX := $(OcamlSources:$(PROJ_SRC_DIR)/%.ml=$(OcamlDir)/%.cmx) + +# Dependencies +# Punting on ocamldep, since its output is only suitable for builds where +# objects are placed directly adjacent to sources, which is not us. +# Unfortunately, this is subtly incorrect and leads to occasional problems. +# ocamlc/ocamlopt really need an option akin to gcc -M or gcc -MD. +$(ObjectsCMO): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi) +$(ObjectsCMX): $(ObjectsCMI) $(UsedOcamLibs:%=$(OcamlDir)/%.cmi) + +# Installation targets +DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a +DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma +DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa + + +##===- Build static library from C sources --------------------------------===## + +all-local:: $(LibraryA) +clean-local:: clean-a +install-local:: install-a +uninstall-local:: uninstall-a + +$(LibraryA): $(ObjectsO) $(OcamlDir)/.dir + $(Echo) "Building $(BuildMode) $(notdir $@)" + -$(Verb) $(RM) -f $@ + $(Verb) $(Archive) $@ $(ObjectsO) + $(Verb) $(Ranlib) $@ + +clean-a:: + -$(Verb) $(RM) -f $(LibraryA) + +install-a:: $(LibraryA) + $(Echo) "Installing $(BuildMode) $(DestA)" + $(Verb) $(MKDIR) $(PROJ_libocamldir) + $(Verb) $(LTInstall) $(LibraryA) $(DestA) + $(Verb) + +uninstall-a:: + $(Echo) "Uninstalling $(DestA)" + -$(Verb) $(RM) -f $(DestA) + + +##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===## + +all-local:: build-cmis +clean-local:: clean-cmis +install-local:: install-cmis +uninstall-local:: uninstall-cmis + +build-cmis: $(ObjectsCMI) + +$(OcamlDir)/%.cmi: $(PROJ_SRC_DIR)/%.mli $(OcamlDir)/.dir + $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" + $(Verb) $(Compile.CMI) $@ $< + +clean-cmis:: + -$(Verb) $(RM) -f $(ObjectsCMI) + +# Also install the .mli's (headers) as documentation. +install-cmis: $(ObjectsCMI) + $(Verb) $(MKDIR) $(PROJ_libocamldir) + $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \ + $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ + $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ + done + $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \ + $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ + $(DataInstall) $(PROJ_SRC_DIR)/$$i "$(PROJ_libocamldir)/$$i"; \ + done + +uninstall-cmis:: + $(Verb) for i in $(patsubst $(OcamlDir)/%,%,$(ObjectsCMI)); do \ + $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ + $(RM) -f "$(PROJ_libocamldir)/$$i"; \ + done + $(Verb) for i in $(patsubst $(PROJ_SRC_DIR)/%,%,$(OcamlHeaders)); do \ + $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ + $(RM) -f "$(PROJ_libocamldir)/$$i"; \ + done + + +##===- Build ocaml bytecode archive (.ml's -> .cmo's -> .cma) -------------===## + +all-local:: $(LibraryCMA) +clean-local:: clean-cma +install-local:: install-cma +uninstall-local:: uninstall-cma + +$(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: $(PROJ_SRC_DIR)/%.ml $(OcamlDir)/.dir + $(Echo) "Compiling $(notdir $<) for $(BuildMode) build" + $(Verb) $(Compile.CMO) $@ $< + +clean-cma:: + $(Verb) $(RM) -f $(LibraryCMA) + +install-cma:: $(LibraryCMA) + $(Echo) "Installing $(BuildMode) $(DestCMA)" + $(Verb) $(MKDIR) $(PROJ_libocamldir) + $(Verb) $(DataInstall) $(LibraryCMA) "$(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) -------===## + +# The ocamlopt compiler is supported on a set of targets disjoint from LLVM's. +# If unavailable, 'configure' will not define OCAMLOPT in Makefile.config. +ifdef OCAMLOPT + +all-local:: $(LibraryCMXA) +clean-local:: clean-cmxa +install-local:: install-cmxa +uninstall-local:: uninstall-cmxa + +$(LibraryCMXA): $(ObjectsCMX) + $(Echo) "Archiving $(notdir $@) for $(BuildMode) build" + $(Verb) $(Archive.CMXA) $@ $(ObjectsCMX) + $(Verb) $(RM) -f $(@:.cmxa=.o) + +$(OcamlDir)/%.cmx: $(PROJ_SRC_DIR)/%.ml + $(Echo) "Compiling optimized $(notdir $<) for $(BuildMode) build" + $(Verb) $(Compile.CMX) $@ $< + +clean-cmxa:: + $(Verb) $(RM) -f $(LibraryCMXA) $(LibraryCMXA:.cmxa=.o) \ + $(LibraryCMXA:.cmxa=.a) $(ObjectsCMX) + +install-cmxa:: $(LibraryCMXA) + $(Verb) $(MKDIR) $(PROJ_libocamldir) + $(Echo) "Installing $(BuildMode) $(DestCMXA)" + $(Verb) $(DataInstall) $(LibraryCMXA) $(DestCMXA) + $(Echo) "Installing $(BuildMode) $(DestCMXA:.cmxa=.a)" + $(Verb) $(DataInstall) $(LibraryCMXA:.cmxa=.a) $(DestCMXA:.cmxa=.a) + $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \ + $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \ + $(DataInstall) $(OcamlDir)/$$i "$(PROJ_libocamldir)/$$i"; \ + done + +uninstall-cmxa:: $(LibraryCMXA) + $(Echo) "Uninstalling $(DestCMXA)" + $(Verb) $(RM) -f $(DestCMXA) + $(Echo) "Uninstalling $(DestCMXA:.cmxa=.a)" + $(Verb) $(RM) -f $(DestCMXA:.cmxa=.a) + $(Verb) for i in $(ObjectsCMX:$(OcamlDir)/%=%); do \ + $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \ + $(RM) -f $(PROJ_libocamldir)/$$i; \ + done + +endif + + +##===- Debugging gunk -----------------------------------------------------===## +printvars:: printcamlvars + +printcamlvars:: + $(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)' + $(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)' + $(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)' + $(Echo) "OCAMLC : " '$(OCAMLC)' + $(Echo) "OCAMLOPT : " '$(OCAMLOPT)' + $(Echo) "Compile.CMI : " '$(Compile.CMI)' + $(Echo) "Compile.CMO : " '$(Compile.CMO)' + $(Echo) "Archive.CMA : " '$(Archive.CMA)' + $(Echo) "Compile.CMX : " '$(Compile.CMX)' + $(Echo) "Archive.CMXA : " '$(Archive.CMXA)' + $(Echo) "CAML_LIBDIR : " '$(CAML_LIBDIR)' + $(Echo) "LibraryCMA : " '$(LibraryCMA)' + $(Echo) "LibraryCMXA : " '$(LibraryCMXA)' + $(Echo) "OcamlSources : " '$(OcamlSources)' + $(Echo) "ObjectsCMI : " '$(ObjectsCMI)' + $(Echo) "ObjectsCMO : " '$(ObjectsCMO)' + $(Echo) "ObjectsCMX : " '$(ObjectsCMX)' + $(Echo) "OCAML_LIBDIR : " '$(OCAML_LIBDIR)' + $(Echo) "DestA : " '$(DestA)' + $(Echo) "DestCMA : " '$(DestCMA)' + $(Echo) "DestCMXA : " '$(DestCMXA)' + $(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 diff --git a/test/Makefile b/test/Makefile index 59cd23e03b3..a09f55da572 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,8 +28,18 @@ CLEANED_TESTSUITE := $(patsubst test/%,%,$(CLEANED_TESTSUITE)) RUNTESTFLAGS := --tool $(CLEANED_TESTSUITE) endif +IGNORE_TESTS := + ifndef RUNLLVM2CPP -RUNTESTFLAGS += --ignore llvm2cpp.exp +IGNORE_TESTS += llvm2cpp.exp +endif + +ifndef OCAMLC +IGNORE_TESTS += ocaml.exp +endif + +ifdef IGNORE_TESTS +RUNTESTFLAGS += --ignore "$(strip $(IGNORE_TESTS))" endif ifneq ($(RUNTEST),) @@ -89,6 +99,7 @@ site.exp: Makefile $(LLVM_OBJ_ROOT)/Makefile.config @echo 'set llvmgxx "$(LLVMGCC)"' >> site.tmp @echo 'set llvmgccmajvers "$(LLVMGCC_MAJVERS)"' >> site.tmp @echo 'set shlibext "$(SHLIBEXT)"' >> site.tmp + @echo 'set ocamlc "$(OCAMLC) -cc $(CXX) -I $(LibDir)/ocaml"' >> site.tmp @echo '## All variables above are generated by configure. Do Not Edit ## ' >>site.tmp @test ! -f site.exp || \ sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp -- 2.34.1