1499c3cd5e058335b2e0b14cb897e1db7e234c5f
[sxemacs] / m4 / sxe-aux.m4
1 dnl sxe-aux.m4 -- just some auxiliary macros
2
3 dnl -------------------------------------------------------------------------
4 dnl Local macros
5 dnl -------------------------------------------------------------------------
6
7 AC_DEFUN([SXE_USAGE_ERROR], [dnl
8 (echo "$progbasename: Usage error:"
9 echo " " $1
10 echo "  Use \`$progname --help' to show usage.") >&2 && exit 1])
11
12 dnl SXE_PRINT_VAR(var var ...)  prints values of shell variables
13 AC_DEFUN([SXE_PRINT_VAR],[for var in patsubst([$1],[[
14 ]+],[ ]); do eval "echo \"$var = '\$$var'\""; done])
15
16 dnl SXE_ADD_RUNPATH_DIR(directory)
17 AC_DEFUN([SXE_ADD_RUNPATH_DIR], [dnl
18 {
19         xe_runpath_dir=$1
20         if test "$xe_runpath_dir" != "/lib" -a \
21                 "$xe_runpath_dir" != "/usr/lib" -a \
22                 -n "`ls ${xe_runpath_dir}/*.s[[ol]] 2>/dev/null`"; then
23                 eval "$xe_add_unique_runpath_dir"
24         fi
25 }
26 ])dnl SXE_ADD_RUNPATH_DIR
27
28
29 AC_DEFUN([SXE_CHECK_USER_SPECIFIED_P], [dnl
30         ## arg1 var-name to check for
31         ## generates a variable `arg1'_uspecified_p
32         pushdef([VARNAME], [$1])
33         pushdef([VARNAME_USPECIFIED_P], [$1_uspecified_p])
34         pushdef([USER_VARNAME], [USER_$1])
35
36         AC_MSG_CHECKING([for user specified ]VARNAME)
37         if test "${[]VARNAME[]-unset}" != "unset"; then
38                 VARNAME_USPECIFIED_P[]=yes;
39                 USER_VARNAME=${[]VARNAME[]}
40         else
41                 VARNAME_USPECIFIED_P[]=no;
42                 USER_VARNAME=
43         fi
44         AC_MSG_RESULT([$]VARNAME_USPECIFIED_P)
45         popdef([VARNAME])
46         popdef([VARNAME_USPECIFIED_P])
47         popdef([USER_VARNAME])
48 ])dnl SXE_CHECK_USER_SPECIFIED_P
49
50 AC_DEFUN([SXE_CHECK_USER_VARS], [dnl
51         ## If we don't set CFLAGS here, AC_PROG_CC will set it.
52         ## But we know better what's good for us, so we do our own
53         ## computation of real CFLAGS later.
54         SXE_CHECK_USER_SPECIFIED_P([CFLAGS])
55         SXE_CHECK_USER_SPECIFIED_P([CPPFLAGS])
56         SXE_CHECK_USER_SPECIFIED_P([LDFLAGS])
57         SXE_CHECK_USER_SPECIFIED_P([XFLAGS])
58         SXE_CHECK_USER_SPECIFIED_P([LIBS])
59         SXE_CHECK_USER_SPECIFIED_P([CC])
60         SXE_CHECK_USER_SPECIFIED_P([CPP])
61         SXE_CHECK_USER_SPECIFIED_P([AR])
62         SXE_CHECK_USER_SPECIFIED_P([YACC])
63         SXE_CHECK_USER_SPECIFIED_P([YFLAGS])
64         SXE_CHECK_USER_SPECIFIED_P([XMKMF])
65 ])dnl SXE_CHECK_USER_VARS
66
67
68 dnl A meta defun that can create those nifty SXE_ADD_*_OBJ macros
69 m4_define([__SXE_MAKE_ADDER], [
70         ## arg1 is the name to be used throughout m4
71         ## arg2 is the library sans _la or _a to be used in the Makefiles
72         ## arg3 are comma-separated additional vars to substitute
73         ## defines SXE_ADD_<arg1>_OBJ
74         ## defines SXE_ADD_<arg1>_OBJS
75         ## defines SXE_SUBST_<arg1>_OBJS
76
77         m4_define([SXE_ADD_]$1[_OBJ], [
78                 $2_objs="$$2_objs $2_a-]$[1]["
79                 if test "$extra_verbose" = "yes"; then
80                         echo "    sxemacs (cat. $1) will be linked with \"]$[1][\""
81                 fi
82         ])dnl
83
84         m4_define([SXE_ADD_]$1[_OBJS], [
85                 for i in ]$[1][; do
86                         ]SXE_ADD_[]$1[]_OBJ([$i])[
87                 done
88         ])dnl
89
90         m4_define([SXE_SUBST_]$1[_OBJS], [
91                 AC_SUBST($2_objs)
92                 ## subst additional vars
93                 m4_foreach_w([var], $3, [AC_SUBST(var)])
94                 ## also define a conditional
95                 AM_CONDITIONAL([NEED_]translit([$2], [-.a-z], [__A-Z]),
96                         [test -n "$$2_objs"])
97         ])dnl
98
99 ])dnl __SXE_MAKE_ADDER
100
101
102 dnl creates SXE_ADD_CORE_{OBJ,OBJS}
103 __SXE_MAKE_ADDER([CORE], [libsxecore])
104
105 dnl creates SXE_ADD_CRUFT_{OBJ,OBJS}
106 __SXE_MAKE_ADDER([CRUFT], [libcruft])
107
108 dnl creates SXE_ADD_DB_{OBJ,OBJS}
109 __SXE_MAKE_ADDER([DB], [libsxedb], [DB_CPPFLAGS DB_LDFLAGS DB_LIBS])
110
111 dnl creates SXE_ADD_ENT_{OBJ,OBJS}
112 __SXE_MAKE_ADDER([ENT], [libent])
113
114 dnl creates SXE_ADD_EVENTS_{OBJ,OBJS}
115 __SXE_MAKE_ADDER([EVENTS], [libsxeevents])
116
117 dnl creates SXE_ADD_MEMALLOC_{OBJ,OBJS}
118 __SXE_MAKE_ADDER([MEMALLOC], [libmemalloc])
119
120 dnl creates SXE_ADD_MM_{OBJ,OBJS}
121 __SXE_MAKE_ADDER([MM], [libmm])
122
123 dnl creates SXE_ADD_MULE_{OBJ,OBJS}
124 __SXE_MAKE_ADDER([MULE], [libmule])
125
126 dnl creates SXE_ADD_SXEUI_{OBJ,OBJS}
127 __SXE_MAKE_ADDER([SXEUI], [libsxeui])
128
129 dnl creates SXE_ADD_SXEUI_{OBJ,OBJS}
130 __SXE_MAKE_ADDER([SXEUITTY], [libsxeuiTTY])
131
132 dnl creates SXE_ADD_SXEUI_{OBJ,OBJS}
133 __SXE_MAKE_ADDER([SXEUIX11], [libsxeuiX11])
134
135 dnl SXE_ADD_STATMOD_A(foo.o ...)
136 AC_DEFUN([SXE_ADD_STATMOD_A], [
137         statmod_archives="$statmod_archives [$1]" && \
138         if test "$extra_verbose" = "yes"; then
139                 echo "    sxemacs (cat. static module) will be linked with \"[$1]\""
140         fi
141 ])dnl SXE_ADD_STATMOD_A
142 AC_DEFUN([SXE_SUBST_STATMOD_A], [AC_SUBST(statmod_archives)])
143
144 dnl SXE_APPEND(value, varname)
145 AC_DEFUN([SXE_APPEND],
146 [SXE_CONSECUTIVE_UNDUP($2,"$[$2] [$1]")
147  if test "$extra_verbose" = "yes"; then
148         echo "    Appending \"[$1]\" to [$2]
149         (now \"$[$2]\")"
150  fi])
151
152 dnl SXE_PREPEND(value, varname)
153 AC_DEFUN([SXE_PREPEND],
154 [SXE_CONSECUTIVE_UNDUP($2,"[$1] $[$2]")
155  if test "$extra_verbose" = "yes"; then
156         echo "    Prepending \"[$1]\" to [$2]
157         (now \"$[$2]\")"
158  fi])
159
160 dnl SXE_APPEND(value, varname)
161 AC_DEFUN([SXE_APPEND_UNDUP],
162 [SXE_UNDUP($2,"$[$2] [$1]")
163  if test "$extra_verbose" = "yes"; then
164         echo "    Appending and dedupping \"[$1]\" to [$2]
165         (now \"$[$2]\")"
166  fi])
167
168 dnl SXE_PREPEND(value, varname)
169 AC_DEFUN([SXE_PREPEND_UNDUP],
170 [SXE_UNDUP($2,"[$1] $[$2]")
171  if test "$extra_verbose" = "yes"; then
172         echo "    Prepending and dedupping \"[$1]\" to [$2]
173         (now \"$[$2]\")"
174  fi])
175
176 dnl SXE_DIE(message)
177 AC_DEFUN([SXE_DIE], [{ echo "Error:" $1 >&2; exit 1; }])
178
179
180 dnl some helpers
181 AC_DEFUN([SXE_INIT_MSG_LEVEL], [
182         sxe_msg_level=0
183 ])dnl SXE_INIT_MSG_LEVEL
184
185 AC_DEFUN([SXE_MSG_CHECKING], [
186         ## like AC_MSG_CHECKING but nestable
187         if test "$sxe_msg_level" -le 0; then
188                 AC_MSG_CHECKING([$1])
189         fi
190         sxe_msg_level=$(($sxe_msg_level + 1))
191 ])dnl SXE_MSG_CHECKING
192
193 AC_DEFUN([SXE_MSG_RESULT], [
194         ## like AC_MSG_RESULT but nestable
195         sxe_msg_level=$(($sxe_msg_level - 1))
196         if test "$sxe_msg_level" -le 0; then
197                 AC_MSG_RESULT([$1])
198         fi
199 ])dnl SXE_MSG_RESULT
200
201 dnl SXE_CHECK_FEATURE_DEPENDENCY(feature1, feature2)
202 AC_DEFUN([SXE_CHECK_FEATURE_DEPENDENCY],
203 [if test "$with_$1 $with_$2" = "yes no"; then
204         SXE_USAGE_ERROR("--with-$1 requires --with-$2")
205 elif test "$with_$2" = "no" ; then with_$1=no
206 elif test "$with_$1" = "yes"; then with_$2=yes
207 fi
208 ])
209
210 dnl SXE_STRIP_4TH_COMPONENT(var)
211 dnl Changes i986-pc-linux-gnu to i986-pc-linux, as God (not RMS) intended.
212 AC_DEFUN([SXE_STRIP_4TH_COMPONENT],
213 [$1=`echo "$$1" | sed '[s/^\([^-][^-]*-[^-][^-]*-[^-][^-]*\)-.*$/\1/]'`])
214
215 dnl AC_DEFUN([SXE_DEBUG_AC], [AS_MESSAGE($@)])
216 AC_DEFUN([SXE_DEBUG_AC], [])
217
218 dnl Do our best to deal with automounter brokenness
219 dnl SXE_CANONICALISE_PATH(varname)
220 AC_DEFUN([SXE_CANONICALISE_PATH], [dnl
221         ## arg #1 is the file/path to canonicalise
222         pushdef([tmpp], [$1])
223
224         SXE_DEBUG_AC([canonicalising \$]tmpp[: "]$[]tmpp["])
225
226         if test -d "/net"; then
227                 if test -d "/tmp_mnt/net"; then
228                         tdir="tmp_mnt/net";
229                 else
230                         tdir="tmp_mnt";
231                 fi
232                 tmpp[]=$(echo "[$]tmpp[]" | \
233                         sed -e "s|^${tdir}/|/net/|" \
234                             -e "s|^/a/|/net/|" \
235                             -e "s|^/amd/|/net/|")
236         fi
237
238 dnl     if test -d "[$]tmpp"; then
239 dnl             ## the easy way ...
240 dnl             ## just let the filesystem implementation do the hard work
241 dnl             tmpp[]=$(cd [$]tmpp[] && echo $(pwd))
242 dnl     elif test -f "[$]tmpp"; then
243 dnl             ## the easy way ...
244 dnl             ## just let the filesystem implementation do the hard work
245 dnl             tmpp[]=$(cd $(dirname [$]tmpp[]) && \
246 dnl                     echo $(pwd)/$(basename [$]tmpp[]))
247 dnl     else
248                 ## simple magic
249                 canonicalised="no"
250                 while test "$canonicalised" = "no"; do
251                         _SXE_CANONICALISE_STEP(tmpp,
252                                 [canonicalised="yes"], [canonicalised="no"])
253                 done
254 dnl     fi
255
256         SXE_DEBUG_AC([canonicalised \$]tmpp[: "]$[]tmpp["])
257         popdef([tmpp])
258 ])dnl SXE_CANONICALISE_PATH
259
260 AC_DEFUN([_SXE_CANONICALISE_STEP], [
261         ## _SXE_CANONICALISE_STEP( VAR, DO-ON-SUCCESS, DO-ON-FAILURE)
262         ## arg #1 is the varname to canonicalise
263         ## arg #2 is the code to execute on success
264         ## arg #3 is the code to execute on failure
265         pushdef([tmpvar], [$1])
266         pushdef([dosucc], [$2])
267         pushdef([dofail], [$3])
268
269         tmp2=[$]tmpvar
270         tmp3=
271         tmp4=$(basename "$tmp2")
272         ## assume we had success
273         dosucc
274         while test "$tmp4" != "/" -a "$tmp4" != "."; do
275                 if test "$tmp4" = ".." -a \
276                         $(basename $(dirname "$tmp2")) = "."; then
277                         ## we prepend and we know the path
278                         ## is still dirty but wont do anything
279                         ## alternative would be to prepend $(pwd) now
280                         dosucc
281                         tmp3="$(basename $tmp2)/$tmp3"
282                 elif test "$tmp4" = ".." -a \
283                         $(basename $(dirname "$tmp2")) != ".."; then
284                         tmp2=$(dirname "$tmp2")
285                 elif test "$tmp4" = ".."; then
286                         ## we prepend, but now we know the path
287                         ## is still dirty
288                         dofail
289                         tmp3="$(basename $tmp2)/$tmp3"
290                 elif test -n "$tmp3"; then
291                         ## ordinary component, just prepend
292                         tmp3="$(basename $tmp2)/$tmp3"
293                 else
294                         ## just set
295                         tmp3="$(basename $tmp2)"
296                 fi
297                 tmp2=$(dirname "$tmp2")
298                 tmp4=$(basename "$tmp2")
299         done
300
301         tmp3="$tmp4/$tmp3"
302         tmpvar[]=$(echo "$tmp3" | sed -e "s@//@/@g")
303
304         popdef([tmpvar])
305         popdef([dosucc])
306         popdef([dofail])
307 ])dnl _SXE_CANONICALISE_STEP
308
309
310 dnl SXE_PROTECT_LINKER_FLAGS(shell_var)
311 AC_DEFUN([SXE_PROTECT_LINKER_FLAGS], [
312 if test "$GCC" = "yes"; then
313   set x $[$1]; shift; [$1]=""
314   while test -n "[$]1"; do
315     case [$]1 in
316       -L  | -l  | -u               ) [$1]="$[$1] [$]1 [$]2"; shift ;;
317       -L* | -l* | -u* | -Wl* | -pg ) [$1]="$[$1] [$]1" ;;
318       -Xlinker* ) ;;
319       * ) [$1]="$[$1] -Xlinker [$]1" ;;
320     esac
321     shift
322   done
323 fi])dnl
324
325
326 dnl Allow use of either ":" or spaces for lists of directories
327 AC_DEFUN([SXE_COLON_TO_SPACE],
328   [case "$[$1]" in *:* [)] [$1]="`echo '' $[$1] | sed -e 's/^ //' -e 's/:/ /g'`";; esac])dnl
329
330
331 dnl The construct foo=`echo $w1 $w2 $w3` fails on some systems if $w1 = -e or -n
332 dnl So we use the following instead.
333 dnl SXE_SPACE(var, words)
334 AC_DEFUN([SXE_SPACE],[
335 T=""
336 for W in $2; do if test -z "$T"; then T="$W"; else T="$T $W"; fi; done
337 $1="$T"
338 ])dnl SXE_SPACE
339
340 dnl SXE_CONSECUTIVE_UNDUP(var, words)
341 AC_DEFUN([SXE_CONSECUTIVE_UNDUP],[
342 $1=`echo "$2" | ${AWK-awk} 'BEGIN {RS=" "} {if([$]1[] != SXEL) {printf "%s ", [$]1[]} SXEL=[$]1[]}' `
343 ])dnl SXE_CONSECUTIVE_UNDUP
344
345 dnl SXE_UNDUP(var, words)
346 AC_DEFUN([SXE_UNDUP],[
347 $1=`echo "$2" | ${AWK-awk} 'BEGIN {RS=" "} {VAL=[$]1[]; if(VAL in SXEL){}else{printf "%s ", VAL} SXEL[[VAL]]=1}' `
348 ])dnl SXE_UNDUP
349
350 \f
351 AC_DEFUN([SXE_LANG_WERROR], [dnl
352         dnl like AC_LANG_WERROR but working
353         dnl call goes: SXE_LANG_WERROR([on|off|push|pop|push+off|push+on])
354
355         pushdef([tmppush], [
356                 if test -n "$ac_c_werror_flag"; then
357                         sxe_cv_aux_werror_stack="on $sxe_cv_aux_werror_stack"
358                 else
359                         sxe_cv_aux_werror_stack="off $sxe_cv_aux_werror_stack"
360                 fi
361                 ])
362         pushdef([tmpon], [ac_c_werror_flag="-Werror"])
363         pushdef([tmpoff], [ac_c_werror_flag=""])
364
365         m4_if([$1], [on], [tmpon])
366
367         m4_if([$1], [off], [tmpoff])
368
369         m4_if([$1], [push], [tmppush])
370         m4_if([$1], [push+off], [
371                 tmppush
372                 tmpoff
373                 ])
374         m4_if([$1], [push+on], [
375                 tmppush
376                 tmpon
377                 ])
378
379         m4_if([$1], [pop], [
380                 ## thanks for the tip, Aidan
381                 $(echo $sxe_cv_aux_werror_stack | \
382                         read sxe_cv_tmp_stackcar sxe_cv_aux_werror_stack)
383                 if test "$sxe_cv_tmp_stackcar" = "on"; then
384                         tmpon
385                 elif test "$sxe_cv_tmp_stackcar" = "off"; then
386                         tmpoff
387                 else
388                         ## rather turn it off than on, dont ya think?
389                         tmpoff
390                 fi
391                 ])
392
393 ])dnl SXE_LANG_WERROR
394
395
396 AC_DEFUN([SXE_DUMP_LIBS], [
397         save_c_switch_site="$c_switch_site"
398         save_LIBS="$LIBS"
399         save_ld_switch_site="$ld_switch_site"
400         save_ld_switch_machine="$ld_switch_machine"
401         save_CC="$CC"
402         save_CFLAGS="$CFLAGS"
403         save_CPPFLAGS="$CPPFLAGS"
404         save_LDFLAGS="$LDFLAGS"
405
406         SXE_LANG_WERROR([push])
407 ])dnl SXE_DUMP_LIBS
408
409 AC_DEFUN([SXE_RESTORE_LIBS], [
410         LIBS="$save_LIBS"
411         c_switch_site="$save_c_switch_site"
412         ld_switch_site="$save_ld_switch_site"
413         ld_switch_machine="$save_ld_switch_machine"
414         CC="$save_CC"
415         CFLAGS="$save_CFLAGS"
416         CPPFLAGS="$save_CPPFLAGS"
417         LDFLAGS="$save_LDFLAGS"
418
419         SXE_LANG_WERROR([pop])
420 ])dnl SXE_RESTORE_LIBS
421
422 AC_DEFUN([SXE_SEARCH_CONFIG_PROG], [
423         ## arg #1 program to search
424         pushdef([config_prog], [$1])
425         pushdef([have_config_prog], [have_]translit([$1], [-.], [__]))
426         pushdef([CONFIG_PROG], translit([$1], [-.a-z], [__A-Z]))
427         AC_CHECK_PROG(have_config_prog, config_prog, [yes], [no])
428         AC_PATH_PROG(CONFIG_PROG, config_prog, [echo])
429         popdef([config_prog])
430         popdef([have_config_prog])
431         popdef([CONFIG_PROG])
432 ])dnl SXE_SEARCH_CONFIG_PROG
433
434
435 AC_DEFUN([_SXE_CHECK_pkgconfig_based], [
436         ## assumes $PKG_CONFIG is defined
437         ## arg #1: MM param name
438         ## arg #2: lib to check
439         ## arg #3: version of that lib
440
441         pushdef([IO_LIB], [$1])
442
443         AC_REQUIRE([SXE_CHECK_PKGCONFIG])
444
445         AC_MSG_CHECKING([for ]IO_LIB[ support])
446         AC_MSG_RESULT([])
447
448         if test "$have_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
449                 AS_MESSAGE([*** pkg-config not found. See http://pkgconfig.sourceforge.net])
450                 AS_MESSAGE([*** Cannot check for ]IO_LIB[.])
451                 have_pkg_config=no
452                 PKG_CONFIG=
453         fi
454
455         pushdef([IO_MOD], [$2])
456         pushdef([IO_MOD_REQUIRED_VERSION], [$3])
457         AC_MSG_CHECKING([whether ]IO_MOD[ is at least ]IO_MOD_REQUIRED_VERSION)
458         if test -n "$PKG_CONFIG" && \
459              $PKG_CONFIG --atleast-version IO_MOD_REQUIRED_VERSION IO_MOD; then
460                 IO_LIB[]_version=`$PKG_CONFIG --modversion []IO_MOD[]`
461                 AC_MSG_RESULT([yes ($]IO_LIB[_version)])
462                 have_[]IO_LIB[]_pkg="yes"
463                 ## define some useful variables
464                 IO_LIB[]_libs=`$PKG_CONFIG --libs []IO_MOD[]`
465                 IO_LIB[]_libs_L=`$PKG_CONFIG --libs-only-L []IO_MOD[]`
466                 IO_LIB[]_libs_l=`$PKG_CONFIG --libs-only-l []IO_MOD[]`
467                 IO_LIB[]_libs_other=`$PKG_CONFIG --libs-only-other []IO_MOD[]`
468                 IO_LIB[]_cflags=`$PKG_CONFIG --cflags []IO_MOD[]`
469                 IO_LIB[]_cflags_I=`$PKG_CONFIG --cflags-only-I []IO_MOD[]`
470                 IO_LIB[]_cflags_other=`$PKG_CONFIG --cflags-only-other []IO_MOD[]`
471         elif test -n "$PKG_CONFIG"; then
472                 IO_LIB[]_version=`$PKG_CONFIG --modversion []IO_MOD[]`
473                 AC_MSG_RESULT([no ($]IO_LIB[_version)])
474                 have_[]IO_LIB[]_pkg="no"
475         else
476                 have_[]IO_LIB[]_pkg="uncertain"
477                 AC_MSG_RESULT([$have_]IO_LIB[])
478         fi
479         popdef([IO_LIB])
480         popdef([IO_MOD_REQUIRED_VERSION])
481         popdef([IO_MOD])
482 ])dnl _SXE_CHECK_pkgconfig_based
483
484 AC_DEFUN([_SXE_MM_CHECK_pkgconfig_based], [
485         ## assumes $PKG_CONFIG is defined
486         ## arg #1: MM param name
487         ## arg #2: lib to check
488         ## arg #3: version of that lib
489         ## arg #4: funs to check
490         ## arg #5: headers to check
491         ## arg #6: success action
492         ## arg #7: failure action
493
494         pushdef([MM_LIB], [$1])
495         pushdef([MM_SUCC], [$6])
496         pushdef([MM_FAIL], [$7])
497
498         AC_REQUIRE([SXE_CHECK_PKGCONFIG])
499
500         AC_MSG_CHECKING([for ]MM_LIB[ support])
501         AC_MSG_RESULT([])
502
503         if test "$have_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
504                 AS_MESSAGE([*** pkg-config not found. See http://pkgconfig.sourceforge.net])
505                 AS_MESSAGE([*** Cannot check for ]MM_LIB[.])
506                 have_pkg_config=no
507                 PKG_CONFIG=
508                 MM_FAIL
509         fi
510
511         pushdef([MM_MOD], [$2])
512         pushdef([MM_MOD_REQUIRED_VERSION], [$3])
513         pushdef([MM_MOD_FUNS], [$4])
514         pushdef([MM_MOD_HDRS], [$5])
515         AC_MSG_CHECKING([whether ]MM_MOD[ is at least ]MM_MOD_REQUIRED_VERSION)
516         if test -n "$PKG_CONFIG" && \
517              $PKG_CONFIG --atleast-version MM_MOD_REQUIRED_VERSION MM_MOD; then
518                 actual_version=`$PKG_CONFIG --modversion []MM_MOD[]`
519                 AC_MSG_RESULT([yes ($actual_version)])
520                 AC_MSG_CHECKING([for ]mm_lib[ libraries])
521                 MM_MOD_LIBS_L=`$PKG_CONFIG --libs-only-l []MM_MOD[]`
522                 MM_MOD_LIBS=`echo $MM_MOD_LIBS_L | sed -e "s/-l//g"`
523                 MM_MOD_LIB=`echo $MM_MOD_LIBS | sed -e "s/ .*$//"`
524                 MM_MOD_OTHER_LIBS=`echo $MM_MOD_LIBS_L | sed -e "s/^[^ ]*//"`
525                 AC_MSG_RESULT([$MM_MOD_LIBS])
526
527                 ## backup our site flags
528                 SXE_DUMP_LIBS
529                 MM_MOD_LIBS_SITE=`$PKG_CONFIG --libs-only-L []MM_MOD[]`
530                 MM_MOD_HDRS_SITE=`$PKG_CONFIG --cflags-only-I []MM_MOD[]`
531                 SXE_PREPEND_UNDUP([$MM_MOD_HDRS_SITE], [CPPFLAGS])
532                 SXE_PREPEND_UNDUP([$MM_MOD_LIBS_SITE], [LDFLAGS])
533
534                 MM_SUCC
535                 SXE_CHECK_HEADERS([]MM_MOD_HDRS[], [:], [MM_FAIL])
536                 for i in MM_MOD_FUNS; do
537                         AC_CHECK_LIB([$MM_MOD_LIB], [$i], [:], [MM_FAIL],
538                                 [$MM_MOD_LIBS_L])
539                 done
540
541                 ## restore old values
542                 SXE_RESTORE_LIBS
543         elif test -n "$PKG_CONFIG"; then
544                 actual_version=`$PKG_CONFIG --modversion []MM_MOD[]`
545                 AC_MSG_RESULT([no ($actual_version)])
546         else
547                 AC_MSG_RESULT([uncertain])
548         fi
549         popdef([MM_LIB])
550         popdef([MM_MOD_FUNS])
551         popdef([MM_MOD_HDRS])
552         popdef([MM_MOD_REQUIRED_VERSION])
553         popdef([MM_MOD])
554         popdef([MM_SUCC])
555         popdef([MM_FAIL])
556 ])dnl _SXE_MM_CHECK_pkgconfig_based
557
558
559 AC_DEFUN([SXE_CHECK_SUFFICIENCY], [dnl
560         ## arg #1 is the option to check sufficiency on
561         ## arg #2 is a description
562         ## arg #3 are additional actions to perform when support is sufficient
563         ## arg #4 are additional actions to perform when support is insufficient
564         pushdef([og_group], translit([$1], [-], [_]))
565         pushdef([og_descr], [$2])
566         pushdef([OG_GROUP], translit([$1], [-a-z], [_A-Z]))
567         pushdef([IF_YES_DO], [$3])
568         pushdef([IF_NO_DO], [$4])
569
570         tmp=${[have_]og_group[]-uncertain}
571         if test "$with_[]og_group" != "no"; then
572                 AC_MSG_CHECKING([for sufficient ]og_descr[ support])
573                 AC_MSG_RESULT([$tmp])
574                 if test "$tmp" = "yes"; then
575                         AC_DEFINE([HAVE_]OG_GROUP, [1],
576                                 [Whether ]og_descr[ is doable])
577                         :
578                         IF_YES_DO
579                 else
580                         :
581                         IF_NO_DO
582                 fi
583         else
584                 :
585                 IF_NO_DO
586         fi
587         AM_CONDITIONAL([HAVE_]OG_GROUP,
588                 [test "$have_[]og_group" = "yes" -a "$with_[]og_group" != "no"])
589         popdef([og_group])
590         popdef([og_descr])
591         popdef([OG_GROUP])
592         popdef([IF_YES_DO])
593         popdef([IF_NO_DO])
594 ])dnl SXE_CHECK_SUFFICIENCY
595
596
597 AC_DEFUN([SXE_CHECK_HEADERS], [dnl
598         dnl One day, this macro will only check for headers if
599         dnl their presence is yet unknown
600         AC_CHECK_HEADERS($1,$2,$3,$4)
601 ])dnl SXE_CHECK_HEADERS
602
603 AC_DEFUN([SXE_CHECK_LIB_FUNCS], [dnl
604         pushdef([SXE_LIB], [$1])
605         pushdef([SXE_FUNCS], [$2])
606
607         for i in SXE_LIB; do
608                 for j in SXE_FUNCS; do
609                         AC_CHECK_LIB([$i], [$j], [:], [:])
610                 done
611         done
612
613         popdef([SXE_LIB])
614         popdef([SXE_FUNCS])
615 ])dnl SXE_CHECK_LIB_FUNCS
616
617
618 AC_DEFUN([_SXE_CHECK_PURE_OPT], [dnl
619         unq_opt=$(echo $1 | tr -d "'\"")
620
621         case "$unq_opt" in
622         ## first autoconf's options
623         --enable-largefile | --disable-largefile | \
624         --enable-dependency-tracking | --disable-dependency-tracking | \
625         --enable-option-checking | --disable-option-checking | \
626         --with-x | --x-includes | --x-libraries | \
627         --build | --host | \
628         --program-prefix | --program-suffix | --program-transform-name | \
629         --prefix | --exec-prefix | --bindir | --sbindir | \
630         --libexecdir | --sysconfdir | \
631         --sharedstatedir | --localstatedir | \
632         --libdir | --includedir | --oldincludedir | \
633         --datarootdir | --datadir | --infodir | --localedir | \
634         --mandir | --docdir | --htmldir | --dvidir | --pdfdir | --psdir | \
635         -n | --no-create | -C | --config-cache | --cache-file | \
636         -q | --quiet | --silent | --version )
637                 AC_MSG_CHECKING([if option $1 is known])
638                 AC_MSG_RESULT([yes])
639                 ;;
640
641         ## now the hard-coded libtool ones
642         --enable-ltdl-install | --disable-ltdl-install | \
643         --enable-ltdl-convenience | --disable-ltdl-convenience | \
644         --enable-libtool-lock | --disable-libtool-lock | \
645         --enable-fast-install | --disable-fast-install | \
646         --enable-shared | --disable-shared | \
647         --enable-static | --disable-static | \
648         --with-gcc-arch | --with-pic | --with-included-ltdl )
649                 AC_MSG_CHECKING([if option $1 is known])
650                 AC_MSG_RESULT([yes])
651                 ;;
652
653         ## now our own stuff
654         --enable-* | --disable-* )
655                 AC_MSG_CHECKING([if option $1 is known])
656                 strp_opt=$(echo $unq_opt | \
657                         sed -e "s/^--enable-//g" -e "s/^--disable-//g")
658                 OG_CHECK_OPTION([enable], [$strp_opt],
659                         AC_MSG_RESULT([yes]),
660                         AC_MSG_RESULT([no])
661                         [bogus_cmd_opts="$bogus_cmd_opts $unq_opt"])
662                 ;;
663         ## more of our own
664         --with-* | --without-* )
665                 AC_MSG_CHECKING([if option $1 is known])
666                 strp_opt=$(echo $unq_opt | \
667                         sed -e "s/^--with-//g" -e "s/^--without-//g")
668                 OG_CHECK_OPTION([with], [$strp_opt],
669                         AC_MSG_RESULT([yes]),
670                         AC_MSG_RESULT([no])
671                         [bogus_cmd_opts="$bogus_cmd_opts $unq_opt"])
672                 ;;
673
674         ## strange constructions
675         -* )
676                 case "$1" in
677                 \'-*)
678                         AC_MSG_CHECKING([if option $1 is known])
679                         AC_MSG_RESULT([no])
680                         bogus_cmd_opts="$bogus_cmd_opts $unq_opt"
681                         ;;
682                 esac
683                 ;;
684         ## rest goes here
685         * )
686                 ## whatever that is
687                 ;;
688         esac
689 ])dnl _SXE_CHECK_PURE_OPT
690
691 AC_DEFUN([SXE_CHECK_COMMAND_LINE], [dnl
692         dnl Check for bogus options
693         sxe_with_options="$sxe_with_options x"
694         cmd_line_args="$ac_configure_args"
695
696         ## make sure our bogus stuff is empty once we get into here
697         ## this allows us to call this stuff more than once
698         ## (which never happens of course)
699         bogus_cmd_opts=""
700
701         for opt in $cmd_line_args; do
702                 pure_opt=$(echo $opt | sed -e "s/=.*$//g")
703                 _SXE_CHECK_PURE_OPT([$pure_opt])
704         done
705
706         dnl Final command line argument checks.
707         dnl --with-quantify or --with-purify imply --with-system-malloc
708         if test "$with_purify" = "yes" -o "$with_quantify" = "yes"; then
709                 if test "$with_system_malloc" = "default"; then
710                         with_system_malloc="yes"
711                 fi
712         fi
713 ])dnl SXE_CHECK_COMMAND_LINE
714
715
716 AC_DEFUN([SXE_EXPAND_VAR], [dnl
717         ## arg #1 the variable to expand
718         ## arg #2 (optional) the variable to put the result in
719         pushdef([VAR], [$1])
720         pushdef([RES], ifelse($2,[],[sxe_cv_tmp_expand_var],$2))
721
722         RES=[]VAR[]
723         __tmp=
724         while test "${RES}" != "${__tmp}"; do
725                 __tmp=${RES}
726                 RES=$(eval echo ${__tmp})
727         done
728         popdef([RES])
729         popdef([VAR])
730 ])dnl SXE_EXPAND_VAR
731
732
733 dnl sxe-aux.m4 ends here