# Source of configuration for C++ interface of QDBM



#================================================================
# Generic Settings
#================================================================


# Targets
AC_INIT(qdbm-plus, 1.0.0)

# Export variables
LIBVER=3
LIBREV=0
TARGETS="all"
MYDEFS=""
MYOPTS=""
LD="ld"
AR="ar"

# Building paths
pathtmp="$PATH"
PATH="$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
PATH="$PATH:/usr/ccs/bin:/usr/ucb:/usr/xpg4/bin:/usr/xpg6/bin:$pathtmp"
LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LIBRARY_PATH"
LD_LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH"
CPATH="$HOME/include:/usr/local/include:$CPATH"
export PATH LIBRARY_PATH LD_LIBRARY_PATH CPATH



#================================================================
# Options
#================================================================


# Debug mode
AC_ARG_ENABLE(debug, [  --enable-debug          build for debugging])
if test "$enable_debug" = "yes"
then
  TARGETS="debug"
fi

# Developping mode
AC_ARG_ENABLE(devel, [  --enable-devel          build for development])
if test "$enable_devel" = "yes"
then
  TARGETS="devel"
fi



#================================================================
# Checking Commands to Build with
#================================================================


# C compiler
AC_PROG_CC

# C++ compiler
AC_PROG_CXX
if test "$GXX" != "yes"
then
  printf '#================================================================\n' 1>&2
  printf '# WARNING: g++ (GCC) is required to build this package.\n' 1>&2
  printf '#================================================================\n' 1>&2
fi
if uname | egrep -i 'SunOS' > /dev/null 2>&1
then
  MYOPTS="-O1"
fi
if uname | egrep -i 'BSD' > /dev/null 2>&1
then
  MYOPTS="-O1"
fi
if gcc --version | egrep -i '^2\.(8|9)' > /dev/null 2>&1
then
  MYOPTS="-O1"
fi

# Linker
printf 'checking for ld... '
if which ld | grep '/ld$' > /dev/null 2>&1
then
  LD=`which ld`
  printf '%s\n' "$LD"
else
  printf 'no\n'
  printf '#================================================================\n' 1>&2
  printf '# WARNING: ld is not found in PATH.\n' 1>&2
  printf '#================================================================\n' 1>&2
fi

# Archiver
printf 'checking for ar... '
if which ar | grep '/ar$' > /dev/null 2>&1
then
  AR=`which ar`
  printf '%s\n' "$AR"
else
  printf 'no\n'
  printf '#================================================================\n' 1>&2
  printf '# WARNING: ar is not found in PATH.\n' 1>&2
  printf '#================================================================\n' 1>&2
fi



#================================================================
# Checking Libraries
#================================================================


# Underlying libraries
AC_CHECK_LIB(c, main)
AC_CHECK_LIB(rt, main)
AC_CHECK_LIB(pthread, main)
AC_CHECK_LIB(z, main)
AC_CHECK_LIB(lzo2, main)
AC_CHECK_LIB(bz2, main)
AC_CHECK_LIB(iconv, main)
AC_CHECK_LIB(stdc++, main)

# Fundamental QDBM libraries
AC_CHECK_LIB(qdbm, main, true,
  printf 'checking whether /usr/local/lib/libqdbm.* is... '
  if ls /usr/local/lib/libqdbm.* > /dev/null 2>&1
  then
    printf 'yes\n'
  else
    printf 'no\n'
    printf '#================================================================\n' 1>&2
    printf '# WARNING: Install QDBM libraries before installation.\n' 1>&2
    printf '#================================================================\n' 1>&2
  fi
)

# For old BSDs
if uname -a | grep BSD > /dev/null &&
  test -f /usr/lib/libc_r.a && test ! -f /usr/lib/libpthread.a
then
  LIBS=`printf '%s' "$LIBS" | sed 's/-lc/-lc_r/g'`
fi

# Duplication of QDBM for C++
AC_CHECK_LIB(xqdbm, main,
  printf '#================================================================\n' 1>&2
  printf '# WARNING: The existing library was detected.\n' 1>&2
  printf '#================================================================\n' 1>&2
)



#================================================================
# Generic Settings
#================================================================


# Export variables
AC_SUBST(LIBVER)
AC_SUBST(LIBREV)
AC_SUBST(TARGETS)
AC_SUBST(MYDEFS)
AC_SUBST(MYOPTS)
AC_SUBST(LD)
AC_SUBST(AR)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

# Targets
AC_OUTPUT(Makefile)



# END OF FILE
