Make unitwaittime block exploding a nuke in place.
[freeciv.git] / m4 / ggz.m4
blobe03181c806499cdbb43437582ea639950c667604
1 dnl ======================================
2 dnl GGZ Gaming Zone - Configuration Macros
3 dnl ======================================
4 dnl
5 dnl Copyright (C) 2001 - 2007 Josef Spillner, josef@ggzgamingzone.org
6 dnl This file has heavily been inspired by KDE's acinclude :)
7 dnl It is published under the conditions of the GNU General Public License.
8 dnl
9 dnl ======================================
10 dnl
11 dnl This file is common to most GGZ modules, and should be kept in sync
12 dnl between them all.  The master copy resides with libggz.
13 dnl Currently the following modules use it:
14 dnl   kde-games, kde-client, gtk-games, gtk-client, utils, grubby,
15 dnl   ggz-client-libs, ggzd, gnome-client, txt-client, sdl-games, libggz
16 dnl See /docs/ggz-project/buildsystem for documentation.
17 dnl
18 dnl ======================================
19 dnl
20 dnl History:
21 dnl   See the SVN log for a full history.
22 dnl
23 dnl ------------------------------------------------------------------------
24 dnl Content of this file:
25 dnl ------------------------------------------------------------------------
26 dnl High-level macros:
27 dnl   AC_GGZ_CHECK - Checks for presence of GGZ client and server libraries.
28 dnl                  GGZ users can call this macro to determine at compile
29 dnl                  time whether to include GGZ support.  Server and client
30 dnl                  are checked separately.  GGZ_SERVER and GGZ_CLIENT are
31 dnl                  defined in config.h, and created as conditionals in
32 dnl                  the Makefiles.
33 dnl   AC_GGZ_CHECK_SERVER - The same, but server libs only.
34 dnl
35 dnl Low-level macros:
36 dnl   AC_GGZ_INIT - initialization and paths/options setup
37 dnl   AC_GGZ_VERSION - ensure a minimum version of GGZ
38 dnl   AC_GGZ_LIBGGZ - find the libggz headers and libraries
39 dnl   AC_GGZ_GGZCORE - find the ggzcore headers and libraries
40 dnl   AC_GGZ_CONFIG - find the ggz-config tool and set up configuration
41 dnl   AC_GGZ_GGZMOD - find the ggzmod library
42 dnl   AC_GGZ_GGZDMOD - find the ggzdmod library
43 dnl   AC_GGZ_SERVER - set up game and room path for ggzd game servers
44 dnl
45 dnl   Each macro takes two arguments:
46 dnl     1.  Action-if-found (or empty for no action).
47 dnl     2.  Action-if-not-found (or empty for error, or "ignore" to ignore).
48 dnl
49 dnl Internal functions:
50 dnl   AC_GGZ_ERROR - user-friendly error messages
51 dnl   AC_GGZ_FIND_FILE - macro for convenience (thanks kde)
52 dnl   AC_GGZ_REMOVEDUPS - eliminate duplicate list elements
53 dnl
55 # Version number of this script.
56 # First part is upstream (ggz) version and second Freeciv modifications.
57 # serial 0014.4
59 dnl ------------------------------------------------------------------------
60 dnl Find a directory containing a single file
61 dnl Synopsis: AC_GGZ_FIND_FILE(file, directorylist, <returnvar>)
62 dnl ------------------------------------------------------------------------
63 dnl
64 AC_DEFUN([AC_GGZ_FIND_FILE],
66 $3=NO
67 for i in $2;
69   for j in $1;
70   do
71     echo "configure: __oline__: $i/$j" >&AS_MESSAGE_LOG_FD
72     if test -r "$i/$j"; then
73       echo "taking that" >&AS_MESSAGE_LOG_FD
74       $3=$i
75       break 2
76     fi
77   done
78 done
81 dnl ------------------------------------------------------------------------
82 dnl Remove duplicate entries in a list, and remove all NO's
83 dnl Synopsis: AC_GGZ_REMOVEDUPS(list, <returnlist>)
84 dnl ------------------------------------------------------------------------
85 dnl
86 AC_DEFUN([AC_GGZ_REMOVEDUPS],
88 ret=""
89 for i in $1; do
90   add=yes
91   for j in $ret; do
92     if test "x$i" = "x$j"; then
93       add=no
94     fi
95   done
96   if test "x$i" = "xNO"; then
97     add=no
98   fi
99   if test "x$add" = "xyes"; then
100   ret="$ret $i"
101   fi
102 done
103 $2=$ret
106 dnl ------------------------------------------------------------------------
107 dnl User-friendly error messages
108 dnl Synopsis: AC_GGZ_ERROR(libraryname, headerdirlist, libdirlist)
109 dnl ------------------------------------------------------------------------
111 AC_DEFUN([AC_GGZ_ERROR],
113   AC_MSG_WARN([no
114   The library '$1' does not seem to be installed correctly.
115   Headers searched in: $2
116   Libraries searched in: $3
117   Please read QuickStart.GGZ in order to fix this.
118   ])
119   exit 1
122 dnl ------------------------------------------------------------------------
123 dnl Initialization, common values and such
124 dnl Synopsis: AC_GGZ_INIT([export], [defaults])
125 dnl ------------------------------------------------------------------------
127 AC_DEFUN([AC_GGZ_INIT],
129 if test "x$prefix" = "xNONE"; then
130   prefix="${ac_default_prefix}"
132 if test "x$exec_prefix" = "xNONE"; then
133   exec_prefix='${prefix}'
136 ac_ggz_prefix=""
137 AC_ARG_WITH(ggz-dir,
138     AS_HELP_STRING([--with-ggz-dir=DIR],[Path to GGZ Gaming Zone]),
139     [  ac_ggz_prefix="$withval"
140     ])
142 if test "x$ac_ggz_prefix" != "xno" ; then
143   if test "x${prefix}" = "xNONE"; then
144     ac_ggz_prefix_incdir="${ac_default_prefix}/include"
145     ac_ggz_prefix_libdir="${ac_default_prefix}/lib"
146     ac_ggz_prefix_bindir="${ac_default_prefix}/bin"
147     ac_ggz_prefix_etcdir="${ac_default_prefix}/etc"
148   else
149     unq_includedir="${includedir}"
150     unq_libdir="${libdir}"
151     unq_bindir="${bindir}"
152     unq_sysconfdir="${sysconfdir}"
154     eval unq_includedir=`echo $unq_includedir`
155     eval unq_includedir=`echo $unq_includedir`
156     eval unq_libdir=`echo $unq_libdir`
157     eval unq_libdir=`echo $unq_libdir`
158     eval unq_bindir=`echo $unq_bindir`
159     eval unq_bindir=`echo $unq_bindir`
160     eval unq_sysconfdir=`echo $unq_sysconfdir`
161     eval unq_sysconfdir=`echo $unq_sysconfdir`
163     ac_ggz_prefix_incdir="${unq_includedir}"
164     ac_ggz_prefix_libdir="${unq_libdir}"
165     ac_ggz_prefix_bindir="${unq_bindir}"
166     ac_ggz_prefix_etcdir="${unq_sysconfdir}"
167   fi
168   ac_ggz_stdinc="$ac_ggz_prefix_incdir"
169   ac_ggz_stdlib="$ac_ggz_prefix_libdir"
170   ac_ggz_stdbin="$ac_ggz_prefix_bindir"
171   ac_ggz_stdetc="$ac_ggz_prefix_etcdir/ggzd"
172   if test "x$ac_ggz_prefix" != "x"; then
173     ac_ggz_stdinc="$ac_ggz_stdinc $ac_ggz_prefix/include"
174     ac_ggz_stdlib="$ac_ggz_stdlib $ac_ggz_prefix/lib $ac_ggz_prefix/lib64"
175     ac_ggz_stdbin="$ac_ggz_stdbin $ac_ggz_prefix/bin"
176     ac_ggz_stdetc="$ac_ggz_stdetc $ac_ggz_prefix/etc/ggzd"
177   fi
178   if test "x$1" = "xdefaults" || test "x$2" = "xdefaults"; then
179     ac_ggz_stdinc="$ac_ggz_stdinc /usr/local/include /usr/include"
180     ac_ggz_stdlib="$ac_ggz_stdlib /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64"
181     ac_ggz_stdbin="$ac_ggz_stdbin /usr/local/bin /usr/bin"
182     ac_ggz_stdetc="$ac_ggz_stdetc /usr/local/etc/ggzd /etc/ggzd"
183   fi
184   if test "x$1" = "xexport" || test "x$2" = "xexport"; then
185     CPPFLAGS="$CPPFLAGS -I ${ac_ggz_prefix_incdir} -I /usr/local/include"
186     LDFLAGS="$LDFLAGS -L${ac_ggz_prefix_libdir} -L/usr/local/lib"
187   fi
189   save_cflags=$CFLAGS
190   save_cxxflags=$CXXFLAGS
191   if test "x$GCC" = xyes; then
192         CFLAGS="-Wall -Werror"
193         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
194                 [[void signedness(void){char c;if(c==-1)c=0;}]])],
195                 [],
196                 [save_cflags="$save_cflags -fsigned-char"
197                  save_cxxflags="$save_cxxflags -fsigned-char"])
198   else
199         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
200                 [[#if defined(__SUNPRO_C) || (__SUNPRO_C >= 0x550)
201                 #else
202                 # include "Error: Only GCC and Sun Studio are supported compilers."
203                 #endif]], [[]])],
204                 [save_cflags="$save_cflags -xchar=signed"
205                  save_cxxflags="$save_cxxflags -xchar=signed"],
206                 [])
208   fi
209   CFLAGS=$save_cflags
210   CXXFLAGS=$save_cxxflags
214 dnl ------------------------------------------------------------------------
215 dnl Ensure that a minimum version of GGZ is present
216 dnl Synopsis: AC_GGZ_VERSION(major, minor, micro,
217 dnl                          action-if-found, action-if-not-found)
218 dnl ------------------------------------------------------------------------
220 AC_DEFUN([AC_GGZ_VERSION],
222         major=$1
223         minor=$2
224         micro=$3
226         testprologue="#include <ggz.h>"
227         testbody=""
228         testbody="$testbody if(LIBGGZ_VERSION_MAJOR > $major) return 0;"
229         testbody="$testbody if(LIBGGZ_VERSION_MAJOR < $major) return -1;"
230         testbody="$testbody if(LIBGGZ_VERSION_MINOR > $minor) return 0;"
231         testbody="$testbody if(LIBGGZ_VERSION_MINOR < $minor) return -1;"
232         testbody="$testbody if(LIBGGZ_VERSION_MICRO > $micro) return 0;"
233         testbody="$testbody if(LIBGGZ_VERSION_MICRO < $micro) return -1;"
234         testbody="$testbody return 0;"
236         save_libs=$LIBS
237         save_ldflags=$LDFLAGS
238         save_cppflags=$CPPFLAGS
239         save_ldlibrary_path=$LD_LIBRARY_PATH
240         LDFLAGS=$LIBGGZ_ldflags
241         LIBS=$LIB_GGZ
242         CPPFLAGS=$LIBGGZ_INCLUDES
243         LD_LIBRARY_PATH=$save_ldlibrary_path:$libggz_libraries
244         export LD_LIBRARY_PATH
246         AC_MSG_CHECKING([for GGZ library version: $major.$minor.$micro])
247         AC_RUN_IFELSE(
248                 [AC_LANG_PROGRAM([[$testprologue]], [[$testbody]])],
249                 [ac_ggz_version_check=yes],
250                 [ac_ggz_version_check=no],
251                 [ac_ggz_version_check="skipped due to cross-compiling"]
252         )
253         if test "$ac_ggz_version_check" = "no"; then
254                 AC_MSG_RESULT([no])
255                 if test "x$5" = "x"; then
256                         AC_MSG_ERROR([The GGZ version is too old. Version $major.$minor.$micro is required.])
257                 fi
258                 $5
259         else
260                 AC_MSG_RESULT($ac_ggz_version_check)
261                 $4
262         fi
264         LIBS=$save_libs
265         LDFLAGS=$save_ldflags
266         CPPFLAGS=$save_cppflags
267         LD_LIBRARY_PATH=$save_ldlibrary_path
270 dnl ------------------------------------------------------------------------
271 dnl Try to find the libggz headers and libraries.
272 dnl $(LIBGGZ_ldflags) will be -L ... (if needed)
273 dnl and $(LIBGGZ_INCLUDES) will be -I ... (if needed)
274 dnl ------------------------------------------------------------------------
276 AC_DEFUN([AC_GGZ_LIBGGZ],
278 AC_MSG_CHECKING([for GGZ library: libggz])
280 ac_libggz_includes=NO ac_libggz_libraries=NO
281 libggz_libraries=""
282 libggz_includes=""
284 AC_ARG_WITH(libggz-dir,
285     AS_HELP_STRING([--with-libggz-dir=DIR],[libggz installation prefix]),
286     [  ac_libggz_includes="$withval"/include
287        ac_libggz_libraries="$withval"/lib
288     ])
289 AC_ARG_WITH(libggz-includes,
290     AS_HELP_STRING([--with-libggz-includes=DIR],[where the libggz includes are]),
291     [  ac_libggz_includes="$withval"
292     ])
293 AC_ARG_WITH(libggz-libraries,
294     AS_HELP_STRING([--with-libggz-libraries=DIR],[where the libggz libs are]),
295     [  ac_libggz_libraries="$withval"
296     ])
298 AC_CACHE_VAL(ac_cv_have_libggz,
300 libggz_incdirs="$ac_libggz_includes $ac_ggz_stdinc"
301 AC_GGZ_REMOVEDUPS($libggz_incdirs, libggz_incdirs)
302 libggz_header=ggz.h
304 AC_GGZ_FIND_FILE($libggz_header, $libggz_incdirs, libggz_incdir)
305 ac_libggz_includes="$libggz_incdir"
307 libggz_libdirs="$ac_libggz_libraries $ac_ggz_stdlib"
308 AC_GGZ_REMOVEDUPS($libggz_libdirs, libggz_libdirs)
310 libggz_libdir=NO
311 for dir in $libggz_libdirs; do
312   try="ls -1 $dir/libggz.la $dir/libggz.so"
313   if test -n "`$try 2> /dev/null`"; then libggz_libdir=$dir; break; else echo "tried $dir" >&AS_MESSAGE_LOG_FD ; fi
314 done
316 ac_libggz_libraries="$libggz_libdir"
318 if test "$ac_libggz_includes" = NO || test "$ac_libggz_libraries" = NO; then
319   ac_cv_have_libggz="have_libggz=no"
320   ac_libggz_notfound=""
321 else
322   have_libggz="yes"
326 eval "$ac_cv_have_libggz"
328 if test "$have_libggz" != yes; then
329   if test "x$2" = "xignore"; then
330     AC_MSG_RESULT([$have_libggz (ignored)])
331   else
332     AC_MSG_RESULT([$have_libggz])
333     if test "x$2" = "x"; then
334       AC_GGZ_ERROR(libggz, $libggz_incdirs, $libggz_libdirs)
335     fi
337     # perform actions given by argument 2.
338     $2
339   fi
340 else
341   ac_cv_have_libggz="have_libggz=yes \
342     ac_libggz_includes=$ac_libggz_includes ac_libggz_libraries=$ac_libggz_libraries"
343   AC_MSG_RESULT([$have_libggz (libraries $ac_libggz_libraries, headers $ac_libggz_includes)])
345   libggz_libraries="$ac_libggz_libraries"
346   libggz_includes="$ac_libggz_includes"
348   AC_SUBST(libggz_libraries)
349   AC_SUBST(libggz_includes)
351   LIBGGZ_INCLUDES="-I $libggz_includes"
352   LIBGGZ_ldflags="-L$libggz_libraries"
354   AC_SUBST(LIBGGZ_INCLUDES)
355   AC_SUBST(LIBGGZ_ldflags)
357   LIB_GGZ='-lggz'
358   AC_SUBST(LIB_GGZ)
360   # perform actions given by argument 1.
361   $1
366 dnl ------------------------------------------------------------------------
367 dnl Try to find the ggzcore headers and libraries.
368 dnl $(GGZCORE_LDFLAGS) will be -L ... (if needed)
369 dnl and $(GGZCORE_INCLUDES) will be -I ... (if needed)
370 dnl ------------------------------------------------------------------------
372 AC_DEFUN([AC_GGZ_GGZCORE],
374 AC_MSG_CHECKING([for GGZ library: ggzcore])
376 ac_ggzcore_includes=NO ac_ggzcore_libraries=NO
377 ggzcore_libraries=""
378 ggzcore_includes=""
380 AC_ARG_WITH(ggzcore-dir,
381     AS_HELP_STRING([--with-ggzcore-dir=DIR],[ggzcore installation prefix]),
382     [  ac_ggzcore_includes="$withval"/include
383        ac_ggzcore_libraries="$withval"/lib
384     ])
385 AC_ARG_WITH(ggzcore-includes,
386     AS_HELP_STRING([--with-ggzcore-includes=DIR],[where the ggzcore includes are]),
387     [  ac_ggzcore_includes="$withval"
388     ])
389 AC_ARG_WITH(ggzcore-libraries,
390     AS_HELP_STRING([--with-ggzcore-libraries=DIR],[where the ggzcore libs are]),
391     [  ac_ggzcore_libraries="$withval"
392     ])
394 AC_CACHE_VAL(ac_cv_have_ggzcore,
396 ggzcore_incdirs="$ac_ggzcore_includes $ac_ggz_stdinc"
397 AC_GGZ_REMOVEDUPS($ggzcore_incdirs, ggzcore_incdirs)
398 ggzcore_header=ggzcore.h
400 AC_GGZ_FIND_FILE($ggzcore_header, $ggzcore_incdirs, ggzcore_incdir)
401 ac_ggzcore_includes="$ggzcore_incdir"
403 ggzcore_libdirs="$ac_ggzcore_libraries $ac_ggz_stdlib"
404 AC_GGZ_REMOVEDUPS($ggzcore_libdirs, ggzcore_libdirs)
406 ggzcore_libdir=NO
407 for dir in $ggzcore_libdirs; do
408   try="ls -1 $dir/libggzcore.la $dir/libggzcore.so"
409   if test -n "`$try 2> /dev/null`"; then ggzcore_libdir=$dir; break; else echo "tried $dir" >&AS_MESSAGE_LOG_FD ; fi
410 done
412 ac_ggzcore_libraries="$ggzcore_libdir"
414 if test "$ac_ggzcore_includes" = NO || test "$ac_ggzcore_libraries" = NO; then
415   ac_cv_have_ggzcore="have_ggzcore=no"
416   ac_ggzcore_notfound=""
417 else
418   have_ggzcore="yes"
422 eval "$ac_cv_have_ggzcore"
424 if test "$have_ggzcore" != yes; then
425   if test "x$2" = "xignore"; then
426     AC_MSG_RESULT([$have_ggzcore (intentionally ignored)])
427   else
428     AC_MSG_RESULT([$have_ggzcore])
429     if test "x$2" = "x"; then
430       AC_GGZ_ERROR(ggzcore, $ggzcore_incdirs, $ggzcore_libdirs)
431     fi
433     # Perform actions given by argument 2.
434     $2
435   fi
436 else
437   ac_cv_have_ggzcore="have_ggzcore=yes \
438     ac_ggzcore_includes=$ac_ggzcore_includes ac_ggzcore_libraries=$ac_ggzcore_libraries"
439   AC_MSG_RESULT([$have_ggzcore (libraries $ac_ggzcore_libraries, headers $ac_ggzcore_includes)])
441   ggzcore_libraries="$ac_ggzcore_libraries"
442   ggzcore_includes="$ac_ggzcore_includes"
444   AC_SUBST(ggzcore_libraries)
445   AC_SUBST(ggzcore_includes)
447   GGZCORE_INCLUDES="-I $ggzcore_includes"
448   GGZCORE_LDFLAGS="-L$ggzcore_libraries"
450   AC_SUBST(GGZCORE_INCLUDES)
451   AC_SUBST(GGZCORE_LDFLAGS)
453   LIB_GGZCORE='-lggzcore'
454   AC_SUBST(LIB_GGZCORE)
456   # Perform actions given by argument 1.
457   $1
462 dnl ------------------------------------------------------------------------
463 dnl Try to find the ggz-config binary.
464 dnl Sets GGZ_CONFIG to the path/name of the program.
465 dnl Sets also: ggz_gamedir, ggz_datadir etc.
466 dnl ------------------------------------------------------------------------
468 AC_DEFUN([AC_GGZ_CONFIG],
470 AC_MSG_CHECKING([for GGZ configuration tool: ggz-config])
472 ac_ggz_config=NO
473 ggz_config=""
475 AC_ARG_WITH(ggzconfig,
476     AS_HELP_STRING([--with-ggzconfig=DIR],[path to ggz-config]),
477     [  ac_ggz_config="$withval"
478     ])
480 ac_ggz_config_orig=$ac_ggz_config
482 AC_CACHE_VAL(ac_cv_have_ggzconfig,
484 ggz_config_dirs="$ac_ggz_config $ac_ggz_stdbin"
486 AC_GGZ_FIND_FILE(ggz-config, $ggz_config_dirs, ggz_config_dir)
487 ac_ggz_config="$ggz_config_dir"
489 if test "$ac_ggz_config" = NO; then
490   ac_cv_have_ggzcore="have_ggz_config=no"
491   ac_ggz_config_notfound=""
492   have_ggz_config="no"
493 else
494   have_ggz_config="yes"
498 eval "$ac_cv_have_ggz_config"
500 if test "$have_ggz_config" != yes; then
501   if test "x$2" = "xignore"; then
502     AC_MSG_RESULT([$have_ggz_config (intentionally ignored)])
503     GGZ_CONFIG="true"
504     ggzexecmoddir="\${libdir}/ggz"
505     ggzdatadir="\${datadir}/ggz"
506     AC_SUBST(GGZ_CONFIG)
507     AC_SUBST(ggzexecmoddir)
508     AC_SUBST(ggzdatadir)
509     AC_DEFINE_UNQUOTED([GAMEDIR], ["${libdir}/ggz"], [Path where to install the games])
510     AC_DEFINE_UNQUOTED([GGZDATADIR], ["${datadir}/ggz"], [Path where the games should look for their data files])
511   else
512     AC_MSG_RESULT([$have_ggz_config])
513     if test "x$2" = "x"; then
514       AC_MSG_ERROR([ggz-config not found. Please check your installation! ])
515     fi
517     # Perform actions given by argument 2.
518     $2
519   fi
520 else
521   pathto_app=`echo $prefix/bin/ | tr -s "/"`
522   pathto_ggz=`echo $ac_ggz_config/ | tr -s "/"`
524   if test "$ac_ggz_config_orig" != "NO"; then
525     pathto_app=$pathto_ggz
526   fi
528   if test "x$pathto_app" != "x$pathto_ggz"; then
529     AC_MSG_RESULT([$have_ggz_config (dismissed due to different prefix)])
530     GGZ_CONFIG="true"
531     ggzexecmoddir="\${libdir}/ggz"
532     ggzdatadir="\${datadir}/ggz"
533     AC_SUBST(GGZ_CONFIG)
534     AC_SUBST(ggzexecmoddir)
535     AC_SUBST(ggzdatadir)
536     AC_DEFINE_UNQUOTED([GGZMODULECONFDIR], ["${sysconfdir}"], [Path where the game registry is located])
537     AC_DEFINE_UNQUOTED([GAMEDIR], ["${libdir}/ggz"], [Path where to install the games])
538     AC_DEFINE_UNQUOTED([GGZDATADIR], ["${datadir}/ggz"], [Path where the games should look for their data files])
539   else
540     ac_cv_have_ggz_config="have_ggz_config=yes \
541       ac_ggz_config=$ac_ggz_config"
542     AC_MSG_RESULT([$ac_ggz_config/ggz-config])
544     ggz_config="$ac_ggz_config"
545     AC_SUBST(ggz_config)
547     AC_ARG_ENABLE([noregistry],
548       AS_HELP_STRING([--enable-noregistry],[Do not register game modules.]),
549       [enable_noregistry=yes], [enable_noregistry=no])
551     GGZ_CONFIG="${ggz_config}/ggz-config"
552     if test "$enable_noregistry" = yes; then
553       GGZ_CONFIG="$GGZ_CONFIG --noregistry=$enableval"
554     fi
555     AC_SUBST(GGZ_CONFIG)
557     ggzmoduleconfdir=`$GGZ_CONFIG --configdir`
558     AC_DEFINE_UNQUOTED([GGZMODULECONFDIR], ["${ggzmoduleconfdir}"], [Path where the game registry is located])
559     ggzexecmoddir=`$GGZ_CONFIG --gamedir`
560     AC_DEFINE_UNQUOTED([GAMEDIR], ["${ggzexecmoddir}"], [Path where to install the games])
561     ggzdatadir=`$GGZ_CONFIG --datadir`
562     AC_DEFINE_UNQUOTED([GGZDATADIR], ["${ggzdatadir}"], [Path where the games should look for their data files])
563     packagesrcdir=`cd $srcdir && pwd`
564     AC_DEFINE_UNQUOTED([PACKAGE_SOURCE_DIR], ["${packagesrcdir}"], [Path where the source is located])
566     if test "$ggzmoduleconfdir" = ""; then
567       AC_MSG_ERROR([ggz-config is unusable. Maybe LD_LIBRARY_PATH needs to be set.])
568     fi
570     AC_SUBST(ggzmoduleconfdir)
571     AC_SUBST(ggzexecmoddir)
572     AC_SUBST(ggzdatadir)
573     AC_SUBST(packagesrcdir)
575     # Perform actions given by argument 1.
576     $1
577   fi
582 dnl ------------------------------------------------------------------------
583 dnl Try to find the ggzmod headers and libraries.
584 dnl $(GGZMOD_ldflags) will be -L ... (if needed)
585 dnl and $(GGZMOD_INCLUDES) will be -I ... (if needed)
586 dnl ------------------------------------------------------------------------
588 AC_DEFUN([AC_GGZ_GGZMOD],
590 AC_MSG_CHECKING([for GGZ library: ggzmod])
592 ac_ggzmod_includes=NO ac_ggzmod_libraries=NO
593 ggzmod_libraries=""
594 ggzmod_includes=""
596 AC_ARG_WITH(ggzmod-dir,
597     AS_HELP_STRING([--with-ggzmod-dir=DIR],[ggzmod installation prefix]),
598     [  ac_ggzmod_includes="$withval"/include
599        ac_ggzmod_libraries="$withval"/lib
600     ])
601 AC_ARG_WITH(ggzmod-includes,
602     AS_HELP_STRING([--with-ggzmod-includes=DIR],[where the ggzmod includes are]),
603     [  ac_ggzmod_includes="$withval"
604     ])
605 AC_ARG_WITH(ggzmod-libraries,
606     AS_HELP_STRING([--with-ggzmod-libraries=DIR],[where the ggzmod libs are]),
607     [  ac_ggzmod_libraries="$withval"
608     ])
610 AC_CACHE_VAL(ac_cv_have_ggzmod,
612 ggzmod_incdirs="$ac_ggzmod_includes $ac_ggz_stdinc"
613 AC_GGZ_REMOVEDUPS($ggzmod_incdirs, ggzmod_incdirs)
614 ggzmod_header=ggzmod.h
616 AC_GGZ_FIND_FILE($ggzmod_header, $ggzmod_incdirs, ggzmod_incdir)
617 ac_ggzmod_includes="$ggzmod_incdir"
619 ggzmod_libdirs="$ac_ggzmod_libraries $ac_ggz_stdlib"
620 AC_GGZ_REMOVEDUPS($ggzmod_libdirs, ggzmod_libdirs)
622 ggzmod_libdir=NO
623 for dir in $ggzmod_libdirs; do
624   try="ls -1 $dir/libggzmod.la $dir/libggzmod.so"
625   if test -n "`$try 2> /dev/null`"; then ggzmod_libdir=$dir; break; else echo "tried $dir" >&AS_MESSAGE_LOG_FD ; fi
626 done
628 ac_ggzmod_libraries="$ggzmod_libdir"
630 if test "$ac_ggzmod_includes" = NO || test "$ac_ggzmod_libraries" = NO; then
631   ac_cv_have_ggzmod="have_ggzmod=no"
632   ac_ggzmod_notfound=""
633 else
634   have_ggzmod="yes"
638 eval "$ac_cv_have_ggzmod"
640 if test "$have_ggzmod" != yes; then
641   if test "x$2" = "xignore"; then
642     AC_MSG_RESULT([$have_ggzmod (intentionally ignored)])
643   else
644     AC_MSG_RESULT([$have_ggzmod])
645     if test "x$2" = "x"; then
646       AC_GGZ_ERROR(ggzmod, $ggzmod_incdirs, $ggzmod_libdirs)
647     fi
649     # Perform actions given by argument 2.
650     $2
651   fi
652 else
653   ac_cv_have_ggzmod="have_ggzmod=yes \
654     ac_ggzmod_includes=$ac_ggzmod_includes ac_ggzmod_libraries=$ac_ggzmod_libraries"
655   AC_MSG_RESULT([$have_ggzmod (libraries $ac_ggzmod_libraries, headers $ac_ggzmod_includes)])
657   ggzmod_libraries="$ac_ggzmod_libraries"
658   ggzmod_includes="$ac_ggzmod_includes"
660   AC_SUBST(ggzmod_libraries)
661   AC_SUBST(ggzmod_includes)
663   GGZMOD_INCLUDES="-I $ggzmod_includes"
664   GGZMOD_ldflags="-L$ggzmod_libraries"
666   AC_SUBST(GGZMOD_INCLUDES)
667   AC_SUBST(GGZMOD_ldflags)
669   LIB_GGZMOD='-lggzmod'
670   AC_SUBST(LIB_GGZMOD)
672   # Perform actions given by argument 1.
673   $1
678 dnl ------------------------------------------------------------------------
679 dnl Try to find the ggzdmod headers and libraries.
680 dnl $(GGZDMOD_ldflags) will be -L ... (if needed)
681 dnl and $(GGZDMOD_INCLUDES) will be -I ... (if needed)
682 dnl ------------------------------------------------------------------------
684 AC_DEFUN([AC_GGZ_GGZDMOD],
686 AC_MSG_CHECKING([for GGZ library: ggzdmod])
688 ac_ggzdmod_includes=NO ac_ggzdmod_libraries=NO
689 ggzdmod_libraries=""
690 ggzdmod_includes=""
692 AC_ARG_WITH(ggzdmod-dir,
693     AS_HELP_STRING([--with-ggzdmod-dir=DIR],[ggzdmod installation prefix]),
694     [  ac_ggzdmod_includes="$withval"/include
695        ac_ggzdmod_libraries="$withval"/lib
696     ])
697 AC_ARG_WITH(ggzdmod-includes,
698     AS_HELP_STRING([--with-ggzdmod-includes=DIR],[where the ggzdmod includes are]),
699     [  ac_ggzdmod_includes="$withval"
700     ])
701 AC_ARG_WITH(ggzdmod-libraries,
702     AS_HELP_STRING([--with-ggzdmod-libraries=DIR],[where the ggzdmod libs are]),
703     [  ac_ggzdmod_libraries="$withval"
704     ])
706 AC_CACHE_VAL(ac_cv_have_ggzdmod,
708 ggzdmod_incdirs="$ac_ggzdmod_includes $ac_ggz_stdinc"
709 AC_GGZ_REMOVEDUPS($ggzdmod_incdirs, ggzdmod_incdirs)
710 ggzdmod_header=ggzdmod.h
712 AC_GGZ_FIND_FILE($ggzdmod_header, $ggzdmod_incdirs, ggzdmod_incdir)
713 ac_ggzdmod_includes="$ggzdmod_incdir"
715 ggzdmod_libdirs="$ac_ggzdmod_libraries $ac_ggz_stdlib"
716 AC_GGZ_REMOVEDUPS($ggzdmod_libdirs, ggzdmod_libdirs)
718 ggzdmod_libdir=NO
719 for dir in $ggzdmod_libdirs; do
720   try="ls -1 $dir/libggzdmod.la $dir/libggzdmod.so"
721   if test -n "`$try 2> /dev/null`"; then ggzdmod_libdir=$dir; break; else echo "tried $dir" >&AS_MESSAGE_LOG_FD ; fi
722 done
724 ac_ggzdmod_libraries="$ggzdmod_libdir"
726 if test "$ac_ggzdmod_includes" = NO || test "$ac_ggzdmod_libraries" = NO; then
727   ac_cv_have_ggzdmod="have_ggzdmod=no"
728   ac_ggzdmod_notfound=""
729 else
730   have_ggzdmod="yes"
734 eval "$ac_cv_have_ggzdmod"
736 if test "$have_ggzdmod" != yes; then
737   if test "x$2" = "xignore"; then
738     AC_MSG_RESULT([$have_ggzdmod (intentionally ignored)])
739   else
740     AC_MSG_RESULT([$have_ggzdmod])
741     if test "x$2" = "x"; then
742       AC_GGZ_ERROR(ggzdmod, $ggzdmod_incdirs, $ggzdmod_libdirs)
743     fi
745     # Perform actions given by argument 2.
746     $2
747   fi
748 else
749   ac_cv_have_ggzdmod="have_ggzdmod=yes \
750     ac_ggzdmod_includes=$ac_ggzdmod_includes ac_ggzdmod_libraries=$ac_ggzdmod_libraries"
751   AC_MSG_RESULT([$have_ggzdmod (libraries $ac_ggzdmod_libraries, headers $ac_ggzdmod_includes)])
753   ggzdmod_libraries="$ac_ggzdmod_libraries"
754   ggzdmod_includes="$ac_ggzdmod_includes"
756   AC_SUBST(ggzdmod_libraries)
757   AC_SUBST(ggzdmod_includes)
759   GGZDMOD_INCLUDES="-I $ggzdmod_includes"
760   GGZDMOD_ldflags="-L$ggzdmod_libraries"
762   AC_SUBST(GGZDMOD_INCLUDES)
763   AC_SUBST(GGZDMOD_ldflags)
765   LIB_GGZDMOD='-lggzdmod'
766   AC_SUBST(LIB_GGZDMOD)
768   # Perform actions given by argument 1.
769   $1
774 dnl ------------------------------------------------------------------------
775 dnl Try to find the ggz-gtk headers and libraries.
776 dnl $(GGZGTK_LDFLAGS) will be -L ... (if needed)
777 dnl and $(GGZGTK_INCLUDES) will be -I ... (if needed)
778 dnl ------------------------------------------------------------------------
780 AC_DEFUN([AC_GGZ_GTK],
782 AC_MSG_CHECKING([for GGZ library: ggz-gtk])
784 ac_ggz_gtk_includes=NO ac_ggz_gtk_libraries=NO
785 ggz_gtk_libraries=""
786 ggz_gtk_includes=""
788 AC_ARG_WITH(ggz-gtk-dir,
789     AS_HELP_STRING([--with-ggz-gtk-dir=DIR],[ggz-gtk installation prefix]),
790     [  ac_ggz_gtk_includes="$withval"/include
791        ac_ggz_gtk_libraries="$withval"/lib
792     ])
793 AC_ARG_WITH(ggz-gtk-includes,
794     AS_HELP_STRING([--with-ggz-gtk-includes=DIR],[where the ggz-gtk includes are]),
795     [  ac_ggz_gtk_includes="$withval"
796     ])
797 AC_ARG_WITH(ggz-gtk-libraries,
798     AS_HELP_STRING([--with-ggz-gtk-libraries=DIR],[where the ggz-gtk libs are]),
799     [  ac_ggz_gtk_libraries="$withval"
800     ])
802 AC_CACHE_VAL(ac_cv_have_ggz_gtk,
804 ggz_gtk_incdirs="$ac_ggz_gtk_includes $ac_ggz_stdinc"
805 AC_GGZ_REMOVEDUPS($ggz_gtk_incdirs, ggz_gtk_incdirs)
806 ggz_gtk_header=ggz-gtk.h
808 AC_GGZ_FIND_FILE($ggz_gtk_header, $ggz_gtk_incdirs, ggz_gtk_incdir)
809 ac_ggz_gtk_includes="$ggz_gtk_incdir"
811 ggz_gtk_libdirs="$ac_ggz_gtk_libraries $ac_ggz_stdlib"
812 AC_GGZ_REMOVEDUPS($ggz_gtk_libdirs, ggz_gtk_libdirs)
814 ggz_gtk_libdir=NO
815 for dir in $ggz_gtk_libdirs; do
816   try="ls -1 $dir/libggz-gtk.la $dir/libggz-gtk.so"
817   if test -n "`$try 2> /dev/null`"; then ggz_gtk_libdir=$dir; break; else echo "tried $dir" >&AS_MESSAGE_LOG_FD ; fi
818 done
820 ac_ggz_gtk_libraries="$ggz_gtk_libdir"
822 if test "$ac_ggz_gtk_includes" = NO || test "$ac_ggz_gtk_libraries" = NO; then
823   ac_cv_have_ggz_gtk="have_ggz_gtk=no"
824   ac_ggz_gtk_notfound=""
825 else
826   have_ggz_gtk="yes"
830 eval "$ac_cv_have_ggz_gtk"
832 if test "$have_ggz_gtk" != yes; then
833   if test "x$2" = "xignore"; then
834     AC_MSG_RESULT([$have_ggz_gtk (intentionally ignored)])
835   else
836     AC_MSG_RESULT([$have_ggz_gtk])
837     if test "x$2" = "x"; then
838       AC_GGZ_ERROR(ggz-gtk, $ggz_gtk_incdirs, $ggz_gtk_libdirs)
839     fi
841     # Perform actions given by argument 2.
842     $2
843   fi
844 else
845   ac_cv_have_ggz_gtk="have_ggz_gtk=yes \
846     ac_ggz_gtk_includes=$ac_ggz_gtk_includes ac_ggz_gtk_libraries=$ac_ggz_gtk_libraries"
847   AC_MSG_RESULT([$have_ggz_gtk (libraries $ac_ggz_gtk_libraries, headers $ac_ggz_gtk_includes)])
849   ggz_gtk_libraries="$ac_ggz_gtk_libraries"
850   ggz_gtk_includes="$ac_ggz_gtk_includes"
852   AC_SUBST(ggz_gtk_libraries)
853   AC_SUBST(ggz_gtk_includes)
855   GGZ_GTK_INCLUDES="-I $ggz_gtk_includes"
856   GGZ_GTK_ldflags="-L$ggz_gtk_libraries"
858   AC_SUBST(GGZ_GTK_INCLUDES)
859   AC_SUBST(GGZ_GTK_ldflags)
861   LIB_GGZ_GTK='-lggz-gtk'
862   AC_SUBST(LIB_GGZ_GTK)
864   # Perform actions given by argument 1.
865   $1
869 dnl ------------------------------------------------------------------------
870 dnl Setup the game server configuration.
871 dnl Sets ggzdconfdir (ggzd configuration).
872 dnl Sets ggzddatadir (for game server data).
873 dnl ------------------------------------------------------------------------
875 AC_DEFUN([AC_GGZ_SERVER],
877 AC_MSG_CHECKING([for GGZ server: ggzd])
878 AC_ARG_WITH(ggzd-confdir,
879     AS_HELP_STRING([--with-ggzd-confdir=DIR],[directory for room/game data]),
880 [ ac_ggzd_confdir="$withval"
883 AC_CACHE_VAL(ac_cv_have_ggzdconf,
885         if test "x$1" = "xforce"; then
886                 if test "x$ac_ggzd_confdir" = "x"; then
887                         ggzdconfdirs="$ac_ggz_stdetc"
888                 else
889                         ggzdconfdirs="$ac_ggzd_confdir"
890                 fi
891         else
892                 ggzdconfdirs="$ac_ggzd_confdir $ac_ggz_stdetc"
893         fi
895         ggzdconfdir=NONE
896         for dir in $ggzdconfdirs; do
897                 if test -n "`ls -d $dir/rooms 2> /dev/null`"; then
898                         if test -n "`ls -d $dir/rooms 2> /dev/null`"; then
899                                 ggzdconfdir=$dir; break;
900                         else
901                                 echo "tried $dir" >&AS_MESSAGE_LOG_FD;
902                         fi
903                 else
904                         echo "tried $dir" >&AS_MESSAGE_LOG_FD;
905                 fi
906         done
908         if test "x$ggzdconfdir" = "xNONE"; then
909                 have_ggzdconf="no"
910         else
911                 have_ggzdconf="yes"
912         fi
915 eval "$ac_cv_have_ggzdconf"
917 if test "$have_ggzdconf" != yes; then
918         if test "x$2" = "xignore"; then
919           AC_MSG_RESULT([$have_ggzdconf (intentionally ignored)])
920         elif test "x$2" = "xforce"; then
921           if test "x$ac_ggzd_confdir" = "x"; then
922             ggzdconfdir="\${sysconfdir}/ggzd"
923           else
924             ggzdconfdir=$ac_ggzd_confdir
925           fi
926           AC_MSG_RESULT([$have_ggzdconf (but forced to ${ggzdconfdir})])
927         else
928           AC_MSG_RESULT([$have_ggzdconf])
929           if test "x$2" = "x"; then
930             AC_MSG_ERROR([GGZ server configuration not found. Please check your installation! ])
931           fi
933           # Perform actions given by argument 2.
934           $2
935         fi
936 else
937         prefixed=0
938         if test "x${prefix}" != "xNONE" && test "x${prefix}" != "x${ac_default_prefix}"; then
939                 if test "x$ac_ggzd_confdir" = "x"; then
940                         prefixed=1
941                 fi
942         fi
943         if test "x$ggzdconfdir" != "x${sysconfdir}/ggzd" && test "x$prefixed" = "x1"; then
944                 AC_MSG_RESULT([$have_ggzdconf ($ggzdconfdir, but using ${sysconfdir}/ggzd nevertheless)])
945                 ggzdconfdir="\${sysconfdir}/ggzd"
946         else
947                 AC_MSG_RESULT([$have_ggzdconf ($ggzdconfdir)])
948         fi
951 if test "$have_ggzdconf" = yes || test "x$2" = "xforce"; then
952         AC_SUBST(ggzdconfdir)
954         ggzddatadir=${datadir}/${PACKAGE}
955         AC_DEFINE_UNQUOTED([GGZDDATADIR], ["${ggzddatadir}"], [Game server data directory])
956         AC_SUBST(ggzddatadir)
958         if test "x${libdir}" = 'x${exec_prefix}/lib'; then
959           if test "x${exec_prefix}" = "xNONE"; then
960             if test "x${prefix}" = "xNONE"; then
961               ggzdexecmoddir="\${ac_default_prefix}/lib/ggzd"
962               ggzdexecmodpath="${ac_default_prefix}/lib/ggzd"
963             else
964               ggzdexecmoddir="\${prefix}/lib/ggzd"
965               ggzdexecmodpath="${prefix}/lib/ggzd"
966             fi
967           else
968             ggzdexecmoddir="\${exec_prefix}/lib/ggzd"
969             ggzdexecmodpath="${exec_prefix}/lib/ggzd"
970           fi
971         else
972           ggzdexecmoddir="\${libdir}/ggzd"
973           ggzdexecmodpath="${libdir}/ggzd"
974         fi
975         AC_SUBST(ggzdexecmoddir)
976         AC_SUBST(ggzdexecmodpath)
978         # Perform actions given by argument 1.
979         $1
984 dnl ------------------------------------------------------------------------
985 dnl AC_GGZ_CHECK_SERVER
986 dnl   Check for presence of GGZ server libraries.
988 dnl   Simply call this function in programs that use GGZ.  GGZ_SERVER will
989 dnl   be #defined in config.h, and created as a conditional
990 dnl   in Makefile.am files, if server libraries are present.
991 dnl ------------------------------------------------------------------------
993 AC_DEFUN([AC_GGZ_CHECK_SERVER],
995   AC_GGZ_LIBGGZ([try_ggz="yes"], [try_ggz="no"])
996   if test "$try_ggz" = "yes"; then
997     # For now, version 0.0.14 is required.  This could be an additional
998     # parameter.
999     AC_GGZ_VERSION([0], [99], [4], [], [try_ggz=no])
1000   fi
1002   ggz_server="no"
1003   AC_ARG_WITH(ggz-server,
1004               AS_HELP_STRING([--with-ggz-server],[Force GGZ server support]),
1005               [try_ggz_server=$withval])
1007   if test "x$try_ggz_server" != "xno"; then
1008     if test "$try_ggz" = "yes"; then
1009       # Must pass something as the action-if-failed, or the macro will exit
1010       AC_GGZ_GGZDMOD([ggz_server="yes"], [ggz_server="no"])
1011     fi
1012     if test "$ggz_server" = "yes"; then
1013       AC_GGZ_SERVER
1014       AC_DEFINE([GGZ_SERVER], [1], [Server support for GGZ])
1015     else
1016       if test "$try_ggz_server" = "yes"; then
1017         AC_MSG_ERROR([Could not configure GGZ server support. See above messages.])
1018       fi
1019     fi
1020   fi
1022   AM_CONDITIONAL(GGZ_SERVER, test "$ggz_server" = "yes")
1025 dnl ------------------------------------------------------------------------
1026 dnl AC_GGZ_CHECK
1027 dnl   Check for presence of GGZ client and server libraries.
1029 dnl   Simply call this function in programs that use GGZ.  GGZ_SERVER and
1030 dnl   GGZ_CLIENT will be #defined in config.h, and created as conditionals
1031 dnl   in Makefile.am files.
1033 dnl   The only argument accepted gives the frontend for client embedding:
1034 dnl      "gtk" => means the libggz-gtk library will be checked
1035 dnl ------------------------------------------------------------------------
1037 AC_DEFUN([AC_GGZ_CHECK],
1039   AC_GGZ_INIT([defaults])
1041   if test x$ac_ggz_prefix != xno ; then
1042     AC_GGZ_LIBGGZ([try_ggz="yes"], [try_ggz="no"])
1043   else
1044     try_ggz=no
1045   fi
1047   if test "$try_ggz" = "yes"; then
1048     # For now, version 0.0.14 is required.  This could be an additional
1049     # parameter.
1050     AC_GGZ_VERSION([0], [0], [14], [], [try_ggz=no])
1051   fi
1053   ggz_client="no"
1054   AC_ARG_WITH(ggz-client,
1055               AS_HELP_STRING([--with-ggz-client],[Force GGZ client support]),
1056               [try_ggz_client=$withval])
1058   if test "x$try_ggz_client" != "xno"; then
1059     if test "$try_ggz" = "yes"; then
1060       # Must pass something as the action-if-failed, or the macro will exit
1061       AC_GGZ_GGZMOD([AC_GGZ_CONFIG([ggz_client="yes"], [ggz_client="no"])],
1062                     [ggz_client="no"])
1063     fi
1064     if test "$ggz_client" = "yes"; then
1065       AC_DEFINE([GGZ_CLIENT], [1], [Client support for GGZ])
1066     else
1067       if test "$try_ggz_client" = "yes"; then
1068         AC_MSG_ERROR([Could not configure GGZ client support. See above messages.])
1069       fi
1070     fi
1071   fi
1073   ggz_gtk="no"
1074   if test "$ggz_client" = "yes"; then
1075     if test "x$1" = "xgtk"; then
1076       AC_GGZ_GTK([ggz_gtk="yes"])
1077       if test $ggz_gtk = "yes"; then
1078         AC_DEFINE([GGZ_GTK], [1], [Support for embedded GGZ through libggz-gtk])
1079       fi
1080     fi
1081   fi
1083   AM_CONDITIONAL(GGZ_CLIENT, test "$ggz_client" = "yes")
1084   AM_CONDITIONAL(GGZ_GTK, test "$ggz_gtk" = "yes")
1086   AC_GGZ_CHECK_SERVER