aAPT
dDebian
fFFmpeg
jJava
mMercurial: Usage
oOCaml
pPostgreSQL

Home Build Systems Autotools

Autotools: OCaml extension

Sample project structure

src
 |____foo
 |     |____Makefile.am
 |     |
 |     |____foo.ml
 |
 |____Makefile.am

autogen.sh
configure.ac
Makefile.am

autogen.sh

#!/bin/sh

autoreconf -v --install || exit 1

if test -z "$NOCONFIGURE"; then
    ./configure "$@"
fi

configure.ac

AC_INIT(foo, 0.0.1)
AC_CONFIG_AUX_DIR([bin])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_INSTALL

AC_PROG_OCAML
if test "$OCAMLOPT" = "no"; then
    AC_MSG_ERROR([You must install the OCaml compiler])
fi

AC_PROG_FINDLIB
if test "$OCAMLFIND" = "no"; then
    AC_MSG_ERROR([You must install OCaml findlib (the ocamlfind command)])
fi
  
AC_CHECK_OCAML_MODULE(OCAML_MODULE_str, Str, [Str], [str])
if test "$OCAML_MODULE_str" = "no"; then
    AC_MSG_ERROR([Module Str is required])
fi

AC_CHECK_OCAML_PKG([threads])
if test "$OCAML_PKG_threads" = "no"; then
    AC_MSG_ERROR([Thread support is required])
fi

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/foo/Makefile])
AC_OUTPUT

Makefile.am

SUBDIRS = src
ACLOCAL_AMFLAGS = -I m4

src/Makefile.am

SUBDIRS = foo

src/foo/Makefile.am

bin_PROGRAMS = foo$(EXEEXT)
foo_SOURCES = foo.ml
man_MANS = foo.1
EXTRA_DIST = foo.1

CLEANFILES = *.cm* *.o

OCAMLPACKAGES := -package @OCAML_PKG_threads@
OCAMLPACKAGES += -package @OCAML_MODULE_str@
OCAMLLIB = -thread -linkpkg
OCAMLCFLAGS := -ccopt -s

foo$(EXEEXT): $(SOURCES)
	$(OCAMLFIND) $(OCAMLOPT) $(OCAMLPACKAGES) $(OCAMLLIB) $(OCAMLCFLAGS) $(SOURCES) -o $@