File: configure.ac

package info (click to toggle)
milter-greylist 3.0-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 920 kB
  • ctags: 787
  • sloc: ansic: 6,864; sh: 3,205; yacc: 736; lex: 321; makefile: 166
file content (698 lines) | stat: -rw-r--r-- 20,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# $Id: configure.ac,v 1.189.2.10 2006/11/20 20:51:37 manu Exp $
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.57)
AC_INIT(milter-greylist, 3.0, manu@netbsd.org)
AC_CONFIG_SRCDIR([milter-greylist.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_LEX
AC_PROG_YACC
AC_PROG_INSTALL
AC_CHECK_PROGS(MKDEP, mkdep)
AC_CHECK_PROGS(RM, rm)
AC_CHECK_PROGS(MV, mv)
AC_CHECK_PROGS(TEST, test)
AC_CHECK_PROGS(SED, sed)
AC_CHECK_PROGS(TRUE, true)

# Check that the compiler won't bug us for -Wall
AC_MSG_CHECKING([if compiler accepts -Wall])
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -Wall"
wall="no"
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [wall="yes"; SAVEDCFLAGS=$CFLAGS])
AC_MSG_RESULT([$wall])
CFLAGS=$SAVEDCFLAGS

# Check if the linker accepts --rpath (for Darwin)
AC_MSG_CHECKING([if ld accepts --rpath])
SAVEDLDFLAGS=$LDFLAGS
LDFLAGS=$LDFLAGS" -Wl,--rpath=/"
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 
    [rpath="--rpath="; ldrpath=yes], [rpath="-L"; ldrpath=no])
LDFLAGS=$SAVEDLDFLAGS
AC_MSG_RESULT([$ldrpath])

