File: configure.ac

package info (click to toggle)
c-icap 1:0.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,600 kB
  • sloc: ansic: 27,220; sh: 4,415; makefile: 242; perl: 95; awk: 10
file content (1006 lines) | stat: -rw-r--r-- 24,545 bytes parent folder | download | duplicates (2)
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
dnl Process this file with autoconf to produce a configure script.


dnl AC_INIT(c_icap,m4_normalize(m4_include([VERSION.m4])))
AC_INIT(c_icap,0.5.3)
CICAPLIB_VERSION=5:3:0
AC_SUBST(CICAPLIB_VERSION)
dnl CICAPLIB_VERSION is the libtool current[:revision[:age]] version info
dnl libtool directions about version info
dnl - library source code has changed since the last update c:r:a => c:r+1:a
dnl - interfaces have been added, removed, or changed c:r:a => c+1:0:a
dnl - interfaces have been added c:r:a => c:r:a+1
dnl - interfaces have been removed  c:r:a => c:r:0

AC_CONFIG_SRCDIR(aserver.c)
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(autoconf.h)

AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_MACRO_DIR([m4])

AC_CANONICAL_HOST

AC_USE_SYSTEM_EXTENSIONS

AC_PROG_AWK
AC_PROG_CC
AM_PROG_CC_C_O
AC_C_BIGENDIAN

AC_DISABLE_STATIC
AC_LIBTOOL_DLOPEN
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

dnl Define c-icap version
C_ICAP_HEX_VERSION=`echo $PACKAGE_VERSION | $AWK -f $srcdir/build/c_icap_version.awk`
AC_SUBST(C_ICAP_HEX_VERSION)

dnl Checks for OS specific flags and posix threads libraries.....

case "$host_os" in
     linux*)
	CFLAGS="-D_REENTRANT $CFLAGS"
	THREADS_LDADD="-lpthread"
	THREADS_LDFLAGS=""
     ;;
     solaris2.*)
     	  CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS $CFLAGS"
          LIBS="-lsocket -lnsl -lrt $LIBS"
	  THREADS_LDADD="-lpthread"
	  THREADS_LDFLAGS=""
      ;;
      freebsd5*)
## If I understand how all those threading models works correctly
## in FreeBSD I will make an option in configure script
## --with-freebsd-threads={c_r,pthreads,linuxthreads,thr}
## If I am correct I must compile c-icap with the way
## external libraries are compiled. (The clamav uses -lc_r and I had problems
## using a different threading model)

##    FreeBSD linuxthreads flags
#      	CFLAGS="-D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads $CFLAGS"
#	THREADS_LDADD="-llthread -lgcc_r"
#	THREADS_LDFLAGS="-L/usr/local/lib"

##    FreeBSD Standard threads
      	CFLAGS="-pthread -D_THREAD_SAFE  $CFLAGS"
	THREADS_LDADD="-XCClinker -lc_r"
	THREADS_LDFLAGS=""
## FreeBSD has pthreads rwlocks from version 3 (I think)
#	AC_DEFINE(HAVE_PTHREADS_RWLOCK,1,[Define HAVE_PTHREADS_RWLOCK if pthreads library supports rwlocks])
##   1:1 threads
#      	CFLAGS="-D_THREAD_SAFE  $CFLAGS"
#	THREADS_LDADD="-XCClinker -lthr"
#	THREADS_LDFLAGS=""

      ;;

      freebsd6*)
        CFLAGS="-D_THREAD_SAFE  $CFLAGS"
        THREADS_LDADD="-XCClinker -lthr"
        THREADS_LDFLAGS=""
      ;;

      cygwin*)
	CFLAGS="-D_REENTRANT $CFLAGS"
	THREADS_LDADD="-lpthread"
	THREADS_LDFLAGS="";
	iscygwin="yes"
      ;;
      *)
      	CFLAGS="-D_REENTRANT $CFLAGS"
	THREADS_LDADD="-lpthread"
	THREADS_LDFLAGS=""
      ;;
esac

TEST_LIBS="$TEST_LIBS $THREADS_LDADD"
AC_SUBST(THREADS_LDADD)
AC_SUBST(THREADS_LDFLAGS)

AC_DEFINE_UNQUOTED(C_ICAP_CONFIGURE_OPTIONS, "$ac_configure_args",
                   [configure command line used to configure c-icap])
