File: configure.in

package info (click to toggle)
gravit 0.5.1+dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 10,416 kB
  • sloc: ansic: 6,841; makefile: 63; sh: 43
file content (393 lines) | stat: -rw-r--r-- 11,874 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
 #                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

# ===============================================================================================
# ToDo:
# -------------
# * improve agar detection (check for version >= 1.4.1)
#
# Changes (FrMo, April 2012):
# -------------
# * auto-detect agar library
#
# Changes (FrMo, Sept 2011):
# -------------
# * better linux support
# * silent build
# * try some compiler-specific optimization flags (gcc, intel icc, open64)
#
# Changes (FrMo, Aug 2011):
# -------------
# * minor updates needed for newer autoconf versions
# * added acinclude
# * windres support (windows resources)
# * Fixed LUA detection      (LUA >= 5.1 does not need lualib)
# * Fix GL and GLU detection (other lib names required on Win32) - borrowed from SDL_ttf
# * support for new features (-DWITH_LUA -DHAVE_LUA -DHAVE_SSE -DHAVE_PNG -DUSE_PTHREAD)
#   - Detect OpenMP support and add -fopenmp to CFLAGS and LDFLAGS
#   - Detect SSE support    and define -DHAVE_SSE
#   - Detect libPNG         and define -DHAVE_PNG
#
# ===============================================================================================


AC_PREREQ(2.59)
AC_INIT(gravit, 0.5.1, gravit@slowchop.com)
AC_CONFIG_SRCDIR([src/config.c])
AC_CONFIG_HEADER(src/config.h)

dnl Detect the canonical build and host environments
AC_CANONICAL_HOST

dnl Setup for automake
AM_INIT_AUTOMAKE(gravit, 0.5.1)
#Enable quiet compiles on automake 1.11.
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

# set default optimization flags
# use "-Wall -O2 -g" if you want to debug
: ${CFLAGS="-Wall -O3"}
# Checks for programs.
AC_PROG_CC
AC_LANG_C
AC_EXEEXT
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AX_COMPILER_VENDOR

# check for OpenMP support
#AX_OPENMP
AC_OPENMP
AC_CHECK_HEADERS([omp.h],[
	CFLAGS="$CFLAGS $OPENMP_CFLAGS"
	CPPFLAGS="$CPPFLAGS $OPENMP_CFLAGS"
	LDFLAGS="$LDFLAGS $OPENMP_CFLAGS"
     ])

# check for supported SIMD extensions (gcc specific)
# if SSE is supported, HAVE_SSE will be set
AX_EXT_SSE
CFLAGS="$CFLAGS $SIMD_FLAGS -I/usr/local/include"
LDFLAGS="$SIMD_FLAGS $LDFLAGS -L/usr/local/lib"

# windows gcc needs -mstackrealign (to avoid crash on XP)
if test x"$ax_cv_c_compiler_vendor" = x"gnu" ; then
    if test x"$host" = x"i686-pc-mingw32" ; then
        CFLAGS="$CFLAGS -mstackrealign"
        LDFLAGS="$LDFLAGS -mstackrealign"
    fi
fi

# try to add compiler-specific optimization flags
if test x"$ax_cv_c_compiler_vendor" = x"intel"; then
   #check for intel (icc) style flags
   AX_CHECK_COMPILE_FLAG(-ipo, CFLAGS="$CFLAGS -O3 -ipo")
   AX_CHECK_COMPILE_FLAG(-parallel, CFLAGS="$CFLAGS -parallel")
   AX_CHECK_COMPILE_FLAG(-fomit-frame-pointer, CFLAGS="$CFLAGS -fomit-frame-pointer")
   AX_CHECK_COMPILE_FLAG(-no-prec-div, CFLAGS="$CFLAGS -no-prec-div")
   AX_CHECK_COMPILE_FLAG(-static-intel, CFLAGS="$CFLAGS -static-intel")
   #only for intel core i3/i5/i7 and newer
   #AX_CHECK_COMPILE_FLAG(-xSSE4.1, CFLAGS="$CFLAGS -xSSE4.1")
   #AX_CHECK_COMPILE_FLAG(-xSSE4.2, CFLAGS="$CFLAGS -xSSE4.2")
