#!/bin/sh
# configure script for AKFAvatar - library and program for using an avatar
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Andreas K. Foerster
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Antonio Diaz Diaz.
#
# This configure script is free software; you have unlimited permission
# to copy, distribute and modify it.


# Version and name
VERSION=0
SUBVERSION=24
REVISION=3
BUILD=0 # set to 0 for official releases
#VARIANT="-testing"
LIBNAME=libakfavatar.so.${VERSION}.${SUBVERSION}.${REVISION}
SONAME=libakfavatar.so.${VERSION}.${SUBVERSION}

invocation_name=$0
args=
no_create=
pkgname=akfavatar
srctrigger=avatar-sdl.c
SIZE=DEFAULT
OPENPTY=
WCHAR_ENCODING=
USE_LINUXFB="no"
USE_SDL="yes"
SDL_IMAGE="yes"
LINK_SDL_IMAGE="no"
NO_LUA="no"
STATIC_LUA="no"
NO_DEPRECATED="no"
FONT="9x18.bdf"
OBJAVATAR="avatar-sdl"
OBJAUDIO="audio-sdl"

if [ ${BUILD} -gt 0 ]
then pkgversion="${VERSION}.${SUBVERSION}.${REVISION}${VARIANT}-${BUILD}"
else pkgversion="${VERSION}.${SUBVERSION}.${REVISION}${VARIANT}"
fi

# clear some things potentially inherited from environment.
srcdir=
prefix=/usr/local
exec_prefix='${prefix}'
bindir='${exec_prefix}/bin'
libdir='${exec_prefix}/lib'
includedir='${exec_prefix}/include'
datadir='${prefix}/share'
infodir='${datadir}/info'
docdir='${datadir}/doc/${pkgname}'
mandir='${datadir}/man'
sysconfdir='${prefix}/etc'
hosttype=
CC=
CXX=
CPPFLAGS=
CFLAGS='-O2'
CXXFLAGS='-O2'
LDFLAGS=
SDL_CONFIG='sdl-config'
AVATARSAY_LDFLAGS=
WINDRES='windres'
INSTALL='install'
AR='ar'
RANLIB='ranlib'
LDCONFIG='ldconfig'
AWK='awk'
TARGET='default'
DISTBIN="dist-bin-default"

