Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
687 lines (598 sloc) 16.3 KB
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.61])
AC_INIT([naev], [0.7.0], [bobbens@gmail.com])
AC_CONFIG_SRCDIR([src/naev.c])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build])
AM_INIT_AUTOMAKE([foreign subdir-objects])
# M4 defines __unix__ to be the empty string on UNIX-like systems. This
# causes AC_DEFINE to fail if it is used to define __unix__. This seems to
# fix the problem.
ifdef([__unix__], define([__unix__], [[__unix__]]))
#
# Utility functions
#
# If A='$B' and B='hello', then "expand_variable A" will cause A='hello'
expand_variable()
{
while true; do
eval local value=\$$1
eval "$1=\"$value\""
echo "$value" | grep -qE '(^|[^\\])\$' || break
done
}
# Temporarily changes the value of a variable, until it is restored later.
# $1: name of variable
# $2: temporary value
define([VAR_SAVE], [
OLD_$1="$$1"
$1=$2
])
# Restores the saved variable.
# $1: name of variable
define([VAR_RESTORE], [
$1="$OLD_$1"
])
#
# Checks for variables
#
# Fix missing prefix
AS_IF([test "$prefix" = "NONE"], [
prefix="$ac_default_prefix"
])
AS_IF([test "$exec_prefix" = "NONE"], [
exec_prefix="$prefix"
])
# Check if we have custom CFLAGS
AS_IF([test -n "$CFLAGS"], [have_custom_cflags=yes], [have_custom_cflags=no])
#
# Checks for programs.
#
AC_PROG_CC
AC_PROG_OBJC
AC_PROG_LN_S
AC_PROG_RANLIB
PKG_PROG_PKG_CONFIG
AC_CHECK_PROG([CUT], [cut], [cut])
AS_IF([test -z "$CUT"],[
AC_ERROR([cut not found])
])
AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen])
AC_CHECK_PROG([LDOC], [ldoc], [ldoc])
AC_CHECK_PROG([GIT], [git], [git])
#
# Checks for build environment
#
AC_MSG_CHECKING([whether we are building utils])
AS_IF([test -d "$srcdir/utils"], [
have_utils=yes
], [
have_utils=no
])
AC_MSG_RESULT([$have_utils])
AC_MSG_CHECKING([whether we have docs])
AS_IF([test -d "$srcdir/docs"], [
have_docs=yes
], [
have_docs=no
])
AC_MSG_RESULT([$have_docs])
#
# Platform checks
#
AC_CANONICAL_HOST
AC_MSG_CHECKING([[if we need a __unix__ define]])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#ifndef __unix__
# if defined __APPLE__ /* add other known platforms here */
# error should have __unix__ but don't
# endif
#endif
])], [AC_MSG_RESULT([no])],
[
AC_MSG_RESULT([yes])
AC_DEFINE([__unix__], 1,
[Define to 1 if running on a UNIX-like system where __unix__ is missing])
])
#
# Checks for command-line arguments
#
# --enable-debug
AC_MSG_CHECKING([whether to enable debug mode])
AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug=@<:@no|yes|paranoid@:>@],
[enable debug mode (default: yes)]), [
case "$enableval" in
no)
enable_debug=no
;;
paranoid)
enable_debug=paranoid
;;
*)
enable_debug=yes
;;
esac
], [
enable_debug=yes
])
AC_MSG_RESULT([$enable_debug])
AS_IF([test "$enable_debug" != "no"], [
AS_IF([test "$have_custom_cflags" = "no"], [
# Undo the default CFLAGS set by autoconf
AS_IF([test "$ac_cv_prog_cc_g" = "yes"], [
CFLAGS="-g -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes -Winline -Wcast-align -Wmissing-declarations -Wredundant-decls -Wno-long-long -Wcast-align -Wformat -Wformat-security"
], [
CFLAGS=
])
])
case "$host" in
*-linux-gnu)
AC_CHECK_LIB([bfd], [bfd_init], [
AC_CHECK_HEADERS([bfd.h], [
have_bfd=yes
], [
AC_WARN([debug mode is enabled but bfd.h is missing; disabling])
have_bfd=no
])
], [
AC_WARN([debug mode is enabled but libbfd is missing; disabling])
have_bfd=no
])
;;
esac
])
# --with-sdl2
AC_MSG_CHECKING([whether to use SDL2 instead of SDL])
AC_ARG_WITH([sdl2],
AC_HELP_STRING([--with-sdl2],
[use SDL2 instead of SDL (default: yes)]), [
AS_IF([test "$withval" = "yes"], [
with_sdl2=yes
], [
with_sdl2=no
])
], [
with_sdl2=yes
])
AC_MSG_RESULT([$with_sdl2])
# --with-openal
AC_MSG_CHECKING([whether to use OpenAL])
AC_ARG_WITH([openal],
AC_HELP_STRING([--with-openal],
[use the OpenAL sound backend (default: yes)]), [
AS_IF([test "$withval" = "yes"], [
with_openal=yes
], [
with_openal=no
])
], [
with_openal=yes
])
AC_MSG_RESULT([$with_openal])
# --with-sdlmixer
AC_MSG_CHECKING([whether to use SDL_mixer])
AC_ARG_WITH([sdlmixer],
AC_HELP_STRING([--with-sdlmixer],
[use the SDL_mixer sound backend (default: yes)]), [
AS_IF([test "$withval" = "yes"], [
with_sdlmixer=yes
], [
with_sdlmixer=no
])
], [
with_sdlmixer=yes
])
AC_MSG_RESULT([$with_sdlmixer])
# --with-libzip
AC_MSG_CHECKING([whether to use libzip])
AC_ARG_WITH([libzip],
AC_HELP_STRING([--with-libzip],
[use libzip for ndata (default: yes)]), [
AS_IF([test "$withval" = "yes"], [
with_libzip=yes
], [
with_libzip=no
])
], [
with_libzip=yes
])
AC_MSG_RESULT([$with_libzip])
# --enable-lua
AC_MSG_CHECKING([which lua to use])
AC_ARG_ENABLE([lua],
AC_HELP_STRING([--enable-lua=@<:@internal|shared|luajit@:>@],
[lua to use (default: luajit)]), [
case "$enableval" in
luajit)
used_lua=luajit
;;
shared)
used_lua=shared
;;
*)
used_lua=internal
;;
esac
], [
used_lua=luajit
])
AC_MSG_RESULT([$used_lua])
# --with-ndata
ndata_path="$datadir/$PACKAGE_NAME/ndata"
expand_variable ndata_path
AC_MSG_CHECKING([for path to ndata])
AC_ARG_WITH([ndata-path],
AC_HELP_STRING([--with-ndata-path=PATH], [path to the ndata file]),
[ndata_path="$withval"], [])
AC_MSG_RESULT([$ndata_path])
AS_IF([test -z "$ndata_path" || test "$ndata_path" = "yes"], [
AC_ERROR([The data path must be explicitly specified])
])
AC_SUBST([ndata_path])
#
# Checks for libraries.
#
# SDL
AS_IF([test "$with_sdl2" = "yes"], [
SDL2_VERSION=2.0.0
AM_PATH_SDL2($SDL2_VERSION, [have_sdl2=yes], [have_sdl2=no])
], [have_sdl2=no]
)
AS_IF([test "$have_sdl2" = "no"], [
AM_PATH_SDL
AS_IF([test -z "$SDL_CFLAGS" && test -z "$SDL_LIBS"], [
AC_ERROR([SDL not found])
])
])
# libxml2
PKG_CHECK_MODULES([XML], [libxml-2.0])
# FreeType
PKG_CHECK_MODULES([FREETYPE], [freetype2])
# FontConfig
PKG_CHECK_MODULES([FONTCONFIG], [fontconfig])
# vorbis
PKG_CHECK_MODULES([VORBIS], [vorbis])
# vorbisfile
PKG_CHECK_MODULES([VORBISFILE], [vorbisfile])
# libpng
PKG_CHECK_MODULES([PNG], [libpng])
# libzip
AS_IF([test "$with_libzip" = "yes"], [
PKG_CHECK_MODULES([ZIP], [libzip])
])
# lua
case "$used_lua" in
luajit)
PKG_CHECK_MODULES([LUA], [luajit], [
have_lua=yes
LUA_CFLAGS+=" -DHAVE_LUAJIT"
], [
AC_WARN([Lua is set to LuaJIT but can not find library; using internal Lua])
have_lua=no
])
;;
shared)
have_lua=no
m4_foreach([pkgname], [lua-5.1, lua5.1, lua51, lua], [
AS_IF([test "$have_lua" = "no"], [
PKG_CHECK_MODULES([LUA], [pkgname], [have_lua=yes], [have_lua=no])
])
])
AS_IF([test "$have_lua" = "no"], [AC_WARN([Lua is set to shared but can not find library; using internal Lua])])
;;
*)
have_lua=no
;;
esac
AS_IF([test "$have_lua" = "no"], [
LUA_CFLAGS="-I\"\$(top_srcdir)/lib/lua\""
LUA_LIBS="\$(top_builddir)/lib/lua/liblua.a"
have_lua=yes
used_lua=internal
])
# sqrt is required for system csparse to work
AC_SEARCH_LIBS([sqrt], [m])
# csparse
AC_CHECK_LIB([csparse], [cs_spalloc], [have_csparse_lib=yes], [have_csparse_lib=no])
AC_CHECK_LIB([cxsparse], [cs_di_spalloc], [have_cxsparse_lib=yes], [have_cxsparse_lib=no])
AS_IF([test "$have_csparse_lib" = "yes" -a "$have_cxsparse_lib" = "yes"], [
AC_CHECK_HEADERS([cs.h], [have_cs_h=yes], [have_cs_h=no])
AC_CHECK_HEADERS([suitesparse/cs.h], [have_suitesparse_cs_h=yes], [have_suitesparse_cs_h=no])
AS_IF([test $have_cs_h = yes -o $have_suitesparse_cs_h = yes], [
used_csparse=shared
CSPARSE_LIBS="-lcsparse -lcxsparse"
], [
used_csparse=internal
])
], [
used_csparse=internal
])
AS_IF([test "$used_csparse" = "internal"], [
CSPARSE_CFLAGS="-I\"\$(top_srcdir)/lib/csparse\""
CSPARSE_LIBS="\$(top_builddir)/lib/csparse/libcsparse.a"
])
# OpenAL
AS_IF([test "$with_openal" = "yes"], [
AM_PATH_OPENAL([have_openal=yes], [have_openal=no])
])
# SDL_mixer
AS_IF([test "$have_sdl2" = "yes"], [SDLMIXER_NAME=SDL2_mixer], [SDLMIXER_NAME=SDL_mixer])
AS_IF([test "$with_sdlmixer" = "yes"], [
PKG_CHECK_MODULES([SDLMIXER], [$SDLMIXER_NAME], [have_sdlmixer=yes], [have_sdlmixer=no])
], [have_sdlmixer=no])
# SDL_image
VAR_SAVE([LIBS])
AS_IF([test "$have_sdl2" = "yes"], [SDLIMAGE_NAME=SDL2_image], [SDLIMAGE_NAME=SDL_image])
AC_SEARCH_LIBS([IMG_Load], [$SDLIMAGE_NAME], [
SDLIMAGE_CFLAGS=
SDLIMAGE_LIBS="$LIBS"
have_mkspr=yes
], [
SDLIMAGE_CFLAGS=
SDLIMAGE_LIBS=
have_mkspr=no
], [])
VAR_RESTORE([LIBS])
# OpenGL
AM_PATH_OPENGL([], [
AC_MSG_ERROR([OpenGL not found])
])
#
# Compiler flags
#
AS_IF([test "$have_sdl2" = "yes"], [
SDL_CFLAGS="$SDL_CFLAGS -DSDLKey=SDL_Keycode -DSDLMod=SDL_Keymod -DSDL_BUTTON_WHEELUP=SDL_BUTTON_X1 -DSDL_BUTTON_WHEELDOWN=SDL_BUTTON_X2 -DKMOD_LMETA=KMOD_LGUI -DKMOD_RMETA=KMOD_RGUI -DSDLK_NUMLOCK=SDLK_NUMLOCKCLEAR -DSDLK_SCROLLOCK=SDLK_SCROLLLOCK -DSDLK_RMETA=SDLK_RGUI -DSDLK_LMETA=SDLK_LGUI"
case "$host" in
*-linux*)
SDL_CFLAGS="$SDL_CFLAGS -D_GNU_SOURCE=1"
;;
esac
# Disable mkspr
SDL_IMAGE_CFLAGS=
SDL_IMAGE_LIBS=
have_mkspr=no
])
# global
GLOBAL_CFLAGS="-include \"\$(top_builddir)/src/config.h\""
GLOBAL_CFLAGS="$GLOBAL_CFLAGS -I\"\$(top_srcdir)/src\""
GLOBAL_LIBS=
AS_IF([test "$enable_debug" != "no"], [
GLOBAL_CFLAGS="$GLOBAL_CFLAGS -DLUA_USE_APICHECK"
])
case "$host" in
*-linux*)
GLOBAL_LIBS="$NAEV_LIBS -lm" # feels so wrong
;;
*-mingw*)
GLOBAL_LIBS="$NAEV_LIBS -lwsock32"
;;
esac
AC_SUBST([GLOBAL_CFLAGS])
AC_SUBST([GLOBAL_LIBS])
# naev
WIDGET_LIBS="\$(top_builddir)/src/tk/widget/libwidget.a"
NAEV_CFLAGS="$GLOBAL_CFLAGS"
NAEV_LIBS="$GLOBAL_LIBS $WIDGET_LIBS"
AS_IF([test "$enable_debug" != "no"], [
AC_DEFINE([DEBUGGING], 1, [Define to 1 to enable debug code])
AC_DEFINE([DEBUG], 1, [Define to 1 to enable debug code])
AS_IF([test "$have_bfd" != "no"], [
case "$host" in
*-linux-gnu)
AC_DEFINE([HAS_BFD], 1, [Define to 1 to enable bfd backtrace code])
NAEV_LIBS="$NAEV_LIBS -lbfd -liberty -rdynamic -ldl"
;;
esac
])
])
AS_IF([test "$enable_debug" = "paranoid"], [
AC_DEFINE([DEBUG_PARANOID], 1, [Define to 1 to enable paranoid debug code])
])
NAEV_CFLAGS="$NAEV_CFLAGS $CSPARSE_CFLAGS $SDL_CFLAGS $XML_CFLAGS \
$FREETYPE_CFLAGS $FONTCONFIG_CFLAGS $LUA_CFLAGS $VORBIS_CFLAGS $VORBISFILE_CFLAGS \
$PNG_CFLAGS $ZIP_CFLAGS $OPENGL_CFLAGS"
NAEV_LIBS="$NAEV_LIBS $CSPARSE_LIBS $SDL_LIBS $XML_LIBS \
$FREETYPE_LIBS $FONTCONFIG_LIBS $LUA_LIBS $VORBIS_LIBS $VORBISFILE_LIBS \
$PNG_LIBS $ZIP_LIBS $OPENGL_LIBS"
AS_IF([test "$have_openal" = "yes"], [
NAEV_CFLAGS="$NAEV_CFLAGS $OPENAL_CFLAGS"
NAEV_LIBS="$NAEV_LIBS $OPENAL_LIBS"
])
AS_IF([test "$have_sdlmixer" = "yes"], [
NAEV_CFLAGS="$NAEV_CFLAGS $SDLMIXER_CFLAGS"
NAEV_LIBS="$NAEV_LIBS $SDLMIXER_LIBS"
])
case "$host" in
*-mingw*)
NAEV_LIBS="$NAEV_LIBS -mwindows"
;;
*-darwin*)
NAEV_LIBS="$NAEV_LIBS -framework Foundation"
;;
esac
# This is a list of in-tree static libs that naev depends on. It is used by
# automake to detect when the binary needs recompiling after a library has been
# changed.
NAEV_DEPENDENCIES="$WIDGET_LIBS"
AS_IF([test "$used_lua" == "internal"], [
NAEV_DEPENDENCIES="$NAEV_DEPENDENCIES $LUA_LIBS"
])
AS_IF([test "$used_csparse" == "internal"], [
NAEV_DEPENDENCIES="$NAEV_DEPENDENCIES $CSPARSE_LIBS"
])
AC_SUBST([NAEV_CFLAGS])
AC_SUBST([NAEV_LIBS])
AC_SUBST([NAEV_DEPENDENCIES])
# liblua
LIBLUA_CFLAGS="$GLOBAL_CFLAGS"
case "$host" in
*-mingw*)
LIBLUA_CFLAGS="$LIBLUA_CFLAGS -DLUA_ANSI"
;;
*)
LIBLUA_CFLAGS="$LIBLUA_CFLAGS -DLUA_USE_POSIX"
;;
esac
AC_SUBST([LIBLUA_CFLAGS])
MKSPR_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS $PNG_CFLAGS -DNOLOGPRINTFCONSOLE"
MKSPR_LIBS="$GLOBAL_LIBS $SDL_LIBS $SDLIMAGE_LIBS $PNG_LIBS"
AC_SUBST([MKSPR_CFLAGS])
AC_SUBST([MKSPR_LIBS])
#
# Checks for headers
#
AC_CHECK_HEADERS([fenv.h])
#
# Checks for typedefs, structures, and compiler characteristics.
#
AC_TYPE_OFF_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
#
# Checks for functions
#
VAR_SAVE([LIBS], ["-lm"])
AC_CHECK_FUNCS([feenableexcept])
VAR_RESTORE([LIBS])
AC_CHECK_FUNCS([clock_gettime])
# if it is not available directly, check it in librt (glibc does this).
AS_IF([test $ac_cv_func_clock_gettime = no], [
AC_CHECK_LIB(rt, clock_gettime,
[LIBS="-lrt $LIBS"])
], [])
VAR_SAVE([CFLAGS], ["$VORBISFILE_CFLAGS"])
VAR_SAVE([LIBS], ["$VORBISFILE_LIBS"])
AC_CHECK_FUNCS([ov_read_filter])
VAR_RESTORE([CFLAGS])
VAR_RESTORE([LIBS])
#
# Misc checks
#
AC_MSG_CHECKING([for the current Git commit identifier])
AS_IF([test -n "$GIT" && test -d "$srcdir/.git"], [
GIT_COMMIT=$(cd "$srcdir" && "$GIT" rev-parse --short HEAD)
AC_MSG_RESULT([$GIT_COMMIT])
], [
GIT_COMMIT=
AC_MSG_RESULT([unknown])
])
#
# Defines in config.h
#
# Version variables
VMAJOR=$(echo "$VERSION" | cut -d. -f1)
VMINOR=$(echo "$VERSION" | cut -d. -f2)
VREV=$(echo "$VERSION" | cut -d. -f3)
AC_DEFINE_UNQUOTED([VMAJOR], [$VMAJOR], [Define to the major version component])
AC_DEFINE_UNQUOTED([VMINOR], [$VMINOR], [Define to the minor version component])
AC_DEFINE_UNQUOTED([VREV], [$VREV], [Define to the revision version component])
AC_SUBST([VMAJOR])
AC_SUBST([VMINOR])
AC_SUBST([VREV])
# USE_OPENAL
AS_IF([test "x$have_openal" = "xyes"], [
AC_DEFINE([USE_OPENAL], 1, [Define to 1 if using OpenAL])
])
# USE_SDLMIX
AS_IF([test "x$have_sdlmixer" = "xyes"], [
AC_DEFINE([USE_SDLMIX], 1, [Define to 1 if using SDL_mixer])
])
# USE_LIBZIP
AS_IF([test "x$with_libzip" = "xyes"], [
AC_DEFINE([USE_LIBZIP], 1, [Define to 1 if using libzip])
])
# Operating system
case "$host" in
*-linux*)
AC_DEFINE([LINUX], 1, [Define to 1 if running on Linux])
;;
*-freebsd*)
AC_DEFINE([FREEBSD], 1, [Define to 1 if running on FreeBSD])
;;
*-mingw*)
AC_CHECK_TOOL(WINDRES, windres)
AC_DEFINE([WIN32], 1, [Define to 1 if running on Windows])
;;
*-darwin*)
AC_DEFINE([MACOS], 1, [Define to 1 if running on macOS])
have_macos=yes
;;
esac
# NDATA_DEF
AC_DEFINE_UNQUOTED([NDATA_DEF], ["$ndata_path"],
[Define to the path to the data file])
# GIT_COMMIT
AS_IF([test -n "$GIT_COMMIT"], [
AC_DEFINE_UNQUOTED([GIT_COMMIT], ["$GIT_COMMIT"],
[Define to the current Git commit identifier])
AC_SUBST([GIT_COMMIT])
])
#
# Automake conditionals
#
AM_CONDITIONAL([HAVE_WINDRES], [test -n "$WINDRES"])
AM_CONDITIONAL([HAVE_MACOS], [test "x$have_macos" = "xyes"])
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
AM_CONDITIONAL([HAVE_LDOC], [test -n "$LDOC"])
AM_CONDITIONAL([HAVE_UTILS], [test "x$have_utils" = "xyes"])
AM_CONDITIONAL([HAVE_DOCS], [test "x$have_docs" = "xyes"])
AM_CONDITIONAL([HAVE_MKSPR], [test "x$have_mkspr" = "xyes"])
AM_CONDITIONAL([LUA_INTERNAL], [test "x$used_lua" = "xinternal"])
AM_CONDITIONAL([CSPARSE_INTERNAL], [test "x$used_csparse" = "xinternal"])
#
# Output
#
SHAVE_INIT([build], [enable])
AC_CONFIG_FILES([Makefile
lib/Makefile
src/Makefile
src/tk/Makefile
src/tk/widget/Makefile
build/shave])
AS_IF([test "x$have_utils" = "xyes"], [
AC_CONFIG_FILES([utils/Makefile
utils/mkspr/Makefile])
])
AS_IF([test "x$have_docs" = "xyes"], [
AC_CONFIG_FILES([docs/Makefile])
])
AS_IF([test "x$used_lua" = "xinternal"], [
AC_CONFIG_FILES([lib/lua/Makefile])
])
AS_IF([test "x$used_csparse" = "xinternal"], [
AC_CONFIG_FILES([lib/csparse/Makefile])
])
AC_OUTPUT
echo
AC_MSG_NOTICE([prefix: $prefix])
AC_MSG_NOTICE([ndata: $ndata_path])
echo
AC_MSG_NOTICE([SDL2: $have_sdl2])
echo
AC_MSG_NOTICE([sound backends:])
AC_MSG_NOTICE([ OpenAL: $have_openal])
AC_MSG_NOTICE([ SDL_mixer: $have_sdlmixer])
echo
AC_MSG_NOTICE([lib:])
AC_MSG_NOTICE([ csparse: $used_csparse])
AC_MSG_NOTICE([ lua: $used_lua])
AC_MSG_NOTICE([ libzip: $with_libzip])
echo
AC_MSG_NOTICE([utils: $have_utils])
AC_MSG_NOTICE([ mkspr: $have_mkspr])
echo
AC_MSG_NOTICE([debug mode: $enable_debug])
AS_IF([test "x$enable_debug" != "xno"], [
case "$host" in
*-linux*)
AC_MSG_NOTICE([ bfd: $have_bfd])
;;
esac
])