else
   #check for gcc-style optimization flags
   AX_CHECK_COMPILE_FLAG(-Ofast, CFLAGS="$CFLAGS -Ofast" LDFLAGS="$LDFLAGS -Ofast")
   AX_CHECK_COMPILE_FLAG(-fomit-frame-pointer, CFLAGS="$CFLAGS -fomit-frame-pointer")
   AX_CHECK_COMPILE_FLAG(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
   #only for intel corei3/5/7 and newer
   #AX_CHECK_COMPILE_FLAG(-msse4, CFLAGS="$CFLAGS -msse4")
   #AX_CHECK_COMPILE_FLAG(-msse4.1, CFLAGS="$CFLAGS -msse4.1")
   #AX_CHECK_COMPILE_FLAG(-msse4.2, CFLAGS="$CFLAGS -msse4.2")
fi


# Checks for header files.
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_CHECK_HEADERS([stdlib.h string.h sys/time.h sys/timeb.h termios.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T

dnl get X11 default libs
AC_PATH_XTRA
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
LIBS="$X_PRE_LIBS $LIBS $X_LIBS $X_EXTRA_LIBS"

#check if we need to link with -lm
AC_CHECK_LIB([m], [pow])

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([atexit floor ftime memset mkdir pow select sqrt strchr strdup strerror strstr])

# check for functions to do aligned malloc
AC_CHECK_HEADERS([intrin.h x86intrin.h xmmintrin.h malloc.h memory.h])
AC_CHECK_FUNCS([memalign _mm_malloc _mm_free _aligned_malloc __mingw_aligned_malloc])
# AC_CHECK_FUNCS([posix_memalign])
AX_FUNC_POSIX_MEMALIGN
if test "$ax_cv_func_posix_memalign_works" = "yes" ; then
   AC_DEFINE([HAVE_WORKING_POSIX_MEMALIGN], [1], [use 'posix_memalign' instead of memalign])
fi


# check for windres (windows ressource compiler)
if test -z "$host_alias"; then
    hostaliaswindres=
else
    hostaliaswindres="$host_alias-windres"
fi
AC_CHECK_PROGS(WINDRES, [windres $hostaliaswindres $host_os-windres])
if test x$WINDRES != x; then
     use_icon_rc=true
fi
AC_SUBST(WINDRES)
AM_CONDITIONAL(USE_ICON_RC, test x$use_icon_rc = xtrue)


dnl Call in pkg-config explicitly, so we can safely put the first
dnl PKG_CHECK_EXISTS inside an if
PKG_PROG_PKG_CONFIG

dnl Check for SDL
SDL_VERSION=1.2.10
AC_SUBST(SDL_VERSION)
AM_PATH_SDL($SDL_VERSION, :, [AC_MSG_ERROR(SDL is required for Gravit)])
CFLAGS="$CFLAGS $SDL_CFLAGS"
CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"

# Checks for libraries.
AC_CHECK_LIB([SDL_image], [IMG_Load], [], [AC_MSG_ERROR(SDL_image is required)])
AC_CHECK_LIB([SDL_ttf], [TTF_Init], [], [AC_MSG_ERROR(SDL_ttf is required)])

dnl Check for OpenGL - try pkg-config first
PKG_CHECK_EXISTS([gl], [have_gl=yes], [have_gl=no])
PKG_CHECK_EXISTS([glu], [have_glu=yes], [have_glu=no])
if test x"$have_gl" = x"yes" -a  x"$have_glu" = x"yes" ; then
   PKG_CHECK_MODULES(GL, [gl])
   PKG_CHECK_MODULES(GLU, [glu])
   #GLU requires GL, so it's enough to use GLU_CFLAGS and GLU_LIBS
   CFLAGS="$CFLAGS $GLU_CFLAGS"
   LIBS="$LIBS $GLU_LIBS"
else
dnl Check for OpenGL - borrowed from SDL_ttf
   case "$host" in
    *-*-cygwin* | *-*-mingw*)
        MATHLIB=""
        SYS_GL_LIBS="-lopengl32 -lglu32"
        ;;
    *-*-beos*)
        MATHLIB=""
        SYS_GL_LIBS="-lGL -lGLU"
        ;;
    *-*-darwin*)
        MATHLIB=""
	# cocoa video
        SYS_GL_LIBS="-Wl,-framework,OpenGL"
	# carbon video
        #SYS_GL_LIBS="-Wl,-framework,AGL"
        ;;
    *-*-aix*)
        if test x$ac_cv_prog_gcc = xyes; then
            CFLAGS="-mthreads"
	fi
        SYS_GL_LIBS=""
        ;;
    *)
        MATHLIB="-lm"
        AC_PATH_X
        AC_PATH_XTRA
        if test x$have_x = xyes; then
            CFLAGS="$CFLAGS $X_CFLAGS"
            SYS_GL_LIBS="$X_LIBS -lGL -lGLU"
        else
            SYS_GL_LIBS="-lGL -lGLU"
        fi
        ;;
   esac
   AC_MSG_CHECKING(for OpenGL support)
   have_opengl=no
   AC_TRY_COMPILE([
    #include "SDL_opengl.h"
   ],[
    GLuint texture;
   ],[
   have_opengl=yes
   ])
   AC_MSG_RESULT($have_opengl)
   if test x$have_opengl = xyes; then
       GL_LIBS="$SYS_GL_LIBS"
   else
       GL_LIBS=""
       AC_MSG_ERROR(GL is required)
   fi
   LIBS="$LIBS $SYS_GL_LIBS $MATHLIB"
