summaryrefslogtreecommitdiff
path: root/configure.in
blob: 3794c1593dbe5ddbed6fc71654ae2f955186ea62 (plain)
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
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.2)
AC_INIT(src/xmlsec.c)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST

XMLSEC_PACKAGE=xmlsec1
XMLSEC_VERSION_MAJOR=1
XMLSEC_VERSION_MINOR=1
XMLSEC_VERSION_SUBMINOR=0
XMLSEC_VERSION="$XMLSEC_VERSION_MAJOR.$XMLSEC_VERSION_MINOR.$XMLSEC_VERSION_SUBMINOR"
XMLSEC_VERSION_INFO=`echo $XMLSEC_VERSION | awk -F. '{ printf "%d:%d:%d", $1+$2, $3, $2 }'`
XMLSEC_VERSION_SAFE=`echo $XMLSEC_VERSION | sed 's/\./_/g'`

PACKAGE=$XMLSEC_PACKAGE
VERSION=$XMLSEC_VERSION

AC_SUBST(XMLSEC_VERSION)
AC_SUBST(XMLSEC_PACKAGE)
AC_SUBST(XMLSEC_VERSION_SAFE)
AC_SUBST(XMLSEC_VERSION_MAJOR)
AC_SUBST(XMLSEC_VERSION_MINOR)
AC_SUBST(XMLSEC_VERSION_SUBMINOR)
AC_SUBST(XMLSEC_VERSION_INFO)

AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
AM_MAINTAINER_MODE

dnl
dnl Check the environment
dnl
AC_PROG_CC
AC_PROG_INSTALL
AC_ARG_PROGRAM
AC_STDC_HEADERS
AM_PROG_LIBTOOL
AC_PATH_PROG(RM, rm, /bin/rm)
AC_PATH_PROG(MV, mv, /bin/mv)
AC_PATH_PROG(TAR, tar, /bin/tar)

dnl Make sure we have an ANSI compiler
AM_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([stdio.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([string.h])
AC_CHECK_HEADERS([ctype.h])
AC_CHECK_HEADERS([errno.h])
AC_CHECK_HEADERS([ansidecl.h])
AC_CHECK_HEADERS([time.h])
AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf timegm)



XMLSEC_DEFINES=""


dnl ==========================================================================
dnl Specific setup for Aleksey's development environment: 
dnl	- with xkms support (while in development)
dnl	- with debug
dnl 	- with pedantic compiler flags
dnl	- with static binaries
dnl ==========================================================================
AC_MSG_CHECKING(for development environment) 
AC_ARG_ENABLE(development,   [  --enable-development    enable development environment (no)])
if test "$enable_development" = "yes" -o "${LOGNAME}" = "aleksey" ; then
    enable_xkms="yes"
    enable_debuging="yes"
    enable_pedantic="yes"
    enable_static_linking="yes"
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi    


dnl ==========================================================================
dnl Perform host specific configuration
dnl ==========================================================================
case "${host}" in
    *aix* )
	CFLAGS="${CFLAGS} -D_ALL_SOURCE"
	;;
esac


dnl ==========================================================================
dnl check do we have size_t and its size, 
dnl TODO: will need to replace this and the xmlSecSize define with 
dnl typedef on next ABI refresh
dnl ==========================================================================
AC_CHECK_SIZEOF(size_t)
if test "$ac_cv_sizeof_size_t" -ne "4" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_SIZE_T"
fi

dnl ==========================================================================
dnl find libxml
dnl ==========================================================================
LIBXML_WITHOUT="no"
LIBXML_MIN_VERSION=2.4.24
LIBXML_CONFIG="xml2-config"
LIBXML_PREFIX=""
LIBXML_CFLAG=""
LIBXML_LIBS=""
AC_MSG_CHECKING(for libxml2 libraries >= $LIBXML_MIN_VERSION) 
AC_ARG_WITH(libxml, [  --with-libxml=[PFX]       libxml2 location])
if test "$with_libxml" = "no" ; then 
    AC_MSG_ERROR(libxml2 is required for $PACKAGE)
else
    if test "$with_libxml" != "" ; then
	LIBXML_PREFIX=$with_libxml
	LIBXML_CONFIG=$LIBXML_PREFIX/bin/$LIBXML_CONFIG
    fi

    if ! $LIBXML_CONFIG --version > /dev/null 2>&1
    then
	AC_MSG_ERROR(Could not find libxml2 anywhere (see config.log for details).)
    fi
    vers=`$LIBXML_CONFIG --version | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
    minvers=`echo $LIBXML_MIN_VERSION | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
    if test "$vers" -ge "$minvers"
    then
        LIBXML_LIBS="`$LIBXML_CONFIG --libs`"
        LIBXML_CFLAGS="`$LIBXML_CONFIG --cflags`"
	LIBXML_VERSION="`$LIBXML_CONFIG --version`"
        AC_MSG_RESULT(yes ('$LIBXML_VERSION'))
    else
        AC_MSG_ERROR(You need at least libxml2 $LIBXML_MIN_VERSION for this version of $PACKAGE)
    fi