# Path to required packages
AC_ARG_WITH(db,
        [  --with-db=DIR   Find Berkeley DB in DIR],
        [CFLAGS=$CFLAGS" -I$withval/include"
            LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"])
AC_ARG_WITH(libmilter, 
	[  --with-libmilter=DIR   Find libmilter in DIR],
	[CFLAGS=$CFLAGS" -I$withval/include" 
	    LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"])
AC_ARG_WITH(libpthread, 
	[  --with-libpthread=DIR  Find libpthread in DIR],
	[CFLAGS=$CFLAGS" -I$withval/include" 
	    LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"])
use_libbind=no
AC_ARG_WITH(libbind, 
	[  --with-libbind=DIR	Find libbind in DIR],
	[CFLAGS=$CFLAGS" -I$withval/include/bind -I$withval/include"
	    LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
	    LIBS="-lbind $LIBS"
	    use_libbind=yes
	 ])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h stdlib.h string.h strings.h sys/socket.h sys/time.h syslog.h unistd.h sys/param.h netdb.h getopt.h sys/cdefs.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME

# Do we need -lpthread with -lbind?
if test $use_libbind = yes ; then
	AC_MSG_CHECKING([if -lbind needs -lpthread to link])
	lbind_needs_lpthread=no
	SAVEDLIBS=$LIBS
	AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], 
	    [],
	    [
		LIBS="-lpthread $LIBS"
		AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
		    [lbind_needs_lpthread=yes]);
	    ]);
	if test $lbind_needs_lpthread = yes ; then
		SAVEDLIBS=$LIBS
	fi
	AC_MSG_RESULT($lbind_needs_lpthread)
	LIBS=$SAVEDLIBS
fi

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_STRFTIME
AC_FUNC_MEMCMP
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_SETVBUF_REVERSED
AC_FUNC_STAT
AC_CHECK_FUNCS([bzero gettimeofday malloc inet_ntoa strerror select socket initgroups strlcat vsyslog])


# Check for libpthread. On FreeBSD, the libc_r does the job.
# On digitalUNIX, libpthreads (with a trailing s) is the library to use
# FIXME: FreeBSD 4.x wants -pthread
AC_CHECK_LIB([pthread], [pthread_create], 
    [LIBS="$LIBS -lpthread"],
    [AC_CHECK_LIB([c_r], [pthread_create], 
        [LIBS="$LIBS -lc_r"],
	[AC_CHECK_LIB([pthreads -lpthread], [pthread_create],
            [LIBS="$LIBS -lpthreads -lpthread"],
                [echo "Required libpthread not found. Use --with-libpthread"; 
                 exit 1;])
	])
     ])

# Try to configure for libspf2
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
AC_ARG_WITH(libspf2,
       [  --with-libspf2=DIR  Find libspf2 in DIR],
       [LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
           CFLAGS=$CFLAGS" -I$withval/include"
           AC_CHECK_LIB(spf2, SPF_server_new, [
               SAVEDLDFLAGS=$LDFLAGS
               SAVEDCFLAGS=$CFLAGS
               LIBS=$LIBS" -lspf2"
               AC_DEFINE([HAVE_SPF2], [], [we use libspf2])
               ],[AC_CHECK_LIB([spf2 -lintl],  SPF_server_new, [
                       SAVEDLDFLAGS=$LDFLAGS
                       SAVEDCFLAGS=$CFLAGS
                       LIBS=$LIBS" -lspf2 -lintl"
                       AC_DEFINE([HAVE_SPF2], [], [we use libspf2])
               ], [echo "libspf2 not found, check config.log for details"
                   echo "Remove --with-libspf2 to build without SPF support"
                   exit 1;])
       ])
])
LDFLAGS=$SAVEDLDFLAGS
CFLAGS=$SAVEDCFLAGS

# Try to configure for libspf2 1.0
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
AC_ARG_WITH(libspf2_10,
       [  --with-libspf2_10=DIR  Find libspf2 1.0 in DIR],
       [LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
           CFLAGS=$CFLAGS" -I$withval/include"
           AC_CHECK_LIB(spf2, SPF_create_config, [
               SAVEDLDFLAGS=$LDFLAGS
               SAVEDCFLAGS=$CFLAGS
               LIBS=$LIBS" -lspf2"
               AC_DEFINE([HAVE_SPF2_10], [], [we use libspf2 1.0])
               ],[AC_CHECK_LIB([spf2 -lintl],  SPF_create_config, [
                       SAVEDLDFLAGS=$LDFLAGS
                       SAVEDCFLAGS=$CFLAGS
                       LIBS=$LIBS" -lspf2 -lintl"
                       AC_DEFINE([HAVE_SPF2_10], [], [we use libspf2 1.0])
               ], [echo "libspf2 1.0 not found, check config.log for details"
                   echo "Remove --with-libspf2_10 to build without SPF support"
                   exit 1;])
       ])
])
LDFLAGS=$SAVEDLDFLAGS
CFLAGS=$SAVEDCFLAGS

# Try to configure for libspf_alt
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
AC_ARG_WITH(libspf_alt, 
	[  --with-libspf_alt=DIR  Find libspf_alt in DIR],
	[LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
	    CFLAGS=$CFLAGS" -I$withval/include"
	    AC_CHECK_LIB(spf_alt, SPF_create_config, [
		SAVEDLDFLAGS=$LDFLAGS
		SAVEDCFLAGS=$CFLAGS
		LIBS=$LIBS" -lspf_alt"
		AC_DEFINE([HAVE_SPF_ALT], [], [we use libspf_alt])
		],[AC_CHECK_LIB([spf_alt -lintl],  SPF_create_config, [
			SAVEDLDFLAGS=$LDFLAGS
			SAVEDCFLAGS=$CFLAGS
			LIBS=$LIBS" -lspf_alt -lintl"
			AC_DEFINE([HAVE_SPF_ALT], [], [we use libspf_alt])
		], [echo "libspf_alt not found, check config.log for details"
		    echo "Remove --with-libspf_alt to build without SPF support"
		    exit 1;])
	])
])
LDFLAGS=$SAVEDLDFLAGS
CFLAGS=$SAVEDCFLAGS

# Try to configure for libspf
SAVEDLDFLAGS=$LDFLAGS
SAVEDCFLAGS=$CFLAGS
AC_ARG_WITH(libspf, 
	[  --with-libspf=DIR  Find libspf in DIR],
	[LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"
	    CFLAGS=$CFLAGS" -I$withval/include"
	    AC_CHECK_LIB(spf, SPF_init, [
		SAVEDLDFLAGS=$LDFLAGS
		SAVEDCFLAGS=$CFLAGS
		LIBS=$LIBS" -lspf"
		AC_DEFINE([HAVE_SPF], [], [we use libspf])
		], [echo "libspf not found, check config.log for details"
		    echo "Remove --with-libspf to build without SPF support"
		    exit 1;])
])
LDFLAGS=$SAVEDLDFLAGS
CFLAGS=$SAVEDCFLAGS

# Check for socket functions linking. On Solaris, -lsocket -lnsl is required
AC_CHECK_LIB([socket], [socket], [LIBS="$LIBS -lsocket"], 
	[AC_CHECK_LIB([socket -lnsl], [socket], 
		[LIBS="$LIBS -lsocket -lnsl"], [])
	])

# Check for inet_aton (libmilter uses it). On solaris, -lresolv is required
AC_CHECK_LIB([resolv], [inet_aton], [LIBS="$LIBS -lresolv"], []) 

# Check for inet_pton (libmilter uses it). On solaris, -lnsl is required
AC_CHECK_LIB([nsl], [inet_pton], [LIBS="$LIBS -lnsl"], []) 

# Check for getaddrinfo and getnameinfo
AC_DEFUN([IPv6_CHECK_FUNC], [
AH_TEMPLATE(AS_TR_CPP(HAVE_$1), [Define to 1 if you have the `]$1[' function.])
AC_CHECK_FUNC($1, [dnl
  ac_cv_lib_socket_$1=no
  ac_cv_lib_inet6_$1=no
], [dnl
  AC_CHECK_LIB(socket, $1, [dnl
    LIBS="$LIBS -lsocket"
    ac_cv_lib_inet6_$1=no
  ], [dnl
    AC_MSG_CHECKING([whether your system has IPv6 directory])
    AC_CACHE_VAL(ipv6_cv_dir, [dnl
      for ipv6_cv_dir in /usr/local/v6 /usr/inet6 no; do
	if test $ipv6_cv_dir = no -o -d $ipv6_cv_dir; then
	  break
	fi
      done])dnl
    AC_MSG_RESULT($ipv6_cv_dir)
    if test $ipv6_cv_dir = no; then
      ac_cv_lib_inet6_$1=no
    else
      if test x$ipv6_libinet6 = x; then
	ipv6_libinet6=no
	SAVELDFLAGS="$LDFLAGS"
	LDFLAGS="$LDFLAGS -L$ipv6_cv_dir/lib"
      fi
      AC_CHECK_LIB(inet6, $1, [dnl
	if test $ipv6_libinet6 = no; then
	  ipv6_libinet6=yes
	  LIBS="$LIBS -linet6"
	fi],)dnl
      if test $ipv6_libinet6 = no; then
	LDFLAGS="$SAVELDFLAGS"
      fi
    fi])dnl
])dnl
ipv6_cv_$1=no
if test $ac_cv_func_$1 = yes -o $ac_cv_lib_socket_$1 = yes \
     -o $ac_cv_lib_inet6_$1 = yes
then
  ipv6_cv_$1=yes
fi
if test $ipv6_cv_$1 = no; then
  if test $1 = getaddrinfo; then
    for ipv6_cv_pfx in o n; do
      AC_EGREP_HEADER(${ipv6_cv_pfx}$1, netdb.h,
		      [AC_CHECK_FUNC(${ipv6_cv_pfx}$1)])
      if eval test X\$ac_cv_func_${ipv6_cv_pfx}$1 = Xyes; then
        ipv6_cv_$1=yes
        break
      fi
    done
  fi
fi
if test $ipv6_cv_$1 = yes; then
  AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1))
  ifelse([$2], , :, [$2])
else
  ifelse([$3], , :, [$3])
fi])

IPv6_CHECK_FUNC(getaddrinfo)
IPv6_CHECK_FUNC(getnameinfo)

# Check if <time.h> defines timeradd (and timersub)
AC_MSG_CHECKING([if <time.h> defines timeradd])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#if HAVE_TIME_H
		#include <time.h>
		#endif
		#ifdef HAVE_SYS_TIME_H
		#include <sys/time.h>
		#endif
	],[
		#ifndef timeradd
		error timeradd undefined
		#endif
	])], [timeradd=yes], 
	[AC_DEFINE([HAVE_MISSING_TIMERADD], 
	    [], [<time.h> defines timeradd]) timeradd=no])
AC_MSG_RESULT([$timeradd])

# Check if -D_REENTRANT is needed for localtime_r, gmtime_r
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -ansi -Wall -Werror"
AC_MSG_CHECKING([if -D_REENTRANT is needed to use localtime_r])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
               #include <time.h>
       ],[[

               (void)localtime_r(NULL, NULL);
       ]])], [dreentrant=no],
               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
                               #define _REENTRANT
                               #include <time.h>
                       ],[[
                                (void)localtime_r(NULL, NULL);
                       ]])],
                       [SAVEDCFLAGS=$SAVEDCFLAGS" -D_REENTRANT";
                        dreentrant=yes], [dreentrant=no])
       ])
AC_MSG_RESULT([$dreentrant])
CFLAGS=$SAVEDCFLAGS

# Check if -D__EXTENSIONS__ is needed for snprintf, getopt, seteuid...
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -ansi -Wall -Werror"
AC_MSG_CHECKING([if -D__EXTENSIONS__ is needed to use snprintf])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <stdio.h>
	],[[
		char dst[16 + 1];

		snprintf(dst, 16, "test");
	]])], [dextensions=no],
		[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
				#define __EXTENSIONS__
				#include <stdio.h>
			],[[
				char dst[16 + 1];

				snprintf(dst, 16, "test");
			]])], 
			[SAVEDCFLAGS=$SAVEDCFLAGS" -D__EXTENSIONS__"; 
			 dextensions=yes], [dextensions=no])
	])
AC_MSG_RESULT([$dextensions])
CFLAGS=$SAVEDCFLAGS

# Check for DRAC
AC_ARG_ENABLE(drac,
	[  --enable-drac	Enable DRAC support],
	[if test x$enableval = xyes; then CFLAGS=$CFLAGS" -DUSE_DRAC"; fi])

# Check for libmilter. For sendmail-8.12.1, -lsm is required too.
# This uses a gross hack on the second AC_CHECK_LIB first argument, but using 
# [-lsm] in the optionnal 5th argument does not seems to help at all.
AC_CHECK_LIB(milter, smfi_register,
    [LIBS="$LIBS -lmilter"],
    [AC_CHECK_LIB([milter -lsm], smfi_register,
        [LIBS="$LIBS -lmilter -lsm"],
        [AC_CHECK_LIB([milter -lsmutil], smfi_register,
            [LIBS="$LIBS -lmilter -lsmutil"],
                [echo "Required libmilter not found. Use --with-libmilter"; 
                exit 1;])
        ])
])

# Check if -lpthreads is needed after -lmilter
AC_MSG_CHECKING([if -lpthread is needed after -lmilter])
SAVEDLIBS=$LIBS
AC_LINK_IFELSE([AC_LANG_PROGRAM([
		#include <pthread.h>
		#include <libmilter/mfapi.h>
	],[
		pthread_self();
		smfi_main();
	])], [pthend=no], [LIBS=$LIBS" -lpthread"; 
		AC_LINK_IFELSE([AC_LANG_PROGRAM([
			#include <pthread.h>
			#include <libmilter/mfapi.h>
		],[
			pthread_self();
			smfi_main();
		])], [pthend=yes; SAVEDLIBS=$LIBS], [pthend=no])
	])

LIBS=$SAVEDLIBS
AC_MSG_RESULT([$pthend])

# Some Linux flavors have an outdated <sys/queue.h>
AC_MSG_CHECKING([if <sys/queue.h> is outdated])
oldqueue=no
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <sys/queue.h>
	],[
		#ifndef TAILQ_FIRST
		error Your <sys/queue.h> is outdated
		#endif
	])], [oldqueue=no], 
	[AC_DEFINE([HAVE_OLD_QUEUE_H], [], [old <sys/queue.h>]) oldqueue=yes])
AC_MSG_RESULT([$oldqueue])

# Darwin is unable to define two __RCSID in the same file
AC_MSG_CHECKING([if __RCSID can be used twice in the same source])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <sys/cdefs.h>
		#ifdef __RCSID
		__RCSID("Id1");
		__RCSID("Id2");
		#endif
	],[
		/* nothing */
	])], [rcsidtwice=yes], 
	[AC_DEFINE([HAVE_BROKEN_RCSID], [], 
	    [__RCSID cannot be used twice]) rcsidtwice=no])
AC_MSG_RESULT([$rcsidtwice])

# Digital UNIX's native compiler require -pthread when using libpthread
# It also require -D_XOPEN_SOURCE=500 for various reasons I have not 
# been abe to isolate. Let's define both there.
AC_MSG_CHECKING([whether <pthreads.h> wants -pthread])
SAVEDCFLAGS=$CFLAGS
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],[])],
	[pthreadfl=no], 
	[CFLAGS=$CFLAGS" -pthread -D_XOPEN_SOURCE=500";
	 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],[])],
		[pthreadfl=yes; SAVEDCLFAGS=$CFLAGS], [pthreadfl=no])
	])
CLFAGS=$SAVEDCFLAGS
AC_MSG_RESULT([$pthreadfl])

# Linux requires -D_XOPEN_SOURCE=500 to build with libpthread and -Wall
AC_MSG_CHECKING([whether you need -D_XOPEN_SOURCE to use libpthread])
xopen=no
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <sys/types.h>
		#include <pthread.h>
	],[
		pthread_rwlock_t lock;
	])], [xopen=no], [CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500"; xopen=yes])
AC_MSG_RESULT([$xopen])

# IRIX requires -D_SGI_SOURCE to use <stdio.h> and -ansi
AC_MSG_CHECKING([whether you need -D_SGI_SOURCE to use <stdio.h> with -ansi])
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -ansi"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <stdio.h>
	],[
		FILE *f;

		f = fdopen(0, "w+");
	])], [xstdio=no], 
	[SAVEDCFLAGS=$SAVEDCFLAGS" -D_SGI_SOURCE"; 
	 xstdio=yes])
CFLAGS=$SAVEDCFLAGS
AC_MSG_RESULT([$xstdio])

# IRIX may also require -D_XOPEN_SOURCE=500 to use <stdio.h> and -ansi
AC_MSG_CHECKING([whether you need -D_XOPEN_SOURCE to use <stdio.h> with -ansi])
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -ansi"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <stdio.h>
	],[
		FILE *f;

		f = fdopen(0, "w+");
	])], [xstdio=no], 
	[SAVEDCFLAGS=$SAVEDCFLAGS" -D_XOPEN_SOURCE=500"; 
	 xstdio=yes])
CFLAGS=$SAVEDCFLAGS
AC_MSG_RESULT([$xstdio])


# Tru64 Unix needs -D_OSF_SOURCE for IPV6 support
SAVEDCFLAGS=$CFLAGS
CFLAGS=$CFLAGS" -D_XOPEN_SOURCE=500 -D_BSD_SOURCE"
AC_MSG_CHECKING([if -D_OSF_SOURCE is needed for IPV6 support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <sys/types.h>
		#include <sys/socket.h>
		#include <netinet/in.h>
	],[[
		#ifdef AF_INET6
		  struct in6_addr s;
		#endif
	]])], [dosfsource=no],
		[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
				#define _OSF_SOURCE
				#include <sys/socket.h>
				#include <netinet/in.h>
			],[[
				#ifdef AF_INET6
				  struct in6_addr s;
				#endif
			]])], 
			[SAVEDCFLAGS=$SAVEDCFLAGS" -D_OSF_SOURCE"; 
			 dosfsource=yes], [dosfsource=no])
	])
AC_MSG_RESULT([$dosfsource])
CFLAGS=$SAVEDCFLAGS

# Linux does not have a sa_len field in sockaddr
AC_CHECK_MEMBER([struct sockaddr.sa_len],
	[AC_DEFINE([HAVE_SA_LEN], [], [sa_len field in struct sockaddr])],, [
		#include <sys/types.h>
		#include <sys/socket.h>
	])

# Pre-RFC2553 system does not have a sin6_scope_id field in sockaddr_in6
AC_CHECK_MEMBER([struct sockaddr_in6.sin6_scope_id],
	[AC_DEFINE([HAVE_SIN6_SCOPE_ID], [1],
	    [sin6_scope_id field in struct sockaddr_in6])],, [
		#include <sys/types.h>
		#include <sys/socket.h>
		#include <netinet/in.h>
	])

# Darwin seems to have no definition for socklen_t beyond _BSD_SOCKLEN_T_
AC_MSG_CHECKING([if socklen_t is missing])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
		#include <sys/types.h>
		#include <sys/socket.h>
	],[
		socklen_t slen;
	])], [socklen=no], 
	[AC_DEFINE([HAVE_MISSING_SOCKLEN_T], [], 
	    [missing socklen_t definition]) socklen=yes])
AC_MSG_RESULT([$socklen])

# GNU pth-2.0.0 has a bug with rwlock. 
AC_MSG_CHECKING([for broken rwlock in libpthread])
brokenpth=yes
AC_RUN_IFELSE([AC_LANG_PROGRAM([
		#if STDC_HEADERS
		# include <stdlib.h>
		#else
		# ifdef __cplusplus
		extern "C" void exit (int);
		# else
		void exit (int);
		# endif
		#endif

		#if HAVE_SYS_TIME_H
		# include <sys/time.h>
		#else
		struct timeval {
			long tv_sec;
			long tv_usec;
		};
		#endif

		#if HAVE_SYS_TYPES_H
		# include <sys/types.h>
		#else 
		#endif

		#if HAVE_UNISTD_H
		# include <unistd.h>
		#else
		# ifdef __cplusplus
		extern "C" unsigned int exit (unsigned int);
		extern "C" int 
		    select(int, void *, void *, void *, struct timeval *);
		# else
		unsigned int exit (unsigned int);
		int select(int, void *, void *, void *, struct timeval *);
		# endif
		#endif

		#include <pthread.h>
		pthread_rwlock_t lock;
  
		#ifdef __cplusplus
		extern "C" void testfunc (void *);
		extern "C" void yield(void);
		#else
		void testfunc();
		void yeild(void);
		#endif

		/*
		 * On some Linux flavors, using sleep(3) instead
		 * of select causes an infinite hang.
		 */
		void yield (void)
		{
			struct timeval tv;

			tv.tv_sec = 1;
			tv.tv_usec = 0;
			if (select(0, NULL, NULL, NULL, &tv) != 0)
				exit(EXIT_FAILURE);
			return;
		}

		#ifdef __cplusplus
		void testfunc (void *dontcare)
		#else
		void testfunc (dontcare) void *dontcare;
		#endif
		{
			if (pthread_rwlock_rdlock(&lock) != 0)
				exit(EXIT_FAILURE);
			yield();
			if (pthread_rwlock_unlock(&lock) != 0)
				exit(EXIT_FAILURE);
			return;
		}
	],[
		pthread_t tid;

		if (pthread_rwlock_init(&lock, NULL) != 0)
			exit(EXIT_FAILURE);
		if (pthread_create(&tid, NULL, (void *)testfunc, NULL) != 0)
			exit(EXIT_FAILURE);
		if (pthread_rwlock_rdlock(&lock) != 0)
			exit(EXIT_FAILURE);
		yield();
		if (pthread_rwlock_unlock(&lock) != 0)
			exit(EXIT_FAILURE);
		if (pthread_join(tid, NULL) != 0)
			exit(EXIT_FAILURE);
		return 0;
	])], [brokenpth=no], 
	AC_DEFINE([HAVE_BROKEN_RWLOCK], [], [broken rwlock in libpthread]))
AC_MSG_RESULT([$brokenpth])

# Check is DNS resolver is re-entrant
AC_ARG_WITH(thread-safe-resolver,
	[  --with-thread-safe-resolver   Resolver is thread-safe],
	[rdns=yes],[
		SAVEDCFLAGS=$CFLAGS
		CFLAGS=$CFLAGS" -Wall -Werror"
		AC_MSG_CHECKING([if DNS resolver is re-entrant])
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
				#define _BSD_SOURCE

				#include <sys/types.h>
				#include <netinet/in.h>
				#include <arpa/inet.h>
				#include <arpa/nameser.h>
				#include <resolv.h>
			],[
				struct __res_state res;

				res_ninit(&res);
			])], [rdns=yes], [rdns=no])
		AC_MSG_RESULT([$rdns])
		CFLAGS=$SAVEDCFLAGS
	])

# Check for DNSRBL
AC_ARG_ENABLE(dnsrbl,
	[  --enable-dnsrbl	Enable DNSRBL support],
	[if test x$enableval = xyes -a $rdns = yes; then
		CFLAGS=$CFLAGS" -DUSE_DNSRBL"
	 else
		echo "--enable-dnsrbl used but DNS resolver is not thread safe";
		echo "Try installing BIND9 and using --with-libbind, or if you";
		echo "know what you are doing, use --with-thread-safe-resolver";
		exit 1;
	 fi
	])


# Record the build environnement for milter-greylist -r
AC_DEFINE_UNQUOTED([BUILD_ENV], ["`logname`@`uname -n`:`pwd` `date`"], 
    [Build environnement]) 

# Options
AC_ARG_WITH(user,
	[  --with-user=USERNAME   The user that will run milter-greylist ],
	[AC_SUBST(USER, $withval)], [AC_SUBST(USER, root)])
AC_ARG_WITH(conffile,  
	[  --with-conffile=PATH Location of config file],
	[CFLAGS=$CFLAGS" -DCONFFILE=\\\"$withval\\\""])
AC_ARG_WITH(dumpfile,
	[  --with-dumpfile=PATH   Location of dump file],
	[CFLAGS=$CFLAGS" -DDUMPFILE=\\\"$withval\\\""])
AC_ARG_WITH(delay,  
	[  --with-delay=VALUE     Delay before accepting mail],
	[CFLAGS=$CFLAGS" -DGLDELAY=$withval"])
AC_ARG_WITH(timeout,  
	[  --with-timeout=VALUE   Timeout before we forget about a send],
	[CFLAGS=$CFLAGS" -DTIMEOUT=$withval"])
AC_ARG_WITH(autowhite,  
	[  --with-autowhite=VALUE How long auto-whitelisting lasts],
	[CFLAGS=$CFLAGS" -DAUTOWHITE_DELAY=$withval"])
AC_ARG_WITH([drac-db],
	[  --with-drac-db=PATH   Where is the DRAC database ],
	[CFLAGS=$CFLAGS" -DDRACDB=\\\"$withval\\\""])

AC_CONFIG_FILES([Makefile milter-greylist.spec])
AC_OUTPUT