AC_DEFINE_UNQUOTED(C_ICAP_CONFIG_HOST_TYPE, "$host",[Host type from configure])


CFLAGS="$CFLAGS -Wall"

AC_CACHE_CHECK([for __attribute__((visibility("default")))],
    ac_cv_default_visibility_attribute, [
    echo 'int __attribute__ ((visibility ("default"))) foo_visible (void) { return 1; } int foo_invisible(void) {return 1;}' > conftest.c
    ac_cv_default_visibility_attribute=no
    if AC_TRY_COMMAND(${CC-cc} -fvisibility=hidden -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD);
    then
        if grep '\.hidden.*foo_invisible' conftest.s >/dev/null && ! grep '\.hidden.*foo_visible' conftest.s >/dev/null;
        then
            ac_cv_default_visibility_attribute=yes
        fi
# Else try to detect visibility for Sun solaris:
#    CC -xldscope={global|hidden}
# and use __global/__hidden inside C code
#   elif
    fi
    rm -f conftest.*
    ])

INVISIBILITY_CFLAG=""
VISIBILITY_ATTR="0"
if test $ac_cv_default_visibility_attribute = yes;
then
    AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE, 1,
          [Define if __attribute__((visibility("default"))) is supported.])
    INVISIBILITY_CFLAG="-fvisibility=hidden"
    VISIBILITY_ATTR="1"
fi
AC_SUBST(INVISIBILITY_CFLAG)
AC_SUBST(VISIBILITY_ATTR)

AC_ARG_ENABLE(large_files,
[  --enable-large-files	Enable large files support],
[ if test $enableval = "yes"; then
    large_file_support="yes"
  else
    large_file_support="no"
  fi
],
   [ large_file_support="yes" ]
)

echo "checking whether large file support should enabled:"$large_file_support
if test $large_file_support = "yes"; then
   CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"
#here I must put a check if the -D_FILE_OFFSET_BITS makes the off_t  an 64bit integer
# and if not supported warning the user
#Possibly checks for systems which supports large files using different defines....
#later .......
fi

USE_IPV6="0"
AC_ARG_ENABLE(ipv6,
[  --enable-ipv6	Enable ipv6 support],
[ if test $enableval = "yes"; then
    ipv6_support="yes"
    AC_DEFINE(HAVE_IPV6,1,[Define HAVE_IPV6 if OS supports ipv6])
    USE_IPV6="1"
  fi
],
   [ ipv6_support="no" ]
)
AC_SUBST(USE_IPV6)

AC_ARG_ENABLE(sysvipc,
[  --enable-sysvipc	Enable SYSV/IPC for shared memory if supported],
[ if test $enableval = "yes"; then
    sysvipc="yes"
  else
    sysvipc="no"
  fi
],
   [ sysvipc="yes" ]
)

AC_ARG_ENABLE(poll,
[  --disable-poll	Disable poll(2) support],
[ if test $enableval = "no"; then
    enablepoll="no"
  else
    enablepoll="yes"
  fi
],
   [ enablepoll="yes" ]
)

USE_COMPAT="0"
AC_MSG_CHECKING([Keep library compatibility])
AC_ARG_ENABLE(lib_compat,
[  --enable-lib-compat	Enable library compatibility with older c-icap versions],
[ if test $enableval = "yes"; then
    lib_compat="yes"
    AC_MSG_RESULT(yes)
    USE_COMPAT="1"
  fi
],
   [ lib_compat="no"
     AC_MSG_RESULT(no)
    ]
)
AC_SUBST(USE_COMPAT)


# Checks for programs
AC_CHECK_PROG(has_doxygen, doxygen, "yes", "no")
if test a"$has_doxygen" = "ayes"; then
   doxygen_bin=doxygen
else
   doxygen_bin="echo Doxygen is not installed /"
fi
AC_SUBST(doxygen_bin)

# Check if we need to enable rpath when linking with libraries
AC_ARG_ENABLE(rpath,
[  --enable-rpath       hardcode runtime library paths],
[
     case "$enableval" in
     yes)
	enable_rpath="yes";
     ;;
     no)
	enable_rpath="no";
     ;;
     *)
	enable_rpath="yes";
        # Build list with libraries to use rpath
        ENABLE_RPATH_LIBS=`echo $enableval| tr ';:,' ' '`
        echo "Enable rpath for libs:"$ENABLE_RPATH_LIBS
        # search into $ENABLE_RPATH_LIBS using:
        # if test "${ENABLE_RPATH_LIBS#*zlib}" != "$ENABLE_RPATH_LIBS"; then echo found; fi
     ;;
     esac
],
   [enable_rpath="no"]
)