fi
AC_SUBST(LIBXML_WITHOUT)
AC_SUBST(LIBXML_MIN_VERSION)
AC_SUBST(LIBXML_CONFIG)	
AC_SUBST(LIBXML_PREFIX)
AC_SUBST(LIBXML_CFLAGS)
AC_SUBST(LIBXML_LIBS)

dnl ==========================================================================
dnl find libxslt
dnl ==========================================================================
LIBXSLT_WITHOUT="no"
LIBXSLT_MIN_VERSION=1.0.20
LIBXSLT_CONFIG="xslt-config"
LIBXSLT_PREFIX=""
LIBXSLT_CFLAGS=""
LIBXSLT_LIBS=""
AC_MSG_CHECKING(for libxslt libraries >= $LIBXSLT_MIN_VERSION) 
AC_ARG_WITH(libxslt, [  --with-libxslt=[PFX]      libxslt location])
if test "$with_libxslt" = "no" ; then
    LIBXSLT_WITHOUT="yes"
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_XSLT=1"
    AC_MSG_RESULT(no)
else
    if test "$with_libxslt" != "" ; then
	LIBXSLT_PREFIX=$with_libxslt
	LIBXSLT_CONFIG=$LIBXSLT_PREFIX/bin/$LIBXSLT_CONFIG
    fi
    if ! $LIBXSLT_CONFIG --version > /dev/null 2>&1
    then
	if test "$with_libxslt" != "" ; then
	    AC_MSG_ERROR(Unable to find libxslt at '$with_libxslt')
	else 
	    LIBXSLT_WITHOUT="yes"
	    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_XSLT=1"
	    AC_MSG_RESULT(no)
	fi
    else
        vers=`$LIBXSLT_CONFIG --version | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
	minvers=`echo $LIBXSLT_MIN_VERSION | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
	if test "$vers" -ge "$minvers"
	then
    	    LIBXSLT_LIBS="`$LIBXSLT_CONFIG --libs`"
	    LIBXSLT_CFLAGS="`$LIBXSLT_CONFIG --cflags`"
	    LIBXSLT_VERSION="`$LIBXSLT_CONFIG --version`"
    	    AC_MSG_RESULT(yes ('$LIBXSLT_VERSION'))
	else
    	    AC_MSG_ERROR(You need at least libxslt $LIBXSLT_MIN_VERSION for this version of $PACKAGE)
	fi	
    fi
fi
AC_SUBST(LIBXSLT_WITHOUT)
AC_SUBST(LIBXSLT_MIN_VERSION)
AC_SUBST(LIBXSLT_PREFIX)
AC_SUBST(LIBXSLT_CONFIG)	
AC_SUBST(LIBXSLT_CFLAGS)
AC_SUBST(LIBXSLT_LIBS)

dnl ==========================================================================
dnl See if we can find a crypto library
dnl ==========================================================================
XMLSEC_CRYPTO=""
XMLSEC_CRYPTO_LIST=""
XMLSEC_CRYPTO_DISABLED_LIST=""
XMLSEC_CRYPTO_LIB=""
XMLSEC_CRYPTO_CFLAGS=""
XMLSEC_CRYPTO_CFLAGS_APP=""
XMLSEC_CRYPTO_LIBS=""
XMLSEC_CRYPTO_LDADDS=""

dnl ==========================================================================
dnl OpenSSL
dnl ==========================================================================
ac_openssl_lib_dir="/usr/local/lib /usr/lib /usr/local /usr/local/ssl /usr/local/ssl/lib /usr/pkg"
ac_openssl_inc_dir="/usr/local/include /usr/include /usr/local /usr/local/ssl /usr/pkg /usr/local/ssl/include"

OPENSSL_WITHOUT="yes"
OPENSSL_MIN_VERSION="0.9.6"
OPENSSL_VERSION=""
OPENSSL_PREFIX=""
OPENSSL_CFLAGS="-DXMLSEC_CRYPTO=\\\"openssl\\\" -DXMLSEC_CRYPTO_OPENSSL=1"
OPENSSL_LIBS=""
OPENSSL_LDADDS=""
OPENSSL_CRYPTO_LIB="xmlsec1-openssl"
AC_MSG_CHECKING(for openssl libraries >= $OPENSSL_MIN_VERSION) 
AC_ARG_WITH(openssl, [  --with-openssl=[PFX]      openssl location])
if test "$with_openssl" = "no" ; then
    OPENSSL_WITHOUT="yes"
    XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST openssl"
    AC_MSG_RESULT(no)
