AC_PREREQ(2.50)

AC_INIT([OGRE], [1.4.7])

AC_CANONICAL_TARGET

# New syntax; PACKAGE gets defined as 'OGRE' not 'ogre'
#AM_INIT_AUTOMAKE([OGRE], 1.4.7)
AM_INIT_AUTOMAKE([OGRE], 1.4.7)
AC_CONFIG_HEADERS([OgreMain/include/config.h])

dnl Check for programs
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_YACC
AM_PROG_LEX

dnl Setup target-specific parameters
OGRE_SETUP_FOR_TARGET

AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AC_LIBTOOL_LANG_CXX_CONFIG

# OGRE_CFLAGS contains the compiler flags crucial for stand-alone client
# programs. They are exported via pkg-config, but not used while building
# Ogre itself; instead, they are defined in config.h.
AC_SUBST(OGRE_CFLAGS)

# Check if compiler supports symbol visibility
# There are quirks for x86_64 and debug builds with gcc < 4.2
AC_LANG_PUSH(C++)
AC_LIBTOOL_COMPILER_OPTION([if $CXX supports -fvisibility],
    [ogre_prog_compiler_supports_visibility],
    [-fvisibility=hidden -fvisibility-inlines-hidden], [],
    [CFLAGS_VISIBILITY="-fvisibility=hidden -fvisibility-inlines-hidden -DOGRE_GCC_VISIBILITY";
    case $target_cpu in
        x86_64* )
            if ! echo "$CFLAGS $CXXFLAGS" | grep -q "\-O"; then
                echo "***********************************************************************"
                echo "WARNING: It looks like you're doing a debug build for an x86_64 target."
                echo "The -fvisibility-inlines-hidden flag is known to give problems in such"
                echo "situations with libstdc++ < 4.2. Disabling the compiler flag."
                echo "***********************************************************************"
                CFLAGS_VISIBILITY="-fvisibility=hidden -DOGRE_GCC_VISIBILITY"
            fi
        ;;
    esac
    case $CXX in
        icpc )
            echo "***********************************************************************"
            echo "WARNING: The intel compiler currently has bugs in its -fvisibility"
            echo "implementation. Disabling the compiler flag."
            echo "***********************************************************************"
            CFLAGS_VISIBILITY=""
        ;;
    esac
    ])
AC_SUBST(CFLAGS_VISIBILITY)
AC_LANG_POP

dnl Other stuff we need
OGRE_USE_STLPORT
AC_CHECK_FT2(9.0.0)

AC_CHECK_LIB(dl, dlopen)
AC_CHECK_LIB(m, pow)
AC_CHECK_LIB(z, gzopen)
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_FUNC(snprintf, AC_DEFINE(HAVE_SNPRINTF,,snprintf))
AC_CHECK_FUNC(vsnprintf, AC_DEFINE(HAVE_VSNPRINTF,,vsnprintf))

OGRE_CHECK_CPPUNIT

PKG_CHECK_MODULES(ZZIPLIB, zziplib)
AC_SUBST(ZZIPLIB_CFLAGS)
AC_SUBST(ZZIPLIB_LIBS)

dnl Get the GL and Platform libs for target build
OGRE_GET_PLATFORM
OGRE_GET_GLSUPPORT

dnl Find the optional components we should build
OGRE_CHECK_GUI
OGRE_CHECK_DOUBLE
OGRE_CHECK_THREADING
OGRE_CHECK_FREEIMAGE
OGRE_CHECK_DEVIL
OGRE_CHECK_CG
OGRE_CHECK_OPENEXR
OGRE_CHECK_DX9
OGRE_CHECK_SSE

dnl Check to see if Ogre platform and GUI are the same
dnl Fixes problem running make distclean when both are set to GLX
OGRE_PLATFORM_AND_GUI

dnl Check to see if user wants to disable building of demos (defaults is to build) - also checks for OIS
OGRE_BUILD_DEMOS

