# Init Autoconf
AC_PREREQ([2.64])

AC_INIT([GNOME LaTeX],
	[3.44.0],
	[https://gitlab.gnome.org/swilmet/gnome-latex/-/issues],
	[gnome-latex],
	[https://gitlab.gnome.org/swilmet/gnome-latex])

AX_REQUIRE_DEFINED([AX_IS_RELEASE])
AX_IS_RELEASE([git-directory])

AC_CONFIG_SRCDIR([src/liblatexila/latexila.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])

# Init Automake
# gnu strictness to generate the INSTALL file.
AM_INIT_AUTOMAKE([1.14 gnu tar-ustar no-dist-gzip dist-xz -Wno-portability])
AM_MAINTAINER_MODE([enable])
AM_SILENT_RULES([yes])

# Init Libtool
LT_PREREQ([2.2])
LT_INIT

# Check for programs
AC_PROG_CC
AC_PROG_INSTALL

VALA_REQUIRED_VERSION="0.46"
AM_PROG_VALAC([${VALA_REQUIRED_VERSION}],
	      [found_vala=true]
	      [found_vala=false])

AX_REQUIRE_DEFINED([PKG_PROG_PKG_CONFIG])
AX_REQUIRE_DEFINED([PKG_CHECK_VAR])
PKG_PROG_PKG_CONFIG
PKG_CHECK_VAR([GLIB_MKENUMS], [glib-2.0], [glib_mkenums])
PKG_CHECK_VAR([GLIB_COMPILE_RESOURCES], [gio-2.0], [glib_compile_resources])
PKG_CHECK_VAR([GDBUS_CODEGEN], [gio-2.0], [gdbus_codegen])

# Dependencies
AX_REQUIRE_DEFINED([PKG_CHECK_MODULES])
PKG_CHECK_MODULES([DEP], [
	gio-2.0 >= 2.56
	gtk+-3.0 >= 3.22
	gspell-1 >= 1.8
	amtk-5 >= 5.6
	gtksourceview-4
	tepl-6 >= 6.4
	gee-0.8 >= 0.10
	gsettings-desktop-schemas
])

GLIB_TARGET_VERSION_FOR_VALA="2.70"
AC_SUBST([GLIB_TARGET_VERSION_FOR_VALA])

# dconf migration option
AC_ARG_ENABLE([dconf_migration],
	      [AS_HELP_STRING([--disable-dconf-migration],
			      [do not add support for latexila to gnome-latex dconf migration])],
	      [enable_dconf_migration=$enableval],
	      [enable_dconf_migration=yes])

if test x$enable_dconf_migration = xyes; then
	PKG_CHECK_MODULES([DCONF_DEP], [dconf])
	AC_DEFINE_UNQUOTED([HAVE_DCONF_MIGRATION], [1], [Whether dconf migration is supported])
else
	AC_DEFINE_UNQUOTED([HAVE_DCONF_MIGRATION], [0], [Whether dconf migration is supported])
fi

AM_CONDITIONAL([DCONF_MIGRATION_BUILD], [test x$enable_dconf_migration = xyes])

# Native Language Support
AM_GNU_GETTEXT([external])
# TODO: Remove AM_GNU_GETTEXT_VERSION once autoreconf supports AM_GNU_GETTEXT_REQUIRE_VERSION.
AM_GNU_GETTEXT_VERSION([0.19.6])
AM_GNU_GETTEXT_REQUIRE_VERSION([0.19.6])

GETTEXT_PACKAGE=${PACKAGE_TARNAME}
AC_SUBST([GETTEXT_PACKAGE])
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],
		   ["${GETTEXT_PACKAGE}"],
		   [The domain to use with gettext])

# Compile warnings. There can be deprecation warnings at any time, so disable
# -Werror by default with the [yes] argument.
AX_REQUIRE_DEFINED([AX_COMPILER_FLAGS])
AX_COMPILER_FLAGS([WARN_CFLAGS], [WARN_LDFLAGS], [yes])

# Misc
AX_REQUIRE_DEFINED([YELP_HELP_INIT])
YELP_HELP_INIT

AX_REQUIRE_DEFINED([GLIB_GSETTINGS])
GLIB_GSETTINGS

AX_REQUIRE_DEFINED([GOBJECT_INTROSPECTION_CHECK])
GOBJECT_INTROSPECTION_CHECK([1.30.0])

AX_REQUIRE_DEFINED([GTK_DOC_CHECK])
GTK_DOC_CHECK([1.14], [--flavour no-tmpl])

AX_REQUIRE_DEFINED([AX_CODE_COVERAGE])
AX_CODE_COVERAGE

AX_REQUIRE_DEFINED([APPSTREAM_XML])
APPSTREAM_XML

# Generate files
AC_CONFIG_FILES([
	Makefile
	data/Makefile
	data/org.gnome.gnome-latex.gschema.xml
	data/build_tools/Makefile
	data/icons/Makefile
	data/icons/16x16/Makefile
	data/icons/24x24/Makefile
	data/images/Makefile
	data/templates/Makefile
	docs/Makefile
	docs/reference/Makefile
	help/Makefile
	man/Makefile
	po/Makefile.in
	src/Makefile
	src/evince/Makefile
	src/liblatexila/Makefile
	src/ui/Makefile
	tests/Makefile
])

AC_OUTPUT

if ${found_vala}
then
	vala_compiler="valac >= ${VALA_REQUIRED_VERSION} not found."
else
	vala_compiler=${VALAC}
fi

# Print a summary of the configuration
echo "
Configuration:

	${PACKAGE_NAME} version ${PACKAGE_VERSION}

	Source code location:	${srcdir}
	Prefix:			${prefix}
	C compiler:		${CC}
	Vala compiler:		${vala_compiler}
	Dev documentation:	${enable_gtk_doc}
	GObject introspection:	${found_introspection}
	Code coverage:		${enable_code_coverage}
	dconf migration:	${enable_dconf_migration}
"
