1AC_PREREQ(2.60)
2AC_INIT([ManaPlus], [2.1.3.17], [akaras@inbox.ru], [manaplus])
3AM_INIT_AUTOMAKE([1.9])
4AC_LANG_CPLUSPLUS
5
6AC_DEFUN([AC_CHECK_CXX_FLAG],
7    [
8        AC_MSG_CHECKING([whether $CC supports $1])
9        OLD_CXXFLAGS="$CXXFLAGS"
10        CXXFLAGS="$CXXFLAGS -Werror $1"
11        $2=no
12        AC_COMPILE_IFELSE(
13            [AC_LANG_SOURCE([int foo;])],
14            [
15                AC_MSG_RESULT([yes])
16                $2=yes
17            ],
18            [
19                AC_MSG_RESULT([no])
20                $2=no
21            ]
22        )
23        CXXFLAGS="$OLD_CXXFLAGS"
24    ]
25)
26
27AC_DEFUN([AC_CHECK_LD_FLAG],
28    [
29        AC_MSG_CHECKING([whether $LD supports $1])
30        OLD_CXXFLAGS="$CXXFLAGS"
31        OLD_LDFLAGS="$LDFLAGS"
32        CXXFLAGS=""
33        LDFLAGS="$LDFLAGS $1"
34        $2=no
35        AC_LINK_IFELSE(
36            [AC_LANG_SOURCE([
37                int main(int argc, char **argv)
38                {
39                    return 0;
40                }
41            ])],
42            [
43                AC_MSG_RESULT([yes])
44                $2=yes
45            ],
46            [
47                AC_MSG_RESULT([no])
48                $2=no
49            ]
50        )
51        CXXFLAGS="$OLD_CXXFLAGS"
52        LDFLAGS="$OLD_LDFLAGS"
53    ]
54)
55
56AC_DEFUN([AC_CHECK_GLXEXT],
57    [
58        AC_MSG_CHECKING([whether have glext.h])
59        OLD_CXXFLAGS="$CXXFLAGS"
60        CXXFLAGS=""
61        $1=no
62        AC_LINK_IFELSE(
63            [AC_LANG_SOURCE([
64                #include <GL/gl.h>
65                #include <GL/glext.h>
66                #ifndef __gl_glext_h_
67                #error __gl_glext_h_ not defined
68                #endif
69                int main(int argc, char **argv)
70                {
71                    return 0;
72                }
73            ])],
74            [
75                AC_MSG_RESULT([yes])
76                $1=yes
77            ],
78            [
79                AC_MSG_RESULT([no])
80                $1=no
81            ]
82        )
83        CXXFLAGS="$OLD_CXXFLAGS"
84    ]
85)
86
87# Enable -Werror
88AC_ARG_ENABLE(werror,
89[  --enable-werror    Fail build if warning present],
90[case "${enableval}" in
91  yes) werror_enabled=true
92 ;;
93  no)  werror_enabled=false
94 ;;
95  *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
96esac],[werror_enabled=false])
97
98AM_CONDITIONAL(ENABLE_WERROR, test x$werror_enabled = xtrue)
99
100# Enable asserts
101AC_ARG_ENABLE(asserts,
102[  --enable-asserts    Enable asserts in log],
103[case "${enableval}" in
104  yes) asserts_enabled=true
105 ;;
106  no)  asserts_enabled=false
107 ;;
108  *) AC_MSG_ERROR(bad value ${enableval} for --enable-asserts) ;;
109esac],[asserts_enabled=true])
110
111AM_CONDITIONAL(ENABLE_ASSERTS, test x$asserts_enabled = xtrue)
112
113# Enable -D_GLIBCXX_DEBUG
114AC_ARG_ENABLE(glibcdebug,
115[  --enable-glibcdebug    Enable glibc++ debug mode],
116[case "${enableval}" in
117  yes) glibcdebug_enabled=true
118 ;;
119  no)  glibcdebug_enabled=false
120 ;;
121  *) AC_MSG_ERROR(bad value ${enableval} for --enable-glibcdebug) ;;
122esac],[glibcdebug_enabled=false])
123
124AM_CONDITIONAL(ENABLE_GLIBCDEBUG, test x$glibcdebug_enabled = xtrue)
125
126# Enable mse classes replacements for stl
127AC_ARG_ENABLE(stldebug,
128[  --enable-stldebug    Enable mse libs],
129[case "${enableval}" in
130  yes) stldebug_enabled=true
131 ;;
132  no)  stldebug_enabled=false
133 ;;
134  *) AC_MSG_ERROR(bad value ${enableval} for --enable-stldebug) ;;
135esac],[stldebug_enabled=false])
136
137AM_CONDITIONAL(ENABLE_STLDEBUG, test x$stldebug_enabled = xtrue)
138
139# Enable OpenGL error reporting
140AC_ARG_ENABLE(openglerrors,
141[  --enable-openglerrors    Enable OpenGL errors reporting],
142[case "${enableval}" in
143  yes) openglerrors_enabled=true
144 ;;
145  no)  openglerrors_enabled=false
146 ;;
147  *) AC_MSG_ERROR(bad value ${enableval} for --enable-openglerrors) ;;
148esac],[openglerrors_enabled=false])
149
150AM_CONDITIONAL(ENABLE_OPENGLERRORS, test x$openglerrors_enabled = xtrue)
151
152# Enable password from command line
153AC_ARG_ENABLE(commandlinepassword,
154[  --enable-commandlinepassword    Enable command line option for set password],
155[case "${enableval}" in
156  yes) commandlinepassword_enabled=true
157 ;;
158  no)  commandlinepassword_enabled=false
159 ;;
160  *) AC_MSG_ERROR(bad value ${enableval} for --enable-commandlinepassword) ;;
161esac],[commandlinepassword_enabled=false])
162
163AM_CONDITIONAL(ENABLE_COMMANDLINEPASSWORD, test x$commandlinepassword_enabled = xtrue)
164
165# Checks for android.
166AC_ARG_ENABLE(androidbuild,
167[  --enable-androidbuild    Turn on android building],
168[case "${enableval}" in
169  yes) androidbuild_enabled=true
170       dyecmd_enabled=false
171 ;;
172  no)  androidbuild_enabled=false
173 ;;
174  *) AC_MSG_ERROR(bad value ${enableval} for --enable-androidbuild) ;;
175esac],[androidbuild_enabled=false])
176
177# Enable for dyecmd
178AC_ARG_WITH(dyecmd,[  --with-dyecmd        build dyecmd tool ] )
179if test "x$with_dyecmd" == "xno"; then
180    with_dyecmd=no
181else
182    if test "x$androidbuild_enabled" == "xfalse"; then
183        with_dyecmd=yes
184    else
185        with_dyecmd=no
186    fi
187fi
188
189AM_CONDITIONAL(ENABLE_DYECMD, test x$with_dyecmd = xyes)
190
191# Option to enable ManaPlus game
192AC_ARG_WITH(manaplusgame,[  --without-manaplusgame        don't build ManaPlus game ] )
193if test "x$with_manaplusgame" == "xno"; then
194    with_manaplusgame=no
195else
196    with_manaplusgame=yes
197fi
198AM_CONDITIONAL(ENABLE_MANAPLUSGAME, test x$with_manaplusgame = xyes)
199
200# Enable nacl build
201AC_ARG_ENABLE(naclbuild,
202[  --enable-naclbuild    Turn on nacl building],
203[case "${enableval}" in
204  yes) naclbuild_enabled=true
205 ;;
206  no)  naclbuild_enabled=false
207 ;;
208  *) AC_MSG_ERROR(bad value ${enableval} for --enable-naclbuild) ;;
209esac],[naclbuild_enabled=false])
210
211# Checks for programs.
212AC_PROG_CXX
213AM_PROG_CC_C_O
214AC_PROG_INSTALL
215
216# Checks for typedefs, structures, and compiler characteristics.
217AC_HEADER_TIME
218
219# Checks for library functions.
220AC_FUNC_ERROR_AT_LINE
221
222# disabled because look like build issue with some libc versions with asan
223#if test "x$androidbuild_enabled" == "xfalse"; then
224#    if test "x$naclbuild_enabled" == "xfalse"; then
225#        AC_FUNC_MALLOC
226#        AC_FUNC_REALLOC
227#    fi
228#fi
229
230AC_C_INLINE
231AC_FUNC_SELECT_ARGTYPES
232AC_FUNC_VPRINTF
233AC_FUNC_FORK
234AC_FUNC_MMAP
235AC_CHECK_FUNCS([atexit floor getcwd gethostbyname memset mkdir select socket])
236AC_CHECK_FUNCS([clock_gettime dup2 gettimeofday memchr memmove pow putenv])
237AC_CHECK_FUNCS([realpath setenv setlocale sqrt strchr munmap])
238AC_CHECK_FUNCS([malloc_trim])
239#AC_CHECK_HEADER_STDBOOL
240AC_CHECK_HEADERS([libintl.h limits.h sys/param.h sys/time.h wchar.h])
241
242AC_TYPE_INT8_T
243AC_TYPE_UINT8_T
244AC_TYPE_INT16_T
245AC_TYPE_UINT16_T
246AC_TYPE_INT32_T
247AC_TYPE_UINT32_T
248AC_TYPE_INT64_T
249AC_TYPE_SSIZE_T
250
251# Search for *-config
252PKG_PROG_PKG_CONFIG
253AC_PATH_PROG(CURL_CONFIG, curl-config)
254AC_PATH_PROG(ICU_CONFIG, icu-config)
255
256LIBS="$LIBS `$PKG_CONFIG --libs zlib`"
257CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags zlib`"
258LIBS="$LIBS `$PKG_CONFIG --libs libpng`"
259CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags libpng`"
260
261# Checks for internationalization support
262AM_GNU_GETTEXT([external],[need-ngettext])
263AM_GNU_GETTEXT_VERSION([0.16.1])
264
265case $host in
266  (*mingw*)
267    skip_check_lib="yes"
268    mingw=true
269    LIBS="$LIBS -lintl"
270    ;;
271  (*)
272    skip_check_lib="no"
273    mingw=false
274    ;;
275esac
276
277AM_CONDITIONAL(MINGW, test x$mingw = xtrue)
278
279
280# Option to enable internal sdl-gfx for SDL2 (for now it enabled by default)
281AC_ARG_WITH(internalsdlgfx,[  --without-internalsdlgfx        don't use internal sdlgfx (for SDL2 only) ] )
282
283AC_DEFUN([AC_CHECK_SDL],
284[
285# Enable sdl2
286AC_ARG_WITH(sdl2,[  --with-sdl2        enable SDL 2 support] )
287if test "x$with_sdl2" == "xyes"; then
288    AC_PATH_PROG(SDL_CONFIG, sdl2-config)
289    if test -n "$SDL_CONFIG"; then
290        LIBS="$LIBS `$SDL_CONFIG --libs`"
291        CPPFLAGS="$CPPFLAGS `$SDL_CONFIG --cflags`"
292    fi
293    if test "x$with_internalsdlgfx" == "xno"; then
294        LIBS="$LIBS `$PKG_CONFIG --libs SDL2_gfx`"
295        CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL2_gfx`"
296    fi
297    LIBS="$LIBS `$PKG_CONFIG --libs SDL2_image`"
298    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL2_image`"
299    LIBS="$LIBS `$PKG_CONFIG --libs SDL2_mixer`"
300    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL2_mixer`"
301    LIBS="$LIBS `$PKG_CONFIG --libs SDL2_net`"
302    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL2_net`"
303    LIBS="$LIBS `$PKG_CONFIG --libs SDL2_ttf`"
304    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL2_ttf`"
305
306    if test "$skip_check_lib" == "no"; then
307        AC_CHECK_LIB([SDL2], [SDL_Init], ,
308        AC_MSG_ERROR([ *** Unable to find SDL2 library (http://www.libsdl.org/)]))
309
310        AC_CHECK_LIB(SDL2_image, IMG_LoadPNG_RW, ,
311        AC_MSG_ERROR([ *** Unable to find SDL2_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)]))
312
313        AC_CHECK_LIB(SDL2_ttf, TTF_Quit, ,
314        AC_MSG_ERROR([ *** Unable to find SDL2_ttf library (http://www.libsdl.org/projects/SDL_ttf/)]))
315
316        AC_CHECK_LIB([SDL2_mixer], [Mix_OpenAudio], ,
317        AC_MSG_ERROR([ *** Unable to find SDL2_mixer library (http://www.libsdl.org/projects/SDL_mixer/)]))
318
319        AC_CHECK_LIB(SDL2_net, SDLNet_Init, ,
320        AC_MSG_ERROR([ *** Unable to find SDL2_net library]))
321    fi
322    with_sdl2=yes
323else
324    AC_PATH_PROG(SDL_CONFIG, sdl-config)
325    if test -n "$SDL_CONFIG"; then
326        LIBS="$LIBS `$SDL_CONFIG --libs`"
327        CPPFLAGS="$CPPFLAGS `$SDL_CONFIG --cflags`"
328    fi
329    LIBS="$LIBS `$PKG_CONFIG --libs SDL_gfx`"
330    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL_gfx`"
331    LIBS="$LIBS `$PKG_CONFIG --libs SDL_image`"
332    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL_image`"
333    LIBS="$LIBS `$PKG_CONFIG --libs SDL_mixer`"
334    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL_mixer`"
335    LIBS="$LIBS `$PKG_CONFIG --libs SDL_net`"
336    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL_net`"
337    LIBS="$LIBS `$PKG_CONFIG --libs SDL_ttf`"
338    CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags SDL_ttf`"
339
340    if test "x$naclbuild_enabled" == "xfalse"; then
341        if test "$skip_check_lib" == "no"; then
342            AC_CHECK_LIB([SDL], [SDL_Init], ,
343            AC_MSG_ERROR([ *** Unable to find SDL library (http://www.libsdl.org/)]))
344
345            AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, ,
346            AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)]))
347
348            AC_CHECK_LIB(SDL_ttf, TTF_Quit, ,
349            AC_MSG_ERROR([ *** Unable to find SDL_ttf library (http://www.libsdl.org/projects/SDL_ttf/)]))
350
351            AC_CHECK_LIB([SDL_mixer], [Mix_OpenAudio], ,
352            AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/projects/SDL_mixer/)]))
353
354            AC_CHECK_LIB(SDL_gfx, rotozoomSurfaceXY, ,
355            AC_MSG_ERROR([ *** Unable to find SDL_gfx library (http://www.ferzkopp.net/joomla/software-mainmenu-14/4-ferzkopps-linux-software/19-sdlgfx)]))
356
357            AC_CHECK_LIB(SDL_net, SDLNet_Init, ,
358            AC_MSG_ERROR([ *** Unable to find SDL_net library]))
359        fi
360        AC_CHECK_HEADERS(SDL_rotozoom.h, ,)
361    fi
362
363    with_sdl2=no
364fi
365
366AM_CONDITIONAL(USE_SDL2, test x$with_sdl2 = xyes)
367
368AC_CHECK_GLXEXT(have_glext)
369AM_CONDITIONAL(HAVE_GLEXT, test x$have_glext = xyes)
370
371# Option to enable internal sdl-gfx for SDL2 (for now it enabled by default)
372if test "x$with_internalsdlgfx" == "xno"; then
373    with_internalsdlgfx=no
374
375    if test "$skip_check_lib" == "no"; then
376        AC_CHECK_LIB(SDL2_gfx, rotozoomSurfaceXY, ,
377        AC_MSG_ERROR([ *** Unable to find SDL2_gfx library (http://www.ferzkopp.net/joomla/software-mainmenu-14/4-ferzkopps-linux-software/19-sdlgfx)]))
378    fi
379    AC_CHECK_HEADERS(SDL2_rotozoom.h, ,)
380else
381    with_internalsdlgfx=yes
382    AC_DEFINE(USE_INTERNALSDLGFX, 1, [Defines if ManaPlus should use internal sdlgfx2])
383fi
384AM_CONDITIONAL(USE_INTERNALSDLGFX, test x$with_internalsdlgfx = xyes)
385
386AC_CHECK_HEADERS([SDL.h], ,
387AC_MSG_ERROR([ *** SDL library found but cannot find headers (http://www.libsdl.org/)]))
388])
389
390if test "x$naclbuild_enabled" == "xfalse"; then
391    AC_CHECK_SDL()
392fi
393
394# Checks for libraries
395AC_ARG_WITH(pthread,[  --without-pthread        don't check for pthread ] )
396if test "x$with_pthread" == "xno"; then
397    without_pthread=yes
398else
399    if test "x$androidbuild_enabled" == "xfalse"; then
400        if test "$skip_check_lib" == "no"; then
401            AC_CHECK_LIB([pthread], [pthread_create], ,
402            AC_MSG_ERROR([ *** Unable to find pthread library]))
403        fi
404    fi
405    withoud_pthread=no
406fi
407
408if test "$skip_check_lib" == "no"; then
409    AC_CHECK_LIB([z], [inflate], ,
410    AC_MSG_ERROR([ *** Unable to find zlib (http://www.gzip.org/zlib/)]))
411fi
412
413if test -n "$CURL_CONFIG"; then
414    LIBS="$LIBS `$CURL_CONFIG --libs`"
415    CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`"
416fi
417if test "$skip_check_lib" == "no"; then
418    AC_CHECK_LIB([curl], [curl_global_init], ,
419    AC_MSG_ERROR([ *** Unable to find CURL library (http://curl.haxx.se/)]))
420fi
421AC_CHECK_HEADERS([curl/curl.h], ,
422AC_MSG_ERROR([ *** CURL library found but cannot find headers (http://curl.haxx.se/)]))
423
424
425# select xml lib
426AC_ARG_ENABLE(libxml,
427    AC_HELP_STRING([--enable-libxml=ARG],
428        [xml libs: libxml (default), pugixml (experimental)]),
429    [
430        xmllib="${enableval}"
431    ],
432    [
433        xmllib="libxml"
434    ]
435)
436
437case $xmllib in
438    "libxml")
439        AM_CONDITIONAL(ENABLE_LIBXML, true)
440        AM_CONDITIONAL(ENABLE_PUGIXML, false)
441        AM_CONDITIONAL(ENABLE_TINYXML2, false)
442        ;;
443    "pugixml")
444        AM_CONDITIONAL(ENABLE_LIBXML, false)
445        AM_CONDITIONAL(ENABLE_PUGIXML, true)
446        AM_CONDITIONAL(ENABLE_TINYXML2, false)
447        ;;
448    "tinyxml2")
449        AM_CONDITIONAL(ENABLE_LIBXML, false)
450        AM_CONDITIONAL(ENABLE_PUGIXML, false)
451        AM_CONDITIONAL(ENABLE_TINYXML2, true)
452        ;;
453    *)
454        AC_MSG_ERROR([[Wrong xml lib name]])
455        ;;
456esac
457
458if test "$xmllib" == "libxml"; then
459    if test -n "$PKG_CONFIG"; then
460        LIBS="$LIBS `$PKG_CONFIG --libs libxml-2.0`"
461        CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags libxml-2.0`"
462    fi
463    if test "$skip_check_lib" == "no"; then
464        AC_CHECK_LIB([xml2], [xmlInitParser], ,
465        AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)]))
466    fi
467    AC_CHECK_HEADERS(
468        [libxml/xmlreader.h],
469        ,
470        # workaround for icu-59 issue.
471        CPPFLAGS="$CPPFLAGS --std=c++0x"
472        AC_MSG_RESULT([no])
473        AC_MSG_CHECKING([Checking libxml2 headers with icu bug fix])
474        icu_bug=yes
475        $as_unset ac_cv_header_libxml_xmlreader_h
476    )
477    if test "$icu_bug" == "yes"; then
478        AC_CHECK_HEADERS(
479            [libxml/xmlreader.h],
480            ,
481            AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])
482        )
483    fi
484fi
485
486if test "$xmllib" == "pugixml"; then
487    if test "$skip_check_lib" == "no"; then
488        AC_CHECK_LIB([pugixml], [main], ,
489        AC_MSG_ERROR([ *** Unable to find pugixml library (http://pugixml.org/)]))
490    fi
491    AC_CHECK_HEADERS([pugixml.hpp], ,
492    AC_MSG_ERROR([ *** pugixml library found but cannot find headers (http://pugixml.org/)]))
493fi
494
495# hack for support unversioned api change in tinyxml2 (master branch)
496tinyxml2_old=yes
497if test "$xmllib" == "tinyxml2"; then
498    if test "$skip_check_lib" == "no"; then
499        AC_CHECK_LIB([tinyxml2], [main], ,
500        AC_MSG_ERROR([ *** Unable to find tinyxml2 library (http://grinninglizard.com/tinyxml2/)]))
501        AC_MSG_CHECKING([whether tinyxml supports old error api])
502        AC_COMPILE_IFELSE(
503            [AC_LANG_SOURCE([
504                #ifndef GCC_VERSION
505                #define GCC_VERSION (__GNUC__ * 10000 \
506                    + __GNUC_MINOR__ * 100 \
507                    + __GNUC_PATCHLEVEL__)
508                #endif  // GCC_VERSION
509                #ifdef __clang__
510                #ifndef CLANG_VERSION
511                #define CLANG_VERSION (__clang_major__ * 10000 \
512                    + __clang_minor__ * 100 \
513                    + __clang_patchlevel__)
514                #endif  // CLANG_VERSION
515                #endif  // __clang__
516                #if GCC_VERSION >= 49000
517                #define PRAGMA49(str) _Pragma(#str)
518                #else  // GCC_VERSION > 49000
519                #define PRAGMA49(str)
520                #endif  // GCC_VERSION > 49000
521                #if GCC_VERSION >= 40600
522                #define PRAGMACLANG6GCC(str) _Pragma(#str)
523                #elif defined(__clang__) && CLANG_VERSION >= 30800
524                #define PRAGMACLANG6GCC(str) _Pragma(#str)
525                #else  // __clang__
526                #define PRAGMACLANG6GCC(str)
527                #endif  // __clang__
528
529                PRAGMA49(GCC diagnostic push)
530                PRAGMA49(GCC diagnostic ignored "-Wzero-as-null-pointer-constant")
531                PRAGMA49(GCC diagnostic ignored "-Wsuggest-override")
532                PRAGMACLANG6GCC(GCC diagnostic push)
533                PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
534                #include <tinyxml2.h>
535                PRAGMACLANG6GCC(GCC diagnostic pop)
536                PRAGMA49(GCC diagnostic pop)
537
538                int main(int, char **)
539                {
540                    tinyxml2::XMLDocument doc;
541                    const char *str = doc.ErrorStr();
542                    return !str;
543                }
544            ])],
545            [
546                AC_MSG_RESULT([no])
547                tinyxml2_old=no
548            ],
549            [
550                AC_MSG_RESULT([yes])
551                tinyxml2_old=yes
552            ]
553        )
554    fi
555    AC_CHECK_HEADERS([tinyxml2.h], ,
556    AC_MSG_ERROR([ *** tinyxml2 library found but cannot find headers (http://grinninglizard.com/tinyxml2/)]))
557fi
558
559AM_CONDITIONAL(USE_TINYXML_OLD, test x$tinyxml2_old = xyes)
560
561if test "$skip_check_lib" == "no"; then
562    AC_CHECK_LIB(png, png_write_info, ,
563    AC_MSG_ERROR([ *** Unable to find png library]))
564fi
565
566use_x11=no
567# === Check for X11 (check borrowed from Wormux) ========================
568# Deactivated on purpose under OSX (in case X11 SDK is installed)
569if test "x$OSX" != "xyes" ; then
570  AC_CHECK_HEADER(X11/Xlib.h, check_x11="yes",check_x11="no")
571  if test x${check_x11} = xno ; then
572    AC_CHECK_HEADER(X11R6/Xlib.h,
573                    [ check_x11="yes"
574                      LDFLAGS="-L/usr/X11R6/include $CFLAGS"],
575                    check_x11="no")
576  fi
577  if test x${check_x11} = xyes ; then
578    AC_CHECK_LIB(X11, XOpenDisplay,
579                 [ LIBS="$LIBS -lX11"
580                   AC_DEFINE(USE_X11, 1, [Define to use X11 copy'n'paste])
581                   use_x11=yes
582                 ],
583                 [])
584  fi
585fi
586
587AM_CONDITIONAL(USE_X11, test x$use_x11 = xyes)
588
589# Checks for header files.
590AC_HEADER_STDC
591AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
592
593# Enable mac build
594AC_ARG_ENABLE(applebuild,
595[  --enable-applebuild    Turn on apple building],
596[case "${enableval}" in
597  yes) applebuild_enabled=true
598 ;;
599  no)  applebuild_enabled=false
600 ;;
601  *) AC_MSG_ERROR(bad value ${enableval} for --enable-applebuild) ;;
602esac],[applebuild_enabled=false])
603
604
605# Option to enable gcov
606AC_ARG_WITH(gcov,[  --with-gcov        use gcov ] )
607if test "x$with_gcov" == "xyes"; then
608    with_gcov=yes
609    CPPFLAGS="$CPPFLAGS -coverage"
610    LDFLAGS="$LDFLAGS -coverage"
611else
612    with_gcov=no
613fi
614AM_CONDITIONAL(USE_GCOV, test x$with_gcov = xyes)
615
616# Option to enable OpenGL
617AC_ARG_WITH(opengl,[  --without-opengl        don't use OpenGL ] )
618if test "x$with_opengl" == "xno"; then
619    with_opengl=no
620else
621    with_opengl=yes
622    if test "x$applebuild_enabled" == "xfalse"; then
623        if test "x$androidbuild_enabled" == "xfalse"; then
624            if test "x$naclbuild_enabled" == "xfalse"; then
625                if test "$skip_check_lib" == "no"; then
626                    AC_CHECK_LIB([GL], [glBegin], ,
627                    AC_MSG_ERROR([ *** Unable to find OpenGL library]))
628                fi
629            fi
630        else
631            LDFLAGS="$LDFLAGS -lGLESv1_CM -lEGL"
632        fi
633    else
634        LDFLAGS="$LDFLAGS -framework OpenGL"
635    fi
636case $host in
637  (*mingw*) LIBS="$LIBS `$PKG_CONFIG --libs gl`"
638esac
639
640fi
641AM_CONDITIONAL(USE_OPENGL, test x$with_opengl = xyes)
642
643# Option to enable mumble support
644AC_ARG_WITH(mumble,[  --without-mumble        don't use mumble integration ] )
645if test "x$with_mumble" == "xno"; then
646    with_mumble=no
647else
648    if test "x$androidbuild_enabled" == "xfalse"; then
649        with_mumble=yes
650    else
651        with_mumble=no
652    fi
653fi
654AM_CONDITIONAL(USE_MUMBLE, test x$with_mumble = xyes)
655
656
657AC_ARG_WITH(librt,[  --without-librt        don't link to librt ] )
658if test "x$with_librt" == "xno"; then
659    without_librt=yes
660else
661    if test "x$applebuild_enabled" == "xfalse"; then
662        if test "x$androidbuild_enabled" == "xfalse"; then
663            AC_CHECK_LD_FLAG(-lrt, use_librt)
664            if test "x$use_librt" == "xyes"; then
665                AC_CHECK_LIB(rt, shm_open, ,
666                AC_MSG_ERROR([ *** Unable to find librt library]))
667            fi
668        fi
669    fi
670    without_librt=no
671fi
672
673AM_CONDITIONAL(USE_LIBRT, test x$use_librt = xyes)
674
675# Enable tmwA
676AC_ARG_ENABLE(tmwa,
677[  --enable-tmwa    Turn on tmwA support],
678[case "${enableval}" in
679  yes) with_tmwa=true ;;
680  no)  with_tmwa=false ;;
681  *) AC_MSG_ERROR(bad value ${enableval} for --enable-tmwa) ;;
682esac],[with_tmwa=true])
683
684AM_CONDITIONAL(ENABLE_TMWA, test x$with_tmwa = xtrue)
685
686# Enable checks
687AC_ARG_ENABLE(checks,
688[  --enable-checks    Turn on internal checks (can be slow)],
689[case "${enableval}" in
690  yes) with_checks=true ;;
691  no)  with_checks=false ;;
692  *) AC_MSG_ERROR(bad value ${enableval} for --enable-checks) ;;
693esac],[with_checks=false])
694
695AM_CONDITIONAL(ENABLE_CHECKS, test x$with_checks = xtrue)
696
697# Enable portable
698AC_ARG_ENABLE(portable,
699[  --enable-portable    Turn on portable mode for linux],
700[case "${enableval}" in
701  yes) portable_enabled=true ;;
702  no)  portable_enabled=false ;;
703  *) AC_MSG_ERROR(bad value ${enableval} for --enable-portable) ;;
704esac],[portable_enabled=false])
705
706AM_CONDITIONAL(ENABLE_PORTABLE, test x$portable_enabled = xtrue)
707
708# Enable debug
709AC_ARG_ENABLE(memdebug,
710[  --enable-memdebug    Turn on memory debug mode],
711[case "${enableval}" in
712  yes) memdebug_enabled=true ;;
713  no)  memdebug_enabled=false ;;
714  *) AC_MSG_ERROR(bad value ${enableval} for --enable-memdebug) ;;
715esac],[memdebug_enabled=false])
716
717AM_CONDITIONAL(ENABLE_MEM_DEBUG, test x$memdebug_enabled = xtrue)
718
719# Enable unit tests
720AC_ARG_ENABLE(unittests,
721[  --enable-unittests    Turn on unit tests],
722[case "${enableval}" in
723  yes)
724       unittests_enabled=true
725       unittests_catch=true
726       unittests_doctest=false
727       unittests_embed=true
728 ;;
729  catch)
730       unittests_enabled=true
731       unittests_catch=true
732       unittests_doctest=false
733       unittests_embed=true
734 ;;
735  doctest)
736       unittests_enabled=true
737       unittests_catch=false
738       unittests_doctest=true
739       unittests_embed=true
740 ;;
741  systemcatch)
742       unittests_enabled=true
743       unittests_catch=true
744       unittests_doctest=false
745       unittests_embed=false
746 ;;
747  systemdoctest)
748       unittests_enabled=true
749       unittests_catch=false
750       unittests_doctest=true
751       unittests_embed=false
752 ;;
753  no)
754       unittests_enabled=false
755       unittests_embed=true
756 ;;
757  *) AC_MSG_ERROR(bad value ${enableval} for --enable-unittests) ;;
758esac],[unittests_enabled=false])
759
760AM_CONDITIONAL(ENABLE_UNITTESTS, test x$unittests_enabled = xtrue)
761AM_CONDITIONAL(ENABLE_UNITTESTS_CATCH, test x$unittests_catch = xtrue)
762AM_CONDITIONAL(ENABLE_UNITTESTS_DOCTEST, test x$unittests_doctest = xtrue)
763AM_CONDITIONAL(ENABLE_UNITTESTS_EMBED, test x$unittests_embed = xtrue)
764
765# Enable unit tests binaries only
766AC_ARG_ENABLE(unittestsbin,
767[  --enable-unittestsbin    Turn on unit tests binary compilation only],
768[case "${enableval}" in
769  yes)
770    unittestsbin_enabled=true
771    unittestsbin_catch=true
772    unittestsbin_doctest=false
773    unittestsbin_embed=true
774 ;;
775  catch)
776    unittestsbin_enabled=true
777    unittestsbin_catch=true
778    unittestsbin_doctest=false
779    unittestsbin_embed=true
780 ;;
781  doctest)
782    unittestsbin_enabled=true
783    unittestsbin_catch=false
784    unittestsbin_doctest=true
785    unittestsbin_embed=true
786 ;;
787  systemcatch)
788    unittestsbin_enabled=true
789    unittestsbin_catch=true
790    unittestsbin_doctest=false
791    unittestsbin_embed=false
792 ;;
793  systemdoctest)
794    unittestsbin_enabled=true
795    unittestsbin_catch=false
796    unittestsbin_doctest=true
797    unittestsbin_embed=false
798 ;;
799  no)
800    unittestsbin_enabled=false
801    unittestsbin_embed=true
802 ;;
803  *) AC_MSG_ERROR(bad value ${enableval} for --enable-unittestsbin) ;;
804esac],[unittestsbin_enabled=false])
805
806AM_CONDITIONAL(ENABLE_UNITTESTSBIN, test x$unittestsbin_enabled = xtrue)
807AM_CONDITIONAL(ENABLE_UNITTESTSBIN_CATCH, test x$unittestsbin_catch = xtrue)
808AM_CONDITIONAL(ENABLE_UNITTESTSBIN_DOCTEST, test x$unittestsbin_doctest = xtrue)
809AM_CONDITIONAL(ENABLE_UNITTESTSBIN_EMBED, test x$unittestsbin_embed = xtrue)
810
811# Override home directory for unit tests
812AC_ARG_WITH(unittestsdir,
813[  --with-unittestsdir        override home directory for unit tests ],
814[
815    if test "x$withval" != "xno"; then
816        with_unittestsdir=$withval
817        CXXFLAGS="$CXXFLAGS -DUNITESTSDIR=\\\"$withval\\\""
818    fi
819])
820
821# Enable tcmalloc
822AC_ARG_ENABLE(tcmalloc,
823[  --enable-tcmalloc    Turn on tcmalloc],
824[case "${enableval}" in
825  yes) tcmalloc_enabled=true
826LIBS="$LIBS -ltcmalloc"
827 ;;
828  no)  tcmalloc_enabled=false ;;
829  *) AC_MSG_ERROR(bad value ${enableval} for --enable-tcmalloc) ;;
830esac],[tcmalloc_enabled=false])
831
832# Enable google profiler
833AC_ARG_ENABLE(googleprofiler,
834[  --enable-googleprofiler    Turn on google profiler],
835[case "${enableval}" in
836  yes) googleprofiler_enabled=true
837LIBS="$LIBS -lprofiler"
838 ;;
839  no)  googleprofiler_enabled=false ;;
840  *) AC_MSG_ERROR(bad value ${enableval} for --enable-googleprofiler) ;;
841esac],[googleprofiler_enabled=false])
842
843AM_CONDITIONAL(ENABLE_GOOGLE_PROFILER, test x$googleprofiler_enabled = xtrue)
844
845# Enable gcc check plugin
846AC_ARG_ENABLE(checkplugin,
847[  --enable-checkplugin    Turn on gcc check plugin],
848[case "${enableval}" in
849  yes) checkplugin_enabled=true ;;
850  no)  checkplugin_enabled=false ;;
851  *) AC_MSG_ERROR(bad value ${enableval} for --enable-checkplugin) ;;
852esac],[checkplugin_enabled=false])
853
854AM_CONDITIONAL(ENABLE_CHECKPLUGIN, test x$checkplugin_enabled = xtrue)
855
856# Enable custom NLS
857AC_ARG_ENABLE(customnls,
858[  --enable-customnls    Turn on build in translation system (NLS)],
859[case "${enableval}" in
860  yes) customnls_enabled=true ;;
861  no)  customnls_enabled=false ;;
862  *) AC_MSG_ERROR(bad value ${enableval} for --enable-customnls) ;;
863esac],[customnls_enabled=false])
864
865AM_CONDITIONAL(ENABLE_CUSTOMNLS, test x$customnls_enabled = xtrue)
866
867if test "x$naclbuild_enabled" == "xtrue"; then
868    AC_CHECK_SDL()
869fi
870
871AC_CHECK_LD_FLAG(-rdynamic, have_rdynamic)
872AM_CONDITIONAL(HAVE_RDYNAMIC, test x$have_rdynamic = xyes)
873
874AC_CHECK_HEADERS([execinfo.h],
875    [
876        AC_SEARCH_LIBS([backtrace],
877            [execinfo],
878            [
879                have_execinfo=yes
880            ],
881            [
882                have_execinfo=no
883            ]
884        )
885    ],
886    []
887)
888AM_CONDITIONAL(HAVE_EXECINFO, test x$have_execinfo = xyes)
889
890AC_CONFIG_FILES([
891manaplus.spec
892Makefile
893PKGBUILD
894src/Makefile
895data/Makefile
896data/evol/evol.desktop
897data/evol/Makefile
898data/fonts/Makefile
899data/fonts/src/Makefile
900data/graphics/Makefile
901data/graphics/badges/Makefile
902data/graphics/flags/Makefile
903data/graphics/gui/Makefile
904data/graphics/images/Makefile
905data/graphics/shaders/Makefile
906data/graphics/sprites/Makefile
907data/sfx/Makefile
908data/sfx/system/Makefile
909data/test/Makefile
910data/test/dir1/Makefile
911data/test/dir2/Makefile
912data/themes/Makefile
913data/themes/blacknblack/Makefile
914data/themes/blackwood/Makefile
915data/themes/classic/Makefile
916data/themes/enchilado/Makefile
917data/themes/golden-delicious/Makefile
918data/themes/jewelry/Makefile
919data/themes/jewelry-simple/Makefile
920data/themes/mana/Makefile
921data/themes/pink/Makefile
922data/themes/unity/Makefile
923data/themes/wood/Makefile
924data/help/Makefile
925data/help/idx/Makefile
926data/help/tips/Makefile
927data/icons/Makefile
928data/music/Makefile
929data/perserver/Makefile
930data/perserver/default/Makefile
931data/translations/Makefile
932data/translations/help/Makefile
933data/translations/test/Makefile
934docs/Makefile
935po/Makefile.in
936])
937
938AC_CONFIG_FILES([data/evol/evol], [chmod +x data/evol/evol])
939
940AC_OUTPUT
941
942echo
943if test "$with_manaplusgame" == "yes"; then
944    echo "Enabled building manaplus game."
945fi
946if test "$with_dyecmd" == "yes"; then
947    echo "Enabled building dyecmd."
948fi
949if test "$unittests_enabled" == true; then
950    echo "Enabled building unit tests."
951fi
952
953echo "Build with OpenGL: $with_opengl"
954echo
955echo "LIBS: $LIBS"
956echo "CPPFLAGS: $CPPFLAGS"
957
958echo
959echo "configure complete, now type \"make\""
960echo
961