dnl Detect endianness
OGRE_DETECT_ENDIAN

dnl Check to see if -fPIC is required.
OGRE_CHECK_PIC

dnl Check to see if CEGUI is installed.
OGRE_CHECK_CEGUI

CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
LIBS="$LIBS"

dnl Define samples absolute install path
ogreexecdir='${abs_top_builddir}/Samples/Common/bin'
AC_SUBST(abs_top_builddir)
AC_SUBST(ogreexecdir)

dnl Create the makefiles
AC_CONFIG_FILES([Makefile \
    OgreMain/Makefile \
    OgreMain/src/Makefile \
    OgreMain/include/Makefile \
    OgreMain/include/GLX/Makefile \
    OgreMain/include/gtk/Makefile \
    PlugIns/Makefile \
    PlugIns/BSPSceneManager/Makefile \
    PlugIns/BSPSceneManager/src/Makefile \
    PlugIns/BSPSceneManager/include/Makefile \
    PlugIns/CgProgramManager/Makefile \
    PlugIns/CgProgramManager/src/Makefile \
    PlugIns/CgProgramManager/include/Makefile \
    PlugIns/OctreeSceneManager/Makefile \
    PlugIns/OctreeSceneManager/src/Makefile \
    PlugIns/OctreeSceneManager/include/Makefile \
    PlugIns/ParticleFX/Makefile \
    PlugIns/ParticleFX/src/Makefile \
    PlugIns/ParticleFX/include/Makefile \
    RenderSystems/Makefile \
    RenderSystems/GL/Makefile \
    RenderSystems/GL/src/Makefile \
    RenderSystems/GL/include/Makefile \
    RenderSystems/GL/src/atifs/Makefile \
    RenderSystems/GL/src/atifs/include/Makefile \
    RenderSystems/GL/src/atifs/src/Makefile \
    RenderSystems/GL/src/GLSL/Makefile \
    RenderSystems/GL/src/GLSL/include/Makefile \
    RenderSystems/GL/src/GLSL/src/Makefile \
    RenderSystems/GL/src/nvparse/Makefile \
    RenderSystems/Direct3D9/Makefile \
    RenderSystems/Direct3D9/src/Makefile \
    RenderSystems/Direct3D9/include/Makefile \
    Samples/Makefile \
    Samples/Common/Makefile \
    Samples/Common/include/Makefile \
    Samples/Common/bin/Makefile \
    Samples/BezierPatch/Makefile \
    Samples/BezierPatch/src/Makefile \
    Samples/BezierPatch/include/Makefile \
    Samples/CameraTrack/Makefile \
    Samples/CameraTrack/src/Makefile \
    Samples/CelShading/Makefile \
    Samples/CelShading/src/Makefile \
    Samples/Compositor/Makefile \
    Samples/Compositor/src/Makefile \
    Samples/Compositor/include/Makefile \
    Samples/CubeMapping/Makefile \
    Samples/CubeMapping/src/Makefile \
    Samples/CubeMapping/include/Makefile \
    Samples/DeferredShading/Makefile \
    Samples/DeferredShading/src/Makefile \
    Samples/DeferredShading/include/Makefile  \
    Samples/Dot3Bump/Makefile \
    Samples/Dot3Bump/src/Makefile \
    Samples/EnvMapping/Makefile \
    Samples/EnvMapping/src/Makefile \
    Samples/EnvMapping/include/Makefile \
    Samples/FacialAnimation/Makefile \
    Samples/FacialAnimation/src/Makefile \
    Samples/Fresnel/Makefile \
    Samples/Fresnel/src/Makefile \
    Samples/Grass/Makefile \
    Samples/Grass/src/Makefile \
    Samples/Transpacency/Makefile \
    Samples/Transpacency/src/Makefile \
    Samples/Transpacency/include/Makefile \
    Samples/Lighting/Makefile \
    Samples/Lighting/src/Makefile \
    Samples/Lighting/include/Makefile \
    Samples/OceanDemo/Makefile \
    Samples/OceanDemo/src/Makefile \
    Samples/OceanDemo/include/Makefile \
    Samples/ParticleFX/Makefile \
    Samples/ParticleFX/src/Makefile \
    Samples/ParticleFX/include/Makefile \
    Samples/RenderToTexture/Makefile \
    Samples/RenderToTexture/src/Makefile \
    Samples/TextureFX/Makefile \
    Samples/TextureFX/src/Makefile \
    Samples/TextureFX/include/Makefile \
    Samples/Shadows/Makefile \
    Samples/Shadows/src/Makefile \
    Samples/SkyBox/Makefile \
    Samples/SkyBox/src/Makefile \
    Samples/SkyBox/include/Makefile \
    Samples/SkyDome/Makefile \
    Samples/SkyDome/src/Makefile \
    Samples/SkyDome/include/Makefile \
    Samples/SkyPlane/Makefile \
    Samples/SkyPlane/src/Makefile \
    Samples/SkyPlane/include/Makefile \
    Samples/Smoke/Makefile \
    Samples/Smoke/src/Makefile \
    Samples/Smoke/include/Makefile \
    Samples/BSP/Makefile \
    Samples/BSP/src/Makefile \
    Samples/SkeletalAnimation/Makefile \
    Samples/SkeletalAnimation/src/Makefile \
    Samples/SkeletalAnimation/include/Makefile \
    Samples/Terrain/Makefile \
    Samples/Terrain/src/Makefile \
    Samples/Terrain/include/Makefile \
    Samples/Water/Makefile \
    Samples/Water/src/Makefile \
    Samples/Water/include/Makefile \
    Samples/DynTex/Makefile \
    Samples/DynTex/src/Makefile \
    Samples/DynTex/include/Makefile \
    Samples/VolumeTex/Makefile \
    Samples/VolumeTex/src/Makefile \
    Samples/VolumeTex/include/Makefile \
    Samples/Instancing/Makefile \
    Samples/Instancing/src/Makefile \
    Samples/Instancing/include/Makefile \
    Tests/Makefile \
    Tests/src/Makefile \
    Tools/Makefile \
    Tools/MaterialUpgrader/Makefile \
    Tools/MaterialUpgrader/src/Makefile \
    Tools/MaterialUpgrader/include/Makefile \
    Tools/MeshUpgrader/Makefile \
    Tools/MeshUpgrader/src/Makefile \
    Tools/XMLConverter/Makefile \
    Tools/XMLConverter/src/Makefile \
    Tools/XMLConverter/include/Makefile \
    Tools/LightwaveConverter/Makefile \
    Tools/LightwaveConverter/src/Makefile \
    Tools/LightwaveConverter/include/Makefile \
    OGRE.pc
    ])

AC_OUTPUT

dnl Provide a nice final configuration status display

ft_detected=yes
test "x$no_ft" == "xyes" && ft_detected=no

echo "--------===[ Configuration summary ]===--------"
echo "    Target platform                 : $OGRE_PLATFORM"
echo "    OpenGL Ogre support             : $OGRE_GLSUPPORT"
echo "    GUI library to use              : $with_gui"
echo "    Use double precision arithmetic : $build_double"
echo "    Support for threading           : $build_threads"
echo "    Use STLport                     : $ac_cv_use_stlport"
echo "    Use FreeType                    : $ft_detected"
echo "    Use FreeImage                   : $build_freeimage"
echo "    Use DevIL                       : $build_il"
echo "    Build OGRE demos                : $build_ogre_demos"
test "x$build_ogre_demos" == "xyes" && \
echo "    Build CEGUI demos               : $build_cegui_sample"
echo "    Build the OpenEXR plugin        : $build_exr"
echo "    Build the Cg plugin             : $build_cg"
echo "    Build the DirectX 9 plugin      : $build_dx9"
echo "--------===============================--------"