# Loop over all args
while [ x"$1" != x ] ; do

	# Get the first arg, and shuffle
	option=$1
	shift

	# Add quoted option to args
	args="${args} \"${option}\""

	# Split out the argument for options that take them
	case ${option} in
	*=*) optarg=`echo ${option} | sed -e 's,^[^=]*=,,'` ;;
	esac

	# Process the options
	case ${option} in
	--help | --he*)
		echo "Usage: configure [options]"
		echo
		echo "Options: [defaults in brackets]"
		echo "  --help                display this help and exit"
		echo "  --version             output version information and exit"
		echo "  --srcdir=DIR          find the sources in DIR [. or ..]"
		echo "  --prefix=DIR          install into DIR [${prefix}]"
		echo "  --exec-prefix=DIR     base directory for arch-dependent files [${exec_prefix}]"
		echo "  --bindir=DIR          user executables directory [${bindir}]"
		echo "  --datadir=DIR         base directory for doc and data [${datadir}]"
		echo "  --infodir=DIR         info files directory [${infodir}]"
		echo "  --mandir=DIR          man pages directory [${mandir}]"
		echo "  --docdir=DIR          documentation directory [${docdir}]"
		echo "  --sysconfdir=DIR      read-only single-machine data directory [${sysconfdir}]"
		echo "  --host=mingw          cross-compile with mingw (experimental)"
		echo "  --with-openpty        use openpty instead of posix_openpt"
		echo "  --with-sdl2           use SDL2"
		echo "  --with-linuxfb        build for linux framebuffer (no mouse, no sound)"
		echo "  --with-static-lua     try to link Lua statically"
		echo "  --disable-audio       disable audio support"
		echo "  --disable-sdl-image   disable support for SDL_image completely"
		echo "  --disable-deprecated  disable support for deprecated functions"
		echo "  --disable-lua         build without Lua"
		echo "  --enable-link-sdl-image link directly to SDL_image"
		echo "  --enable-size=vga     compile for VGA size (640x480)"
		echo "  CC=COMPILER           C compiler to use [gcc -std=gnu99]"
		#echo "  CXX=COMPILER          C++ compiler to use [g++]"
		echo "  CPPFLAGS=OPTIONS      command line options for the preprocessor [${CPPFLAGS}]"
		echo "  CFLAGS=OPTIONS        command line options for the C compiler [${CFLAGS}]"
		#echo "  CXXFLAGS=OPTIONS      command line options for the C++ compiler [${CXXFLAGS}]"
		echo "  LDFLAGS=OPTIONS       command line options for the linker [${LDFLAGS}]"
		echo "  AR=program            ar program to use [${AR}]"
		echo "  RANLIB=program        ranlib program to use [${RANLIB}]"
		echo "  INSTALL=program       install program to use [${INSTALL}]"
		echo "  LDCONFIG=program      ldconfig program to use [${LDCONFIG}]"
		echo "  AWK=program           AWK program to use [${AWK}]"
		echo
		exit 0 ;;
	--version | --ve*)
		echo "Configure script for ${pkgname} version ${pkgversion}"
		exit 0 ;;
	--srcdir* | --sr*)
		srcdir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--prefix* | --pr*)
		prefix=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--exec-prefix* | --ex*)
		exec_prefix=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--bindir* | --bi*)
		bindir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--datadir* | --da*)
		datadir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--infodir* | --in*)
		infodir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--docdir* | --do*)
		docdir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--mandir* | --ma*)
		mandir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--sysconfdir* | --sy*)
		sysconfdir=`echo ${optarg} | sed -e 's,/$,,'` ;;
	--no-create | --no-c*)
		no_create=yes ;;
	--host*)
		hosttype=`echo ${optarg} | sed -e 's,/$,,'` ;;
	CC=*)       CC=${optarg} ;;
	CXX=*)      CXX=${optarg} ;;
	CPPFLAGS=*) CPPFLAGS=${optarg} ;;
	CFLAGS=*)   CFLAGS=${optarg} ;;
	CXXFLAGS=*) CXXFLAGS=${optarg} ;;
	LDFLAGS=*)  LDFLAGS=${optarg} ;;
	AR=*)       AR=${optarg} ;;
	RANLIB=*)   RANLIB=${optarg} ;;
	INSTALL=*)  INSTALL=${optarg} ;;
	LDCONFIG=*) LDCONFIG=${optarg} ;;
	AWK=*)      AWK=${optarg} ;;

	--with-openpty) OPENPTY="yes" ;;
	--with-static-lua) STATIC_LUA="yes" ;;
	--with-linuxfb) USE_LINUXFB="yes" ;;
	--with-sdl2) SDL_CONFIG="sdl2-config" ;;
	--enable-lua=no | \
	--disable-lua | \
	--disable-lua=yes) NO_LUA="yes" ;;
	--enable-link-sdl-image | \
	--enable-link-sdl-image=yes) LINK_SDL_IMAGE="yes" ;;
	--enable-link-sdl-image=no | \
	--disable-link-sdl-image | \
	--disable-link-sdl-image=yes) LINK_SDL_IMAGE="no" ;;
	--disable-sdl-image | \
	--disable-sdl-image=yes) SDL_IMAGE="no" ;;
	--enable-sdl-image | \
	--enable-sdl-image=yes) SDL_IMAGE="yes" ;;
	--enable-deprecated=no | \
	--disable-deprecated | \
	--disable-deprecated=yes) NO_DEPRECATED="yes" ;;
	--enable-vga | --enable-vga=yes | --enable-size=vga) SIZE="VGA" ;;
	--disable-audio | \
	--enable-audio=no | \
	--disable-audio=yes) NO_AUDIO="yes" ;;
	
	--build=* | --enable-* | --with-* | --*dir=* | *=* | *-*-*) ;;
	*)
		echo "configure: Unrecognized option: \"${option}\"; use --help for usage." 1>&2
		exit 1 ;;
	esac
done

if [ "$SIZE" = "VGA" ]
then
  CFLAGS="$CFLAGS -DVGA"
  FONT="7x14.bdf"
fi

if [ "$OPENPTY" = "yes" ]; then
  CFLAGS="$CFLAGS -DUSE_OPENPTY"
  AVATARSAY_LDFLAGS="-lutil"
fi

