dnl Copyright (C) 2001-2012 Peter Selinger.
dnl This file is part of the upprint package. It is free software and
dnl is distributed under the terms of the GNU general public license.
dnl See the file COPYING for details.

dnl Process this file with autoconf to produce a configure script.

dnl ----------------------------------------------------------------------
dnl Package info
AC_INIT(upprint, 1.7)
AC_CONFIG_SRCDIR(psdim/psdim.c)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)

DATE="February 2012"
RPMRELEASE="1"

dnl ----------------------------------------------------------------------
dnl The names of the installed executables. They are not really
dnl configurable without Makefile changes.

PSDIM=psdim
AC_DEFINE_UNQUOTED(PSDIM,"$PSDIM",Name of the psdim binary)

dnl ----------------------------------------------------------------------
dnl Check for compiler and compiler options

dnl remember user's CFLAGS, if any
iCFLAGS="$CFLAGS"

dnl Check for compiler
AC_PROG_CC

dnl If compiler is gcc, use our own CFLAGS unless user overrides them
if test "$GCC" = "yes" && test "$iCFLAGS" = ""; then
  CFLAGS="-g -O2 -Wall -ffloat-store"
fi

dnl ----------------------------------------------------------------------
dnl Check for library functions.
AC_CHECK_FUNC(getopt_long, , EXTRA_OBJS="$EXTRA_OBJS getopt.o getopt1.o")

dnl ----------------------------------------------------------------------
dnl -lm may be needed for floor() and ceil().

AC_CHECK_LIB(m, ceil)

dnl ----------------------------------------------------------------------
dnl Check for programs
AC_CHECK_PROGS(GS,gs ghostscript)
if test "$GS" = ""; then 
   AC_MSG_ERROR([cannot find ghostscript (required).])
fi
AC_DEFINE_UNQUOTED(GS,"$GS",Name of the ghostscript binary)

dnl ----------------------------------------------------------------------
dnl check for features

dnl Enable optional features
AC_ARG_ENABLE(metric, 
[  --enable-metric         use metric units (centimeters) as default])
if test "$enable_metric" = yes; then
   AC_DEFINE(USE_METRIC,, do we use metric units by default?)
   DEFAULT_UNIT=cm
   DEFAULT_UNIT_POINTS='(72/2.54)'
else
   DEFAULT_UNIT=in
   DEFAULT_UNIT_POINTS='72.0'
fi
AC_DEFINE_UNQUOTED(DEFAULT_UNIT_NAME, "${DEFAULT_UNIT}", [Name of the default unit, as a string])
AC_DEFINE_UNQUOTED(DEFAULT_UNIT_POINTS, ${DEFAULT_UNIT_POINTS}, [Size of the default unit in points, as a double constant])

AC_ARG_ENABLE(a4, 
[  --enable-a4             use a4 as the default papersize])
if test "$enable_a4" = yes; then
   AC_DEFINE(USE_A4,, do we use a4 papersize by default?)
   DEFAULT_FORMAT=a4
else
   DEFAULT_FORMAT=letter
fi
AC_DEFINE_UNQUOTED(PAPER, "${DEFAULT_FORMAT}", default paper format)

dnl ----------------------------------------------------------------------
dnl Check for location of "lpr".
AC_PATH_PROG(LPR,lpr)
if test "$LPR" = ""; then 
   LPR=/usr/bin/lpr
fi

dnl ----------------------------------------------------------------------
dnl set the installation prefix to match that of "lpr"
AC_PREFIX_PROGRAM(lpr)

dnl ----------------------------------------------------------------------
dnl Set up substitutions of non-standard configuration parameters
AC_SUBST(DATE)
AC_SUBST(PSDIM)
AC_SUBST(EXTRA_OBJS)
AC_SUBST(GS)
AC_SUBST(DEFAULT_UNIT)
AC_SUBST(DEFAULT_FORMAT)
AC_SUBST(LPR)
AC_SUBST(RPMRELEASE)

dnl ----------------------------------------------------------------------
AC_OUTPUT([Makefile
	   psdim/Makefile 
	   pstops-clip/Makefile 
	   rpm/Makefile
	   rpm/rpm.spec
	   man/Makefile
	   man/psdim.1
	   man/pstops-clip.1
	   man/lprwrap.1
	   lprwrap/Makefile 
	   lprwrap/lprwrap
          ])