fi

dnl Check for lua - borrowed from lighttpd
AC_MSG_CHECKING(if lua support is requested)
AC_ARG_WITH(lua, AC_HELP_STRING([--with-lua], [LUA support for custom spawn locations (recommended)]), [WITH_LUA=$withval], [WITH_LUA=yes])

AC_MSG_RESULT($WITH_LUA)
if test "$WITH_LUA" != "no"; then
 AM_CONDITIONAL(LUA, true)

 #try lua-config
 AC_PATH_PROG(LUACONFIG, lua-config)
 if test x"$LUACONFIG" != x; then
   LUA_CFLAGS=`$LUACONFIG --include`
   LUA_LIBS=`$LUACONFIG --libs --extralibs`
   AC_DEFINE([HAVE_LUA], [1], [liblua])
   AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
   AC_MSG_RESULT($LUACONFIG)
 else

   #try pkgconfig
   AC_MSG_CHECKING(for pkg-config lua)
   for lua_name in lua5.2 lua-5.2 lua52 lua5.1 lua-5.1 lua51 lua5.3 lua-5.3 lua53 lua
   do
       PKG_CHECK_EXISTS([$lua_name], [LUA_NAME=$lua_name; have_lua=yes; break], [have_lua=no])
   done

   if test x$have_lua = xyes
   then
       AC_MSG_RESULT($LUA_NAME)
       PKG_CHECK_MODULES(LUA,$LUA_NAME >= 5.0,[have_lua=yes], [have_lua=no])
   else
       AC_MSG_RESULT(no)
   fi

   if test x$have_lua = xyes; then
     AC_DEFINE([HAVE_LUA], [1], [liblua])
     AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
   fi

   # fallback: try to find the library directly

   if test x"$LUA_LIBS" = x; then
   # try linking with several possible lua libs
     for lua_name in lua52 lua5.2 lua51 lua5.1 lua53 lua5.3 lua
     do
       if test x"$LUA_LIBS" = x; then
         AC_CHECK_LIB($lua_name, lua_close, [
           AC_CHECK_HEADERS([lua.h],[
             LUA_LIBS="-l$lua_name"
             AC_DEFINE([HAVE_LUA], [1], [liblua])
             AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
             LUA_NAME=$lua_name
           ])
         ])
       fi
     done
   fi
 fi

 if test x"$LUA_LIBS" = x; then
   # show error
   AC_MSG_ERROR(LUA (version 5.1 or newer) was not found)
 fi

 AC_SUBST(LUA_CFLAGS)
 AC_SUBST(LUA_LIBS)
