1dnl
2dnl $Source$
3dnl $Date$
4dnl $Revision$
5dnl
6dnl DESCRIPTION:
7dnl Local macro definitions for Gambit configure.in
8dnl
9
10dnl ---------------------------------------------------------------------------
11dnl Macros for wxWidgets detection. Typically used in configure.in as:
12dnl
13dnl     AC_ARG_ENABLE(...)
14dnl     AC_ARG_WITH(...)
15dnl        ...
16dnl     AM_OPTIONS_WXCONFIG
17dnl        ...
18dnl        ...
19dnl     AM_PATH_WXCONFIG(2.6.0, wxWin=1)
20dnl     if test "$wxWin" != 1; then
21dnl        AC_MSG_ERROR([
22dnl                wxWidgets must be installed on your system
23dnl                but wx-config script couldn't be found.
24dnl
25dnl                Please check that wx-config is in path, the directory
26dnl                where wxWidgets libraries are installed (returned by
27dnl                'wx-config --libs' command) is in LD_LIBRARY_PATH or
28dnl                equivalent variable and wxWidgets version is 2.3.4 or above.
29dnl        ])
30dnl     fi
31dnl     CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS"
32dnl     CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS_ONLY"
33dnl     CFLAGS="$CFLAGS $WX_CFLAGS_ONLY"
34dnl
35dnl     LIBS="$LIBS $WX_LIBS"
36dnl ---------------------------------------------------------------------------
37
38dnl ---------------------------------------------------------------------------
39dnl AM_OPTIONS_WXCONFIG
40dnl
41dnl adds support for --wx-prefix, --wx-exec-prefix, --with-wxdir and
42dnl --wx-config command line options
43dnl ---------------------------------------------------------------------------
44
45AC_DEFUN([AM_OPTIONS_WXCONFIG],
46[
47    AC_ARG_WITH(wxdir,
48                [  --with-wxdir=PATH       Use uninstalled version of wxWidgets in PATH],
49                [ wx_config_name="$withval/wx-config"
50                  wx_config_args="--inplace"])
51    AC_ARG_WITH(wx-config,
52                [  --with-wx-config=CONFIG wx-config script to use (optional)],
53                wx_config_name="$withval" )
54    AC_ARG_WITH(wx-prefix,
55                [  --with-wx-prefix=PREFIX Prefix where wxWidgets is installed (optional)],
56                wx_config_prefix="$withval", wx_config_prefix="")
57    AC_ARG_WITH(wx-exec-prefix,
58                [  --with-wx-exec-prefix=PREFIX
59                          Exec prefix where wxWidgets is installed (optional)],
60                wx_config_exec_prefix="$withval", wx_config_exec_prefix="")
61])
62
63dnl Helper macro for checking if wx version is at least $1.$2.$3, set's
64dnl wx_ver_ok=yes if it is:
65AC_DEFUN([_WX_PRIVATE_CHECK_VERSION],
66[
67    wx_ver_ok=""
68    if test "x$WX_VERSION" != x ; then
69      if test $wx_config_major_version -gt $1; then
70        wx_ver_ok=yes
71      else
72        if test $wx_config_major_version -eq $1; then
73           if test $wx_config_minor_version -gt $2; then
74              wx_ver_ok=yes
75           else
76              if test $wx_config_minor_version -eq $2; then
77                 if test $wx_config_micro_version -ge $3; then
78                    wx_ver_ok=yes
79                 fi
80              fi
81           fi
82        fi
83      fi
84    fi
85])
86
87dnl ---------------------------------------------------------------------------
88dnl AM_PATH_WXCONFIG(VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND
89dnl                  [, WX-LIBS [, ADDITIONAL-WX-CONFIG-FLAGS]]]])
90dnl
91dnl Test for wxWidgets, and define WX_C*FLAGS, WX_LIBS and WX_LIBS_STATIC
92dnl (the latter is for static linking against wxWidgets). Set WX_CONFIG_NAME
93dnl environment variable to override the default name of the wx-config script
94dnl to use. Set WX_CONFIG_PATH to specify the full path to wx-config - in this
95dnl case the macro won't even waste time on tests for its existence.
96dnl
97dnl Optional WX-LIBS argument contains comma- or space-separated list of
98dnl wxWidgets libraries to link against (it may include contrib libraries). If
99dnl it is not specified then WX_LIBS and WX_LIBS_STATIC will contain flags to
100dnl link with all of the core wxWidgets libraries.
101dnl
102dnl Optional ADDITIONAL-WX-CONFIG-FLAGS argument is appended to wx-config
103dnl invocation command in present. It can be used to fine-tune lookup of
104dnl best wxWidgets build available.
105dnl
106dnl Example use:
107dnl   AM_PATH_WXCONFIG([2.6.0], [wxWin=1], [wxWin=0], [html,core,net]
108dnl                    [--unicode --debug])
109dnl ---------------------------------------------------------------------------
110
111dnl
112dnl Get the cflags and libraries from the wx-config script
113dnl
114AC_DEFUN([AM_PATH_WXCONFIG],
115[
116  dnl do we have wx-config name: it can be wx-config or wxd-config or ...
117  if test x${WX_CONFIG_NAME+set} != xset ; then
118     WX_CONFIG_NAME=wx-config
119  fi
120
121  if test "x$wx_config_name" != x ; then
122     WX_CONFIG_NAME="$wx_config_name"
123  fi
124
125  dnl deal with optional prefixes
126  if test x$wx_config_exec_prefix != x ; then
127     wx_config_args="$wx_config_args --exec-prefix=$wx_config_exec_prefix"
128     WX_LOOKUP_PATH="$wx_config_exec_prefix/bin"
129  fi
130  if test x$wx_config_prefix != x ; then
131     wx_config_args="$wx_config_args --prefix=$wx_config_prefix"
132     WX_LOOKUP_PATH="$WX_LOOKUP_PATH:$wx_config_prefix/bin"
133  fi
134  if test "$cross_compiling" = "yes"; then
135     wx_config_args="$wx_config_args --host=$host_alias"
136  fi
137
138  dnl don't search the PATH if WX_CONFIG_NAME is absolute filename
139  if test -x "$WX_CONFIG_NAME" ; then
140     AC_MSG_CHECKING(for wx-config)
141     WX_CONFIG_PATH="$WX_CONFIG_NAME"
142     AC_MSG_RESULT($WX_CONFIG_PATH)
143  else
144     AC_PATH_PROG(WX_CONFIG_PATH, $WX_CONFIG_NAME, no, "$WX_LOOKUP_PATH:$PATH")
145  fi
146
147  if test "$WX_CONFIG_PATH" != "no" ; then
148    WX_VERSION=""
149
150    min_wx_version=ifelse([$1], ,2.2.1,$1)
151    if test -z "$5" ; then
152      AC_MSG_CHECKING([for wxWidgets version >= $min_wx_version])
153    else
154      AC_MSG_CHECKING([for wxWidgets version >= $min_wx_version ($5)])
155    fi
156
157    WX_CONFIG_WITH_ARGS="$WX_CONFIG_PATH $wx_config_args $5 $4"
158
159    WX_VERSION=`$WX_CONFIG_WITH_ARGS --version 2>/dev/null`
160    wx_config_major_version=`echo $WX_VERSION | \
161           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
162    wx_config_minor_version=`echo $WX_VERSION | \
163           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
164    wx_config_micro_version=`echo $WX_VERSION | \
165           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
166
167    wx_requested_major_version=`echo $min_wx_version | \
168           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
169    wx_requested_minor_version=`echo $min_wx_version | \
170           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
171    wx_requested_micro_version=`echo $min_wx_version | \
172           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
173
174    _WX_PRIVATE_CHECK_VERSION([$wx_requested_major_version],
175                              [$wx_requested_minor_version],
176                              [$wx_requested_micro_version])
177
178    if test -n "$wx_ver_ok"; then
179
180      AC_MSG_RESULT(yes (version $WX_VERSION))
181      WX_LIBS=`$WX_CONFIG_WITH_ARGS --libs`
182
183      dnl is this even still appropriate?  --static is a real option now
184      dnl and WX_CONFIG_WITH_ARGS is likely to contain it if that is
185      dnl what the user actually wants, making this redundant at best.
186      dnl For now keep it in case anyone actually used it in the past.
187      AC_MSG_CHECKING([for wxWidgets static library])
188      WX_LIBS_STATIC=`$WX_CONFIG_WITH_ARGS --static --libs 2>/dev/null`
189      if test "x$WX_LIBS_STATIC" = "x"; then
190        AC_MSG_RESULT(no)
191      else
192        AC_MSG_RESULT(yes)
193      fi
194
195      dnl starting with version 2.2.6 wx-config has --cppflags argument
196      wx_has_cppflags=""
197      if test $wx_config_major_version -gt 2; then
198        wx_has_cppflags=yes
199      else
200        if test $wx_config_major_version -eq 2; then
201           if test $wx_config_minor_version -gt 2; then
202              wx_has_cppflags=yes
203           else
204              if test $wx_config_minor_version -eq 2; then
205                 if test $wx_config_micro_version -ge 6; then
206                    wx_has_cppflags=yes
207                 fi
208              fi
209           fi
210        fi
211      fi
212
213      dnl starting with version 2.7.0 wx-config has --rescomp option
214      wx_has_rescomp=""
215      if test $wx_config_major_version -gt 2; then
216        wx_has_rescomp=yes
217      else
218        if test $wx_config_major_version -eq 2; then
219           if test $wx_config_minor_version -ge 7; then
220              wx_has_rescomp=yes
221           fi
222        fi
223      fi
224      if test "x$wx_has_rescomp" = x ; then
225         dnl cannot give any useful info for resource compiler
226         WX_RESCOMP=
227      else
228         WX_RESCOMP=`$WX_CONFIG_WITH_ARGS --rescomp`
229      fi
230
231      if test "x$wx_has_cppflags" = x ; then
232         dnl no choice but to define all flags like CFLAGS
233         WX_CFLAGS=`$WX_CONFIG_WITH_ARGS --cflags`
234         WX_CPPFLAGS=$WX_CFLAGS
235         WX_CXXFLAGS=$WX_CFLAGS
236
237         WX_CFLAGS_ONLY=$WX_CFLAGS
238         WX_CXXFLAGS_ONLY=$WX_CFLAGS
239      else
240         dnl we have CPPFLAGS included in CFLAGS included in CXXFLAGS
241         WX_CPPFLAGS=`$WX_CONFIG_WITH_ARGS --cppflags`
242         WX_CXXFLAGS=`$WX_CONFIG_WITH_ARGS --cxxflags`
243         WX_CFLAGS=`$WX_CONFIG_WITH_ARGS --cflags`
244
245         WX_CFLAGS_ONLY=`echo $WX_CFLAGS | sed "s@^$WX_CPPFLAGS *@@"`
246         WX_CXXFLAGS_ONLY=`echo $WX_CXXFLAGS | sed "s@^$WX_CFLAGS *@@"`
247      fi
248
249      ifelse([$2], , :, [$2])
250
251    else
252
253       if test "x$WX_VERSION" = x; then
254          dnl no wx-config at all
255          AC_MSG_RESULT(no)
256       else
257          AC_MSG_RESULT(no (version $WX_VERSION is not new enough))
258       fi
259
260       WX_CFLAGS=""
261       WX_CPPFLAGS=""
262       WX_CXXFLAGS=""
263       WX_LIBS=""
264       WX_LIBS_STATIC=""
265       WX_RESCOMP=""
266       ifelse([$3], , :, [$3])
267
268    fi
269  else
270
271    WX_CFLAGS=""
272    WX_CPPFLAGS=""
273    WX_CXXFLAGS=""
274    WX_LIBS=""
275    WX_LIBS_STATIC=""
276    WX_RESCOMP=""
277
278    ifelse([$3], , :, [$3])
279
280  fi
281
282  AC_SUBST(WX_CPPFLAGS)
283  AC_SUBST(WX_CFLAGS)
284  AC_SUBST(WX_CXXFLAGS)
285  AC_SUBST(WX_CFLAGS_ONLY)
286  AC_SUBST(WX_CXXFLAGS_ONLY)
287  AC_SUBST(WX_LIBS)
288  AC_SUBST(WX_LIBS_STATIC)
289  AC_SUBST(WX_VERSION)
290  AC_SUBST(WX_RESCOMP)
291])
292
293dnl ---------------------------------------------------------------------------
294dnl Get information on the wxrc program for making C++, Python and xrs
295dnl resource files.
296dnl
297dnl     AC_ARG_ENABLE(...)
298dnl     AC_ARG_WITH(...)
299dnl        ...
300dnl     AM_OPTIONS_WXCONFIG
301dnl        ...
302dnl     AM_PATH_WXCONFIG(2.6.0, wxWin=1)
303dnl     if test "$wxWin" != 1; then
304dnl        AC_MSG_ERROR([
305dnl                wxWidgets must be installed on your system
306dnl                but wx-config script couldn't be found.
307dnl
308dnl                Please check that wx-config is in path, the directory
309dnl                where wxWidgets libraries are installed (returned by
310dnl                'wx-config --libs' command) is in LD_LIBRARY_PATH or
311dnl                equivalent variable and wxWidgets version is 2.6.0 or above.
312dnl        ])
313dnl     fi
314dnl
315dnl     AM_PATH_WXRC([HAVE_WXRC=1], [HAVE_WXRC=0])
316dnl     if test "x$HAVE_WXRC" != x1; then
317dnl         AC_MSG_ERROR([
318dnl                The wxrc program was not installed or not found.
319dnl
320dnl                Please check the wxWidgets installation.
321dnl         ])
322dnl     fi
323dnl
324dnl     CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS"
325dnl     CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS_ONLY"
326dnl     CFLAGS="$CFLAGS $WX_CFLAGS_ONLY"
327dnl
328dnl     LDFLAGS="$LDFLAGS $WX_LIBS"
329dnl ---------------------------------------------------------------------------
330
331
332
333dnl ---------------------------------------------------------------------------
334dnl AM_PATH_WXRC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
335dnl
336dnl Test for wxWidgets' wxrc program for creating either C++, Python or XRS
337dnl resources.  The variable WXRC will be set and substituted in the configure
338dnl script and Makefiles.
339dnl
340dnl Example use:
341dnl   AM_PATH_WXRC([wxrc=1], [wxrc=0])
342dnl ---------------------------------------------------------------------------
343
344dnl
345dnl wxrc program from the wx-config script
346dnl
347AC_DEFUN([AM_PATH_WXRC],
348[
349  AC_ARG_VAR([WXRC], [Path to wxWidget's wxrc resource compiler])
350
351  if test "x$WX_CONFIG_NAME" = x; then
352    AC_MSG_ERROR([The wxrc tests must run after wxWidgets test.])
353  else
354
355    AC_MSG_CHECKING([for wxrc])
356
357    if test "x$WXRC" = x ; then
358      dnl wx-config --utility is a new addition to wxWidgets:
359      _WX_PRIVATE_CHECK_VERSION(2,5,3)
360      if test -n "$wx_ver_ok"; then
361        WXRC=`$WX_CONFIG_WITH_ARGS --utility=wxrc`
362      fi
363    fi
364
365    if test "x$WXRC" = x ; then
366      AC_MSG_RESULT([not found])
367      ifelse([$2], , :, [$2])
368    else
369      AC_MSG_RESULT([$WXRC])
370      ifelse([$1], , :, [$1])
371    fi
372
373    AC_SUBST(WXRC)
374  fi
375])
376