xref: /freebsd/contrib/ntp/sntp/libopts/m4/libopts.m4 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1
2dnl do always before generated macros:
3dnl
4AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
5  AC_REQUIRE([AC_HEADER_STDC])
6  AC_HEADER_DIRENT
7
8  # =================
9  # AC_CHECK_HEADERS
10  # =================
11  AC_CHECK_HEADERS([ \
12      sys/mman.h    sys/param.h   sys/poll.h    sys/procset.h \
13      sys/select.h  sys/socket.h  sys/stropts.h sys/time.h \
14      sys/un.h      sys/wait.h    dlfcn.h       errno.h \
15      fcntl.h       libgen.h      libintl.h     memory.h \
16      netinet/in.h  setjmp.h      stdbool.h     sysexits.h \
17      unistd.h      utime.h])
18
19  AC_CHECK_HEADERS([stdarg.h     varargs.h],
20      [lo_have_arg_hdr=true;break],
21      [lo_have_arg_hdr=false])
22
23  AC_CHECK_HEADERS([string.h     strings.h],
24      [lo_have_str_hdr=true;break],
25      [lo_have_str_hdr=false])
26
27  AC_CHECK_HEADERS([limits.h     sys/limits.h  values.h],
28      [lo_have_lim_hdr=true;break],
29      [lo_have_lim_hdr=false])
30
31  AC_CHECK_HEADERS([inttypes.h   stdint.h],
32      [lo_have_typ_hdr=true;break],
33      [lo_have_typ_hdr=false])
34  gl_STDNORETURN_H
35
36  # ----------------------------------------------------------------------
37  # check for various programs used during the build.
38  # On OS/X, "wchar.h" needs "runetype.h" to work properly.
39  # ----------------------------------------------------------------------
40  AC_CHECK_HEADERS([runetype.h wchar.h], [], [],[
41  AC_INCLUDES_DEFAULT
42  #if HAVE_RUNETYPE_H
43  # include <runetype.h>
44  #endif
45  ])
46
47  AC_ARG_ENABLE([nls],
48  AS_HELP_STRING([--disable-nls],[disable nls support in libopts]))
49  AS_IF([test "x$enable_nls" != "xno" && \
50  test "X${ac_cv_header_libintl_h}" = Xyes], [
51  AC_DEFINE([ENABLE_NLS],[1],[nls support in libopts])])
52
53  # --------------------------------------------
54  # Verify certain entries from AC_CHECK_HEADERS
55  # --------------------------------------------
56  [${lo_have_arg_hdr} || \
57    ]AC_MSG_ERROR([you must have stdarg.h or varargs.h on your system])[
58
59  ${lo_have_str_hdr} || \
60    ]AC_MSG_ERROR([you must have string.h or strings.h on your system])[
61
62  ${lo_have_lim_hdr} || \
63    ]AC_MSG_ERROR(
64      [you must have one of limits.h, sys/limits.h or values.h])[
65
66  ${lo_have_typ_hdr} || \
67    ]AC_MSG_ERROR([you must have inttypes.h or stdint.h on your system])[
68
69  for f in sys_types sys_param sys_stat string errno stdlib memory setjmp
70  do eval as_ac_var=\${ac_cv_header_${f}_h}
71     test "X${as_ac_var}" = Xyes || {
72       ]AC_MSG_ERROR([you must have ${f}.h on your system])[
73     }
74  done
75  test "X${ac_cv_header_inttypes_h-no}" = Xyes || \
76    echo '#include <stdint.h>' > inttypes.h]
77
78  # ----------------------------------------------------------------------
79  # Checks for typedefs
80  # ----------------------------------------------------------------------
81  AC_CHECK_TYPES(wchar_t)
82  AC_CHECK_TYPES(wint_t, [], [], [
83    AC_INCLUDES_DEFAULT
84    #if HAVE_RUNETYPE_H
85    # include <runetype.h>
86    #endif
87    #if HAVE_WCHAR_H
88    # include <wchar.h>
89    #endif
90  ])
91  AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
92  intptr_t, uintptr_t, uint_t, pid_t, size_t, ptrdiff_t])
93  AC_CHECK_SIZEOF(char *, 8)
94  AC_CHECK_SIZEOF(int,    4)
95  AC_CHECK_SIZEOF(long,   8)
96  AC_CHECK_SIZEOF(short,  2)
97
98  # ------------
99  # AC_CHECK_LIB
100  # ------------
101  AC_CHECK_LIB(gen, pathfind)
102  AC_CHECK_LIB(intl,gettext)
103  AC_FUNC_VPRINTF
104  AC_FUNC_FORK
105  AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \
106                 strrchr strsignal fchmod fstat chmod])
107  AC_PROG_SED
108  [while :
109  do
110      test -x "$POSIX_SHELL" && break
111      POSIX_SHELL=`which bash`
112      test -x "$POSIX_SHELL" && break
113      POSIX_SHELL=`which dash`
114      test -x "$POSIX_SHELL" && break
115      POSIX_SHELL=/usr/xpg4/bin/sh
116      test -x "$POSIX_SHELL" && break
117      POSIX_SHELL=`/bin/sh -c '
118          exec 2>/dev/null
119          if ! true ; then exit 1 ; fi
120          echo /bin/sh'`
121      test -x "$POSIX_SHELL" && break
122      ]AC_MSG_ERROR([cannot locate a working POSIX shell])[
123  done]
124  AC_DEFINE_UNQUOTED([POSIX_SHELL], ["${POSIX_SHELL}"],
125           [define to a working POSIX compliant shell])
126  AC_SUBST([POSIX_SHELL])
127])
128
129dnl
130dnl @synopsis  INVOKE_LIBOPTS_MACROS
131dnl
132dnl  This macro will invoke the AutoConf macros specified in libopts.def
133dnl  that have not been disabled with "omit-invocation".
134dnl
135AC_DEFUN([LIBOPTS_WITH_REGEX_HEADER],[
136  AC_ARG_WITH([regex-header],
137    AS_HELP_STRING([--with-regex-header], [a reg expr header is specified]),
138    [libopts_cv_with_regex_header=${with_regex_header}],
139    AC_CACHE_CHECK([whether a reg expr header is specified], libopts_cv_with_regex_header,
140      libopts_cv_with_regex_header=no)
141  ) # end of AC_ARG_WITH
142  if test "X${libopts_cv_with_regex_header}" != Xno
143  then
144    AC_DEFINE_UNQUOTED([REGEX_HEADER],[<${libopts_cv_with_regex_header}>])
145  else
146    AC_DEFINE([REGEX_HEADER],[<regex.h>],[name of regex header file])
147  fi
148
149]) # end of AC_DEFUN of LIBOPTS_WITH_REGEX_HEADER
150
151
152AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
153  AC_ARG_WITH([libregex],
154    AS_HELP_STRING([--with-libregex], [libregex installation prefix]),
155    [libopts_cv_with_libregex_root=${with_libregex}],
156    AC_CACHE_CHECK([whether with-libregex was specified], libopts_cv_with_libregex_root,
157      libopts_cv_with_libregex_root=no)
158  ) # end of AC_ARG_WITH libregex
159
160  if test "${with_libregex+set}" = set && \
161     test "X${withval}" = Xno
162  then ## disabled by request
163    libopts_cv_with_libregex_root=no
164    libopts_cv_with_libregex_cflags=no
165    libopts_cv_with_libregex_libs=no
166  else
167
168  AC_ARG_WITH([libregex-cflags],
169    AS_HELP_STRING([--with-libregex-cflags], [libregex compile flags]),
170    [libopts_cv_with_libregex_cflags=${with_libregex_cflags}],
171    AC_CACHE_CHECK([whether with-libregex-cflags was specified], libopts_cv_with_libregex_cflags,
172      libopts_cv_with_libregex_cflags=no)
173  ) # end of AC_ARG_WITH libregex-cflags
174
175  AC_ARG_WITH([libregex-libs],
176    AS_HELP_STRING([--with-libregex-libs], [libregex link command arguments]),
177    [libopts_cv_with_libregex_libs=${with_libregex_libs}],
178    AC_CACHE_CHECK([whether with-libregex-libs was specified], libopts_cv_with_libregex_libs,
179      libopts_cv_with_libregex_libs=no)
180  ) # end of AC_ARG_WITH libregex-libs
181
182  case "X${libopts_cv_with_libregex_cflags}" in
183  Xyes|Xno|X )
184    case "X${libopts_cv_with_libregex_root}" in
185    Xyes|Xno|X ) libopts_cv_with_libregex_cflags=no ;;
186    * ) libopts_cv_with_libregex_cflags=-I${libopts_cv_with_libregex_root}/include ;;
187    esac
188  esac
189  case "X${libopts_cv_with_libregex_libs}" in
190  Xyes|Xno|X )
191    case "X${libopts_cv_with_libregex_root}" in
192    Xyes|Xno|X ) libopts_cv_with_libregex_libs=no ;;
193    * )        libopts_cv_with_libregex_libs="-L${libopts_cv_with_libregex_root}/lib -lregex" ;;
194    esac
195  esac
196  libopts_save_CPPFLAGS="${CPPFLAGS}"
197  libopts_save_LIBS="${LIBS}"
198  case "X${libopts_cv_with_libregex_cflags}" in
199  Xyes|Xno|X )
200    libopts_cv_with_libregex_cflags="" ;;
201  * ) CPPFLAGS="${CPPFLAGS} ${libopts_cv_with_libregex_cflags}" ;;
202  esac
203  case "X${libopts_cv_with_libregex_libs}" in
204  Xyes|Xno|X )
205    libopts_cv_with_libregex_libs="" ;;
206  * )
207    LIBS="${LIBS} ${libopts_cv_with_libregex_libs}" ;;
208  esac
209  LIBREGEX_CFLAGS=""
210  LIBREGEX_LIBS=""
211  AC_MSG_CHECKING([whether libregex functions properly])
212  AC_CACHE_VAL([libopts_cv_with_libregex],[
213  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <stdio.h>
214@%:@include <stdlib.h>
215@%:@include <sys/types.h>
216@%:@include REGEX_HEADER
217static regex_t re;
218void comp_re(char const * pzPat) {
219  int res = regcomp( &re, pzPat, REG_EXTENDED|REG_ICASE|REG_NEWLINE );
220  if (res == 0) return;
221  exit( res ); }
222int main() {
223  regmatch_t m@<:@2@:>@;
224  comp_re( "^.*\@S|@"   );
225  comp_re( "()|no.*" );
226  comp_re( "."       );
227  if (regexec( &re, "X", 2, m, 0 ) != 0)  return 1;
228  if ((m@<:@0@:>@.rm_so != 0) || (m@<:@0@:>@.rm_eo != 1)) {
229    fputs( "error: regex -->.<-- did not match\n", stderr );
230    return 1;
231  }
232  return 0; }] )],
233    [libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no],
234    [libopts_cv_with_libregex=no]) # end of AC_RUN_IFELSE
235  ]) # end of AC_CACHE_VAL for libopts_cv_with_libregex
236  fi ## disabled by request
237  AC_MSG_RESULT([${libopts_cv_with_libregex}])
238  if test "X${libopts_cv_with_libregex}" != Xno
239  then
240    AC_DEFINE([WITH_LIBREGEX],[1],
241        [Define this if a working libregex can be found])
242  else
243    CPPFLAGS="${libopts_save_CPPFLAGS}"
244    LIBS="${libopts_save_LIBS}"
245    libopts_cv_with_libregex_root=no
246libopts_cv_with_libregex_cflags=no
247libopts_cv_with_libregex_libs=no
248libopts_cv_with_libregex=no
249  fi
250
251]) # end of AC_DEFUN of LIBOPTS_WITHLIB_REGEX
252
253
254AC_DEFUN([LIBOPTS_RUN_PATHFIND],[
255  AC_MSG_CHECKING([whether pathfind(3) works])
256  AC_CACHE_VAL([libopts_cv_run_pathfind],[
257  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <string.h>
258@%:@include <stdlib.h>
259int main (int argc, char ** argv) {
260   char * pz = pathfind( getenv( "PATH" ), "sh", "x" );
261   return (pz == 0) ? 1 : 0;
262}] )],
263    [libopts_cv_run_pathfind=yes],[libopts_cv_run_pathfind=no],[libopts_cv_run_pathfind=no]
264  ) # end of RUN_IFELSE
265  ]) # end of AC_CACHE_VAL for libopts_cv_run_pathfind
266  AC_MSG_RESULT([${libopts_cv_run_pathfind}])
267  if test "X${libopts_cv_run_pathfind}" != Xno
268  then
269    AC_DEFINE([HAVE_PATHFIND],[1],
270        [Define this if pathfind(3) works])
271  fi
272
273]) # end of AC_DEFUN of LIBOPTS_RUN_PATHFIND
274
275
276AC_DEFUN([LIBOPTS_TEST_DEV_ZERO],[
277  AC_MSG_CHECKING([whether /dev/zero is readable device])
278  AC_CACHE_VAL([libopts_cv_test_dev_zero],[
279    libopts_cv_test_dev_zero=`exec 2> /dev/null
280dzero=\`ls -lL /dev/zero | egrep ^c......r\`
281test -z "${dzero}" && exit 1
282echo ${dzero}`
283    if test $? -ne 0 || test -z "$libopts_cv_test_dev_zero"
284    then libopts_cv_test_dev_zero=no
285    fi
286  ]) # end of CACHE_VAL of libopts_cv_test_dev_zero
287  AC_MSG_RESULT([${libopts_cv_test_dev_zero}])
288  if test "X${libopts_cv_test_dev_zero}" != Xno
289  then
290    AC_DEFINE([HAVE_DEV_ZERO],[1],
291        [Define this if /dev/zero is readable device])
292  fi
293
294]) # end of AC_DEFUN of LIBOPTS_TEST_DEV_ZERO
295
296
297AC_DEFUN([LIBOPTS_RUN_REALPATH],[
298  AC_MSG_CHECKING([whether we have a functional realpath(3C)])
299  AC_CACHE_VAL([libopts_cv_run_realpath],[
300  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <limits.h>
301@%:@include <stdlib.h>
302int main (int argc, char ** argv) {
303@%:@ifndef PATH_MAX
304choke me!!
305@%:@else
306   char zPath@<:@PATH_MAX+1@:>@;
307@%:@endif
308   char *pz = realpath(argv@<:@0@:>@, zPath);
309   return (pz == zPath) ? 0 : 1;
310}] )],
311    [libopts_cv_run_realpath=yes],[libopts_cv_run_realpath=no],[libopts_cv_run_realpath=no]
312  ) # end of RUN_IFELSE
313  ]) # end of AC_CACHE_VAL for libopts_cv_run_realpath
314  AC_MSG_RESULT([${libopts_cv_run_realpath}])
315  if test "X${libopts_cv_run_realpath}" != Xno
316  then
317    AC_DEFINE([HAVE_REALPATH],[1],
318        [Define this if we have a functional realpath(3C)])
319  fi
320
321]) # end of AC_DEFUN of LIBOPTS_RUN_REALPATH
322
323
324AC_DEFUN([LIBOPTS_RUN_STRFTIME],[
325  AC_MSG_CHECKING([whether strftime() works])
326  AC_CACHE_VAL([libopts_cv_run_strftime],[
327  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <time.h>
328@%:@include <string.h>
329char t_buf@<:@ 64 @:>@;
330int main() {
331  static char const z@<:@@:>@ = "Thursday Aug 28 240";
332  struct tm tm;
333  tm.tm_sec   = 36;  /* seconds after the minute @<:@0, 61@:>@  */
334  tm.tm_min   = 44;  /* minutes after the hour @<:@0, 59@:>@ */
335  tm.tm_hour  = 12;  /* hour since midnight @<:@0, 23@:>@ */
336  tm.tm_mday  = 28;  /* day of the month @<:@1, 31@:>@ */
337  tm.tm_mon   =  7;  /* months since January @<:@0, 11@:>@ */
338  tm.tm_year  = 86;  /* years since 1900 */
339  tm.tm_wday  =  4;  /* days since Sunday @<:@0, 6@:>@ */
340  tm.tm_yday  = 239; /* days since January 1 @<:@0, 365@:>@ */
341  tm.tm_isdst =  1;  /* flag for daylight savings time */
342  strftime( t_buf, sizeof( t_buf ), "%A %b %d %j", &tm );
343  return (strcmp( t_buf, z ) != 0); }] )],
344    [libopts_cv_run_strftime=yes],[libopts_cv_run_strftime=no],[libopts_cv_run_strftime=no]
345  ) # end of RUN_IFELSE
346  ]) # end of AC_CACHE_VAL for libopts_cv_run_strftime
347  AC_MSG_RESULT([${libopts_cv_run_strftime}])
348  if test "X${libopts_cv_run_strftime}" != Xno
349  then
350    AC_DEFINE([HAVE_STRFTIME],[1],
351        [Define this if strftime() works])
352  fi
353
354]) # end of AC_DEFUN of LIBOPTS_RUN_STRFTIME
355
356
357AC_DEFUN([LIBOPTS_RUN_FOPEN_BINARY],[
358  AC_MSG_CHECKING([whether fopen accepts "b" mode])
359  AC_CACHE_VAL([libopts_cv_run_fopen_binary],[
360  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <stdio.h>
361int main (int argc, char ** argv) {
362FILE * fp = fopen("conftest.@S|@ac_ext", "rb");
363return (fp == NULL) ? 1 : fclose(fp); }] )],
364    [libopts_cv_run_fopen_binary=yes],[libopts_cv_run_fopen_binary=no],[libopts_cv_run_fopen_binary=no]
365  ) # end of RUN_IFELSE
366  ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_binary
367  AC_MSG_RESULT([${libopts_cv_run_fopen_binary}])
368  if test "X${libopts_cv_run_fopen_binary}" != Xno
369  then
370    AC_DEFINE([FOPEN_BINARY_FLAG],"b",
371	[fopen(3) accepts a 'b' in the mode flag])
372  else
373    AC_DEFINE([FOPEN_BINARY_FLAG],"",
374	[fopen(3) accepts a 'b' in the mode flag])
375  fi
376
377]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_BINARY
378
379
380AC_DEFUN([LIBOPTS_RUN_FOPEN_TEXT],[
381  AC_MSG_CHECKING([whether fopen accepts "t" mode])
382  AC_CACHE_VAL([libopts_cv_run_fopen_text],[
383  AC_RUN_IFELSE([AC_LANG_SOURCE([@%:@include <stdio.h>
384int main (int argc, char ** argv) {
385FILE * fp = fopen("conftest.@S|@ac_ext", "rt");
386return (fp == NULL) ? 1 : fclose(fp); }] )],
387    [libopts_cv_run_fopen_text=yes],[libopts_cv_run_fopen_text=no],[libopts_cv_run_fopen_text=no]
388  ) # end of RUN_IFELSE
389  ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_text
390  AC_MSG_RESULT([${libopts_cv_run_fopen_text}])
391  if test "X${libopts_cv_run_fopen_text}" != Xno
392  then
393    AC_DEFINE([FOPEN_TEXT_FLAG],"t",
394	[fopen(3) accepts a 't' in the mode flag])
395  else
396    AC_DEFINE([FOPEN_TEXT_FLAG],"",
397	[fopen(3) accepts a 't' in the mode flag])
398  fi
399
400]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_TEXT
401
402
403AC_DEFUN([LIBOPTS_DISABLE_OPTIONAL_ARGS],[
404  AC_ARG_ENABLE([optional-args],
405    AS_HELP_STRING([--disable-optional-args], [not wanting optional option args]),
406    [libopts_cv_enable_optional_args=${enable_optional_args}],
407    AC_CACHE_CHECK([whether not wanting optional option args], libopts_cv_enable_optional_args,
408      libopts_cv_enable_optional_args=yes)
409  ) # end of AC_ARG_ENABLE
410  if test "X${libopts_cv_enable_optional_args}" = Xno
411  then
412    AC_DEFINE([NO_OPTIONAL_OPT_ARGS], [1],
413          [Define this if optional arguments are disallowed])
414  fi
415
416]) # end of AC_DEFUN of LIBOPTS_DISABLE_OPTIONAL_ARGS
417
418
419AC_DEFUN([INVOKE_LIBOPTS_MACROS],[
420  AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST])
421  # Check to see if a reg expr header is specified.
422  LIBOPTS_WITH_REGEX_HEADER
423
424  # Check to see if a working libregex can be found.
425  LIBOPTS_WITHLIB_REGEX
426
427  # Check to see if pathfind(3) works.
428  LIBOPTS_RUN_PATHFIND
429
430  # Check to see if /dev/zero is readable device.
431  LIBOPTS_TEST_DEV_ZERO
432
433  # Check to see if we have a functional realpath(3C).
434  LIBOPTS_RUN_REALPATH
435
436  # Check to see if strftime() works.
437  LIBOPTS_RUN_STRFTIME
438
439  # Check to see if fopen accepts "b" mode.
440  LIBOPTS_RUN_FOPEN_BINARY
441
442  # Check to see if fopen accepts "t" mode.
443  LIBOPTS_RUN_FOPEN_TEXT
444
445  # Check to see if not wanting optional option args.
446  LIBOPTS_DISABLE_OPTIONAL_ARGS
447
448]) # end AC_DEFUN of INVOKE_LIBOPTS_MACROS
449
450dnl @synopsis  LIBOPTS_CHECK
451dnl
452dnl If autoopts-config works, add the linking information to LIBS.
453dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all
454dnl the config tests that the library needs.  Invoke the
455dnl "INVOKE_LIBOPTS_MACROS" macro iff we are building libopts.
456dnl
457dnl  This file is part of AutoGen.
458dnl  AutoGen Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
459dnl
460dnl  AutoGen is free software: you can redistribute it and/or modify it
461dnl  under the terms of the GNU General Public License as published by the
462dnl  Free Software Foundation, either version 3 of the License, or
463dnl  (at your option) any later version.
464dnl
465dnl  AutoGen is distributed in the hope that it will be useful, but
466dnl  WITHOUT ANY WARRANTY; without even the implied warranty of
467dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
468dnl  See the GNU General Public License for more details.
469dnl
470dnl  You should have received a copy of the GNU General Public License along
471dnl  with this program.  If not, see <http://www.gnu.org/licenses/>.
472dnl
473dnl Default to system libopts
474dnl
475AC_DEFUN([LIBOPTS_CHECK_COMMON],[
476  AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST])
477  [NEED_LIBOPTS_DIR='']
478  m4_pushdef([AO_Libopts_Dir],
479	    [ifelse($1, , [libopts], [$1])])
480  AC_ARG_ENABLE([local-libopts],
481    AC_HELP_STRING([--enable-local-libopts],
482       [Use the supplied libopts tearoff code]),[
483    if test x$enableval = xyes ; then
484       AC_MSG_NOTICE([Using supplied libopts tearoff])
485       LIBOPTS_CFLAGS='-I$(top_srcdir)/AO_Libopts_Dir'
486       NEED_LIBOPTS_DIR=true
487       LIBOPTS_LDADD='$(top_builddir)/AO_Libopts_Dir/libopts.la'
488    fi])
489
490  AC_ARG_ENABLE([libopts-install],
491    AC_HELP_STRING([--enable-libopts-install],
492       [Install libopts with client installation]))
493  AM_CONDITIONAL([INSTALL_LIBOPTS],[test "X${enable_libopts_install}" = Xyes])
494
495  [if test -z "${NEED_LIBOPTS_DIR}" ; then]
496     AC_MSG_CHECKING([whether autoopts-config can be found])
497     AC_ARG_WITH([autoopts-config],
498        AC_HELP_STRING([--with-autoopts-config],
499             [specify the config-info script]),
500        [lo_cv_with_autoopts_config=${with_autoopts_config}],
501        AC_CACHE_CHECK([whether autoopts-config is specified],
502             [lo_cv_with_autoopts_config],
503             [if autoopts-config --help 2>/dev/null 1>&2
504        then lo_cv_with_autoopts_config=autoopts-config
505        elif libopts-config --help 2>/dev/null 1>&2
506        then lo_cv_with_autoopts_config=libopts-config
507        else lo_cv_with_autoopts_config=no ; fi])
508     ) # end of AC_ARG_WITH
509
510     AC_CACHE_VAL([lo_cv_test_autoopts],[
511        if test -z "${lo_cv_with_autoopts_config}" \
512                -o X"${lo_cv_with_autoopts_config}" = Xno
513        then
514           if autoopts-config --help 2>/dev/null 1>&2
515           then lo_cv_with_autoopts_config=autoopts-config
516           elif libopts-config --help 2>/dev/null 1>&2
517           then lo_cv_with_autoopts_config=libopts-config
518           else lo_cv_with_autoopts_config=false ; fi
519        fi
520        lo_cv_test_autoopts=`
521            ${lo_cv_with_autoopts_config} --libs` 2> /dev/null
522        if test $? -ne 0 -o -z "${lo_cv_test_autoopts}"
523        then lo_cv_test_autoopts=no ; fi
524     ]) # end of CACHE_VAL
525     AC_MSG_RESULT([${lo_cv_test_autoopts}])
526
527     [if test "X${lo_cv_test_autoopts}" != Xno
528     then
529        LIBOPTS_LDADD="${lo_cv_test_autoopts}"
530        LIBOPTS_CFLAGS="`${lo_cv_with_autoopts_config} --cflags`"
531     else
532        LIBOPTS_LDADD='$(top_builddir)/]AO_Libopts_Dir[/libopts.la'
533        LIBOPTS_CFLAGS='-I$(top_srcdir)/]AO_Libopts_Dir['
534        NEED_LIBOPTS_DIR=true
535     fi
536  fi # end of if test -z "${NEED_LIBOPTS_DIR}"
537  if test -n "${LIBOPTS_BUILD_BLOCKED}" ; then
538    NEED_LIBOPTS_DIR=''
539  fi]
540  AM_CONDITIONAL([NEED_LIBOPTS], [test -n "${NEED_LIBOPTS_DIR}"])
541  AC_SUBST(LIBOPTS_LDADD)
542  AC_SUBST(LIBOPTS_CFLAGS)
543  AC_SUBST(LIBOPTS_DIR, AO_Libopts_Dir)
544  m4_popdef([AO_Libopts_Dir])
545[# end of AC_DEFUN of LIBOPTS_CHECK_COMMON]
546])
547dnl
548dnl AC_CONFIG_FILES conditionalization requires using AM_COND_IF, however
549dnl AM_COND_IF is new to Automake 1.11.  To use it on new Automake without
550dnl requiring same, a fallback implementation for older Automake is provided.
551dnl Note that disabling of AC_CONFIG_FILES requires Automake 1.11, this code
552dnl is correct only in terms of m4sh generated script.
553dnl
554m4_ifndef([AM_COND_IF],
555  [AC_DEFUN([AM_COND_IF], [
556    if test -z "$$1_TRUE"; then :
557      m4_n([$2])[]dnl
558      m4_ifval([$3],[
559    else
560      $3
561    ])dnl
562    fi[]dnl
563  ])dnl
564])
565dnl
566AC_DEFUN([LIBOPTS_CHECK_NOBUILD], [
567  m4_pushdef([AO_Libopts_Dir],
568	      [ifelse($1, , [libopts], [$1])])
569  LIBOPTS_BUILD_BLOCKED=true
570  LIBOPTS_CHECK_COMMON(AO_Libopts_Dir)
571  m4_popdef([AO_Libopts_Dir])dnl
572# end of AC_DEFUN of LIBOPTS_CHECK_NOBUILD
573])
574dnl
575AC_DEFUN([LIBOPTS_CHECK], [
576  m4_pushdef([AO_Libopts_Dir],
577	      [ifelse($1, , [libopts], [$1])])
578  LIBOPTS_BUILD_BLOCKED=''
579  LIBOPTS_CHECK_COMMON(AO_Libopts_Dir)
580  AM_COND_IF([NEED_LIBOPTS], [
581    INVOKE_LIBOPTS_MACROS
582  ])
583  AC_CONFIG_FILES(AO_Libopts_Dir/Makefile)
584  m4_popdef([AO_Libopts_Dir])dnl
585# end of AC_DEFUN of LIBOPTS_CHECK
586])
587