else
    if test "$with_openssl" != "" ; then
	OPENSSL_PREFIX=$with_openssl
	OPENSSL_CFLAGS="$OPENSSL_CFLAGS -I$OPENSSL_PREFIX/include"
	OPENSSL_LIBS="-L$OPENSSL_PREFIX/lib -lcrypto"
	OPENSSL_LDADDS="$OPENSSL_PREFIX/lib/libcrypto.a"
	OPENSSL_INCLUDES_FOUND="yes"
	OPENSSL_LIBS_FOUND="yes"
    else
	OPENSSL_INCLUDES_FOUND="no"
	OPENSSL_LIBS_FOUND="no"
	for dir in $ac_openssl_inc_dir; do
	    if test -f $dir/openssl/ssl.h; then
		dnl do not add -I/usr/include because compiler does it anyway
		if test "$dir" = "/usr/include" ; then
		    OPENSSL_CFLAGS="$OPENSSL_CFLAGS "
		else
		    OPENSSL_CFLAGS="$OPENSSL_CFLAGS -I$dir"
		fi
		OPENSSL_INCLUDES_FOUND="yes"
		break
	    fi
	done

	for dir in $ac_openssl_lib_dir; do
	    if test -f $dir/libcrypto.a; then
		dnl do not add -L/usr/lib because compiler does it anyway
		if test "$dir" = "/usr/lib" ; then
		    OPENSSL_LIBS="-lcrypto"
		else
		    OPENSSL_LIBS="-L$dir -lcrypto"
		fi
		OPENSSL_LIBS_FOUND="yes"
		OPENSSL_LDADDS="$dir/libcrypto.a"
		ac_found_openssl_lib_dir=$dir
		break;
	    fi
	done
    fi
    
    if test "$OPENSSL_INCLUDES_FOUND" = "yes" -a "$OPENSSL_LIBS_FOUND" = "yes" ;
    then
	dnl Check the OpenSSL version    
	OLD_CPPFLAGS=$CPPFLAGS
	CPPFLAGS="$OPENSSL_CFLAGS"
	AC_EGREP_CPP(yes,[
	    #include <openssl/opensslv.h>
	    #if OPENSSL_VERSION_NUMBER >= 0x00906000L
		yes
	    #endif
	],[
	    OPENSSL_VERSION="0.9.6"
	],[
    	    AC_MSG_ERROR(You need at least OpenSSL 0.9.6 for this version of $PACKAGE)
	]) 
	AC_EGREP_CPP(yes,[
	    #include <openssl/opensslv.h>
	    #if OPENSSL_VERSION_NUMBER >= 0x00907000L
		yes
	    #endif
	],[
	    OPENSSL_VERSION="0.9.7"
	],[
	    OPENSSL_VERSION="0.9.6"
	    OPENSSL_CFLAGS="$OPENSSL_CFLAGS -DXMLSEC_OPENSSL_096=1"
	])    
	CPPFLAGS=$OLD_CPPFLAGS
	OPENSSL_WITHOUT="no"
	
	dnl first crypto library is default one
	if test "z$XMLSEC_CRYPTO" = "z"
	then
	    XMLSEC_CRYPTO="openssl"
    	    XMLSEC_CRYPTO_LIB="$OPENSSL_CRYPTO_LIB"
	    XMLSEC_CRYPTO_CFLAGS="$OPENSSL_CFLAGS"
	    XMLSEC_CRYPTO_LIBS="$OPENSSL_LIBS"
	    XMLSEC_CRYPTO_LDADDS="$OPENSSL_LDADDS"
	fi	
	XMLSEC_CRYPTO_LIST="$XMLSEC_CRYPTO_LIST openssl"
        AC_MSG_RESULT(yes ('$OPENSSL_VERSION'))
    else
	XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST openssl"
        AC_MSG_RESULT(no)
    fi
fi
AC_SUBST(OPENSSL_WITHOUT)
AC_SUBST(OPENSSL_MIN_VERSION)
AC_SUBST(OPENSSL_VERSION)
AC_SUBST(OPENSSL_CONFIG)	
AC_SUBST(OPENSSL_PREFIX)
AC_SUBST(OPENSSL_CFLAGS)
AC_SUBST(OPENSSL_LIBS)
AC_SUBST(OPENSSL_LDADDS)
AC_SUBST(OPENSSL_CRYPTO_LIB)

dnl ==========================================================================
dnl See if we can find GnuTLS
dnl ==========================================================================
GNUTLS_CONFIG="libgnutls-config"
GNUTLS_WITHOUT="no"
GNUTLS_MIN_VERSION="0.8.1"
GNUTLS_VERSION=""
GNUTLS_PREFIX=""
GNUTLS_CFLAGS="-DXMLSEC_CRYPTO=\\\"gnutls\\\" -DXMLSEC_CRYPTO_GNUTLS=1"
GNUTLS_LIBS=""
GNUTLS_LDADDS=""
GNUTLS_CRYPTO_LIB="xmlsec1-gnutls"