# system specific stuff
SYSTEM=`uname -s`
case ${SYSTEM} in
  Linux | linux)     SYSTEM="gnu-linux" ;;
  FreeBSD | freebsd) SYSTEM="freebsd"
                     LDFLAGS="${LDFLAGS} -lpthread -Wl,-rpath,'${libdir}'" 
                     ;;
  MINGW* | mingw* | windows32* | CYGWIN*)
                    SYSTEM="mingw"
                    ARCH="x86"
                    TARGET="mingw"
                    DISTBIN="dist-mingw"
                    ;;
esac

ARCH=`uname -m`
case ${ARCH} in
  i?86) ARCH="x86" ;;
  x86_64 | x86-64) ARCH="amd64" ;;
esac

# cross-compile
case ${hosttype} in

  x86_64*-mingw* | amd64*-mingw*)
           SYSTEM="mingw"
           ARCH="amd64"
           TARGET="mingw"
           DISTBIN="dist-mingw"

           if [ -x /usr/bin/x86_64-w64-mingw32-gcc ]
           then
             CC="/usr/bin/x86_64-w64-mingw32-gcc -std=gnu99"
             AR=/usr/bin/x86_64-w64-mingw32-ar
             STRIP=/usr/bin/x86_64-w64-mingw32-strip
             RANLIB=/usr/bin/x86_64-w64-mingw32-ranlib
             WINDRES=/usr/bin/x86_64-w64-mingw32-windres
             [ -d /usr/x86_64-w64-mingw32 ] && prefix=/usr/x86_64-w64-mingw32
           fi
           ;;

  *mingw* | *MINGW*) 
           SYSTEM="mingw"
           ARCH="x86"
           TARGET="mingw"
           DISTBIN="dist-mingw"

           if [ -x /usr/bin/i686-w64-mingw32-gcc ]
           then
             CC="/usr/bin/i686-w64-mingw32-gcc -std=gnu99"
             AR=/usr/bin/i686-w64-mingw32-ar
             STRIP=/usr/bin/i686-w64-mingw32-strip
             RANLIB=/usr/bin/i686-w64-mingw32-ranlib
             WINDRES=/usr/bin/i686-w64-mingw32-windres
             [ -d /usr/i686-w64-mingw32 ] && prefix=/usr/i686-w64-mingw32
           elif [ -x /usr/bin/i586-mingw32msvc-gcc ]
           then
             CC="/usr/bin/i586-mingw32msvc-gcc -std=gnu99"
             AR=/usr/bin/i586-mingw32msvc-ar
             STRIP=/usr/bin/i586-mingw32msvc-strip
             RANLIB=/usr/bin/i586-mingw32msvc-ranlib
             WINDRES=/usr/bin/i586-mingw32msvc-windres
             [ -d /usr/i586-mingw32msvc ] && prefix=/usr/i586-mingw32msvc
           fi
           ;;

  *x86* | *i?86*) # private hack
           if [ x"$ARCH" = x"x86" ]
           then
             # unset hosttype, not needed
             hosttype=
           else
             CFLAGS="-m32 $CFLAGS"
             LDFLAGS="-m32 $LDFLAGS"
             ARCH="x86"
             hosttype='x86' # easier for 'if'
           fi
           ;;
esac

###################################################################################
# linux framebuffer

if [ x"$USE_LINUXFB" = x"yes" ]
then

  if [ x"$SYSTEM" != x"gnu-linux" ]
  then
    echo "linuxfb only available for Linux based systems" 1>&2
    exit 1
  fi

  OBJAVATAR="avatar-linuxfb"
  OBJAUDIO="audio-dummy"
  USE_SDL="no"
  NO_AUDIO="yes"
fi

###################################################################################
# SDL