#Routines used for checking libraries
AC_DEFUN([ICFG_STATE_SAVE],[
#save state
ICFG_OLD_CFLAGS=$CFLAGS
ICFG_OLD_LDFLAGS=$LDFLAGS
ICFG_OLD_LIBS=$LIBS
])

#Routines used for checking libraries
AC_DEFUN([ICFG_STATE_ROLLBACK],[
#save state
CFLAGS=$ICFG_OLD_CFLAGS
LDFLAGS=$ICFG_OLD_LDFLAGS
LIBS=$ICFG_OLD_LIBS
])

AC_DEFUN([ICFG_BUILD_FLAGS_2], [
# The *_LNDIR_LDADD used by external programs to link with cicapapi libibrary.
# They must link with libraries options if the cicapapi is not linked with
# -rpath option and not standard directories are used.
# TODO: support multiple directories
if test -n $2; then
    $1_ADD_FLAG=-I$2
else
    $1_ADD_FLAG=""
fi

$1_LNDIR_LDADD=""
if test -n $3; then
    if test "a$enable_rpath" = "ayes"; then
        $1_ADD_LDADD="-Wl,-rpath -Wl,$3 -L$3 "$4
    else
        $1_ADD_LDADD="-L$3 "$4
        $1_LNDIR_LDADD="-L$3 "$4
    fi
else
    $1_ADD_LDADD=$4
fi
  AC_SUBST($1_LNDIR_LDADD)
  AC_SUBST($1_ADD_LDADD)
  AC_SUBST($1_ADD_FLAG)
]
)

AC_DEFUN([ICFG_BUILD_FLAGS], [
  if test "a$2" != "a"; then
       ICFG_BUILD_FLAGS_2($1, $2/include, $2/lib, $3)
  else
       ICFG_BUILD_FLAGS_2($1, "", "", $3)
  fi
]
)

# Checks for libraries

AC_ARG_WITH(perl,
[  --with-perl		Path to perl binary],
[
case "$withval" in
  yes)
       perlbin="perl"
  ;;			
  no )
       perlbin="";
       perlcore="";
  ;;
  * )
      perlbin=$withval
  ;;
  esac
],
[
   perlbin="";
   perlcore="";
]
)

if test a"$perlbin" != a; then
	perlcore=`$perlbin -MConfig -e 'print $Config{archlib}'`/CORE;
        perllib=`$perlbin -MConfig -e 'print $Config{libs}'`;
        perlccflags=`$perlbin -MConfig -e 'print $Config{ccflags}'`;
	perlldflags=`$perlbin -MConfig -e 'print $Config{ccdlflags}'`;
fi



AC_SUBST(perlcore)
AC_SUBST(perllib)
AC_SUBST(perlccflags)
AC_SUBST(perlldflags)

AC_ARG_WITH(openssl,
[  --with-openssl	Path to openssl],
[
case "$withval" in
     yes)
	openssl=yes;
     ;;
     no)
	openssl=no;
     ;;
     *)
	openssl=yes;
        opensslpath=$withval;
     ;;
     esac
],
[ openssl=yes]
)

if test "a$openssl" != "ano"; then
   ICFG_STATE_SAVE(OPENSSL)
   if test "a$opensslpath" != "a"; then
        CFLAGS="$CFLAGS -I$opensslpath/include"
        LDFLAGS="$LDFLAGS -L$opensslpath/lib"
   fi
   LIBS="-lssl -lcrypto $LIBS"
   (test -n "$opensslpath" && echo -n "checking for OpenSSL library under $opensslpath... ") || echo -n "checking for OpenSSL library... ";
   AC_LINK_IFELSE(
         [AC_LANG_SOURCE(
                 [
                   #include <openssl/ssl.h>
                   int main(int argc, char *argv[])
                   {
                      int ret = SSL_library_init();
                      return ret;
                   }
                 ])
               ],
         [openssl=yes; echo "yes";],
         [openssl=no; echo "no"]
   )
   if test "a$openssl" = "ayes"; then
      AC_DEFINE(HAVE_OPENSSL,1,[Define HAVE_OPENSSL if openssl is installed])
      ICFG_BUILD_FLAGS(OPENSSL, $opensslpath, "-lssl -lcrypto")
   fi
   ICFG_STATE_ROLLBACK