AC_MSG_CHECKING(for gnutls libraries >= $GNUTLS_MIN_VERSION) 
AC_ARG_WITH(gnutls, [  --with-gnutls=[PFX]       gnutls location])
if test "$with_gnutls" = "no" ; then
    GNUTLS_WITHOUT="yes"
    XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST gnutls"
    AC_MSG_RESULT(no)
else
    if test "$with_gnutls" != "" ; then
	GNUTLS_PREFIX=$with_gnutls
	GNUTLS_CONFIG=$GNUTLS_PREFIX/bin/$GNUTLS_CONFIG
    fi
    if ! $GNUTLS_CONFIG --version > /dev/null 2>&1
    then
	GNUTLS_WITHOUT="yes"
	if test "$with_gnutls" != "" ; then
	    AC_MSG_ERROR(Unable to find gnutls at '$with_gnutls')
	fi
    else
        vers=`$GNUTLS_CONFIG --version | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
	minvers=`echo $GNUTLS_MIN_VERSION | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
	if test "$vers" -ge "$minvers"
	then
	    GNUTLS_CFLAGS="$GNUTLS_CFLAGS `$GNUTLS_CONFIG --cflags`"
    	    GNUTLS_LIBS="$GNUTLS_LIBS `$GNUTLS_CONFIG --libs`"
	    GNUTLS_VERSION="`$GNUTLS_CONFIG --version`"
	else
    	    AC_MSG_ERROR(You need at least gnutls $GNUTLS_MIN_VERSION for this version of $PACKAGE)
	fi	
    fi

    dnl update crypt libraries list
    if test "$GNUTLS_WITHOUT" = "no" ;
    then
	dnl first crypto library is default one
	if test "z$XMLSEC_CRYPTO" = "z"
	then
	    XMLSEC_CRYPTO="gnutls"
    	    XMLSEC_CRYPTO_LIB="$GNUTLS_CRYPTO_LIB"
	    XMLSEC_CRYPTO_CFLAGS="$GNUTLS_CFLAGS"
	    XMLSEC_CRYPTO_LIBS="$GNUTLS_LIBS"
	    XMLSEC_CRYPTO_LDADDS="$GNUTLS_LDADDS"
	fi	
	XMLSEC_CRYPTO_LIST="$XMLSEC_CRYPTO_LIST gnutls"
    	AC_MSG_RESULT(yes ('$GNUTLS_VERSION'))
    else
	XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST gnutls"
	AC_MSG_RESULT(no)
    fi
fi
AC_SUBST(GNUTLS_WITHOUT)
AC_SUBST(GNUTLS_MIN_VERSION)
AC_SUBST(GNUTLS_VERSION)
AC_SUBST(GNUTLS_CONFIG)	
AC_SUBST(GNUTLS_PREFIX)
AC_SUBST(GNUTLS_CFLAGS)
AC_SUBST(GNUTLS_LIBS)
AC_SUBST(GNUTLS_LDADDS)
AC_SUBST(GNUTLS_CRYPTO_LIB)

dnl ==========================================================================
dnl See if we can find NSS and NSPR
dnl Allow the use of:
dnl   1.  Mozilla style distribution where all mozilla components (NSS, NSPR
dnl       are just 2 of over 100 components) are under one directory.
dnl       options: [--with-mozilla-ver=<VERSION>]
dnl
dnl       Using the version number, various directories are searched
dnl       for NSS & NSPR
dnl
dnl                      AND / OR
dnl
dnl   2.  separate NSS & NSPR distributions
dnl       options: [--with-nss=<PFX>] [--with-nspr=<PFX>]
dnl   
dnl   2 overrides 1
dnl
dnl ==========================================================================
    
NSS_WITHOUT="no"
NSS_MIN_VERSION="3.2"
MOZILLA_MIN_VERSION="1.4"
NSS_VERSION=""
NSS_CFLAGS="-DXMLSEC_CRYPTO=\\\"nss\\\" -DXMLSEC_CRYPTO_NSS=1"
NSS_LIBS=""
NSS_LDADDS=""
NSS_PREFIX=""
NSPR_PREFIX=""
NSS_LIBS_LIST="-lnss3 -lsmime3"
NSPR_LIBS_LIST="-lnspr4 -lplds4 -lplc4"
NSS_CRYPTO_LIB="xmlsec1-nss"

dnl if nss is disabled, bail out early
AC_ARG_WITH(nss, [  --with-nss=[PFX]          nss location])
AC_ARG_WITH(nspr, [  --with-nspr=[PFX]         nspr location (needed for NSS)])
AC_ARG_WITH(mozilla, [  --with-mozilla-ver=[VER]  mozilla version (alt to --with-nss, --with-nspr)])
if test "$with_nss" = "no" ; then
    NSS_WITHOUT="yes"
    XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST nss"
