#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
ACLOCAL_AMFLAGS = -I m4 --install

AC_PREREQ([2.69])
AC_INIT([MakeAppImage], [0.1.0])

# Put autogenerated stuff in subdir cfg, that must be created
# externally. This macro must be set before calling AC_INIT_AUTOMAKE
AC_CONFIG_AUX_DIR(cfg)

AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([./main.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

# Checks for needed executables, libraries and headers which are
# not optional. If missing, treat as fatal error.

# Test function copied from Cinelerra-GG.
# But for some reason I get a syntax error. TODO MatN
AC_DEFUN([REQUIRE_PROG], [
 CHECK_PROG([$1],[$2])
 if test "x$PROG_$1" = "xno"; then
   AC_MSG_ERROR([$2 is missing and required.])
   FATAL_ERROR=1
 fi
])

#REQUIRE_PROG(OBJCOPY, [objcopy])
#REQUIRE_PROG(PATCHELF, [patchelf])

# Note: objcopy is only required because configure creates a
# Makefile with -g in the compile options, which generates debug info.
# It also creates a compile option -I. which is not needed. With
# this option, you get boost compile errors, unless the include files
# are in a different directory. Sources have been adjusted accordingly. TODO MatN


# If a development header is present, then almost certainly
# the library itself is present too, enforced by the package
# manager.

AC_LANG_PUSH([C++])
AC_CHECK_HEADER([boost/filesystem.hpp], ,[ AC_MSG_ERROR([header is missing and required.]) ])
AC_CHECK_HEADER([boost/filesystem/path.hpp], ,[ AC_MSG_ERROR([header is missing and required.]) ])
AC_CHECK_HEADER([boost/regex.hpp],  ,[ AC_MSG_ERROR([header is missing and required.]) ])
AC_LANG_POP([C++])

AC_CHECK_HEADER([libpng16/png.h],  ,[ AC_MSG_ERROR([header is missing and required.]) ])
AC_CHECK_HEADER([zlib.h],  ,[ AC_MSG_ERROR([header is missing and required.]) ])
AC_CHECK_HEADER([jpeglib.h],  ,[ AC_MSG_ERROR([header is missing and required.]) ])


# Don't use += construct, that is from bash and will not work 
# with sh (macOS).
CFLAGS= "-O2"
CXXFLAGS="$CXXFLAGS -DBOOST_NO_CXX11_SCOPED_ENUMS"
CXXFLAGS="$CXXFLAGS -Dcimg_display=0 -Dcimg_use_jpeg=1 -Dcimg_use_png=1"
LIBS=" -lpng16 -lz -ljpeg -lboost_filesystem -lboost_regex -lstdc++"

# Checks for libraries.

# Checks for header files.
AC_PATH_X
AC_CHECK_HEADERS([fcntl.h memory.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_CHECK_FUNCS([dup2 floor gettimeofday memmove memset munmap pow realpath select sqrt strcasecmp strchr strdup strerror strncasecmp strrchr strstr])

# Must be last macro in the file.
AC_OUTPUT