fi

USE_OPENSSL="1"
if test a"$openssl" = "ano"; then
    USE_OPENSSL="0"
fi
AC_SUBST(USE_OPENSSL)

AC_CHECK_LIB(dl,dlopen,DL_ADD_FLAG=" -ldl")
AC_SUBST(DL_ADD_FLAG)

AC_ARG_WITH(zlib,
[  --with-zlib	Path to zlib library],
[
case "$withval" in
     yes)
	zlib=yes;
     ;;
     no)
	zlib=no;
     ;;
     *)
        zlib=yes;
	zlibpath=$withval;
     ;;
     esac
],
[ zlib=yes]
)

if test "a$zlib" != "ano"; then
   ICFG_STATE_SAVE(ZLIB)
   if test "a$zlibpath" != "a"; then
        CFLAGS="$CFLAGS -I$zlib/include"
        LDFLAGS="$LDFLAGS -L$zlib/lib"
   fi
   AC_CHECK_LIB(z,inflate,[zlib=yes],[zlib=no])
   ICFG_STATE_ROLLBACK
fi
if test "a$zlib" = "ano"; then
    AC_MSG_WARN("zlib required for the c-icap's internal filetype recognizer!")
else
    AC_DEFINE(HAVE_ZLIB,1,[Define HAVE_ZLIB if zlib installed])
    ICFG_BUILD_FLAGS(ZLIB, $zlibpath, "-lz")
fi

AC_ARG_WITH(bzlib,
[  --with-bzlib	Path to bzlib library],
[
case "$withval" in
     yes)
	bzlib=yes;
     ;;
     no)
	bzlib=no;
     ;;
     *)
        bzlib=yes;
	bzlibpath=$withval;
     ;;
     esac
],
[ bzlib=yes]
)

if test "a$bzlib" != "ano"; then
   ICFG_STATE_SAVE(BZLIB)
   if test "a$bzlibpath" != "a"; then
        CFLAGS="$CFLAGS -I$bzlibpath/include"
        LDFLAGS="$LDFLAGS -L$bzlibpath/lib"
   fi
   AC_CHECK_LIB(bz2,BZ2_bzDecompressInit,[bzlib=yes],[bzlib=no])
   ICFG_STATE_ROLLBACK
fi
if test "a$bzlib" = "ano"; then
    AC_MSG_WARN("bzlib required for the c-icap's internal filetype recognizer!")
else
    AC_DEFINE(HAVE_BZLIB,1,[Define HAVE_BZLIB if bzlib installed])
    ICFG_BUILD_FLAGS(BZLIB, $bzlibpath, "-lbz2")
fi

AC_ARG_WITH(brotli,
[  --with-brotli	Path to brotli library],
[
case "$withval" in
     yes)
	brotli=yes;
     ;;
     no)
	brotli=no;
     ;;
     *)
        brotli=yes;
	brotlipath=$withval;
     ;;
     esac
],
[ brotli=yes]
)

if test "a$brotli" != "ano"; then
   ICFG_STATE_SAVE(BROTLI)
   if test "a$brotlipath" != "a"; then
        CFLAGS="$CFLAGS -I$brotlipath/include"
        LDFLAGS="$LDFLAGS -L$brotlipath/lib -lbrotlicommon"
   fi
   AC_CHECK_LIB(brotlidec,BrotliDecoderDecompressStream,[brotli=yes],[brotli=no])
   ICFG_STATE_ROLLBACK
fi
if test "a$brotli" = "ano"; then
    AC_MSG_WARN("brotli required for the c-icap's internal filetype recognizer!")
else
    AC_DEFINE(HAVE_BROTLI,1,[Define HAVE_BROTLI if brotli installed])
    ICFG_BUILD_FLAGS(BROTLI, "$brotlipath", "-lbrotlicommon -lbrotlidec -lbrotlienc")
    # fix BROTLI_LNDIR_LDADD the linker does not find brotlicommon even if
    # it is linked to libicapapi using rpath
    if test "a$brotlipath" != "a" -a "a$BROTLI_LNDIR_LDADD" = "a"; then
        BROTLI_LNDIR_LDADD="-L$brotlipath/lib -lbrotlicommon"
        AC_SUBST(BROTLI_LNDIR_LDADD)
    fi
fi