else
    MOZILLA_VERSION="1.4"
    NSPR_MIN_VERSION="4.0"
    NSPR_INCLUDES_FOUND="no"
    NSPR_LIBS_FOUND="no"
    NSS_EXPLICIT="no"
    NSPR_EXPLICIT="no"
    NSPR_PRINIT_H=""
    NSS_NSS_H=""

    dnl process the mozilla options if any

    if test "$with_mozilla_version" != "" ; then
        MOZILLA_VERSION=$with_mozilla_version
    fi

    ac_mozilla_name=mozilla-$MOZILLA_VERSION
    ac_nss_lib_dir="/usr/lib /usr/local/lib /usr/lib/$ac_mozilla_name /usr/local/lib/$ac_mozilla_name"
    ac_nss_inc_dir="/usr/include /usr/include/mozilla /usr/local/include /usr/local/include/mozilla /usr/include/$ac_mozilla_name /usr/local/include/$ac_mozilla_name"

    dnl now look for nspr
    AC_MSG_CHECKING(for nspr libraries >= $NSPR_MIN_VERSION)

    if test "$with_nspr" = "no" ; then
      AC_MSG_RESULT(no)
    else  
      if test "$with_nspr" != "" ; then
         NSPR_PREFIX="$with_nspr"
         NSPR_CFLAGS="-I$with_nspr/include"
         if test "$with_gnu_ld" = yes
         then
           NSPR_LIBS="-Wl,-rpath-link -Wl,$with_nspr/lib -L$with_nspr/lib $NSPR_LIBS_LIST"
         else
           NSPR_LIBS="-L$with_nspr/lib $NSPR_LIBS_LIST"
         fi
         NSPR_LDADDS="-L$with_nspr/lib $NSPR_LIBS_LIST"
         NSPR_INCLUDES_FOUND="yes"
         NSPR_LIBS_FOUND="yes"
         NSPR_EXPLICIT="yes"
         NSPR_PRINIT_H="$with_nspr/include/prinit.h"
      else
         for dir in $ac_nss_inc_dir; do
            if test -f $dir/nspr/prinit.h; then
               dnl do not add -I/usr/include because compiler does it anyway
               if test "$dir" = "/usr/include" ; then
                  NSPR_CFLAGS=""
               else
                  NSPR_CFLAGS="-I$dir/nspr"
               fi
               NSPR_INCLUDES_FOUND="yes"
               NSPR_PRINIT_H="$dir/nspr/prinit.h"
               break
            fi
         done

         for dir in $ac_nss_lib_dir; do
            if test -f $dir/libnspr4.so; then
               dnl do not add -L/usr/lib because compiler does it anyway
               if test "$dir" = "/usr/lib" ; then
                  NSPR_LIBS="$NSPR_LIBS_LIST"
               else
                  if test "$with_gnu_ld" = yes
                  then
                     NSPR_LIBS="-Wl,-rpath-link -Wl,$dir -L$dir $NSPR_LIBS_LIST"
                  else
                     NSPR_LIBS="-L$dir $NSPR_LIBS_LIST"
                  fi
               fi
               NSPR_LIBS_FOUND="yes"
               break
            fi
         done
      fi

      if test "$NSPR_INCLUDES_FOUND" = "yes" -a "$NSPR_LIBS_FOUND" = "yes" ; 
      then
         NSPR_VERSION=`cat $NSPR_PRINIT_H | grep PR_VERSION | grep '#define' | awk -F' ' '{printf "%s", $3}' | sed -e 's/"//g'`
         OLD_CPPFLAGS=$CPPFLAGS
         CPPFLAGS="$NSPR_CFLAGS"
         AC_EGREP_CPP(yes,[
            #include <prinit.h>
            #if PR_VMAJOR >= 4
               yes
            #endif
          ],[
    	    AC_MSG_RESULT(yes ('$NSPR_VERSION'))
          ],[
            NSPR_INCLUDES_FOUND="no"
            AC_MSG_RESULT(no)
            ]) 
         CPPFLAGS="$OLD_CPPFLAGS"
      else
         AC_MSG_RESULT(no)
      fi

    fi

    dnl look for nss
    AC_MSG_CHECKING(for nss libraries >= $NSS_MIN_VERSION)

    if test "$with_nss" != "" ; then
       NSS_PREFIX="$with_nss"
       NSS_CFLAGS="$NSS_CFLAGS -I$with_nss/include"
       if test "$with_gnu_ld" = yes
       then
          NSS_LIBS="$NSS_LIBS -Wl,-rpath-link -Wl,$with_nss/lib -L$with_nss/lib $NSS_LIBS_LIST"
       else
          NSS_LIBS="$NSS_LIBS -L$with_nss/lib $NSS_LIBS_LIST"
       fi
       NSS_LDADDS="-L$with_nss/lib $NSS_LIBS_LIST"
       NSS_INCLUDES_FOUND="yes"
       NSS_LIBS_FOUND="yes"
       NSS_EXPLICIT="yes"
       NSS_NSS_H="$with_nss/include/nss.h"
    else
       for dir in $ac_nss_inc_dir; do
          if test -f $dir/nss/nss.h; then
             dnl do not add -I/usr/include because compiler does it anyway
             if test "$dir" = "/usr/include" ; then
                NSS_CFLAGS="$NSS_CFLAGS"
             else
                NSS_CFLAGS="$NSS_CFLAGS -I$dir/nss"
             fi
             NSS_INCLUDES_FOUND="yes"
             NSS_NSS_H="$dir/nss/nss.h"
             break
          fi
       done
       for dir in $ac_nss_lib_dir; do
          if test -f $dir/libnss3.so; then
             dnl do not add -L/usr/lib because compiler does it anyway
             if test "$dir" = "/usr/lib" ; then
                NSS_LIBS="$NSS_LIBS_LIST"
             else
                if test "$with_gnu_ld" = yes
                then
                   NSS_LIBS="-Wl,-rpath-link -Wl,$dir -L$dir $NSS_LIBS_LIST"
                else
                   NSS_LIBS="-L$dir $NSS_LIBS_LIST"
                fi
             fi
             NSS_LIBS_FOUND="yes"
             break
          fi
       done
    fi

    if test "$NSS_INCLUDES_FOUND" = "yes" -a "$NSS_LIBS_FOUND" = "yes" ; 
    then
       NSS_VERSION=`cat $NSS_NSS_H | grep NSS_VERSION | grep '#define' | awk -F' ' '{printf "%s", $3}' | sed -e 's/"//g'`       
       OLD_CPPFLAGS=$CPPFLAGS
       CPPFLAGS="$NSS_CFLAGS"
       AC_EGREP_CPP(yes,[
          #include <nss.h>
          #if NSS_VMAJOR >= 3 && NSS_VMINOR >= 2
             yes
          #endif
        ],[
    	  AC_MSG_RESULT(yes ('$NSS_VERSION'))
        ],[
          NSS_INCLUDES_FOUND="no"
          AC_MSG_RESULT(no)
          ]) 
       CPPFLAGS="$OLD_CPPFLAGS"
    else
       AC_MSG_RESULT(no)
    fi

    if test "$NSPR_INCLUDES_FOUND" != "yes" -o "$NSPR_LIBS_FOUND" != "yes"
    then
       if test "$NSPR_EXPLICIT" = "yes"
       then 
          AC_MSG_ERROR(You need atleast version 4.0 of NSPR as a pre-requisite for NSS in this version of $PACKAGE)
       else
          NSS_WITHOUT="yes"
       fi
    fi

    if test "$NSS_INCLUDES_FOUND" != "yes" -o "$NSS_LIBS_FOUND" != "yes"
    then
       if test "$NSS_EXPLICIT" = "yes"
       then 
         AC_MSG_ERROR(You need atleast version 3.2 of NSS for this version of $PACKAGE)
       else
         NSS_WITHOUT="yes"
       fi
    fi
    
    if test "$NSS_WITHOUT" = "no"
    then
       NSS_CFLAGS="$NSS_CFLAGS $NSPR_CFLAGS"
       NSS_LIBS="$NSS_LIBS $NSPR_LIBS"
       NSS_LDADDS="$NSS_LDADDS $NSPR_LDADDS"
       dnl first crypto library is default one
       if test "z$XMLSEC_CRYPTO" = "z"
       then
         XMLSEC_CRYPTO="nss"
         XMLSEC_CRYPTO_LIB="$NSS_CRYPTO_LIB"
         XMLSEC_CRYPTO_CFLAGS="$NSS_CFLAGS"
         XMLSEC_CRYPTO_LIBS="$NSS_LIBS"
         XMLSEC_CRYPTO_LDADDS="$NSS_LDADDS"
       fi
       XMLSEC_CRYPTO_LIST="$XMLSEC_CRYPTO_LIST nss"
    else
       XMLSEC_CRYPTO_DISABLED_LIST="$XMLSEC_CRYPTO_DISABLED_LIST nss"
    fi
