dnl Process this file with autoconf to produce a configure script.
AC_INIT(a2ps.h)
AC_CONFIG_HEADER(config.h)

# version of the distribution
VERSION=4.6.1
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(VERSION)

dnl Checks for programs.
AC_PROG_CC
AM_C_PROTOTYPES
AC_PROG_INSTALL
dnl We are not using ln -s AC_PROG_LN_S
dnl Check for the file program
AC_PROG_FILE(FILE_COMMAND, file)
if test -n "$FILE_COMMAND"; then
  AC_DEFINE_UNQUOTED(FILE_COMMAND, "$FILE_COMMAND")
fi
AC_SUBST(FILE_COMMAND)

dnl a2ps may send directly to the printer:
dnl check what print service to use
AC_CHECK_PROG(have_lp,  lp, yes, no)
if test $have_lp = yes; then
  AC_DEFINE(HAVE_LP, 1)
else
  AC_DEFINE(HAVE_LP, 0)
fi
AC_SUBST(HAVE_LP)
AC_CHECK_PROG(have_lpr, lpr, yes, no)
if test $have_lpr = yes; then
  AC_DEFINE(HAVE_LPR, 1)
else
  AC_DEFINE(HAVE_LPR, 0)
fi
AC_SUBST(HAVE_LPR)

dnl Checks for libraries.
dnl Replace `main' with a function in -lnsl:
AC_CHECK_LIB(nsl, main)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_TIME
dnl I don't need this: AC_STRUCT_TM

dnl Checks for library functions.
AC_CHECK_FUNCS(gethostname uname)


#
#	In this section is checked the default value for a2ps
#

# What is the default paper ?
AC_MSG_CHECKING(for default sheet size)
AC_ARG_ENABLE(A4_DFLT,
[  --disable-A4            US letter as default format instead of a4],
if test "$enableval" != no; then
  A4_DFLT=1
  AC_MSG_RESULT(A4)
else
  A4_DFLT=0
  AC_MSG_RESULT(US paper)
fi,
A4_DFLT=1
AC_MSG_RESULT(A4))
AC_DEFINE_UNQUOTED(A4_DFLT, $A4_DFLT)
AC_SUBST(A4_DFLT)

# What is the default char set ?
AC_MSG_CHECKING(for default char set)
AC_ARG_ENABLE(ISOLatin1,
[  --disable-ISOLatin1     do not support ISOLatin1 by default],
if test "$enableval" != no; then
  ISOLATIN1_DFLT=1
  AC_MSG_RESULT(ISOLatin1)
else
  ISOLATIN1_DFLT=0
  AC_MSG_RESULT(ascii (7bits))
fi,
ISOLATIN1_DFLT=1
AC_MSG_RESULT(ISOLatin1))
AC_DEFINE_UNQUOTED(ISOLATIN1_DFLT, $ISOLATIN1_DFLT)
AC_SUBST(ISOLATIN1_DFLT)

# Default printing mode
AC_MSG_CHECKING(for default printing mode)
AC_ARG_ENABLE(auto,
[  --disable-auto          do not guess language style by default],
if test "$enableval" != no; then
  AUTO_DFLT=1
  AC_MSG_RESULT(pretty print)
else
  AUTO_DFLT=0
  AC_MSG_RESULT(plain style)
fi,
AUTO_DFLT=1
AC_MSG_RESULT(pretty print))
AC_DEFINE_UNQUOTED(AUTO_DFLT, $AUTO_DFLT)
AC_SUBST(AUTO_DFLT)

# What is the default output ?
AC_MSG_CHECKING(for default output)
AC_ARG_ENABLE(to-printer,
[  --enable-print-default  send to the printer by default],
if test "$enableval" != no; then
  LPR_PRINT_DFLT=1
  AC_MSG_RESULT(to printer)
else
  LPR_PRINT_DFLT=0
  AC_MSG_RESULT(to standard output)
fi,
LPR_PRINT_DFLT=0
AC_MSG_RESULT(to standard output))
AC_DEFINE_UNQUOTED(LPR_PRINT_DFLT, $LPR_PRINT_DFLT)
AC_SUBST(LPR_PRINT_DFLT)

#
# Now cheking for the printer's options
#

# What is the option to get single sided paper ?
AC_MSG_CHECKING(for one sided printer's option)
AC_ARG_ENABLE(1sided,
[  --enable-1sided=OPT     OPT is the option to get recto printing],
if test -n "$enableval"; then
  ONESIDED=$enableval
  AC_DEFINE_UNQUOTED(ONESIDED, "$ONESIDED")
fi)
AC_SUBST(ONESIDED)
if test -n "$ONESIDED"; then
  AC_MSG_RESULT($ONESIDED)
else
  AC_MSG_RESULT(<none>)
fi

# Recto-verso printing option
AC_MSG_CHECKING(for two sided printer's option)
AC_ARG_ENABLE(2sided,
[  --enable-2sided=OPT     OPT is the option to get recto-verso printing],
if test -n "$enableval"; then
  TWOSIDED=$enableval
  AC_DEFINE_UNQUOTED(TWOSIDED, "$TWOSIDED")
fi)
AC_SUBST(TWOSIDED)
if test -n "$TWOSIDED"; then
  AC_MSG_RESULT($TWOSIDED)
else
  AC_MSG_RESULT(<none>)
  AC_MSG_WARN(... recto-verso printing disabled)
fi


# If 2 sided option is defined, what is the default ?
if test -n "$TWOSIDED"; then
  AC_MSG_CHECKING(for recto-verso default)
    AC_ARG_ENABLE(2-default,
    [  --disable-2-default     default is single sided],
    if test "$enableval" != no; then
      TWOSIDED_DFLT=1
    else
      TWOSIDED_DFLT=0
    fi,
    TWOSIDED_DFLT=1)
    AC_DEFINE_UNQUOTED(TWOSIDED_DFLT, $TWOSIDED_DFLT)
    AC_SUBST(TWOSIDED_DFLT)
    if test "$TWOSIDED_DFLT" != 0; then
      AC_MSG_RESULT(2 sided)
    else
      AC_MSG_RESULT(1 sided)
    fi
fi

AC_OUTPUT(Makefile)