if [ x"$USE_SDL" = x"yes" ]
then

  # Check for SDL version
  sdlversion=`${SDL_CONFIG} --version`
  case ${sdlversion} in
    "")    echo "SDL develop environment not found" 1>&2
           echo "I need version 1.2.x (x >= 6)" 1>&2
           exit 1 ;;
    1.2.* | 2.*)
           echo "SDL ${sdlversion} found - okay" 1>&2
           ;;

    *)     echo "SDL ${sdlversion} found - but I need 1.2.x (x >= 6)" 1>&2
           exit 1 ;;
  esac

  # cross-compile
  case ${hosttype} in
     x86_64*-mingw* | amd64*-mingw*)
       # find sdl-config for cross-compiling
       if [ -x /usr/local/x86_64-w64-mingw32/bin/${SDL_CONFIG} ]
       then
         SDL_CFLAGS=`/usr/local/x86_64-w64-mingw32/bin/${SDL_CONFIG} --cflags`
         SDL_LDFLAGS=`/usr/local/x86_64-w64-mingw32/bin/${SDL_CONFIG} --libs`
       elif [ -x /usr/local/cross-tools/amd64-mingw32/bin/${SDL_CONFIG} ]
       then
         SDL_CFLAGS=`/usr/local/cross-tools/amd64-mingw32/bin/${SDL_CONFIG} --cflags`
         SDL_LDFLAGS=`/usr/local/cross-tools/amd64-mingw32/bin/${SDL_CONFIG} --libs`
       else
         # most probably not the correct directories
         SDL_CFLAGS="-I/usr/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main"
         SDL_LDFLAGS="-L/usr/lib -lmingw32 -lSDLmain -lSDL -mwindows"
       fi
       ;;

     *mingw* | *MINGW*)
       # find sdl-config for cross-compiling
       if [ -x /usr/local/i686-w64-mingw32/bin/${SDL_CONFIG} ]
       then
         SDL_CFLAGS=`/usr/local/i686-w64-mingw32/bin/${SDL_CONFIG} --cflags`
         SDL_LDFLAGS=`/usr/local/i686-w64-mingw32/bin/${SDL_CONFIG} --libs`
       elif [ -x /usr/local/cross-tools/i386-mingw32/bin/${SDL_CONFIG} ]
       then
         SDL_CFLAGS=`/usr/local/cross-tools/i386-mingw32/bin/${SDL_CONFIG} --cflags`
         SDL_LDFLAGS=`/usr/local/cross-tools/i386-mingw32/bin/${SDL_CONFIG} --libs`
       elif [ -x /usr/i586-mingw32msvc/bin/${SDL_CONFIG} ]
       then
         SDL_CFLAGS=`/usr/i586-mingw32msvc/bin/${SDL_CONFIG} --cflags`
         SDL_LDFLAGS=`/usr/i586-mingw32msvc/bin/${SDL_CONFIG} --libs`
       else
         # most probably not the correct directories
         SDL_CFLAGS="-I/usr/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main"
         SDL_LDFLAGS="-L/usr/lib -lmingw32 -lSDLmain -lSDL -mwindows"
       fi
       ;;

    *x86* | *i?86*)  # private hack
        if [ x"$SDL_CONFIG" = x"sdl2-config" ]
        then
          SDL_CFLAGS="-I/usr/local/include/SDL2 -D_REENTRANT"
          SDL_LDFLAGS="-L/usr/local/lib32 -L/usr/lib32 -lSDL2 -lpthread"
        else
          SDL_CFLAGS="-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT"
          SDL_LDFLAGS="-L/usr/local/lib32 -L/usr/lib32 -lSDL -lpthread"
        fi
        ;;

     *)
        SDL_CFLAGS=`${SDL_CONFIG} --cflags`
        SDL_LDFLAGS=`${SDL_CONFIG} --libs`
        ;;
  esac

  if [ x"$SDL_IMAGE" = x"no" ]
  then
    SDL_CFLAGS="$SDL_CFLAGS -DNO_SDL_IMAGE"
    LINK_SDL_IMAGE="no"
  fi

  if [ x"$LINK_SDL_IMAGE" = x"yes" ]
  then
    SDL_CFLAGS="$SDL_CFLAGS -DLINK_SDL_IMAGE"
    SDL_LDFLAGS="$SDL_LDFLAGS -lSDL_image"
  fi
fi

########################################################################################
# Lua

if [ x"$NO_LUA" = x"yes" ]
then
  test x"$TARGET" = x"mingw" && TARGET="mingw-nolua" || TARGET="nolua"
  LUA_CFLAGS=""
  LUA_LDFLAGS=""