fi

AC_SUBST(NSS_WITHOUT)
AC_SUBST(NSS_MIN_VERSION)
AC_SUBST(MOZILLA_MIN_VERSION)
AC_SUBST(NSS_VERSION)
AC_SUBST(NSS_CFLAGS)
AC_SUBST(NSS_LIBS)
AC_SUBST(NSS_LDADDS)
AC_SUBST(NSS_LIBS_LIST)
AC_SUBST(NSPR_LIBS_LIST)
AC_SUBST(NSS_PREFIX)
AC_SUBST(NSPR_PREFIX)
AC_SUBST(NSS_CRYPTO_LIB)

dnl ==========================================================================
dnl Do we have a crypto library?
dnl ==========================================================================
AC_MSG_CHECKING(for crypto library) 
if test "z$XMLSEC_CRYPTO" = "z"
then
    AC_MSG_ERROR(At least one crypto library should exist for $PACKAGE)
else
    AC_MSG_RESULT(yes ('$XMLSEC_CRYPTO'))
fi


dnl ==========================================================================
dnl See do we need SHA1 suport
dnl ==========================================================================
AC_MSG_CHECKING(for SHA1 support) 
AC_ARG_ENABLE(sha1,   [  --enable-sha1           enable SHA1 support (yes)])
if test "$enable_sha1" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_SHA1=1"
    XMLSEC_NO_SHA1="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_SHA1="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_SHA1)

