acinclude.m4 7.88 KB
Newer Older
1
dnl (progn (modify-syntax-entry ?' "'") (modify-syntax-entry ?` "'"))
Niels Möller's avatar
Niels Möller committed
2
dnl AC_CHECK_MEMBER(includes, struct, field)
Pavel Roskin's avatar
Pavel Roskin committed
3
AC_DEFUN([AC_CHECK_MEMBER],
Niels Möller's avatar
Niels Möller committed
4
5
6
7
8
9
10
11
[ AC_CACHE_CHECK([if $2 has member $3],
    lsh_cv_decl_struct_$2_$3,
    [AC_TRY_COMPILE([$1],
changequote(<{, }>)dnl
      <{ struct $2 x; (void) &x.$3; }>,
changequote([, ])dnl
      [lsh_cv_decl_struct_$2_$3=yes],
      [lsh_cv_decl_struct_$2_$3=no])])
12
  if test x$lsh_cv_decl_struct_$2_$3 = xyes; then
Niels Möller's avatar
Niels Möller committed
13
14
15
16
    AC_DEFINE_UNQUOTED(`echo HAVE_$3 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`)
  fi
])

17
dnl AC_CHECK_VAR(VAR, TYPE)
Pavel Roskin's avatar
Pavel Roskin committed
18
AC_DEFUN([AC_CHECK_VAR],
Niels Möller's avatar
Niels Möller committed
19
20
21
[ AC_CACHE_CHECK(
    [for $1],
    lsh_cv_var_$1,
22
    AC_TRY_LINK(, [extern $2 $1; void *p = (void *) &$1;],
Niels Möller's avatar
Niels Möller committed
23
24
25
26
27
28
29
30
		[lsh_cv_var_$1=yes],
		[lsh_cv_var_$1=no]))
  if eval "test \"`echo '$lsh_cv_var_'$1`\" = yes"; then
    AC_DEFINE_UNQUOTED(HAVE_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`)
  fi
])

dnl Try to detect the type of the third arg to getsockname() et al
Pavel Roskin's avatar
Pavel Roskin committed
31
AC_DEFUN([AC_TYPE_SOCKLEN_T],
32
[AC_CACHE_CHECK([for socklen_t in sys/socket.h], ac_cv_type_socklen_t,
Niels Möller's avatar
Niels Möller committed
33
[AC_EGREP_HEADER(socklen_t, sys/socket.h,
34
  [ac_cv_type_socklen_t=yes], [ac_cv_type_socklen_t=no])])
Niels Möller's avatar
Niels Möller committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if test $ac_cv_type_socklen_t = no; then
        AC_MSG_CHECKING(for AIX)
        AC_EGREP_CPP(yes, [
#ifdef _AIX
 yes
#endif
],[
AC_MSG_RESULT(yes)
AC_DEFINE(socklen_t, size_t)
],[
AC_MSG_RESULT(no)
AC_DEFINE(socklen_t, int)
])
fi
])
50

51
dnl checks for gmp version 2 or later. 
52
dnl AC_CHECK_LIBGMP(library, [, if-found [, if-not-found]])
Pavel Roskin's avatar
Pavel Roskin committed
53
AC_DEFUN([AC_CHECK_LIBGMP],
54
55
56
57
[AC_CACHE_CHECK([for mpz_get_d in -l$1], ac_cv_lib_$1_mpz_get_d,
[ac_save_libs="$LIBS"
LIBS="-l$1 $LIBS"
AC_TRY_LINK(dnl
58
59
60
61
62
[#if HAVE_GMP_H
#include <gmp.h>
#elif HAVE_GMP2_GMP_H
#include <gmp2/gmp.h>
#endif
63
64
65
66
67
68
69
70
71
72
73
],
[mpz_get_d(0);],
ac_cv_lib_$1_mpz_get_d=yes,
ac_cv_lib_$1_mpz_get_d=no)
LIBS="$ac_save_LIBS"
])
if test x$ac_cv_lib_$1_mpz_get_d = xyes ; then
ifelse([$2], ,
[AC_DEFINE(HAVE_LIBGMP)
LIBS="-l$1 $LIBS"
], [$2])
74
75
76
77
78
79
80
81
82
ifelse([$3], , ,
[else
$3
])dnl
fi
])

dnl checks for gmp version 2 or later. 
dnl AC_SEARCH_LIBGMP(libraries, [, if-found [, if-not-found]])
Pavel Roskin's avatar
Pavel Roskin committed
83
AC_DEFUN([AC_SEARCH_LIBGMP],
84
85
86
87
[AC_CACHE_CHECK([for library containing mpz_get_d], ac_cv_search_mpz_get_d,
[ac_search_save_LIBS="$LIBS"
ac_cv_search_mpz_get_d="no"
for i in $1; do
88
LIBS="-l$i $ac_search_save_LIBS"
89
AC_TRY_LINK(dnl
90
91
92
93
94
[#if HAVE_GMP_H
#include <gmp.h>
#elif HAVE_GMP2_GMP_H
#include <gmp2/gmp.h>
#endif
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
],
[mpz_get_d(0);],
[ac_cv_search_mpz_get_d=-l$i
break
])
done
LIBS="$ac_search_save_LIBS"
])
if test "x$ac_cv_search_mpz_get_d" != xno ; then
  LIBS="$ac_cv_search_mpz_get_d $LIBS"
ifelse([$2], ,
[AC_DEFINE(HAVE_LIBGMP)
], [$2])
ifelse([$3], , ,
[else
$3
111
112
113
114
])dnl
fi
])

115
dnl LSH_PATH_ADD(path-id, directory)
Pavel Roskin's avatar
Pavel Roskin committed
116
AC_DEFUN([LSH_PATH_ADD],
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
[AC_MSG_CHECKING($2)
ac_exists=no
if test -d "$2/." ; then
  ac_real_dir=`cd $2 && pwd`
  if test -n "$ac_real_dir" ; then
    ac_exists=yes
    for old in $1_REAL_DIRS ; do
      ac_found=no
      if test x$ac_real_dir = x$old ; then
        ac_found=yes;
	break;
      fi
    done
    if test $ac_found = yes ; then
      AC_MSG_RESULT(already added)
    else
      AC_MSG_RESULT(added)
134
      # LDFLAGS="$LDFLAGS -L $2"
135
136
137
138
139
140
141
142
143
144
145
      $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS"
      $1_DIRS="$2 [$]$1_DIRS"
    fi
  fi
fi
if test $ac_exists = no ; then
  AC_MSG_RESULT(not found)
fi
])

dnl LSH_RPATH_ADD(dir)
Pavel Roskin's avatar
Pavel Roskin committed
146
AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)])
147
148

dnl LSH_RPATH_INIT(candidates)
Pavel Roskin's avatar
Pavel Roskin committed
149
AC_DEFUN([LSH_RPATH_INIT],
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
[AC_MSG_CHECKING([for -R flag])
RPATHFLAG=''
case `uname -sr` in
  OSF1\ V4.*)
    RPATHFLAG="-rpath "
    ;;
  IRIX\ 6.*)
    RPATHFLAG="-rpath "
    ;;
  IRIX\ 5.*)
    RPATHFLAG="-rpath "
    ;;
  SunOS\ 5.*)
    if test "$TCC" = "yes"; then
      # tcc doesn't know about -R
      RPATHFLAG="-Wl,-R,"
    else
      RPATHFLAG=-R
    fi
    ;;
  Linux\ 2.*)
    RPATHFLAG="-Wl,-rpath,"
    ;;
  *)
    :
    ;;
esac

if test x$RPATHFLAG = x ; then
  AC_MSG_RESULT(none)
else
  AC_MSG_RESULT([using $RPATHFLAG])
fi

RPATH_CANDIDATE_REAL_DIRS=''
RPATH_CANDIDATE_DIRS=''

AC_MSG_RESULT([Searching for libraries])

for d in $1 ; do
  LSH_RPATH_ADD($d)
done
])    

dnl Try to execute a main program, and if it fails, try adding some
dnl -R flag.
dnl LSH_RPATH_FIX
Pavel Roskin's avatar
Pavel Roskin committed
197
AC_DEFUN([LSH_RPATH_FIX],
198
199
200
201
202
203
204
205
206
[if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
  ac_success=no
  AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
    ac_success=yes, ac_success=no, :)
  
  if test $ac_success = no ; then
    AC_MSG_CHECKING([Running simple test program failed. Trying -R flags])
dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS
    ac_remaining_dirs=''
207
    ac_rpath_save_LDFLAGS="$LDFLAGS"
208
209
210
211
    for d in $RPATH_CANDIDATE_DIRS ; do
      if test $ac_success = yes ; then
  	ac_remaining_dirs="$ac_remaining_dirs $d"
      else
212
213
  	LDFLAGS="$RPATHFLAG$d $LDFLAGS"
dnl echo LDFLAGS = $LDFLAGS
214
215
  	AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
  	  [ac_success=yes
216
  	  ac_rpath_save_LDFLAGS="$LDFLAGS"
217
218
219
  	  AC_MSG_RESULT([adding $RPATHFLAG$d])
  	  ],
  	  [ac_remaining_dirs="$ac_remaining_dirs $d"], :)
220
  	LDFLAGS="$ac_rpath_save_LDFLAGS"
221
222
223
224
225
226
227
228
229
      fi
    done
    RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
  fi
  if test $ac_success = no ; then
    AC_MSG_RESULT(failed)
  fi
fi
])
230
231
232
233
234

dnl Like AC_CHECK_LIB, but uses $KRB_LIBS rather than $LIBS.
dnl AC_CHECK_KRB_LIB(LIBRARY, FUNCTION, [, ACTION-IF-FOUND [,
dnl                  ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])

Pavel Roskin's avatar
Pavel Roskin committed
235
AC_DEFUN([AC_CHECK_KRB_LIB],
236
237
238
239
240
241
242
243
244
245
246
247
248
249
[AC_CHECK_LIB([$1], [$2],
  ifelse([$3], ,
      [ changequote(, )dnl
 	  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
     	    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
        changequote([, ])dnl
        AC_DEFINE_UNQUOTED($ac_tr_lib)
        KRB_LIBS="-l$1 $KRB_LIBS"
      ], [$3]),
  ifelse([$4], , , [$4
])dnl
, [$5 $KRB_LIBS])
])

250
dnl AC_LIB_ARGP(ACTION-IF-OK, ACTION-IF-BAD)
Pavel Roskin's avatar
Pavel Roskin committed
251
AC_DEFUN([AC_LIB_ARGP],
252
253
254
255
256
257
258
259
[ ac_argp_save_LIBS="$LIBS"
  ac_argp_save_LDFLAGS="$LDFLAGS"
  ac_argp_ok=no
  # First check if we can link with argp.
  AC_SEARCH_LIBS(argp_parse, argp,
  [ LSH_RPATH_FIX
    AC_CACHE_CHECK([for working argp],
      lsh_cv_lib_argp_works,
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
      [ AC_TRY_RUN(
[#include <argp.h>
#include <stdlib.h>

static const struct argp_option
options[] =
{
  { NULL, 0, NULL, 0, NULL, 0 }
};

struct child_state
{
  int n;
};

static error_t
child_parser(int key, char *arg, struct argp_state *state)
{
  struct child_state *input = (struct child_state *) state->input;
  
  switch(key)
    {
    default:
      return ARGP_ERR_UNKNOWN;
    case ARGP_KEY_END:
      if (!input->n)
	input->n = 1;
      break;
    }
  return 0;
}

const struct argp child_argp =
{
  options,
  child_parser,
  NULL, NULL, NULL, NULL, NULL
};

struct main_state
{
  struct child_state child;
  int m;
};

static error_t
main_parser(int key, char *arg, struct argp_state *state)
{
  struct main_state *input = (struct main_state *) state->input;

  switch(key)
    {
    default:
      return ARGP_ERR_UNKNOWN;
    case ARGP_KEY_INIT:
      state->child_inputs[0] = &input->child;
      break;
    case ARGP_KEY_END:
      if (!input->m)
	input->m = input->child.n;
      
      break;
    }
  return 0;
}

static const struct argp_child
main_children[] =
{
  { &child_argp, 0, "", 0 },
  { NULL, 0, NULL, 0}
};

static const struct argp
main_argp =
{ options, main_parser, 
  NULL,
  NULL,
  main_children,
  NULL, NULL
};

int main(int argc, char **argv)
{
  struct main_state input = { { 0 }, 0 };
  char *v[2] = { "foo", NULL };

  argp_parse(&main_argp, 1, v, 0, NULL, &input);

  if ( (input.m == 1) && (input.child.n == 1) )
    return 0;
  else
    return 1;
}
], lsh_cv_lib_argp_works=yes,
   lsh_cv_lib_argp_works=no,
356
   lsh_cv_lib_argp_works=no)])
357
358

  if test x$lsh_cv_lib_argp_works = xyes ; then
359
360
361
362
363
364
365
366
    ac_argp_ok=yes
  else
    # Reset link flags
    LIBS="$ac_argp_save_LIBS"
    LDFLAGS="$ac_argp_save_LDFLAGS"
  fi])

  if test x$ac_argp_ok = xyes ; then
367
368
369
370
371
    ifelse([$1],, true, [$1])
  else
    ifelse([$2],, true, [$2])
  fi   
])