libdb="yes"
libdbpath=""
AC_ARG_WITH(bdb,
[  --with-bdb        Where to find Berkeley DB library ],
[ case "$withval" in
    yes)
         libdb="yes"
    ;;
    no )
         libdb="no"
    ;;
    * )
        libdb="yes"
        libdbpath=$withval
    ;;
  esac
],
)

if test "a$libdb" != "ano"; then
   if test "a$libdbpath" != "a"; then
     CFLAGS="-I$libdbpath/include $CFLAGS"
     LDFLAGS="-L$libdbpath/lib $LDFLAGS"
   fi

   # We are going to see if we can found a Berkeley DB located under a
   # libdbpath/include/db4x directory and use lbdbpath/lib/libdb-4.x library.

   ICFG_STATE_SAVE(BDB)
   OLD_LIBS=$LIBS
   for DBVER in "" 6 6.3 6.2 6.1 6.0 5 5.4 5.3 5.2 5.1 5.0 4 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2; do
        if test -z $DBVER; then
           usedblib="-ldb"
           incdbdir=""
        else
           usedblib="-ldb-$DBVER"
           incdbdir=db`echo $DBVER|sed 's/\.//'`"/"
        fi
        if test -z "$libdbpath"; then
           print_libdbpath="..."
        else
            print_libdbpath="under $libdbpath..."
        fi
        echo -n "checking for BerleleyDB v$DBVER $print_libdbpath"
        LIBS="$usedblib $OLD_LIBS"
        AC_LINK_IFELSE(
               [AC_LANG_SOURCE(
                 [
                     #include <${incdbdir}db.h>
                     int main(){
                        int major,minor,patch;
                        if (!db_version(&major,&minor,&patch))
                             return -1;
                        return 0;
                     }
                  ])
               ],
               [echo yes;libdb="yes";],
               [echo "no";libdb="no";]
        )

        if test a"$libdb" = "ayes"; then
           ICFG_BUILD_FLAGS(BDB, "$libdbpath", $usedblib)
           AC_DEFINE(HAVE_BDB, 1, [Define HAVE_BDB if berkeley DB is installed])
           AC_DEFINE_UNQUOTED(BDB_HEADER_PATH(incfile), [<${incdbdir}incfile>], [Set DB_HEADER_PATH macro to compute berkeley DB header subpath])
           break;
        fi
   done

   ICFG_STATE_ROLLBACK
fi

libldap="yes"
AC_ARG_WITH(ldap,
[  --with-ldap        Where to find LDAP libraries ],
[ case "$withval" in
    yes)
         libldap="yes"
    ;;
    no )
         libldap="no"
    ;;
    * )
        libldap="yes"
        libldappath=$withval
    ;;
  esac
],
)

if test "a$libldap" != "ano"; then
   ICFG_STATE_SAVE(LDAP)
   if test "a$libldappath" != "a"; then
        CFLAGS="$CFLAGS -I$libldappath/include"
        LDFLAGS="$LDFLAGS -L$libldappath/lib"
   fi
   AC_CHECK_LIB(ldap,  ldap_search_ext_s,
                [libldap="yes"],
                [libldap="no"]
                )
   if test "a$libldap" = "ayes"; then
       AC_DEFINE(HAVE_LDAP, 1, [Define HAVE_LDAP if LDAP libraries are installed])
       ICFG_BUILD_FLAGS(LDAP, "$libldappath", "-lldap")
   fi
   ICFG_STATE_ROLLBACK
fi

# Detect memcached library
libmemcached="yes"
libmemcachedpath=""
AC_ARG_WITH(memcached,
[  --with-memcached        Where to find Memcached library ],
[ case "$withval" in
    yes)
         libmemcached="yes"
    ;;
    no )
        libmemcached="no"
    ;;
    * )
        libmemcachedpath=$withval
        libmemcached="yes"
    ;;
  esac
],
)

if test a"$libmemcached" != "ano"; then
    ICFG_STATE_SAVE(MEMCACHED)
    if test a"$libmemcachedpath" != "a"; then
       CFLAGS="-l$libmemcachedpath/include $CFLAGS"
    fi
    AC_CHECK_HEADERS(libmemcached/memcached.h, [libmemcached="yes"],[libmemcached="no"])
    if test "a$libmemcached" = "ayes"; then
       ICFG_BUILD_FLAGS(MEMCACHED, "$libmemcachedpath", "-lmemcached -lmemcachedutil")
    fi
    ICFG_STATE_ROLLBACK