dnl ==========================================================================
dnl See do we need RIPEMD-160 suport
dnl ==========================================================================
AC_MSG_CHECKING(for RIPEMD-160 support) 
AC_ARG_ENABLE(ripemd160,   [  --enable-ripemd160      enable RIPEMD-160 support (yes)])
if test "$enable_ripemd160" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_RIPEMD160=1"
    XMLSEC_NO_RIPEMD160="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_RIPEMD160="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_RIPEMD160)

dnl ==========================================================================
dnl See do we need HMAC suport
dnl ==========================================================================
AC_MSG_CHECKING(for HMAC support) 
AC_ARG_ENABLE(hmac,   [  --enable-hmac           enable HMAC support (yes)])
if test "$enable_hmac" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_HMAC=1"
    XMLSEC_NO_HMAC="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_HMAC="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_HMAC)

dnl ==========================================================================
dnl See do we need DSA suport
dnl ==========================================================================
AC_MSG_CHECKING(for DSA support) 
AC_ARG_ENABLE(dsa,   [  --enable-dsa            enable DSA support (yes)])
if test "$enable_dsa" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_DSA=1"
    XMLSEC_NO_DSA="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_DSA="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_DSA)

dnl ==========================================================================
dnl See do we need RSA suport
dnl ==========================================================================
AC_MSG_CHECKING(for RSA support) 
AC_ARG_ENABLE(rsa,   [  --enable-rsa            enable RSA support (yes)])
if test "$enable_rsa" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_RSA=1"
    XMLSEC_NO_RSA="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_RSA="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_RSA)

dnl ==========================================================================
dnl See do we need x509 suport
dnl ==========================================================================
AC_MSG_CHECKING(for x509 support) 
AC_ARG_ENABLE(x509,   [  --enable-x509           enable x509 support (yes)])
if test "$enable_x509" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_X509=1"
    XMLSEC_NO_X509="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_X509="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_X509)

dnl ==========================================================================
dnl See do we need DES suport
dnl ==========================================================================
AC_MSG_CHECKING(for DES support) 
AC_ARG_ENABLE(des,   [  --enable-des            enable DES support (yes)])
if test "$enable_des" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_DES=1"
    XMLSEC_NO_DES="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_DES="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_DES)

dnl ==========================================================================
dnl See do we need AES suport
dnl ==========================================================================
AC_MSG_CHECKING(for AES support) 
AC_ARG_ENABLE(aes,   [  --enable-aes            enable AES support (OpenSSL >= 0.9.7 is required)])
if test "$enable_aes" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_AES=1"
    XMLSEC_NO_AES="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_AES="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_AES)

dnl ==========================================================================
dnl See do we need XMLDSig suport
dnl ==========================================================================
AC_MSG_CHECKING(for XMLDSig support) 
AC_ARG_ENABLE(xmldsig,   [  --enable-xmldsig        enable XMLDSig support (yes)])
if test "$enable_xmldsig" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_XMLDSIG=1"
    XMLSEC_NO_XMLDSIG="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_XMLDSIG="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_XMLDSIG)

dnl ==========================================================================
dnl See do we need XMLEnc suport
dnl ==========================================================================
AC_MSG_CHECKING(for XMLEnc support) 
AC_ARG_ENABLE(xmlenc,   [  --enable-xmlenc         enable XMLEnc support (yes)])
if test "$enable_xmlenc" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_XMLENC=1"
    XMLSEC_NO_XMLENC="1"
    AC_MSG_RESULT(no)
else
    XMLSEC_NO_XMLENC="0"
    AC_MSG_RESULT(yes)
fi    
AC_SUBST(XMLSEC_NO_XMLENC)

dnl ==========================================================================
dnl See do we need XKMS suport
dnl ==========================================================================
AC_MSG_CHECKING(for XMKMS support - under development, not stable yet) 
AC_ARG_ENABLE(xkms,   [  --enable-xkms           enable XKMS support - under development (no)])
if test "$enable_xkms" = "yes" ; then
    XMLSEC_NO_XKMS="0"
    AC_MSG_RESULT(yes)
else
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_XKMS=1"
    XMLSEC_NO_XKMS="1"
    AC_MSG_RESULT(no)
fi    
AC_SUBST(XMLSEC_NO_XKMS)

