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