else
 AM_CONDITIONAL(LUA, false)
fi


dnl Check for libpng - borrowed from SDL_image
AC_ARG_WITH(png, AC_HELP_STRING([--with-png], [use PNG format for screenshots (recommended)]), [enable_png=$withval], [enable_png=yes])
if test "x$enable_png" = xyes; then
    PKG_CHECK_MODULES([LIBPNG], [libpng], [dnl
        have_png_hdr=yes
        CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
	LIBS="$LIBS $LIBPNG_LIBS"
        have_png_lib=yes
        AC_DEFINE([HAVE_PNG], [1], [libpng])
      ], [dnl
        AC_CHECK_HEADER([png.h], [have_png_hdr=yes])
        AC_CHECK_LIB([png], [png_destroy_write_struct], [have_png_lib=yes], [], [-lz])
   	if test x"$have_png_lib" = xyes; then
	   LIBS="$LIBS -lpng -lz"
           AC_DEFINE([HAVE_PNG], [1], [libpng])
	fi
      ])

   if test x"$have_png_hdr" = x; then
      AC_MSG_WARN([*** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)])
      AC_MSG_WARN([PNG screenshot support disabled])
   fi
fi

dnl Check for agar
dnl agar 1.4.1 is required for the new GUI
dnl http://www.libagar.org
AC_MSG_CHECKING(if agar support is requested)
AC_ARG_WITH(agar, AC_HELP_STRING([--with-agar], [AGAR support, required for new GUI (recommended)]), [WITH_AGAR=$withval], [WITH_AGAR=yes])

AC_MSG_RESULT($WITH_AGAR)
if test x"$WITH_AGAR" != x"no"; then
 AM_CONDITIONAL(AGAR, true)
else
 AM_CONDITIONAL(AGAR, false)
 AC_DEFINE([WITHOUT_AGAR], [1], [libagar])
fi

if test x"$WITH_AGAR" != x"no"
then
 #try agar-config
 AC_PATH_PROG(AGARCONFIG, agar-config)
 if test x"$AGARCONFIG" != x
 then
   AGAR_VERSION=`$AGARCONFIG --version`
   AGAR_CFLAGS=`$AGARCONFIG --cflags`
   AGAR_LIBS=`$AGARCONFIG --libs`
   AGAR_LIBDIR=`$AGARCONFIG --prefix`/lib

   AC_DEFINE([HAVE_AGAR], [1], [libagar])
   CFLAGS="$CFLAGS $AGAR_CFLAGS"
   CPPFLAGS="$CPPFLAGS $AGAR_CFLAGS"
   LIBS="$LIBS $AGAR_LIBS"
   have_agar_lib=yes
 else
   #check for libag_gui presence
   if test x"$host" = x"i686-pc-mingw32" ; then
     AC_CHECK_LIB([ag_gui], [AG_DestroyGUI], [have_agar_lib=yes; LIBS="-lag_gui -lag_core $LIBS -lfreetype -lwinmm"], [], [-lag_core -lfreetype -lwinmm])
   else
     AC_CHECK_LIB([ag_gui], [AG_DestroyGUI], [have_agar_lib=yes; LIBS="-lag_gui -lag_core $LIBS -lfreetype"], [], [-lag_core -lfreetype])
   fi
 fi
 
 #check if agar header files can be found 
 AC_CHECK_HEADER([agar/core.h], [have_agar_hdr=yes])
 if test x"$have_agar_hdr" = x -o x"$have_agar_lib" = x
 then
   AM_CONDITIONAL(AGAR, false)
   AC_DEFINE([WITHOUT_AGAR], [1], [libagar])
   AC_MSG_WARN([*** Unable to find AGAR library (http://www.libagar.org)])
   AC_MSG_WARN([new GUI disabled])
 else
  echo found AGAR library "$AGAR_VERSION"
  AC_SUBST(AGAR_CFLAGS)
  AC_SUBST(AGAR_LIBS)
  AC_SUBST(AGAR_LIBDIR)
 fi
fi

#check if we need to link with -ldl
AC_CHECK_LIB([dl], [dlerror])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT