Skip to content

Commit

Permalink
[OCaml] [autoconf] Migrate to ocamlfind.
Browse files Browse the repository at this point in the history
This commit updates the OCaml bindings and tests to use ocamlfind.
The bindings are migrated in order to use ctypes, which are now
required for MCJIT-backed Llvm_executionengine.
The tests are migrated in order to use OUnit and to verify that
the distributed META.llvm allows to build working executables.

Every OCaml toolchain invocation is now chained through ocamlfind,
which (in theory) allows to cross-compile the OCaml bindings.

The configure script now checks for ctypes (>= 0.2.3) and
OUnit (>= 2). The code depending on these libraries will be added
later. The configure script does not check the package versions
in order to keep changes less invasive.

Additionally, OCaml bindings will now be automatically enabled
if ocamlfind is detected on the system, rather than ocamlc, as it
was before.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220899 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark committed Oct 30, 2014
1 parent b9f3251 commit 47f88b5
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 297 deletions.
8 changes: 4 additions & 4 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ DOXYGEN := @DOXYGEN@
GROFF := @GROFF@
GZIPBIN := @GZIPBIN@
GO := @GO@
OCAMLC := @OCAMLC@
OCAMLOPT := @OCAMLOPT@
OCAMLDEP := @OCAMLDEP@
OCAMLDOC := @OCAMLDOC@
OCAMLFIND := @OCAMLFIND@
GAS := @GAS@
POD2HTML := @POD2HTML@
POD2MAN := @POD2MAN@
Expand All @@ -218,6 +215,9 @@ HAVE_DLOPEN := @HAVE_DLOPEN@
HAVE_PTHREAD := @HAVE_PTHREAD@
HAVE_TERMINFO := @HAVE_TERMINFO@

HAVE_OCAMLOPT := @HAVE_OCAMLOPT@
HAVE_OCAML_OUNIT := @HAVE_OCAML_OUNIT@

LIBS := @LIBS@

# Targets that are possible to build
Expand Down
43 changes: 27 additions & 16 deletions autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,11 @@ AC_ARG_ENABLE(clang-static-analyzer,
enableval="yes")
case "$enableval" in
yes) AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[1]) ;;
no)
no)
if test ${clang_arcmt} != "no" ; then
AC_MSG_ERROR([Cannot enable clang ARC Migration Tool while disabling static analyzer.])
fi
AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[0])
AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[0])
;;
default) AC_SUBST(ENABLE_CLANG_STATIC_ANALYZER,[1]);;
*) AC_MSG_ERROR([Invalid setting for --enable-clang-static-analyzer. Use "yes" or "no"]) ;;
Expand Down Expand Up @@ -1288,10 +1288,7 @@ AC_PATH_PROG(GZIPBIN, [gzip])
AC_PATH_PROG(PDFROFF, [pdfroff])
AC_PATH_PROG(ZIP, [zip])
AC_PATH_PROG(GO, [go])
AC_PATH_PROGS(OCAMLC, [ocamlc])
AC_PATH_PROGS(OCAMLOPT, [ocamlopt])
AC_PATH_PROGS(OCAMLDEP, [ocamldep])
AC_PATH_PROGS(OCAMLDOC, [ocamldoc])
AC_PATH_PROGS(OCAMLFIND, [ocamlfind])
AC_PATH_PROGS(GAS, [gas as])

dnl Get the version of the linker in use.
Expand Down Expand Up @@ -1524,7 +1521,7 @@ AC_ARG_WITH(oprofile,
fi ;;
*)
AC_MSG_ERROR([OProfile support is available on Linux only.]) ;;
esac
esac
],
[
AC_SUBST(USE_OPROFILE, [0])
Expand Down Expand Up @@ -1869,7 +1866,7 @@ AC_DEFINE_UNQUOTED(LLVM_DEFAULT_TARGET_TRIPLE, "$target",
dnl Determine which bindings to build.
if test "$BINDINGS_TO_BUILD" = auto ; then
BINDINGS_TO_BUILD=""
if test "x$OCAMLC" != x -a "x$OCAMLDEP" != x ; then
if test "x$OCAMLFIND" != x ; then
BINDINGS_TO_BUILD="ocaml $BINDINGS_TO_BUILD"
fi
if test "x$GO" != x ; then
Expand All @@ -1885,22 +1882,36 @@ binding_prereqs_failed=0
for a_binding in $BINDINGS_TO_BUILD ; do
case "$a_binding" in
ocaml)
if test "x$OCAMLC" = x ; then
AC_MSG_WARN([--enable-bindings=ocaml specified, but ocamlc not found. Try configure OCAMLC=/path/to/ocamlc])
if test "x$OCAMLFIND" = x ; then
AC_MSG_WARN([--enable-bindings=ocaml specified, but ocamlfind not found. Try configure OCAMLFIND=/path/to/ocamlfind])
binding_prereqs_failed=1
fi
if test "x$OCAMLDEP" = x ; then
AC_MSG_WARN([--enable-bindings=ocaml specified, but ocamldep not found. Try configure OCAMLDEP=/path/to/ocamldep])

if $OCAMLFIND opt -version >/dev/null 2>/dev/null ; then
HAVE_OCAMLOPT=1
else
HAVE_OCAMLOPT=0
fi
AC_SUBST(HAVE_OCAMLOPT)

if ! $OCAMLFIND query ctypes >/dev/null 2>/dev/null; then
AC_MSG_WARN([--enable-bindings=ocaml specified, but ctypes is not installed])
binding_prereqs_failed=1
fi
if test "x$OCAMLOPT" = x ; then
AC_MSG_WARN([--enable-bindings=ocaml specified, but ocamlopt not found. Try configure OCAMLOPT=/path/to/ocamlopt])
dnl ocamlopt is optional!

if $OCAMLFIND query oUnit >/dev/null 2>/dev/null; then
HAVE_OCAML_OUNIT=1
else
HAVE_OCAML_OUNIT=0
AC_MSG_WARN([--enable-bindings=ocaml specified, but OUnit 2 is not installed. Tests will not run])
dnl oUnit is optional!
fi
AC_SUBST(HAVE_OCAML_OUNIT)

if test "x$with_ocaml_libdir" != xauto ; then
AC_SUBST(OCAML_LIBDIR,$with_ocaml_libdir)
else
ocaml_stdlib="`"$OCAMLC" -where`"
ocaml_stdlib="`"$OCAMLFIND" ocamlc -where`"
if test "$LLVM_PREFIX" '<' "$ocaml_stdlib" -a "$ocaml_stdlib" '<' "$LLVM_PREFIX~"
then
# ocaml stdlib is beneath our prefix; use stdlib
Expand Down
64 changes: 18 additions & 46 deletions bindings/ocaml/Makefile.ocaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
include $(LEVEL)/Makefile.config

# CFLAGS needs to be set before Makefile.rules is included.
CXX.Flags += -I"$(shell $(OCAMLC) -where)"
C.Flags += -I"$(shell $(OCAMLC) -where)"
CXX.Flags += -I"$(shell $(OCAMLFIND) c -where)"
C.Flags += -I"$(shell $(OCAMLFIND) c -where)"

ifeq ($(ENABLE_SHARED),1)
LINK_COMPONENTS := all
Expand Down Expand Up @@ -55,7 +55,7 @@ endif
endif

# Tools
OCAMLCFLAGS += -I $(ObjDir) -I $(OcamlDir)
OCAMLCFLAGS += -I $(OcamlDir)
ifndef IS_CLEANING_TARGET
ifneq ($(ObjectsO),)
OCAMLAFLAGS += $(patsubst %,-cclib %, \
Expand All @@ -73,9 +73,9 @@ 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)
Compile.CMI := $(strip $(OCAMLFIND) c -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
Compile.CMO := $(strip $(OCAMLFIND) c -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
Compile.CMX := $(strip $(OCAMLFIND) opt -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)

ifdef OCAMLSTUBS
# Avoid the need for LD_LIBRARY_PATH
Expand All @@ -87,26 +87,20 @@ endif
endif

ifdef OCAMLSTUBS
Archive.CMA := $(strip $(OCAMLC) -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \
-o)
Archive.CMA := $(strip $(OCAMLFIND) c -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \
-o)
else
Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
-o)
Archive.CMA := $(strip $(OCAMLFIND) c -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
-o)
endif

ifdef OCAMLSTUBS
Archive.CMXA := $(strip $(OCAMLOPT) -a $(patsubst %,-cclib %, \
Archive.CMXA := $(strip $(OCAMLFIND) opt -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)
Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
endif

# Source files
Expand Down Expand Up @@ -190,15 +184,15 @@ $(ObjectsCMI): $(UsedOcamlInterfaces:%=$(OcamlDir)/%.cmi)
ifdef LIBRARYNAME
$(ObjDir)/$(LIBRARYNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
$(OcamlDir)/.dir $(ObjDir)/.dir
$(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@
$(Verb) $(OCAMLFIND) dep $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@

-include $(ObjDir)/$(LIBRARYNAME).ocamldep
endif

ifdef TOOLNAME
$(ObjDir)/$(TOOLNAME).ocamldep: $(OcamlSources) $(OcamlHeaders) \
$(OcamlDir)/.dir $(ObjDir)/.dir
$(Verb) $(OCAMLDEP) $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@
$(Verb) $(OCAMLFIND) dep $(OCAMLCFLAGS) $(OcamlSources) $(OcamlHeaders) > $@

-include $(ObjDir)/$(TOOLNAME).ocamldep
endif
Expand Down Expand Up @@ -367,8 +361,8 @@ endif
##===- 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
# If unavailable, 'configure' will set HAVE_OCAMLOPT to 0 in Makefile.config.
ifeq ($(HAVE_OCAMLOPT),1)

$(OcamlDir)/%.cmx: $(ObjDir)/%.cmx
$(Verb) $(CP) -f $< $@
Expand Down Expand Up @@ -418,31 +412,11 @@ uninstall-cmxa::
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 $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders)
$(Verb) $(OCAMLFIND) doc -I $(ObjDir) -I $(OcamlDir) -dump $@ $(OcamlHeaders)

ocamldoc: $(ObjDir)/$(LIBRARYNAME).odoc

Expand All @@ -453,9 +427,7 @@ printcamlvars::
$(Echo) "LLVM_CONFIG : " '$(LLVM_CONFIG)'
$(Echo) "OCAMLCFLAGS : " '$(OCAMLCFLAGS)'
$(Echo) "OCAMLAFLAGS : " '$(OCAMLAFLAGS)'
$(Echo) "OCAMLC : " '$(OCAMLC)'
$(Echo) "OCAMLOPT : " '$(OCAMLOPT)'
$(Echo) "OCAMLDEP : " '$(OCAMLDEP)'
$(Echo) "OCAMLFIND : " '$(OCAMLFIND)'
$(Echo) "Compile.CMI : " '$(Compile.CMI)'
$(Echo) "Compile.CMO : " '$(Compile.CMO)'
$(Echo) "Archive.CMA : " '$(Archive.CMA)'
Expand Down
Loading

0 comments on commit 47f88b5

Please sign in to comment.