fi

# Check for PCRE regex library
AC_ARG_WITH(pcre,
[       --with-pcre     Path to PCRE library],
[
case "$withval" in
     yes)
        pcre=yes;
     ;;
     no)
        pcre=no;
     ;;
     *)
        pcre=yes;
        pcrepath=$withval;
     ;;
     esac
],
[ pcre=yes]
)

if test a"$pcre" != "ano"; then
   ICFG_STATE_SAVE(PCRE)
   if test "a$pcrepath" != "a"; then
       CFLAGS="$CFLAGS -I$pcrepath/include"
       LDFLAGS="$LDFLAGS -L$pcrepath/lib"
   fi
   AC_CHECK_HEADERS(pcre.h,
                    AC_CHECK_LIB(pcre, pcre_exec,[pcre=yes],[pcre=no]),
                    [pcre=no]
   )

   if test "a$pcre" = "ayes"; then
       AC_DEFINE(HAVE_PCRE,1,[Define HAVE_PCRE if pcre installed])
       ICFG_BUILD_FLAGS(PCRE, "$pcrepath", "-lpcre")
   fi
   ICFG_STATE_ROLLBACK
fi

# Check for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(strings.h unistd.h sys/stat.h limits.h)
SYS_TYPES_H="0"
AC_CHECK_HEADERS(sys/types.h,
[AC_DEFINE(HAVE_SYS_TYPES_H,1,[Define HAVE_SYS_TYPES_H if you have the <sys/types.h> header file.])
SYS_TYPES_H="1"
]
)
AC_SUBST(SYS_TYPES_H)

INTTYPES_H="0"
AC_CHECK_HEADERS(inttypes.h,
[AC_DEFINE(HAVE_INTTYPES_H,1,[Define HAVE_INTTYPES_H if you have the <inttypes.h> header file.])
INTTYPES_H="1"
]
)
AC_SUBST(INTTYPES_H)

posix_regex=no
AC_CHECK_HEADERS(regex.h,
  [posix_regex=yes;AC_DEFINE(HAVE_REGEX,1,[Define HAVE_REGEX if regex.h exists (posix regular expressions - maybe more tests needed)])],
  [posix_regex=no]
  )

USE_REGEX=0
if test "a$pcre" = "ayes" -o "a$posix_regex" = "ayes"; then
   USE_REGEX=1
fi
AC_SUBST(USE_REGEX)

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
DEFINE_SIZE_T="0"
AC_CHECK_TYPE(size_t,,[DEFINE_SIZE_T="1"])
AC_SUBST(DEFINE_SIZE_T)

DEFINE_OFF_T="0"
AC_CHECK_TYPE(off_t,,[DEFINE_OFF_T="1"])
AC_SUBST(DEFINE_OFF_T)

AC_CHECK_SIZEOF(off_t)
DEFINE_SIZE_OFF_T=$ac_cv_sizeof_off_t
AC_SUBST(DEFINE_SIZE_OFF_T)

AC_CHECK_SIZEOF(void *)
DEFINE_SIZE_VOID_P=$ac_cv_sizeof_void_p
AC_SUBST(DEFINE_SIZE_VOID_P)

DEFINE_UINT8="0"
AC_CHECK_TYPE(uint8_t,,[DEFINE_UINT8="1"])
AC_SUBST(DEFINE_UINT8)

DEFINE_INT8="0"
AC_CHECK_TYPE(int8_t,,[DEFINE_INT8="1"])
AC_SUBST(DEFINE_INT8)

DEFINE_UINT64="0"
AC_CHECK_TYPE(uint64_t,,[DEFINE_UINT64="1"])
AC_SUBST(DEFINE_UINT64)

DEFINE_INT64="0"
AC_CHECK_TYPE(int64_t,,[DEFINE_INT64="1"])
AC_SUBST(DEFINE_INT64)

#some type size (currently they are not used)
AC_CHECK_SIZEOF(short)
DEFINE_SIZEOFF_SHORT=$ac_cv_sizeof_short
AC_CHECK_SIZEOF(int)
DEFINE_SIZEOFF_INT=$ac_cv_sizeof_int
AC_CHECK_SIZEOF(long)
DEFINE_SIZEOFF_LONG=$ac_cv_sizeof_long
AC_CHECK_SIZEOF(long long)
DEFINE_SIZEOFF_LONG_LONG=$ac_cv_sizeof_long_long

