# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-#AC_PREREQ([2.63])
-AC_INIT([ust], [0.0], [pierre-marc dot fournier at polymtl dot ca])
-AC_CONFIG_AUX_DIR(make_scripts)
-AM_INIT_AUTOMAKE([0.0 foreign])
-AC_CONFIG_SRCDIR([ust/localerr.h])
-#AC_CONFIG_HEADERS([config.h])
+AC_INIT([lttng-ust],[1.9.6],[mathieu dot desnoyers at efficios dot com])
+
+# Following the numbering scheme proposed by libtool for the library version
+# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
+AC_SUBST([LTTNG_UST_LIBRARY_VERSION], [0:0:0])
+# note: remember to update tracepoint.h dlopen() to match this version
+# number. TODO: eventually automate by exporting the major number.
+
+AC_CONFIG_AUX_DIR([config])
+AC_CANONICAL_TARGET
+AC_CANONICAL_HOST
+AC_CONFIG_MACRO_DIR([config])
+AM_INIT_AUTOMAKE([foreign])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AC_CONFIG_SRCDIR([include/lttng/tracepoint.h])
+
+# Configuration options, which will be installed in the config.h
+AC_CONFIG_HEADERS([config.h include/lttng/config.h])
+AH_TEMPLATE([HAVE_EFFICIENT_UNALIGNED_ACCESS], [Use efficient unaligned access.])
+AH_TEMPLATE([HAVE_SDT_INTEGRATION], [DTrace/GDB/SystemTap integration via sdt.h])
+
+# Compute minor/major/patchlevel version numbers
+AC_PROG_SED
+major_version=$(echo AC_PACKAGE_VERSION | sed 's/^\([[0-9]]\)*\.[[0-9]]*\.[[0-9]]*$/\1/')
+minor_version=$(echo AC_PACKAGE_VERSION | sed 's/^[[0-9]]*\.\([[0-9]]*\)\.[[0-9]]*$/\1/')
+patchlevel_version=$(echo AC_PACKAGE_VERSION | sed 's/^[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)$/\1/')
+AC_SUBST([MAJOR_VERSION], [$major_version])
+AC_SUBST([MINOR_VERSION], [$minor_version])
+AC_SUBST([PATCHLEVEL_VERSION], [$patchlevel_version])
+AC_DEFINE_UNQUOTED([VERSION_MAJOR], $major_version, [UST major version number])
+AC_DEFINE_UNQUOTED([VERSION_MINOR], $minor_version, [UST minor version number])
+AC_DEFINE_UNQUOTED([VERSION_PATCHLEVEL], $patchlevel_version, [UST patchlevel version number])
+
# Checks for programs.
AC_PROG_CC
+AC_PROG_CXX
AC_PROG_MAKE_SET
-AC_PROG_LIBTOOL
+LT_INIT
## Checks for libraries.
-## FIXME: Replace `main' with a function in `-ldl':
-#AC_CHECK_LIB([dl], [main])
-## FIXME: Replace `main' with a function in `-lmarkers':
-#AC_CHECK_LIB([markers], [main])
-## FIXME: Replace `main' with a function in `-lpthread':
-#AC_CHECK_LIB([pthread], [main])
-## FIXME: Replace `main' with a function in `-ltracectl':
-#AC_CHECK_LIB([tracectl], [main])
-## FIXME: Replace `main' with a function in `-ltracing':
-#AC_CHECK_LIB([tracing], [main])
-## FIXME: Replace `main' with a function in `-lurcu':
-#AC_CHECK_LIB([urcu], [main])
+AC_CHECK_LIB([dl], [dlopen])
+AC_CHECK_LIB([pthread], [pthread_create])
+
+# Check for libuuid
+AC_CHECK_LIB([uuid], [uuid_generate], [],
+ [AC_MSG_ERROR([Cannot find libuuid. Use [LDFLAGS]=-Ldir to specify its location.])]
+)
# Checks for header files.
#AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday munmap socket strerror strtol])
-AC_ARG_WITH(urcu, [ --with-urcu path Path to userspace RCU source], URCU_PATH="$withval", AC_MSG_ERROR([Must specify urcu path.]))
-AC_ARG_WITH(kcompat, [ --with-kcompat path Path to userspace kcompat source], KCOMPAT_PATH="$withval", AC_MSG_ERROR([Must specify kcompat path.]))
-AC_SUBST(URCU_PATH)
-AC_SUBST(KCOMPAT_PATH)
-
-#AC_CONFIG_FILES([Makefile
-# hello/Makefile
-# libmallocwrap/Makefile
-# libmarkers/Makefile
-# libtracectl/Makefile
-# libtracing/Makefile
-# ust/Makefile
-# ustd/Makefile])
-
-AC_CONFIG_FILES([Makefile libmarkers/Makefile libtracectl/Makefile libtracing/Makefile])
+CFLAGS="-Wall $CFLAGS"
+
+# Check for texinfo, required for building the documentation
+# TODO: make this (and building the documentation) optional
+AC_CHECK_PROG([TEXINFO], [makeinfo], [yes])
+AS_IF([test "x$TEXINFO" != "xyes"],[
+ AC_MSG_ERROR([Please install the 'texinfo' program and make sure 'makeinfo' is in the PATH.])
+])
+
+# URCU
+
+# urcu - check if we just find the headers it out of the box.
+AC_CHECK_HEADERS([urcu-bp.h], [], [AC_MSG_ERROR([Cannot find [URCU] headers (urcu-bp.h). Use [CFLAGS]=-Idir to specify their location.
+This error can also occur when the liburcu package's configure script has not been run.])])
+
+AC_MSG_CHECKING([caa_likely()])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#include <urcu/compiler.h>
+void fct(void)
+{
+ if (caa_likely(1)) {
+ }
+}
+]])],[
+ AC_MSG_RESULT([yes])
+],[
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Please upgrade your version of liburcu to 0.6.6 or better])
+
+])
+
+# urcu - check that URCU lib is available to compilation
+AC_CHECK_LIB([urcu-bp], [synchronize_rcu_bp], [], [AC_MSG_ERROR([Cannot find liburcu-bp lib. Use [LDFLAGS]=-Ldir to specify its location.])])
+
+# urcu - check that URCU lib is at least version 0.6
+AC_CHECK_LIB([urcu-bp], [call_rcu_bp], [], [AC_MSG_ERROR([liburcu 0.6 or newer is needed, please update your version or use [LDFLAGS]=-Ldir to specify the right location.])])
+
+
+# Check for various supplementary host information (beyond the
+# triplet) which might affect the library format choices. E.g., we
+# can be building with `i686-unknown-linux-gnu-gcc -m64'
+
+case "${host}" in
+changequote(,)dnl
+ i[34567]86-*-linux*)
+changequote([,])dnl
+ AC_CACHE_CHECK([if building for x86-64], [ust_cv_i386_is_x86_64],
+ [save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $CFLAGS"
+ AC_EGREP_CPP([got it], [
+#if __x86_64__
+got it
+#endif
+ ], [ust_cv_i386_is_x86_64=yes],
+ [ust_cv_i386_is_x86_64=no])
+ CPPFLAGS="$save_CPPFLAGS"])
+ ;;
+esac
+
+AC_MSG_CHECKING([library format for the host system])
+case $host_cpu in
+changequote(,)dnl
+ i[3456]86)
+changequote([,])dnl
+ if test "$ust_cv_i386_is_x86_64" = yes ; then
+ LIBFORMAT="elf64-x86-64"
+ else
+ LIBFORMAT="elf32-i386"
+ fi
+ ;;
+ x86_64) LIBFORMAT="elf64-x86-64" ;;
+ powerpc) LIBFORMAT="elf32-powerpc" ;;
+ ppc64) LIBFORMAT="elf64-powerpc" ;;
+ powerpc64) LIBFORMAT="elf64-powerpc" ;;
+ s390) LIBFORMAT="elf32-s390"; NO_UNALIGNED_ACCESS=1 ;;
+ s390x) LIBFORMAT="elf64-s390"; NO_UNALIGNED_ACCESS=1 ;;
+ armv5) LIBFORMAT="elf32-littlearm"; NO_UNALIGNED_ACCESS=1 ;;
+ arm) LIBFORMAT="elf32-littlearm"; NO_UNALIGNED_ACCESS=1 ;;
+ mips*) LIBFORMAT=""; NO_UNALIGNED_ACCESS=1;;
+ *) AC_MSG_ERROR([unable to detect library format (unsupported architecture ($host_cpu)?)]) ;;
+esac
+AC_SUBST(LIBFORMAT)
+AC_MSG_RESULT($LIBFORMAT)
+
+if test "x$host_cpu" = "xarm" ; then
+AC_MSG_CHECKING([checking for armv5])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#ifndef __ARM_ARCH_5TEJ__
+#error "no arm5 here"
+#endif
+]])],[
+ AC_MSG_RESULT([yes])
+ NO_UNALIGNED_ACCESS=1
+
+],[
+ AC_MSG_RESULT([no])
+
+])
+fi
+if test x$NO_UNALIGNED_ACCESS = x ; then
+AC_DEFINE([HAVE_EFFICIENT_UNALIGNED_ACCESS], [1])
+fi
+
+# Set compile flags to java include files if given
+AC_ARG_WITH([java-jdk],
+ [AS_HELP_STRING([--with-java-jdk=DIR],[use the Java JDK in DIR. Ex : $JAVA_HOME.])],
+ [JAVA_JDK=$withval],
+ [JAVA_JDK=""]
+)
+AS_IF([test $JAVA_JDK],[
+ AS_IF([test -d $JAVA_JDK],[
+ AC_MSG_RESULT([using Java includes in $JAVA_SDK])
+ SUBDIRS=`find $JAVA_JDK/include -type d`
+ CFLAGS+=" "
+ CFLAGS+=`for x in $SUBDIRS; do echo -n "-I$x "; done`
+ CFLAGS+=" "
+ ],[
+ AC_MSG_ERROR(Unable to find Java include files in $JAVA_JDK)
+ ])
+])
+
+# Check for JNI header files if requested
+AC_ARG_WITH([jni-interface],
+ [AS_HELP_STRING([--with-jni-interface],[build JNI interface between C and Java. Needs Java include files [default=no]])],
+ [jni_interface=$withval],
+ [jni_interface=no]
+)
+
+AS_IF([test "x$jni_interface" = "xyes"],[
+ AC_CHECK_HEADERS([jni.h],[],[
+ AC_MSG_ERROR([missing jni.h
+Make sure Sun Java, OpenJDK or GCJ is installed and that this header file exists in the system path.
+Use the --with-java-jdk=DIR flag to point to your Java include files, or disable the JNI interface.])
+ ])
+])
+AM_CONDITIONAL([BUILD_JNI_INTERFACE], [test "x$jni_interface" = "xyes"])
+
+# sdt.h integration
+AC_ARG_WITH([sdt],
+ [AS_HELP_STRING([--with-sdt],[provide DTrace, GDB and SystemTap integration via sdt.h [default=no]])],
+ [with_sdt=$withval],
+ [with_sdt="no"]
+)
+
+AS_IF([test "x$with_sdt" = "xyes"],[
+ AC_CHECK_HEADERS([sys/sdt.h], [
+ AC_DEFINE([HAVE_SDT_INTEGRATION], [1])
+ ],[
+ AC_MSG_ERROR([The sdt.h integration was requested
+but this header file cannot be found. Make sure it is installed
+or use CFLAGS=-I/path/ to specify a non-standard path to sys/sdt.h])
+ ])
+])
+
+#currently disabled.
+ #tests/hello2/Makefile
+ #tests/basic/Makefile
+ #tests/simple_include/Makefile
+ #tests/snprintf/Makefile
+ #tests/test-nevents/Makefile
+ #tests/test-libustinstr-malloc/Makefile
+ #tests/dlopen/Makefile
+ #tests/same_line_marker/Makefile
+ #tests/trace_event/Makefile
+ #tests/tracepoint/Makefile
+ #tests/tracepoint/benchmark/Makefile
+ #tests/register_test/Makefile
+ #tests/libustctl_function_#tests/Makefile
+ #tests/exit-fast/Makefile
+ #tests/basic_long/Makefile
+
+AC_CONFIG_FILES([
+ Makefile
+ include/Makefile
+ include/lttng/ust-version.h
+ snprintf/Makefile
+ libringbuffer/Makefile
+ liblttng-ust-comm/Makefile
+ liblttng-ust/Makefile
+ liblttng-ust-ctl/Makefile
+ liblttng-ust-fork/Makefile
+ liblttng-ust-java/Makefile
+ liblttng-ust-libc-wrapper/Makefile
+ tests/Makefile
+ tests/hello/Makefile
+ tests/hello-static-lib/Makefile
+ tests/hello.cxx/Makefile
+ tests/demo/Makefile
+ tests/fork/Makefile
+ tests/ust-basic-tracing/Makefile
+ tests/ust-multi-test/Makefile
+ lttng-ust.pc
+])
+
AC_OUTPUT
+
+# Report on the configuration options
+AS_ECHO()
+AS_ECHO("LTTng-UST will be built with the following options:")
+AS_ECHO("Library format: $LIBFORMAT")
+
+AS_ECHO()
+AS_ECHO_N("Java support (JNI): ")
+AS_IF([test "x$jni_interface" = "xyes"], [AS_ECHO("Enabled")], [AS_ECHO("Disabled")])
+
+AS_ECHO_N("sdt.h integration: ")
+AS_IF([test "x$with_sdt" = "xyes"], [AS_ECHO("Enabled")], [AS_ECHO("Disabled")])
+
+AS_ECHO()
+AS_ECHO("Type 'make' to compile.")
+