elif [ -n "${hosttype}" ]
then
  case ${hosttype} in
    x86_64*-mingw* | amd64*-mingw*)
      LUA_CFLAGS="-I/usr/local/x86_64-w64-mingw32/include"
      LUA_LDFLAGS="-L/usr/local/x86_64-w64-mingw32/lib -llua52"
      ;;

    *mingw* | *MINGW*)
      if [ -d /usr/local/i686-w64-mingw32/include ]
      then
        LUA_CFLAGS="-I/usr/local/i686-w64-mingw32/include"
        LUA_LDFLAGS="-L/usr/local/i686-w64-mingw32/lib -llua52"
      elif [ -d /usr/local/cross-tools/i386-mingw32/include ]
      then
        LUA_CFLAGS="-I/usr/local/cross-tools/i386-mingw32/include"
        LUA_LDFLAGS="-L/usr/local/cross-tools/i386-mingw32/lib -llua52"
      fi
      ;;

    *x86* | *i?86*)
      LUA_CFLAGS=""
      LUA_LDFLAGS="-llua -lm -ldl -Wl,-E"
      ;;

    *)
      LUA_CFLAGS=""
      if [ x"$SYSTEM" = x"mingw" ]
      then
        LUA_LDFLAGS="-llua52"
      else
        LUA_LDFLAGS="-llua -lm -ldl -Wl,-E" # assume static lib!
      fi
      ;;
  esac
elif [ x"$STATIC_LUA" = x"yes" ]
then
  LUA_CFLAGS=""
  if [ -r /usr/lib/liblua5.2.a ]
  then
    LUA_LDFLAGS="/usr/lib/liblua5.2.a -lm -ldl -Wl,-E"
  elif [ -r /usr/lib/liblua-5.2.a ]
  then
    LUA_LDFLAGS="/usr/lib/liblua-5.2.a -lm -ldl -Wl,-E"
  elif [ -r /usr/lib/liblua.a ]
  then
    LUA_LDFLAGS="/usr/lib/liblua.a -lm -ldl -Wl,-E"
  elif [ -r /usr/local/lib/liblua.a ]
  then
    LUA_LDFLAGS="/usr/local/lib/liblua.a -lm -ldl -Wl,-E"
  else
    echo "static Lua not found" 1>&2
    exit 1
  fi
elif pkg-config --exists lua-5.2  # FreeBSD 8.0
then
  LUA_CFLAGS=`pkg-config lua-5.2 --cflags`
  LUA_LDFLAGS=`pkg-config lua-5.2 --libs`
elif pkg-config --exists lua5.2  # Debian
then
  LUA_CFLAGS=`pkg-config lua5.2 --cflags`
  LUA_LDFLAGS=`pkg-config lua5.2 --libs`
elif pkg-config --exists lua  # Fedora
then
  # hope it's the correct version
  LUA_CFLAGS=`pkg-config lua --cflags`
  LUA_LDFLAGS=`pkg-config lua --libs`
elif [ -r /usr/include/lua5.2/lua.h -a /usr/lib/liblua5.2.so ]
then
  LUA_CFLAGS="-I/usr/include/lua5.2"
  LUA_LDFLAGS="-llua5.2"
elif [ -r /usr/include/lua.h -a /usr/lib/liblua.a ]
then
  LUA_CFLAGS=""
  LUA_LDFLAGS="-llua -lm -ldl -Wl,-E"
elif [ -r /usr/local/include/lua.h -a /usr/local/lib/liblua.a ]
then
  LUA_CFLAGS=""
  LUA_LDFLAGS="-llua -lm -ldl -Wl,-E"
elif [ x"$NO_LUA" != x"yes" ]
then
  echo "Lua 5.2 not found" 1>&2
  echo "use --disable-lua to build without Lua" 1>&2
  exit 1
fi


########################################################################################

if [ x"$NO_AUDIO" = x"yes" ]
then
  OBJAUDIO="audio-dummy"
  CFLAGS="$CFLAGS -DNO_AUDIO"
fi

if [ x"$NO_DEPRECATED" = x"yes" ]
then
  CFLAGS="$CFLAGS -DDISABLE_DEPRECATED"
fi

