# Copyright (C) 1999, 2000, 2001 Lorenzo Bettini <bettini@gnu.org>
#  
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without 
# modifications, as long as this notice is preserved.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

dnl Process this file with autoconf to produce a configure script.
AC_INIT(reconf)

dnl for automake
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(source-highlight,1.11)

AC_SUBST(source_highlightdatadir)
AC_SUBST(source_highlightdocdir)

source_highlightdatadir=$datadir/source-highlight
source_highlightdocdir=$datadir/doc/source-highlight

dnl scanner version

AC_SUBST(JAVA_SCANNER_VERSION)
AC_SUBST(CPP_SCANNER_VERSION)
AC_SUBST(PROLOG_SCANNER_VERSION)
AC_SUBST(PERL_SCANNER_VERSION)
AC_SUBST(PHP3_SCANNER_VERSION)
AC_SUBST(PYTHON_SCANNER_VERSION)

JAVA_SCANNER_VERSION=1.10
CPP_SCANNER_VERSION=1.6
PROLOG_SCANNER_VERSION=0.2.2
PERL_SCANNER_VERSION=1.0
PHP3_SCANNER_VERSION=1.0
PYTHON_SCANNER_VERSION=1.0

AC_DEFINE_UNQUOTED(JAVA_SCANNER_VERSION, "$JAVA_SCANNER_VERSION")
AC_DEFINE_UNQUOTED(CPP_SCANNER_VERSION, "$CPP_SCANNER_VERSION")
AC_DEFINE_UNQUOTED(PROLOG_SCANNER_VERSION, "$PROLOG_SCANNER_VERSION")
AC_DEFINE_UNQUOTED(PERL_SCANNER_VERSION, "$PERL_SCANNER_VERSION")
AC_DEFINE_UNQUOTED(PHP3_SCANNER_VERSION, "$PHP3_SCANNER_VERSION")
AC_DEFINE_UNQUOTED(PYTHON_SCANNER_VERSION, "$PYTHON_SCANNER_VERSION")

dnl Checks for C compiler.
AC_PROG_CC

dnl add options for non GNU compilers
AC_NONGNU_FLAGS

dnl Test for a gotcha in the Sun Forte Developer and, more recently the
dnl Sun ONE Studio, C++ compiler that causes an undef at link time if
dnl the code uses templates and "libx.a" archives are built using the
dnl standard `ar' technique.  `CC' creates a subdirectory set starting
dnl with one named "SunWC_cache" to build additional "*.o" files for the
dnl instantiated templates(?).  The normal way 'ar' is used doesn't work
dnl when generating archive ("libx.a") libraries and `CC' itself must be
dnl used.  The following is a hack provided by Paul Townsend <aab@purdue.edu>.
dnl
AC_MSG_CHECKING( checking whether to use ar cru or CC -xar -o )
cat <<EOF >conftest.c
int conftest(void){return 0;}
EOF
${CXX} -xar -o conftest.a conftest.c >/dev/null 2>&1
if test $? == 0; then
  ar_to_use="\$(CXX) -xar -o"
else
  ar_to_use="\$(AR) cru"
fi
AC_SUBST(ar_to_use)dnl
AC_MSG_RESULT( $ar_to_use )
rm -fr conftest.*

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_CHECK_HEADERS([libintl.h])
AC_CHECK_HEADERS([stddef.h])

dnl for Cygwin32 environment
dnl AM_CYGWIN32 (obsolete)
dnl AC_CYGWIN
AC_EXEEXT

dnl Checks for C++ compiler.
AC_PROG_CXX
AC_LANG_CPLUSPLUS
AC_PROG_AWK

AC_PROG_INSTALL

dnl check for ranlib, for building common code
AC_PROG_RANLIB

dnl test for --enable-warnings command line option
AC_ARG_ENABLE( warnings, [  --enable-warnings       enable compiler warnings], AC_COMPILE_WARNINGS )

dnl check for STL
AC_CXX_HAVE_STL

dnl check for sstream.h
AC_CXX_HAVE_SSTREAM

dnl check for ios_base
AC_CXX_HAVE_IOS_BASE

dnl test for ch-root feature
AC_SUBST(CHROOT_INPUT_DIR)

AC_ARG_ENABLE( input-chroot,   [  --enable-input-chroot=DIR     change the root input dir], if test $enableval = yes || test $enableval = no; then echo "configure: error: you must specify a path for --enable-input-chroot" 1>&2; exit 1; else CHROOT_INPUT_DIR=$enableval; fi, CHROOT_INPUT_DIR= )

AC_DEFINE_UNQUOTED(CHROOT_INPUT_DIR, "$CHROOT_INPUT_DIR")

dnl for txtc (Text-to-C compiler)
LF_PROG_TXTC

dnl for yacc or bison
AC_PROG_YACC

dnl for lex or flex
AM_PROG_LEX

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

dnl check for Electric Fence library, but do not link it automatically
AC_HAVE_LIBRARY(libefence.a, [LIBS="$LIBS"])

dnl if (f)lex library is not present (yywrap won't be found) we provide
dnl a simple implementation (see yywrap.cc) which will be included in
dnl added objs and linked against the program (see src/Makefile.am)
dnl this works with flex generated files (I don't know about others)
AC_REPLACE_FUNCS(yywrap)

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

dnl Checks for library functions.
AC_CHECK_FUNCS(strdup)

dnl check for getopt in standard library
adl_FUNC_GETOPT_LONG

dnl this is only for developers who change src/cmdline.ggo file
dnl GNU gengetopt can be found at http://www.gnu.org/software/gengetopt
AC_PATH_PROGS(GENGETOPT, gengetopt)
AM_CONDITIONAL(NO_GENGETOPT, test -z "$ac_cv_path_GENGETOPT" )

dnl *******************
dnl added by me
dnl *******************


dnl set some flags if it's bison
AC_SUBST(YFLAGS)dnl
YFLAGS="$YFLAGS -d"
AC_MSG_CHECKING( checking if it's bison )
if test "$ac_cv_prog_YACC" = "bison -y"; then
YFLAGS="$YFLAGS -o y.tab.c -l"
AC_MSG_RESULT( $ac_cv_prog_YACC )
else
YFLAGS="$YFLAGS -l"
AC_MSG_RESULT( no: it's $YACC )
fi

CXXFLAGS="-DSOURCE_HIGHLIGHT_DATA_DIR=\\\"$source_highlightdatadir\\\" $CXXFLAGS"

AC_PATH_PROGS(TAR, tar gtar)

AH_TEMPLATE(JAVA_SCANNER_VERSION)
AH_TEMPLATE(CPP_SCANNER_VERSION)
AH_TEMPLATE(PROLOG_SCANNER_VERSION)
AH_TEMPLATE(PERL_SCANNER_VERSION)
AH_TEMPLATE(PHP3_SCANNER_VERSION)
AH_TEMPLATE(PYTHON_SCANNER_VERSION)
AH_TEMPLATE(CHROOT_INPUT_DIR)
AH_BOTTOM([#include "cxxconfig.h"])

AC_CONFIG_FILES(
Makefile
txtc.sh
src/Makefile
src/java2html
src/cpp2html
src/src-hilite-lesspipe.sh
doc/Makefile
doc/source-highlight.html
doc/source-highlight.1
src/includes/Makefile
src/lib/Makefile
src/genhtml/Makefile
src/genesc/Makefile
tests/Makefile
source-highlight.spec
)
AC_OUTPUT
