# This file is part of SWIFT.
# Copyright (C) 2012 pedro.gonnet@durham.ac.uk.
#               2016 p.w.draper@durham.ac.uk.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Init the project.
AC_INIT([PySWIFTsim],[0.1.0],[https://gitlab.cosma.dur.ac.uk/swift/PySWIFTsim])

swift_config_flags="$*"

#  We want to stop when given unrecognised options. No subdirs so this is safe.
enable_option_checking=${enable_option_checking:-fatal}
if test -n "$ac_unrecognized_opts"; then
    case $enable_option_checking in
        no)
        ;;
        fatal)
            { $as_echo "$as_me: error: unrecognized options: $ac_unrecognized_opts" >&2
              { (exit 1); exit 1; }; }
        ;;
        *)
            $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2
        ;;
    esac
fi

AC_COPYRIGHT
AC_CONFIG_SRCDIR([src/wrapper.c])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([subdir-objects])

# Add local macro collection.
AC_CONFIG_MACRO_DIR([m4])

# Stop default CFLAGS from anyone except the environment.
: ${CFLAGS=""}

# Generate header file.
AM_CONFIG_HEADER(config.h)

# Find and test the compiler.
AX_CHECK_ENABLE_DEBUG
AC_PROG_CC
AM_PROG_CC_C_O

# Enable POSIX and platform extension preprocessor macros.
AC_USE_SYSTEM_EXTENSIONS

# Check for compiler version and vendor.
AX_COMPILER_VENDOR
AX_COMPILER_VERSION

#  Restrict support.
AC_C_RESTRICT


# Add libtool support (now that CC is defined).
LT_INIT

# Need C99 and inline support.
AC_PROG_CC_C99
AC_C_INLINE

# Need fortran for grackle and velociraptor
AC_PROG_FC
AC_FC_LIBRARY_LDFLAGS


# Define HAVE_POSIX_MEMALIGN if it works.
AX_FUNC_POSIX_MEMALIGN

# Autoconf stuff.
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_HEADER_STDC

SWIFT_ADD_LIBRARIES

SWIFT_ADD_SPECIAL_FLAGS

# this one should be at the beginning
# it overwrites all the required parameters
SWIFT_ADD_SUBGRID_MODELS



SWIFT_ADD_GRAVITY

SWIFT_ADD_HYDRO

SWIFT_ADD_STARS

SWIFT_ADD_KERNEL

SWIFT_ADD_DIMENSION

SWIFT_ADD_EQUATION_OF_STATE

SWIFT_ADD_CHEMISTRY

SWIFT_ADD_COOLING

SWIFT_ADD_RIEMANN

SWIFT_ADD_TRACER

PYSWIFT_ADD_PYTHON

# Check for git, needed for revision stamps.
AC_PATH_PROG([GIT_CMD], [git])
AC_SUBST([GIT_CMD])

# Make the documentation. Add conditional to handle disable option.
DX_INIT_DOXYGEN(libswift,doc/Doxyfile,doc/)
AM_CONDITIONAL([HAVE_DOXYGEN], [test "$ac_cv_path_ac_pt_DX_DOXYGEN" != ""])

# Check if using EAGLE cooling
AM_CONDITIONAL([HAVEEAGLECOOLING], [test $with_cooling = "EAGLE"])

# Handle .in files.
AC_CONFIG_FILES([Makefile src/Makefile])

# Save the compilation options
AC_DEFINE_UNQUOTED([PYSWIFT_CONFIG_FLAGS],["$swift_config_flags"],[Flags passed to configure])

# Make sure the latest git revision string gets included, when we are
# working in a checked out repository.
test -d ${srcdir}/.git && touch ${srcdir}/src/version.c

AC_DEFINE([PYSWIFT_PACKAGE_URL],["www.swiftsim.com"], [Package web pages])

# Generate output.
AC_OUTPUT