Blob Blame History Raw
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([iptraf-ng], [@@IPTRAF_VERSION@@], [iptraf-ng@fedorahosted.org])

AC_CONFIG_SRCDIR([src/iptraf.c])

config_file=config.mak.autogen
config_append=config.mak.append
config_in=config.mak.in

echo "# ${config_append}.  Generated by configure." > "${config_append}"


## Definitions of macros
# CONF_APPEND_LINE(LINE)
# --------------------------
# Append LINE to file ${config_append}
AC_DEFUN([CONF_APPEND_LINE],
[echo "$1" >> "${config_append}"])# CONF_APPEND_LINE
#
# ARG_SET_PATH(PROGRAM)
# -------------------------
# Provide --with-PROGRAM=PATH option to set PATH to PROGRAM
# Optional second argument allows setting NO_PROGRAM=YesPlease if
# --without-PROGRAM version used.
AC_DEFUN([ARG_SET_PATH],
[AC_ARG_WITH([$1],
 [AS_HELP_STRING([--with-$1=PATH],
                 [provide PATH to $1])],
 [CONF_APPEND_PATH($1,$2)],[])
])# ARG_SET_PATH
#
# CONF_APPEND_PATH(PROGRAM)
# ------------------------------
# Parse --with-PROGRAM=PATH option to set PROGRAM_PATH=PATH
# Used by ARG_SET_PATH(PROGRAM)
# Optional second argument allows setting NO_PROGRAM=YesPlease if
# --without-PROGRAM is used.
AC_DEFUN([CONF_APPEND_PATH],
[PROGRAM=m4_toupper($1); \
if test "$withval" = "no"; then \
	if test -n "$2"; then \
		m4_toupper($1)_PATH=$withval; \
		AC_MSG_NOTICE([Disabling use of ${PROGRAM}]); \
		CONF_APPEND_LINE(NO_${PROGRAM}=YesPlease); \
		CONF_APPEND_LINE(${PROGRAM}_PATH=); \
	else \
		AC_MSG_ERROR([You cannot use git without $1]); \
	fi; \
else \
	if test "$withval" = "yes"; then \
		AC_MSG_WARN([You should provide path for --with-$1=PATH]); \
	else \
		m4_toupper($1)_PATH=$withval; \
		AC_MSG_NOTICE([Setting m4_toupper($1)_PATH to $withval]); \
		CONF_APPEND_LINE(${PROGRAM}_PATH=$withval); \
	fi; \
fi; \
]) # CONF_APPEND_PATH
#
# PARSE_WITH(PACKAGE)
# -----------------------
# For use in AC_ARG_WITH action-if-found, for packages default ON.
# * Set NO_PACKAGE=YesPlease for --without-PACKAGE
# * Set PACKAGEDIR=PATH for --with-PACKAGE=PATH
# * Unset NO_PACKAGE for --with-PACKAGE without ARG
AC_DEFUN([PARSE_WITH],
[PACKAGE=m4_toupper($1); \
if test "$withval" = "no"; then \
	m4_toupper(NO_$1)=YesPlease; \
elif test "$withval" = "yes"; then \
	m4_toupper(NO_$1)=; \
else \
	m4_toupper(NO_$1)=; \
	m4_toupper($1)DIR=$withval; \
	AC_MSG_NOTICE([Setting m4_toupper($1)DIR to $withval]); \
	CONF_APPEND_LINE(${PACKAGE}DIR=$withval); \
fi \
])# PARSE_WITH
#
# PARSE_WITH_SET_MAKE_VAR(WITHNAME, VAR, HELP_TEXT)
# ---------------------
# Set VAR to the value specied by --with-WITHNAME.
# No verification of arguments is performed, but warnings are issued
# if either 'yes' or 'no' is specified.
# HELP_TEXT is presented when --help is called.
# This is a direct way to allow setting variables in the Makefile.
AC_DEFUN([PARSE_WITH_SET_MAKE_VAR],
[AC_ARG_WITH([$1],
 [AS_HELP_STRING([--with-$1=VALUE], $3)],
 if test -n "$withval"; then \
  if test "$withval" = "yes" -o "$withval" = "no"; then \
    AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]
		     [a value for $1 ($2).  Maybe you do...?]); \
  fi; \
  \
  AC_MSG_NOTICE([Setting $2 to $withval]); \
  CONF_APPEND_LINE($2=$withval); \
 fi)])# PARSE_WITH_SET_MAKE_VAR