# Checks for library functions.

#Here we are changing the LIBS variable and save the current value to OLD_LIBS variable
EXTRALIBS=""
OLD_LIBS="$LIBS"
LIBS="$LIBS $TEST_LIBS"

#AC_FUNC_VPRINTF

AC_CHECK_FUNCS(nanosleep,
AC_DEFINE(HAVE_NANOSLEEP,1,[Define HAVE_NANOSLEEP if nanosleep exists])
)

AC_CHECK_FUNCS(inet_aton,
AC_DEFINE(HAVE_INET_ATON,1,[Define HAVE_INET_ATON if inet_aton exists])
)

AC_CHECK_FUNCS(strnstr,
AC_DEFINE(HAVE_STRNSTR,1,[Define HAVE_STRNSTR if strnstr exists])
)

AC_CHECK_FUNCS(strcasestr,
AC_DEFINE(HAVE_STRCASESTR,1,[Define HAVE_STRCASESTR if strcasestr exists])
)

AC_CHECK_FUNCS(strncasestr,
AC_DEFINE(HAVE_STRNCASESTR,1,[Define HAVE_STRNCASESTR if strncasestr exists])
)

AC_CHECK_FUNCS(setgroups)

AC_FUNC_STRERROR_R

USE_POLL="0"
if test a"$enablepoll" != "ano"; then
AC_CHECK_HEADERS(poll.h,
    AC_CHECK_FUNCS(poll,
    USE_POLL="1"
    )
)
fi
AC_SUBST(USE_POLL)
# if test a"$USE_POLL" = "1"; then
#    AC_DEFINE(HAVE_POLL,1,[Define HAVE_POLL if poll(2) exists and we can use it])
# fi

#sysv ipc
SYSV_IPC="0"
AC_CHECK_HEADERS(sys/ipc.h,
[AC_DEFINE(HAVE_SYSV_IPC,1,[Define HAVE_SYSV_IPC if sys/ipc.h exists (maybe more tests needed)])
SYSV_IPC="1"
]
)
AC_SUBST(SYSV_IPC)

POSIX_MAPPED_FILES="0"
AC_CHECK_FUNCS(mmap munmap,
[AC_DEFINE(HAVE_POSIX_MAPPED_FILES,1,[Define HAVE_POSIX_MAPPED_FILES if mmap and munmap exists])
POSIX_MAPPED_FILES="1"
]
)
AC_SUBST(POSIX_MAPPED_FILES)

dnl Checking if union semun exists in this system.
AC_MSG_CHECKING([if union semun defined])
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
],
[union semun a_semun;],
AC_DEFINE(HAVE_UNION_SEMUN,1,[Define HAVE_UNION_SEMUN if union semun defined in ipc])
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
)


dnl Checking if interprocess posix semaphores works....
AC_CACHE_CHECK([if posix 1003.1b interprocess semaphores works], ac_cv_10031b_ipc_sem,
   [AC_TRY_RUN([
   #include <semaphore.h>
   #include <sys/wait.h>

   int main(int argc,char **argv){
         sem_t s;
         pid_t pid;
         int status;
         if(sem_init(&s,1,1)!=0){
              return -1;
         }
         if((pid=fork())==0){
	     if(sem_post(&s)<0){
	          exit(-1);
	     }
	     exit(0);
         } else {
	    waitpid(pid,&status,0);
	    if(WEXITSTATUS(status)!=0)
	         exit(-1);
         }
         sem_destroy(&s);
         exit(0);
   }
   ],
   ac_cv_10031b_ipc_sem=yes,
   ac_cv_10031b_ipc_sem=no,
   [AC_MSG_ERROR([cross-compiling,
	presetting ac_cv_10031b_ipc_sem=(yes|no) will help])]
        )
   ]
)

AS_IF(
      [test $ac_cv_10031b_ipc_sem = yes],
      [AC_DEFINE(HAVE_POSIX_SEMAPHORES,1,[Define HAVE_POSIX_SEMAPHORES if posix 1003.1b semaphores works])
      POSIX_SEMAPHORES="1"
      ],[
      POSIX_SEMAPHORES="0"]
)
AC_SUBST(POSIX_SEMAPHORES)