# Find the source files, if location was not specified.
srcdirtext=
if [ x"${srcdir}" = x ] ; then
	srcdirtext="or . or .." ; srcdir=.
	if [ ! -r ${srcdir}/${srctrigger} ] ; then srcdir=.. ; fi
	if [ ! -r ${srcdir}/${srctrigger} ] ; then
		## the sed command below emulates the dirname command
		srcdir=`echo ${invocation_name} | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
	fi
fi

if [ ! -r ${srcdir}/${srctrigger} ] ; then
	exec 1>&2
	echo
	echo "configure: Can't find sources in ${srcdir} ${srcdirtext}"
	echo "configure: (At least ${srctrigger} is missing)."
	exit 1
fi

# Set srcdir to . if that's what it is.
if [ "`pwd`" = "`cd ${srcdir} ; pwd`" ] ; then srcdir=. ; fi

# checking whether we are using GNU C.
if [ x"${CC}" = x ] ; then		# Let the user override the test.
	if [ -x /bin/gcc ] ||
	   [ -x /usr/bin/gcc ] ||
	   [ -x /usr/local/bin/gcc ] ; then
		CC="gcc -std=gnu99"
	else		# clang is fine, too
		if [ -x /usr/bin/clang ] ||
		   [ -x /usr/local/bin/clang ] ; then
		CC="clang"
		else
		CC="c99"
		fi
	fi
fi

# NOTE: -std=c99 would also define __STRICT_ANSI__ and
# MinGW doesn't define some POSIX functions then

# checking whether we are using GNU C++.
if [ x"${CXX}" = x ] ; then		# Let the user override the test.
	if [ -x /bin/g++ ] ||
	   [ -x /usr/bin/g++ ] ||
	   [ -x /usr/local/bin/g++ ] ; then
		CXX="g++"
	else
		CXX="c++"
	fi
fi

echo
if [ x${no_create} = x ] ; then
	echo "creating config.status"
	rm -f config.status
	cat > config.status << EOF
#!/bin/sh
# This file was generated automatically by configure. Do not edit.
# Run this file to recreate the current configuration.
#
# This script is free software; you have unlimited permission
# to copy, distribute and modify it.

exec /bin/sh ${invocation_name} ${args} --no-create
EOF
	chmod +x config.status
fi

echo "creating Makefile"
echo "VERSION = ${VERSION}"
echo "SUBVERSION = ${SUBVERSION}"
echo "REVISION = ${REVISION}"
echo "BUILD = ${BUILD}"
echo "VARIANT = ${VARIANT}"
echo "LIBNAME = ${LIBNAME}"
echo "SONAME = ${SONAME}"
echo "srcdir = ${srcdir}"
echo "prefix = ${prefix}"
echo "exec_prefix = ${exec_prefix}"
echo "bindir = ${bindir}"
echo "libdir = ${libdir}"
echo "includedir = ${includedir}"
echo "datadir = ${datadir}"
echo "infodir = ${infodir}"
echo "mandir = ${mandir}"
echo "docdir = ${docdir}"
echo "sysconfdir = ${sysconfdir}"
echo "CC = ${CC}"
#echo "CXX = ${CXX}"
echo "CPPFLAGS = ${CPPFLAGS}"
echo "CFLAGS = ${CFLAGS}"
#echo "CXXFLAGS = ${CXXFLAGS}"
echo "LDFLAGS = ${LDFLAGS}"
echo "SDL_CFLAGS = ${SDL_CFLAGS}"
echo "SDL_LDFLAGS = ${SDL_LDFLAGS}"
echo "LUA_CFLAGS = ${LUA_CFLAGS}"
echo "LUA_LDFLAGS = ${LUA_LDFLAGS}"
echo "AVATARSAY_LDFLAGS = ${AVATARSAY_LDFLAGS}"
echo "AR = ${AR}"
echo "RANLIB = ${RANLIB}"
echo "WINDRES = ${WINDRES}"
echo "INSTALL = ${INSTALL}"
echo "AWK = ${AWK}"
echo "LDCONFIG = ${LDCONFIG}"
echo "SYSTEM = ${SYSTEM}"
echo "ARCH = ${ARCH}"
echo "TARGET = ${TARGET}"
echo "DISTBIN = ${DISTBIN}"
echo "FONT = ${FONT}"
echo "OBJAVATAR = ${OBJAVATAR}"
echo "OBJAUDIO = ${OBJAUDIO}"

VERSIONNR=`printf "%02d%02d%02d" ${VERSION} ${SUBVERSION} ${REVISION}`
AVTVERSIONSTR="${VERSION}.${SUBVERSION}.${REVISION}${VARIANT}"
test ${BUILD} -gt 0 && AVTVERSIONSTR="${AVTVERSIONSTR} (build ${BUILD})"

rm -f version.h
cat > version.h << EOF
/* version information */
/* This file was generated automatically by configure. Do not edit. */

#define AVTVERSION ${VERSION}
#define AVTSUBVERSION ${SUBVERSION}
#define AVTREVISION ${REVISION}
#define AVTBUILD ${BUILD}
#define AVTVERSIONSTR "${AVTVERSIONSTR}"
#define AVTVERSIONWIDESTR L"${AVTVERSIONSTR}"
#define AVTVERSIONNR "${VERSIONNR}"
EOF

rm -f Makefile
cat > Makefile << EOF
# Makefile for AKFAvatar
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Andreas K. Foerster
# Copyright (C) 2003, 2004, 2005, 2006, 2007 Antonio Diaz Diaz.
# This file was generated automatically by configure. Do not edit.
#
# This Makefile is free software; you have unlimited permission
# to copy, distribute and modify it.

VERSION = ${VERSION}
SUBVERSION = ${SUBVERSION}
REVISION = ${REVISION}
BUILD = ${BUILD}
VARIANT = ${VARIANT}
LIBNAME = ${LIBNAME}
SONAME = ${SONAME}
pkgname = ${pkgname}
pkgversion = ${pkgversion}
srcdir = ${srcdir}
prefix = ${prefix}
exec_prefix = ${exec_prefix}
bindir = ${bindir}
libdir = ${libdir}
includedir = ${includedir}
datadir = ${datadir}
infodir = ${infodir}
docdir = ${docdir}
mandir = ${mandir}
sysconfdir = ${sysconfdir}
CC = ${CC}
CXX = ${CXX}
CPPFLAGS = ${CPPFLAGS}
CFLAGS = ${CFLAGS}
CXXFLAGS = ${CXXFLAGS}
LDFLAGS = ${LDFLAGS}
AVATARSAY_LDFLAGS = ${AVATARSAY_LDFLAGS}
AR = ${AR}
RANLIB = ${RANLIB}
WINDRES = ${WINDRES}
INSTALL = ${INSTALL}
LDCONFIG = ${LDCONFIG}
SDL_CFLAGS = ${SDL_CFLAGS}
SDL_LDFLAGS = ${SDL_LDFLAGS}
LUA_CFLAGS = ${LUA_CFLAGS}
LUA_LDFLAGS = ${LUA_LDFLAGS}
AWK = ${AWK}
SYSTEM = ${SYSTEM}
ARCH = ${ARCH}
TARGET = ${TARGET}
DISTBIN = ${DISTBIN}
FONT = ${FONT}
OBJAVATAR = ${OBJAVATAR}
OBJAUDIO = ${OBJAUDIO}

EOF

case ${SYSTEM} in
 mingw)
   echo 'lua_dll = $(srcdir)/misc/$(ARCH)/lua52.dll' >> Makefile

   if [ x"$SDL_CONFIG" = x"sdl2-config" ]
   then
     echo 'sdl_dll = $(srcdir)/misc/$(ARCH)/SDL2.dll' >> Makefile
   else
     echo 'sdl_dll = $(srcdir)/misc/$(ARCH)/SDL.dll' >> Makefile
   fi

   cat ${srcdir}/mingw/Makefile.in >> Makefile
   ;;

 *) cat ${srcdir}/Makefile.in >> Makefile ;;
esac


# files for pkg-config
cat > akfavatar.pc << EOF
# AKFAvatar pkg-config file
prefix=${prefix}
exec_prefix=${exec_prefix}
libdir=${libdir}
includedir=${includedir}

Name: AKFAvatar
Description: graphical user interface with an avatar
Version: ${VERSION}.${SUBVERSION}.${REVISION}
URL: http://akfavatar.nongnu.org/
Requires.private: sdl >= 1.2.0
Conflicts:
Libs: -L\${libdir} -lakfavatar
Libs.private:
Cflags: -I\${includedir}
EOF

cat > avtaddons.pc << EOF
# AKFAvatar addons pkg-config file
prefix=${prefix}
exec_prefix=${exec_prefix}
libdir=${libdir}
includedir=${includedir}

Name: AKFAvatar Addons
Description: static addon lib for AKFAvatar
Version: ${VERSION}.${SUBVERSION}.${REVISION}
URL: http://akfavatar.nongnu.org/
Requires: akfavatar
Conflicts:
Libs: -L\${libdir} -lavtaddons
Libs.private:
Cflags: -I\${includedir}
EOF

echo '*'
echo '* OK. Now you can run "make" to build the binaries.'
echo '*'