dnl
dnl CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE)
dnl -----------------------------------------
dnl Similar to AC_CHECK_FUNC, but on systems that do not generate
dnl warnings for missing prototypes (e.g. FreeBSD when compiling without
dnl -Wall), it does not work.  By looking for function definition in
dnl libraries, this problem can be worked around.
AC_DEFUN([CHECK_FUNC],[AC_CHECK_FUNC([$1],[
  AC_SEARCH_LIBS([$1],,
  [$2],[$3])
],[$3])])

dnl
dnl STASH_FLAGS(BASEPATH_VAR)
dnl -----------------------------
dnl Allow for easy stashing of LDFLAGS and CPPFLAGS before running
dnl tests that may want to take user settings into account.
AC_DEFUN([STASH_FLAGS],[
if test -n "$1"; then
   old_CPPFLAGS="$CPPFLAGS"
   old_LDFLAGS="$LDFLAGS"
   CPPFLAGS="-I$1/include $CPPFLAGS"
   LDFLAGS="-L$1/$lib $LDFLAGS"
fi
])

dnl
dnl UNSTASH_FLAGS(BASEPATH_VAR)
dnl -----------------------------
dnl Restore the stashed *FLAGS values.
AC_DEFUN([UNSTASH_FLAGS],[
if test -n "$1"; then
   CPPFLAGS="$old_CPPFLAGS"
   LDFLAGS="$old_LDFLAGS"
fi
])

## Site configuration related to programs (before tests)
## --with-PACKAGE[=ARG] and --without-PACKAGE
#
# Set lib to alternative name of lib directory (e.g. lib64)
AC_ARG_WITH([lib],
 [AS_HELP_STRING([--with-lib=ARG],
                 [ARG specifies alternative name for lib directory])],
 [if test "$withval" = "no" || test "$withval" = "yes"; then \
	AC_MSG_WARN([You should provide name for --with-lib=ARG]); \
else \
	lib=$withval; \
	AC_MSG_NOTICE([Setting lib to '$lib']); \
	CONF_APPEND_LINE(lib=$withval); \
fi; \
],[])

if test -z "$lib"; then
   AC_MSG_NOTICE([Setting lib to 'lib' (the default)])
   lib=lib
fi

#
# Define NO_CURL if you do not have curl installed.  git-http-pull and
# git-http-push are not built, and you cannot use http:// and https://
# transports.
#
# Define CURLDIR=/foo/bar if your curl header and library files are in
# /foo/bar/include and /foo/bar/lib directories.
AC_ARG_WITH(ncurses,
AS_HELP_STRING([--with-ncurses],[support http(s):// transports (default is YES)])
AS_HELP_STRING([],              [ARG can be also prefix for curl library and headers]),
PARSE_WITH(ncurses))


## Checks for programs.
AC_MSG_NOTICE([CHECKS for programs])
#
AC_PROG_CC([cc gcc])
AC_C_INLINE
case $ac_cv_c_inline in
  inline | yes | no)	;;
  *)			AC_SUBST([INLINE], [$ac_cv_c_inline]) ;;
esac
#AC_PROG_INSTALL		# needs install-sh or install.sh in sources
AC_CHECK_TOOLS(AR, [gar ar], :)
AC_CHECK_PROGS(TAR, [gtar tar])

AC_CHECK_PROGS(ASCIIDOC, [asciidoc])
if test -n "$ASCIIDOC"; then
	AC_MSG_CHECKING([for asciidoc version])
	asciidoc_version=`$ASCIIDOC --version 2>/dev/null`
	case "${asciidoc_version}" in
	asciidoc' '7*)
		ASCIIDOC7=YesPlease
		AC_MSG_RESULT([${asciidoc_version} > 7])
		;;
	asciidoc' '8*)
		ASCIIDOC7=
		AC_MSG_RESULT([${asciidoc_version}])
		;;
	*)
		ASCIIDOC7=
		AC_MSG_RESULT([${asciidoc_version} (unknown)])
		;;
	esac
fi
AC_SUBST(ASCIIDOC7)

## Checks for libraries.
AC_MSG_NOTICE([CHECKS for libraries])

if test -z "$NO_NCURSES"; then
STASH_FLAGS($NCURSESSDIR)
AC_CHECK_LIB([ncurses], [initscr],
[NO_NCURSES=],
[NO_NCURSES=YesPlease])
UNSTASH_FLAGS($NCURSESDIR)
AC_SUBST(NO_NCURSES)
fi

CFLAGS="$CFLAGS -W -Wall -std=gnu99 -pedantic"

## Output files
AC_CONFIG_FILES(["${config_file}":"${config_in}":"${config_append}"])
AC_OUTPUT