dnl Checking for file locking
AC_CACHE_CHECK([if fcntl file locking works], ac_cv_fcntl,
   [AC_TRY_RUN([
   #include <unistd.h>
   #include <fcntl.h>


   int main(int argc,char **argv){
     struct flock fl;
     int fd;

     fd=open("autoconf.h.in",O_RDWR);

     fl.l_type=F_WRLCK;
     fl.l_whence=SEEK_SET;
     fl.l_start=0;
     fl.l_len=0;

     if(fcntl(fd,F_SETLKW,&fl)<0){
         close(fd);
          return -1;
     }
     close(fd);
     return 0;
   }
   ],
   ac_cv_fcntl=yes,
   ac_cv_fcntl=no,
   [AC_MSG_ERROR([cross-compiling,
	presetting ac_cv_fcntl=(yes|no) will help])]
        )
   ]
)

AS_IF(
        [test $ac_cv_fcntl = yes],
        [AC_DEFINE(HAVE_POSIX_FILE_LOCK,1,[Define HAVE_POSIX_FILE_LOCK if posix fcntl file locking works])
        POSIX_FILE_LOCK="1"
        ],[
        POSIX_FILE_LOCK="0"
   ]
)
AC_SUBST(POSIX_FILE_LOCK)

AC_MSG_CHECKING([if posix shared mem works])
AC_TRY_COMPILE(
[
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
],
[int fd = shm_open("foo", O_CREAT|O_RDWR, S_IRUSR | S_IWUSR);
  if (fd < 0)
      return 0;
  if (shm_unlink("foo") < 0)
      return 0;
],
AC_DEFINE(HAVE_POSIX_SHARED_MEM, 1, [Define HAVE_POSIX_SHARED_MEM if shm_open/shm_unlink functions implemented])
[AC_MSG_RESULT(yes)
POSIX_SHARED_MEM="1"
],
[AC_MSG_RESULT(no)
POSIX_SHARED_MEM="0"
],
)
if test a"$POSIX_SHARED_MEM" = "a1"; then
# Linux and solaris define the shm_open in -rt library.
# This library already included in LIBS for solaris
case "$host_os" in
     linux*)
        EXTRALIBS="$EXTRALIBS -lrt"
     ;;
     kfreebsd*)
        EXTRALIBS="$EXTRALIBS -lrt"
     ;;
     gnu*)
        EXTRALIBS="$EXTRALIBS -lrt"
     ;;
     *)
esac
fi

AC_SUBST(POSIX_SHARED_MEM)

#pthread_rwlock
PTHREADS_RWLOCK="0"
AC_MSG_CHECKING([if have pthread_rwlock])
AC_TRY_COMPILE(
[#include <pthread.h>],
[pthread_rwlock_t lock;],
AC_DEFINE(HAVE_PTHREADS_RWLOCK,1,[Define HAVE_PTHREADS_RWLOCK if pthreads library supports rwlocks])
PTHREADS_RWLOCK="1"
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no),
)
AC_SUBST(PTHREADS_RWLOCK)

#We are pouting back real LIBS variable
LIBS=$OLD_LIBS
LIBS="$LIBS $EXTRALIBS"

#Configure common flags
MODULES_LIBADD=""
if test a"$iscygwin" != a; then
     MODULES_LIBADD="-L../../ -licapapi"
fi
MODULES_CFLAGS="$INVISIBILITY_CFLAG -DCI_BUILD_MODULE"
AC_SUBST(MODULES_LIBADD)
AC_SUBST(MODULES_CFLAGS)

#general parameters
AM_CONDITIONAL(ISCYGWIN,[test a"$iscygwin" != a])

# Now determine which modules will going to build .....

AM_CONDITIONAL(USE_OPENSSL, [test a"$openssl" != "ano"])
AM_CONDITIONAL(USE_REGEX, [test a"$pcre" = "ayes" -o a"$posix_regex" = "ayes"])
AM_CONDITIONAL(USEPERL,[test a"$perlcore" != a])
AM_CONDITIONAL(USEBDB,   [test a"$libdb" != ano])
AM_CONDITIONAL(USELDAP, [test a"$libldap" != ano])
AM_CONDITIONAL(USEMEMCACHED, [test a"$libmemcached" != ano])
AM_CONDITIONAL(USE_RPATH, [test "a$enable_rpath" != "ano"])

AC_OUTPUT([
include/c-icap-conf.h Makefile utils/Makefile services/Makefile
services/echo/Makefile services/ex-206/Makefile modules/Makefile tests/Makefile
docs/Makefile docs/man/Makefile
])