Blame configure.librdkafka

Packit 2997f0
#!/bin/bash
Packit 2997f0
#
Packit 2997f0
Packit 2997f0
mkl_meta_set "description" "name"      "librdkafka"
Packit 2997f0
mkl_meta_set "description" "oneline"   "The Apache Kafka C/C++ library"
Packit 2997f0
mkl_meta_set "description" "long"      "Full Apache Kafka protocol support, including producer and consumer"
Packit 2997f0
mkl_meta_set "description" "copyright" "Copyright (c) 2012-2015 Magnus Edenhill"
Packit 2997f0
Packit 2997f0
# Enable generation of pkg-config .pc file
Packit 2997f0
mkl_mkvar_set "" GEN_PKG_CONFIG y
Packit 2997f0
Packit 2997f0
Packit 2997f0
mkl_require cxx
Packit 2997f0
mkl_require lib
Packit 2997f0
mkl_require pic
Packit 2997f0
mkl_require atomics
Packit 2997f0
mkl_require good_cflags
Packit 2997f0
mkl_require socket
Packit 2997f0
Packit 2997f0
# Generate version variables from rdkafka.h hex version define
Packit 2997f0
# so we can use it as string version when generating a pkg-config file.
Packit 2997f0
Packit 2997f0
verdef=$(grep '^#define  *RD_KAFKA_VERSION  *0x' src/rdkafka.h | sed 's/^#define  *RD_KAFKA_VERSION  *\(0x[a-f0-9]*\)\.*$/\1/')
Packit 2997f0
mkl_require parseversion hex2str "%d.%d.%d" "$verdef" RDKAFKA_VERSION_STR
Packit 2997f0
Packit 2997f0
mkl_toggle_option "Development" ENABLE_DEVEL "--enable-devel" "Enable development asserts, checks, etc" "n"
Packit 2997f0
mkl_toggle_option "Development" ENABLE_VALGRIND "--enable-valgrind" "Enable in-code valgrind suppressions" "n"
Packit 2997f0
Packit 2997f0
mkl_toggle_option "Development" ENABLE_REFCNT_DEBUG "--enable-refcnt-debug" "Enable refcnt debugging" "n"
Packit 2997f0
Packit 2997f0
mkl_toggle_option "Development" ENABLE_SHAREDPTR_DEBUG "--enable-sharedptr-debug" "Enable sharedptr debugging" "n"
Packit 2997f0
Packit 2997f0
mkl_toggle_option "Feature" ENABLE_LZ4_EXT "--enable-lz4" "Enable external LZ4 library support" "y"
Packit 2997f0
Packit 2997f0
mkl_toggle_option "Feature" ENABLE_SSL "--enable-ssl" "Enable SSL support" "y"
Packit 2997f0
mkl_toggle_option "Feature" ENABLE_SASL "--enable-sasl" "Enable SASL support with Cyrus libsasl2" "y"
Packit 2997f0
Packit 2997f0
Packit 2997f0
function checks {
Packit 2997f0
Packit 2997f0
    # -lrt is needed on linux for clock_gettime: link it if it exists.
Packit 2997f0
    mkl_lib_check "librt" "" cont CC "-lrt"
Packit 2997f0
Packit 2997f0
    # required libs
Packit 2997f0
    mkl_lib_check "libpthread" "" fail CC "-lpthread" \
Packit 2997f0
                  "#include <pthread.h>"
Packit 2997f0
Packit 2997f0
    # Check if dlopen() is available
Packit 2997f0
    mkl_lib_check "libdl" "WITH_LIBDL" disable CC "-ldl" \
Packit 2997f0
"
Packit 2997f0
#include <stdlib.h>
Packit 2997f0
#include <dlfcn.h>
Packit 2997f0
void foo (void) {
Packit 2997f0
   void *h = dlopen(\"__bad_lib\", 0);
Packit 2997f0
   void *p = dlsym(h, \"sym\");
Packit 2997f0
   if (p)
Packit 2997f0
     p = NULL;
Packit 2997f0
   dlclose(h);
Packit 2997f0
}"
Packit 2997f0
Packit 2997f0
    if [[ $WITH_LIBDL == "y" ]]; then
Packit 2997f0
        mkl_allvar_set WITH_PLUGINS WITH_PLUGINS y
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    # optional libs
Packit 2997f0
    mkl_lib_check "zlib" "WITH_ZLIB" disable CC "-lz" \
Packit 2997f0
                  "#include <zlib.h>"
Packit 2997f0
    mkl_lib_check "libcrypto" "" disable CC "-lcrypto"
Packit 2997f0
Packit 2997f0
    if [[ "$ENABLE_LZ4_EXT" == "y" ]]; then
Packit 2997f0
        mkl_lib_check --static=-llz4 "liblz4" "WITH_LZ4_EXT" disable CC "-llz4" \
Packit 2997f0
                      "#include <lz4frame.h>"
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    # Snappy support is built-in
Packit 2997f0
    mkl_allvar_set WITH_SNAPPY WITH_SNAPPY y
Packit 2997f0
Packit 2997f0
    # Enable sockem (tests)
Packit 2997f0
    mkl_allvar_set WITH_SOCKEM WITH_SOCKEM y
Packit 2997f0
Packit 2997f0
    if [[ "$ENABLE_SSL" == "y" ]]; then
Packit 2997f0
	mkl_meta_set "libssl" "deb" "libssl-dev"
Packit 2997f0
        if [[ $MKL_DISTRO == "osx" ]]; then
Packit 2997f0
            # Add brew's OpenSSL pkg-config path on OSX
Packit 2997f0
            export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig"
Packit 2997f0
        fi
Packit 2997f0
	mkl_lib_check "libssl" "WITH_SSL" disable CC "-lssl" \
Packit 2997f0
                      "#include <openssl/ssl.h>"
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    if [[ "$ENABLE_SASL" == "y" ]]; then
Packit 2997f0
        mkl_meta_set "libsasl2" "deb" "libsasl2-dev"
Packit 2997f0
        if ! mkl_lib_check "libsasl2" "WITH_SASL_CYRUS" disable CC "-lsasl2" "#include <sasl/sasl.h>" ; then
Packit 2997f0
	    mkl_lib_check "libsasl" "WITH_SASL_CYRUS" disable CC "-lsasl" \
Packit 2997f0
                          "#include <sasl/sasl.h>"
Packit 2997f0
        fi
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    if [[ "$WITH_SSL" == "y" ]]; then
Packit 2997f0
        # SASL SCRAM requires base64 encoding from OpenSSL
Packit 2997f0
        mkl_allvar_set WITH_SASL_SCRAM WITH_SASL_SCRAM y
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    # CRC32C: check for crc32 instruction support.
Packit 2997f0
    #         This is also checked during runtime using cpuid.
Packit 2997f0
    mkl_compile_check crc32chw WITH_CRC32C_HW disable CC "" \
Packit 2997f0
                      "
Packit 2997f0
#include <inttypes.h>
Packit 2997f0
#include <stdio.h>
Packit 2997f0
#define LONGx1 \"8192\"
Packit 2997f0
#define LONGx2 \"16384\"
Packit 2997f0
void foo (void) {
Packit 2997f0
   const char *n = \"abcdefghijklmnopqrstuvwxyz0123456789\";
Packit 2997f0
   uint64_t c0 = 0, c1 = 1, c2 = 2;
Packit 2997f0
   uint64_t s;
Packit 2997f0
   uint32_t eax = 1, ecx;
Packit 2997f0
   __asm__(\"cpuid\"
Packit 2997f0
           : \"=c\"(ecx)
Packit 2997f0
           : \"a\"(eax)
Packit 2997f0
           : \"%ebx\", \"%edx\");
Packit 2997f0
   __asm__(\"crc32b\t\" \"(%1), %0\"
Packit 2997f0
           : \"=r\"(c0)
Packit 2997f0
           : \"r\"(n), \"0\"(c0));
Packit 2997f0
   __asm__(\"crc32q\t\" \"(%3), %0\n\t\"
Packit 2997f0
           \"crc32q\t\" LONGx1 \"(%3), %1\n\t\"
Packit 2997f0
           \"crc32q\t\" LONGx2 \"(%3), %2\"
Packit 2997f0
           : \"=r\"(c0), \"=r\"(c1), \"=r\"(c2)
Packit 2997f0
           : \"r\"(n), \"0\"(c0), \"1\"(c1), \"2\"(c2));
Packit 2997f0
  s = c0 + c1 + c2;
Packit 2997f0
  printf(\"avoiding unused code removal by printing %d, %d, %d\n\", (int)s, (int)eax, (int)ecx);
Packit 2997f0
}
Packit 2997f0
"
Packit 2997f0
Packit 2997f0
Packit 2997f0
    # Check for libc regex
Packit 2997f0
    mkl_compile_check "regex" "HAVE_REGEX" disable CC "" \
Packit 2997f0
"
Packit 2997f0
#include <stddef.h>
Packit 2997f0
#include <regex.h>
Packit 2997f0
void foo (void) {
Packit 2997f0
   regcomp(NULL, NULL, 0);
Packit 2997f0
   regexec(NULL, NULL, 0, NULL, 0);
Packit 2997f0
   regerror(0, NULL, NULL, 0);
Packit 2997f0
   regfree(NULL);
Packit 2997f0
}"
Packit 2997f0
Packit 2997f0
Packit 2997f0
    # Older g++ (<=4.1?) gives invalid warnings for the C++ code.
Packit 2997f0
    mkl_mkvar_append CXXFLAGS CXXFLAGS "-Wno-non-virtual-dtor"
Packit 2997f0
Packit 2997f0
    # Required on SunOS
Packit 2997f0
    if [[ $MKL_DISTRO == "SunOS" ]]; then
Packit 2997f0
	mkl_mkvar_append CPPFLAGS CPPFLAGS "-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT -D__EXTENSIONS__"
Packit 2997f0
	# Source defines _POSIX_C_SOURCE to 200809L for Solaris, and this is
Packit 2997f0
	# incompatible on that platform with compilers < c99.
Packit 2997f0
	mkl_mkvar_append CFLAGS CFLAGS "-std=c99"
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    # Check if strndup() is available (isn't on Solaris 10)
Packit 2997f0
    mkl_compile_check "strndup" "HAVE_STRNDUP" disable CC "" \
Packit 2997f0
"#include <string.h>
Packit 2997f0
int foo (void) {
Packit 2997f0
   return strndup(\"hi\", 2) ? 0 : 1;
Packit 2997f0
}"
Packit 2997f0
Packit 2997f0
    # Check if strerror_r() is available.
Packit 2997f0
    # The check for GNU vs XSI is done in rdposix.h since
Packit 2997f0
    # we can't rely on all defines to be set here (_GNU_SOURCE).
Packit 2997f0
    mkl_compile_check "strerror_r" "HAVE_STRERROR_R" disable CC "" \
Packit 2997f0
"#include <string.h>
Packit 2997f0
const char *foo (void) {
Packit 2997f0
   static char buf[64];
Packit 2997f0
   strerror_r(1, buf, sizeof(buf));
Packit 2997f0
   return buf;
Packit 2997f0
}"
Packit 2997f0
Packit 2997f0
Packit 2997f0
    # See if GNU's pthread_setname_np() is available, and in what form.
Packit 2997f0
    mkl_compile_check "pthread_setname_gnu" "HAVE_PTHREAD_SETNAME_GNU" disable CC "-D_GNU_SOURCE -lpthread" \
Packit 2997f0
'
Packit 2997f0
#include <pthread.h>
Packit 2997f0
Packit 2997f0
void foo (void) {
Packit 2997f0
  pthread_setname_np(pthread_self(), "abc");
Packit 2997f0
}
Packit 2997f0
'
Packit 2997f0
Packit 2997f0
    # Figure out what tool to use for dumping public symbols.
Packit 2997f0
    # We rely on configure.cc setting up $NM if it exists.
Packit 2997f0
    if mkl_env_check "nm" "" cont "NM" ; then
Packit 2997f0
	# nm by future mk var
Packit 2997f0
	if [[ $MKL_DISTRO == "osx" || $MKL_DISTRO == "AIX" ]]; then
Packit 2997f0
	    mkl_mkvar_set SYMDUMPER SYMDUMPER '$(NM) -g'
Packit 2997f0
	else
Packit 2997f0
	    mkl_mkvar_set SYMDUMPER SYMDUMPER '$(NM) -D'
Packit 2997f0
	fi
Packit 2997f0
    else
Packit 2997f0
	# Fake symdumper
Packit 2997f0
	mkl_mkvar_set SYMDUMPER SYMDUMPER 'echo'
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    # The linker-script generator (lds-gen.py) requires python
Packit 2997f0
    if [[ $WITH_LDS == y ]]; then
Packit Service 9f6c01
        if ! mkl_command_check python "HAVE_PYTHON" "disable" "python3 -V"; then
Packit 2997f0
            mkl_err "disabling linker-script since python is not available"
Packit 2997f0
            mkl_mkvar_set WITH_LDS WITH_LDS "n"
Packit 2997f0
        fi
Packit 2997f0
    fi
Packit 2997f0
Packit 2997f0
    if [[ "$ENABLE_VALGRIND" == "y" ]]; then
Packit 2997f0
	mkl_compile_check valgrind WITH_VALGRIND disable CC "" \
Packit 2997f0
			  "#include <valgrind/memcheck.h>"
Packit 2997f0
    fi
Packit 2997f0
}
Packit 2997f0