dnl ==========================================================================
dnl See do we need Simple Keys Manager 
dnl ==========================================================================
AC_MSG_CHECKING(for Simple Keys Manager testing) 
AC_ARG_ENABLE(skm,   [  --enable-skm            enable Simple Keys Manager testing(yes)])
if test "$enable_skm" = "no" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_SKM_TEST=1"
    AC_MSG_RESULT(no)
else
    AC_MSG_RESULT(yes)
fi    

dnl ==========================================================================
dnl See do we need templates tests
dnl ==========================================================================
AC_MSG_CHECKING(for templates testing) 
AC_ARG_ENABLE(skm,   [  --enable-tmpl-tests     enable templates testing in xmlsec utility (yes)])
if test "$enable_tmpl_tests" = "yes" ; then
    XMLSEC_DEFINES="$XMLSEC_DEFINES -DXMLSEC_NO_TMPL_TEST=1"
    AC_MSG_RESULT(no)
else
    AC_MSG_RESULT(yes)
fi    

dnl ==========================================================================
dnl Debug 
dnl ==========================================================================
AC_MSG_CHECKING(for debuging) 
AC_ARG_ENABLE(debuging,   [  --enable-debuging       enable debuging compilation flags (no)])
if test "$enable_debuging" = "yes" ; then
    CFLAGS="$CFLAGS -g"
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi    

dnl ==========================================================================
dnl Profiling 
dnl ==========================================================================
AC_MSG_CHECKING(for profiling) 
AC_ARG_ENABLE(profiling,   [  --enable-profiling      enable profiling compilation flags (no)])
if test "$enable_profiling" = "yes" ; then
    CFLAGS="$CFLAGS -pg"
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi 

dnl ==========================================================================
dnl Pedantic compilation
dnl ==========================================================================
AC_MSG_CHECKING(for pedantic) 
AC_ARG_ENABLE(pedantic,   [  --enable-pedantic       enable pedantic compilation flags (no)])
if test "$enable_pedantic" = "yes" ; then
    dnl CFLAGS="$CFLAGS -pedantic -Wall -ansi -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls"
    CFLAGS="$CFLAGS -O -pedantic -Wall -ansi -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls"
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi    

dnl ==========================================================================
dnl Static linking
dnl ==========================================================================
XMLSEC_STATIC_BINARIES=""
AC_MSG_CHECKING(for static linking) 
AC_ARG_ENABLE(static_linking,   [  --enable-static-linking enable static linking (no)])
if test "$enable_static_linking" = "yes" ; then
    XMLSEC_STATIC_BINARIES="-static"
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi    
AC_SUBST(XMLSEC_STATIC_BINARIES)

dnl ==========================================================================
dnl Final steps: xmlsec config
dnl ==========================================================================
XMLSEC_CFLAGS="$XMLSEC_DEFINES -I${includedir}/xmlsec1 $LIBXML_CFLAGS $LIBXSLT_CFLAGS $XMLSEC_CRYPTO_CFLAGS"
XMLSEC_LIBS="-L${libdir} -l$XMLSEC_CRYPTO_LIB -lxmlsec1 $LIBXML_LIBS $LIBXSLT_LIBS $XMLSEC_CRYPTO_LIBS"

AC_SUBST(XMLSEC_CFLAGS)
AC_SUBST(XMLSEC_LIBS)

CFLAGS="$CFLAGS $XMLSEC_DEFINES"
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(XMLSEC_DEFINES)

AC_SUBST(XMLSEC_CRYPTO)
AC_SUBST(XMLSEC_CRYPTO_LIST)
AC_SUBST(XMLSEC_CRYPTO_DISABLED_LIST)
AC_SUBST(XMLSEC_CRYPTO_LIB)
AC_SUBST(XMLSEC_CRYPTO_CFLAGS)
AC_SUBST(XMLSEC_CRYPTO_LIBS)
AC_SUBST(XMLSEC_CRYPTO_LDADDS)

dnl ==========================================================================
dnl Which files to process
dnl ==========================================================================
rm -f rm COPYING.LIB COPYING
ln -s $srcdir/Copyright COPYING

if test "$OPENSSL_WITHOUT" = "no"
then
AC_OUTPUT([include/xmlsec/openssl/Makefile src/openssl/Makefile])
fi

if test "$GNUTLS_WITHOUT" = "no"
then
AC_OUTPUT([include/xmlsec/gnutls/Makefile src/gnutls/Makefile])
fi

if test "$NSS_WITHOUT" = "no"
then
AC_OUTPUT([include/xmlsec/nss/Makefile src/nss/Makefile])
fi

AC_OUTPUT([
include/xmlsec/version.h
Makefile
include/Makefile
include/xmlsec/Makefile
src/Makefile
apps/Makefile
docs/Makefile
docs/api/Makefile
man/Makefile
]
[xmlsec1Conf.sh:xmlsecConf.sh.in]
[xmlsec1-config:xmlsec-config.in]
[xmlsec1.pc:xmlsec.pc.in]
[xmlsec1.spec:xmlsec.spec.in]
)