File: configure.in

package info (click to toggle)
ipv6calc 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,400 kB
  • sloc: ansic: 73,764; sh: 5,750; perl: 4,030; xml: 1,194; makefile: 888
file content (1347 lines) | stat: -rw-r--r-- 42,262 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
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
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
dnl Project  : ipv6calc
dnl File     : configure.in
dnl Version  : $Id: 405902326e309a2f51709d2b4c889edcfaab021f $
dnl Copyright: 2001-2017 by Peter Bieringer <pb (at) bieringer.de>

dnl Process this file with autoconf to produce a configure script.

AC_INIT(ipv6calc, 1.0.0, ipv6calc@deepspace6.net, ipv6calc, http://www.deepspace6.net/projects/ipv6calc.html)

COPYRIGHT_YEAR=2017

dnl Program/library version (align with version above)
PACKAGE_VERSION_MAJOR=1
PACKAGE_VERSION_MINOR=0
PACKAGE_VERSION_BUGFIX=0

dnl API version
API_VERSION_MAJOR=1
API_VERSION_MINOR=0
API_VERSION_BUGFIX=0


dnl Generic data definitions
AC_SUBST(COPYRIGHT_YEAR)
AC_DEFINE_UNQUOTED(COPYRIGHT_YEAR, "$COPYRIGHT_YEAR", [Copyright year])

dnl Program/library version variants
PACKAGE_VERSION_NUMERIC=$(echo "$PACKAGE_VERSION_MAJOR $PACKAGE_VERSION_MINOR $PACKAGE_VERSION_BUGFIX" | awk '{ print ( $1 * 1000 + $2 ) * 1000 + $3 }')
PACKAGE_VERSION_STRING=$(echo "$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_BUGFIX")

AC_DEFINE_UNQUOTED(IPV6CALC_PACKAGE_VERSION_MAJOR,   $PACKAGE_VERSION_MAJOR   , "Package version Major")
AC_DEFINE_UNQUOTED(IPV6CALC_PACKAGE_VERSION_MINOR,   $PACKAGE_VERSION_MINOR   , "Package version Minor")
AC_DEFINE_UNQUOTED(IPV6CALC_PACKAGE_VERSION_BUGFIX,  $PACKAGE_VERSION_BUGFIX  , "Package version Bugfix")
AC_DEFINE_UNQUOTED(IPV6CALC_PACKAGE_VERSION_STRING,  "$PACKAGE_VERSION_STRING", "Package version as string")
AC_DEFINE_UNQUOTED(IPV6CALC_PACKAGE_VERSION_NUMERIC, $PACKAGE_VERSION_NUMERIC , "Package version numeric")

dnl API version variants
API_VERSION_NUMERIC=$(echo "$API_VERSION_MAJOR $API_VERSION_MINOR $API_VERSION_BUGFIX" | awk '{ print ( $1 * 1000 + $2 ) * 1000 + $3 }')
API_VERSION_STRING=$(echo "$API_VERSION_MAJOR.$API_VERSION_MINOR.$API_VERSION_BUGFIX")

AC_DEFINE_UNQUOTED(IPV6CALC_API_VERSION_MAJOR,   $API_VERSION_MAJOR   , "API version Major")
AC_DEFINE_UNQUOTED(IPV6CALC_API_VERSION_MINOR,   $API_VERSION_MINOR   , "API version Minor")
AC_DEFINE_UNQUOTED(IPV6CALC_API_VERSION_BUGFIX,  $API_VERSION_BUGFIX  , "API version Bugfix")
AC_DEFINE_UNQUOTED(IPV6CALC_API_VERSION_STRING,  "$API_VERSION_STRING", "API version as string")
AC_DEFINE_UNQUOTED(IPV6CALC_API_VERSION_NUMERIC, $API_VERSION_NUMERIC , "API version numeric")

dnl Define version header
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
dnl AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_MAKE_SET

dnl Checks for header files.
AC_HEADER_STDC

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_C_BIGENDIAN

dnl Checks for library functions.
AC_FUNC_MEMCMP
AC_CHECK_FUNCS(strspn strstr)

dnl *************************************************
dnl check for compiler options -Werror -Werror=format-security
dnl *************************************************
AC_ARG_ENABLE([compiler-warning-to-error], 
	AS_HELP_STRING([--disable-compiler-warning-to-error],
		[Disable extra CFLAGS for mapping warnings to errors during compilation]),
	[
	],[
		AC_MSG_RESULT([*** check for CFLAGS: -Werror=format-security])
		CFLAGS_SAVE="$CFLAGS"
		CFLAGS="$CFLAGS -Wformat -Werror -Werror=format-security"
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
			     [[int a=1;]])
			],
			[
				AC_MSG_RESULT([*** CFLAGS supported: -Werror=format-security])
				CFLAGS_EXTRA="-Wformat -Werror -Werror=format-security"
			],
			[
				AC_MSG_WARN([*** missing CFLAGS support: -Werror=format-security])
				CFLAGS_EXTRA="-Wformat"
			])
		CFLAGS="$CFLAGS_SAVE"

		AC_MSG_RESULT([*** check for CFLAGS: -Wsizeof-array-argument])
		CFLAGS_SAVE="$CFLAGS"
		CFLAGS="$CFLAGS -Wsizeof-array-argument"
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
			     [[int a=1;]])
			],
			[
				AC_MSG_RESULT([*** CFLAGS supported: -Wsizeof-array-argument])
				CFLAGS_EXTRA="$CFLAGS_EXTRA -Wsizeof-array-argument"
			],
			[
				AC_MSG_WARN([*** missing CFLAGS support: -Wsizeof-array-argument])
			])
		CFLAGS="$CFLAGS_SAVE"

		AC_MSG_RESULT([*** check for CFLAGS: -Wparentheses-equality])
		CFLAGS_SAVE="$CFLAGS"
		CFLAGS="$CFLAGS -Wparentheses-equality"
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
			     [[int a=1;]])
			],
			[
				AC_MSG_RESULT([*** CFLAGS supported: -Wparentheses-equality])
				CFLAGS_EXTRA="$CFLAGS_EXTRA -Wparentheses-equality"
			],
			[
				AC_MSG_WARN([*** missing CFLAGS support: -Wparentheses-equality])
			])
		CFLAGS="$CFLAGS_SAVE"

		AC_MSG_RESULT([*** check for CFLAGS: -Wextra])
		CFLAGS_SAVE="$CFLAGS"
		CFLAGS="$CFLAGS -Wextra"
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
			     [[int a=1;]])
			],
			[
				AC_MSG_RESULT([*** CFLAGS supported: -Wextra])
				CFLAGS_EXTRA="$CFLAGS_EXTRA -Wextra"
			],
			[
				AC_MSG_WARN([*** missing CFLAGS support: -Wextra])
			])
		CFLAGS="$CFLAGS_SAVE"
	])

dnl *************************************************
dnl add -Wno-unused-const-variable if supported
dnl *************************************************
dnl AC_MSG_RESULT([*** check for CFLAGS: -Wno-unused-const-variable])
dnl CFLAGS_SAVE="$CFLAGS"
dnl CFLAGS="$CFLAGS -Wno-unused-const-variable"
dnl AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
dnl 	     [[int a=1;]])
dnl 	],
dnl 	[
dnl 		AC_MSG_RESULT([*** CFLAGS supported: -Wno-unused-const-variable])
dnl 		CFLAGS_EXTRA="-Wno-unused-const-variable"
dnl 	],
dnl 	[
dnl 		AC_MSG_WARN([*** missing CFLAGS support: -Wno-unused-const-variable])
dnl 		CFLAGS_EXTRA="-Wformat"
dnl 	])
dnl CFLAGS="$CFLAGS_SAVE"


dnl *************************************************
dnl getopt library
dnl *************************************************
AC_ARG_ENABLE(
	[bundled-getopt],
	AS_HELP_STRING([--enable-bundled-getopt],
		[Enable bundled getopt library (default: autoselected)]),
	[
		if test "$enable_bundled_getopt" = "yes"; then
			AC_MSG_RESULT([*** use of bundled getopt library forced])
			ENABLE_BUNDLED_GETOPT=1
		else
			AC_MSG_RESULT([*** use of system getopt library forced])
		fi
	],
	[
		AC_CHECK_FUNC(getopt_long,
			[
				AC_MSG_RESULT([*** use of system getopt library autoselected])
			],
			[
				AC_MSG_RESULT([*** use of bundled getopt library autoselected])
				ENABLE_BUNDLED_GETOPT=1
			])
	])

if test "$ENABLE_BUNDLED_GETOPT" = "1"; then
	AC_LIBOBJ(../getopt/getopt)
	AC_LIBOBJ(../getopt/getopt1)
	GETOPT_INCLUDE=-I../getopt
	AC_DEFINE(ENABLE_BUNDLED_GETOPT, 1, Define if bundled GETOPT should be used)
fi

AC_SUBST(GETOPT_INCLUDE)
AC_SUBST(ENABLE_BUNDLED_GETOPT)


dnl *************************************************
dnl MD5 library
dnl *************************************************
AC_ARG_ENABLE(
	[bundled-md5],
	AS_HELP_STRING([--enable-bundled-md5],
		[Enable bundled MD5 library (default: autoselected)]),
	[
		if test "$enable_bundled_md5" = "yes"; then
			AC_MSG_RESULT([*** use of bundled MD5 library forced])
			ENABLE_BUNDLED_MD5=1
		else
			AC_MSG_RESULT([*** use of system MD5 library forced])
		fi
	],
	[
		AC_CHECK_HEADER(openssl/md5.h, [
			AC_MSG_RESULT([*** openssl/md5.h header file found])
			AC_CHECK_LIB(crypto, MD5_Init,
			[
				LDFLAGS="-lcrypto $LDFLAGS"
				AC_CHECK_FUNCS(MD5_Init MD5_Update MD5_Final,
					[
						md5_found="yes"
					],
					[
						ENABLE_BUNDLED_MD5=1
					])
				if test "$md5_found" = "yes"; then
					AC_MSG_RESULT([*** use of system MD5 library autoselected])
				else
					AC_MSG_RESULT([*** use of bundled MD5 library autoselected])
				fi
			],
			[
				AC_MSG_WARN([crypto library header files were found but not supporting required MD5 functions (will use bundled MD5 function).])
				ENABLE_BUNDLED_MD5=1
			])
		], [
			AC_MSG_WARN([openssl/md5.h header file not found (will use bundled MD5 function).])
			ENABLE_BUNDLED_MD5=1
		])
	],[
	])

if test "$ENABLE_BUNDLED_MD5" = "1"; then
	AC_LIBOBJ(../md5/md5)
	GETOPT_INCLUDE=-I../md5
	AC_DEFINE(ENABLE_BUNDLED_MD5, 1, Define if bundled MD5 should be used)
else
	LDFLAGS_EXTRA="-lcrypto $LDFLAGS_EXTRA"
	LDFLAGS_EXTRA_STATIC="-lcrypto -lz -ldl $LDFLAGS_EXTRA_STATIC"
fi

AC_SUBST(MD5_INCLUDE)
AC_SUBST(ENABLE_BUNDLED_MD5)


dnl *************************************************
dnl defaults
dnl *************************************************
geoip_db_default="/usr/share/GeoIP"
ip2location_db_default="/usr/share/IP2Location"
dbip_db_default="/usr/share/DBIP"
external_db_default="/usr/share/ipv6calc/db"

geoip_dyn_lib_default="libGeoIP.so.1"
ip2location_dyn_lib_default="libIP2Location.so"


dnl *************************************************
dnl Create binaries ushing shared library
dnl *************************************************
AC_ARG_ENABLE(
	[shared],
	AS_HELP_STRING([--enable-shared],
		[Enable shared library build (default: disabled)])
	)

if test "$enable_shared" = "yes"; then
	AC_MSG_RESULT([*** Shared library build enabled])
	SHARED_LIBRARY="yes"
	AC_DEFINE(SHARED_LIBRARY, 1, Define if you want ipv6calc binaries compiled with shared library libipv6calc)
	LDFLAGS_EXTRA_MOD_IPV6CALC="-Wl,../lib/libipv6calc.so.$PACKAGE_VERSION -Wl,../databases/lib/libipv6calc_db_wrapper.so.$PACKAGE_VERSION $LDFLAGS_EXTRA"
	LDFLAGS_EXTRA="../lib/libipv6calc.so.$PACKAGE_VERSION ../databases/lib/libipv6calc_db_wrapper.so.$PACKAGE_VERSION $LDFLAGS_EXTRA"
	LD_LIBRARY_PATH=../lib:../databases/lib:$LD_LIBRARY_PATH
	LD_LIBRARY_PATH_BASIC=../lib:../databases/lib:$LD_LIBRARY_PATH_BASIC
else
	SHARED_LIBRARY="no"
	IPV6CALC_LIB="-L../lib/ -L../databases/lib/ -lipv6calc_db_wrapper -lipv6calc"
fi

AC_SUBST(SHARED_LIBRARY)
AC_SUBST(IPV6CALC_LIB)


dnl *************************************************
dnl Check for dynamic loading of libraries capability
dnl *************************************************
AC_CHECK_HEADER(dlfcn.h,
	[
		AC_MSG_RESULT([*** Dynamic loading of libraries is SUPPORTED])
		DYNAMIC_LOAD_SUPPORT="yes"
	],
	[
		DYNAMIC_LOAD_SUPPORT="no"
		AC_MSG_WARN(["Dynamic loading of libraries is not supported, no header file found"])
	])

AC_ARG_ENABLE(
	[dynamic-load],
	AS_HELP_STRING([--disable-dynamic-load],
	               [Disable dynamic load of libraries (default: enabled)])
	)

if test "$enable_dynamic_load" = "yes"; then
	DYNAMIC_LOAD="no"
else
	DYNAMIC_LOAD="yes"
fi

if test "$DYNAMIC_LOAD_SUPPORT" = "yes"; then
	if test "$DYNAMIC_LOAD" = "no"; then
		AC_MSG_WARN(["Dynamic loading of libraries forced to be disabled"])
	fi
fi


dnl *************************************************
dnl disable built-in database IEEE
dnl *************************************************
AC_ARG_ENABLE([db-ieee], 
	AS_HELP_STRING([--disable-db-ieee],
		[Disable built-in IEEE database (default: enabled)]),
	[
		DB_IEEE="$enable_db_ieee"
	],[
		DB_IEEE="yes"
		BUILTIN="yes"
	])

if test "$DB_IEEE" = "yes"; then
	AC_DEFINE(SUPPORT_DB_IEEE, 1, Define if you want IEEE database included.)
fi


dnl *************************************************
dnl disable built-in database IPv4
dnl *************************************************
AC_ARG_ENABLE([db-ipv4], 
	AS_HELP_STRING([--disable-db-ipv4],
		[Disable built-in IPv4-to-Registry database (default: enabled)]),
	[
		DB_IPV4="$enable_db_ipv4"
	],[
		DB_IPV4="yes"
		BUILTIN="yes"
	])

if test "$DB_IPV4" = "yes"; then
	AC_DEFINE(SUPPORT_DB_IPV4_REG, 1, Define if you want IPv4-to-Registry database included.)
fi


dnl *************************************************
dnl disable built-in database IPv6
dnl *************************************************
AC_ARG_ENABLE([db-ipv6], 
	AS_HELP_STRING([--disable-db-ipv6],
	               [Disable built-in IPv6-to-Registry database (default: enabled)]),
	[
		DB_IPV6="$enable_db_ipv6"
	],
	[
		DB_IPV6="yes"
		BUILTIN="yes"
	])

if test "$DB_IPV6" = "yes"; then
	AC_DEFINE(SUPPORT_DB_IPV6_REG, 1, Define if you want IPv6-to-Registry database included.)
fi


dnl *************************************************
dnl disable built-in database AS->Registry
dnl *************************************************
AC_ARG_ENABLE([db-as-registry], 
	AS_HELP_STRING([--disable-db-as-registry],
	               [Disable built-in AS-to-Registry database (default: enabled)]),
	[
		DB_AS_REG="$enable_db_as_registry"
	],
	[
		DB_AS_REG="yes"
		BUILTIN="yes"
	])

if test "$DB_AS_REG" = "yes"; then
	AC_DEFINE(SUPPORT_DB_AS_REG, 1, Define if you want AS-to-Registry database included.)
fi


dnl *************************************************
dnl disable built-in database CC->Registry
dnl *************************************************
AC_ARG_ENABLE([db-cc-registry], 
	AS_HELP_STRING([--disable-db-cc-registry],
	               [Disable built-in CountryCode-to-Registry database (default: enabled)]),
	[
		DB_CC_REG="$enable_db_cc_registry"
	],
	[
		DB_CC_REG="yes"
		BUILTIN="yes"
	])

if test "$DB_CC_REG" = "yes"; then
	AC_DEFINE(SUPPORT_DB_CC_REG, 1, Define if you want CC-to-Registry database included.)
fi


dnl *************************************************
dnl enable built-in database support in general
dnl *************************************************
if test "$BUILTIN" = "yes"; then
	AC_DEFINE(SUPPORT_BUILTIN, 1, Define if you want general BuiltIn database included.)
fi


dnl *************************************************
dnl DB-IP.com support
dnl *************************************************
AC_ARG_ENABLE([dbip], 
	AS_HELP_STRING([--enable-dbip],
	               [Enable db-ip.com support (default: disabled)]),
	[
		DBIP="$enable_dbip"
	],
	[
		DBIP="no"
	])

dnl defaults for database directories
AC_ARG_WITH([dbip-db],
	AS_HELP_STRING([--with-dbip-db=DIR],
               [Use specified db-ip.com database directory, default: /usr/share/DBIP]),
	[
		dbip_db="$with_dbip_db"
	],
	[
		dbip_db=$dbip_db_default
	])

if test "$DBIP" = "yes"; then
	require_libdb="yes"

	AC_DEFINE(SUPPORT_DBIP, 1, Define if you want db-ip.com support included.)
	AC_MSG_RESULT([*** db-ip.com db dir: $dbip_db])
	AC_DEFINE_UNQUOTED(DBIP_DB, "$dbip_db", Define db-ip.com database directory.)
fi

DBIP_DB=$dbip_db
AC_SUBST(DBIP_DB)


dnl *************************************************
dnl External ipv6calc db support
dnl *************************************************
AC_ARG_ENABLE([external], 
	AS_HELP_STRING([--enable-external],
	               [Enable external db support (default: disabled)]),
	[
		EXTERNAL="$enable_external"
	],
	[
		EXTERNAL="no"
	])

dnl defaults for database directories
AC_ARG_WITH([external-db],
	AS_HELP_STRING([--with-external-db=DIR],
               [Use specified external database directory, default: /usr/share/ipv6calc/db]),
	[
		external_db="$with_external_db"
	],
	[
		external_db=$external_db_default
	])

if test "$EXTERNAL" = "yes"; then
	require_libdb="yes"

	AC_DEFINE(SUPPORT_EXTERNAL, 1, Define if you want external support included.)
	AC_MSG_RESULT([*** external db dir: $dbip_db])
	AC_DEFINE_UNQUOTED(EXTERNAL_DB, "$external_db", Define external database directory.)
fi

EXTERNAL_DB=$external_db
AC_SUBST(EXTERNAL_DB)


dnl *************************************************
dnl IP2Location support
dnl *************************************************
IP2LOCATION_LIB_NAME="IP2Location"
IP2LOCATION_INCLUDE_VERSION=""

AC_ARG_ENABLE([ip2location], 
	AS_HELP_STRING([--enable-ip2location],
		[Enable IP2Location support (default: disabled)]),
	[
		IP2LOCATION="$enable_ip2location"
	],[
		IP2LOCATION="no"
	])

AC_ARG_WITH([ip2location-dynamic],
	AS_HELP_STRING([--with-ip2location-dynamic],
                [Enable use of dynamic loading of IP2Location library (default=no)]),
	[
		if test "$enable_ip2location_dynamic" != "no"; then
			IP2LOCATION_DYN="yes"
		fi
	],[
		true
	])

AC_ARG_WITH([ip2location-headers],
	AS_HELP_STRING([--with-ip2location-headers=DIR],
		[IP2Location include files location]),
	[
		IP2LOCATION_INCLUDE_DIR="$with_ip2location_headers"
	])

AC_ARG_WITH([ip2location-headers-fallback],
	AS_HELP_STRING([--with-ip2location-headers-fallback],
		[IP2Location include files from internal fallback location (only usable with dynamic load option)]),
	[
		if test "$IP2LOCATION_DYN" != "yes"; then
			AC_MSG_ERROR([IP2Location fallback headers are only usable with dynamic load option set: --with-ip2location-dynamic])
		fi
	
		if test -n "$IP2LOCATION_INCLUDE_DIR"; then
			AC_MSG_ERROR([IP2Location include files location already set by --with-ip2location-headers, skip fallback])
		else
			AC_MSG_RESULT([*** IP2Location fallback headers activated])
			IP2LOCATION_INCLUDE_DIR="external-fallback/IP2Location"
			IP2LOCATION_INCLUDE_VERSION=$(cat external-fallback/IP2Location/VERSION-IP2Location)
		fi
	])

if test -n "$IP2LOCATION_INCLUDE_DIR"; then
	IP2LOCATION_INCLUDE="-I$IP2LOCATION_INCLUDE_DIR"
	if test -d "$IP2LOCATION_INCLUDE_DIR/iMath"; then
		# include iMath where existing (API < 7.0.0)
		IP2LOCATION_INCLUDE="$IP2LOCATION_INCLUDE -I$IP2LOCATION_INCLUDE_DIR/iMath"
	fi
	if echo "$IP2LOCATION_INCLUDE_DIR" | grep -q "^/"; then
		# absolute path
		IP2LOCATION_INCLUDE_L1="-I$IP2LOCATION_INCLUDE_DIR"
		IP2LOCATION_INCLUDE_L2="-I$IP2LOCATION_INCLUDE_DIR"
		if test -d "$IP2LOCATION_INCLUDE_DIR/iMath"; then
			# include iMath where existing (API < 7.0.0)
			IP2LOCATION_INCLUDE_L1="$IP2LOCATION_INCLUDE_L1 -I$IP2LOCATION_INCLUDE_DIR/iMath"
			IP2LOCATION_INCLUDE_L2="$IP2LOCATION_INCLUDE_L2 -I$IP2LOCATION_INCLUDE_DIR/iMath"
		fi
	else
		IP2LOCATION_INCLUDE_L1="-I../$IP2LOCATION_INCLUDE_DIR"
		IP2LOCATION_INCLUDE_L2="-I../../$IP2LOCATION_INCLUDE_DIR"
		if test -d "$IP2LOCATION_INCLUDE_DIR/iMath"; then
			# include iMath where existing (API < 7.0.0)
			IP2LOCATION_INCLUDE_L1="$IP2LOCATION_INCLUDE_L1 -I../$IP2LOCATION_INCLUDE_DIR/iMath"
			IP2LOCATION_INCLUDE_L2="$IP2LOCATION_INCLUDE_L2 -I../../$IP2LOCATION_INCLUDE_DIR/iMath"
		fi
	fi
fi

AC_ARG_WITH([ip2location-lib],
	AS_HELP_STRING([--with-ip2location-lib=FILE],
		[IP2Location library location]),
	[
		if test -d "$with_ip2location_lib"; then 
			IP2LOCATION_LIB_DIR="$with_ip2location_lib"
			IP2LOCATION_LIB="-L$IP2LOCATION_LIB_DIR $IP2LOCATION_LIB"
			AC_MSG_RESULT([IP2Location library directory given: $IP2LOCATION_LIB_DIR])
		else
			AC_MSG_ERROR([IP2Location library directory not found: $with_ip2location_lib])
		fi

		if echo "$IP2LOCATION_LIB_DIR" | grep -q "^/"; then
			# absolute path
			IP2LOCATION_LIB_L1="-L$IP2LOCATION_LIB_DIR"
			IP2LOCATION_LIB_L2="-L$IP2LOCATION_LIB_DIR"
			if test -n "$LD_LIBRARY_PATH"; then
				LD_LIBRARY_PATH=$IP2LOCATION_LIB_DIR:$LD_LIBRARY_PATH
			else
				LD_LIBRARY_PATH=$IP2LOCATION_LIB_DIR
			fi
		else
			IP2LOCATION_LIB_L1="-L../$IP2LOCATION_LIB_DIR"
			IP2LOCATION_LIB_L2="-L../../$IP2LOCATION_LIB_DIR"
			if test -n "$LD_LIBRARY_PATH"; then
				LD_LIBRARY_PATH=../$IP2LOCATION_LIB_DIR:$LD_LIBRARY_PATH
			else
				LD_LIBRARY_PATH=$IP2LOCATION_LIB_DIR
			fi
		fi
	])

# must be tested
#AC_ARG_WITH([ip2location-lib-name],
#	AS_HELP_STRING([--with-ip2location-lib-name=NAME],
#		[IP2Location library name]),
#	[
#		IP2LOCATION_LIB_NAME="$with_geoip_lib_name"
#		IP2LOCATION_LIB="-l$IP2LOCATION_LIB_NAME $IP2LOCATION_LIB"
#		AC_MSG_RESULT([IP2Location library name given: $IP2LOCATION_LIB_NAME])
#        ],[
#	])

AC_ARG_WITH([ip2location-static],
	AS_HELP_STRING([--with-ip2location-static],
		[Explicitly link IP2Location statically (default=no)]),
	[
		if test "$with_ip2location_static" != "no"; then 
			IP2LOCATION_LIB="-Wl,-Bstatic $IP2LOCATION_LIB -Wl,-Bdynamic"
		fi
	])

dnl defaults for database directories
AC_ARG_WITH([ip2location-db],
	AS_HELP_STRING([--with-ip2location-db=DIR],
               [Use specified IP2Location database directory, default: /usr/share/IP2Location]),
	[
		ip2location_db="$with_ip2location_db"
	],
	[
		ip2location_db=$ip2location_db_default
	])

AC_ARG_WITH([ip2location-dyn-lib],
	AS_HELP_STRING([--with-ip2location-dyn-lib=NAME],
		[Use specified IP2Location dynamic library, default: libIP2Location.so]),
	[
		ip2location_dyn_lib="$with_ip2location_dyn_lib"
	],
	[
		ip2location_dyn_lib=$ip2location_dyn_lib_default
	])

if test "$IP2LOCATION" = "yes"; then
	if test "$IP2LOCATION_DYN" != "yes"; then
		IP2LOCATION_LIB="-l$IP2LOCATION_LIB_NAME $IP2LOCATION_LIB"
		IP2LOCATION_LIB_L1="-l$IP2LOCATION_LIB_NAME $IP2LOCATION_LIB_L1"
		IP2LOCATION_LIB_L2="-l$IP2LOCATION_LIB_NAME $IP2LOCATION_LIB_L2"
	else
		AC_MSG_RESULT([**** IP2Location dynamic load support enabled, disable IP2Location linker options])
	fi

	CPPFLAGS="$CPPFLAGS $IP2LOCATION_INCLUDE"

	AC_MSG_RESULT([*** IP2Location support requested])

	AC_MSG_RESULT([***** CPPFLAGS=$CPPFLAGS])
	AC_MSG_RESULT([***** CFLAGS  =$CFLAGS])
	AC_MSG_RESULT([***** LDFLAGS =$LDFLAGS])

	AC_CHECK_HEADER(IP2Location.h, [
		if test -n "$IP2LOCATION_INCLUDE_DIR"; then
			if test -e "$IP2LOCATION_INCLUDE_DIR/IP2Location.h"; then
				CPPFLAGS="$CPPFLAGS -include $IP2LOCATION_INCLUDE_DIR/IP2Location.h"
			else
				AC_MSG_ERROR([IP2Location library header file not found: $IP2LOCATION_INCLUDE_DIR/IP2Location.h])
			fi
		else
			CPPFLAGS="$CPPFLAGS -include IP2Location.h"
		fi

		AC_CHECK_DECL([IP2Location_open],,
			AC_MSG_ERROR([IP2Location library header file misses IP2Location_open]))

		AC_CHECK_DECLS([IP2Location_close,
			IP2Location_get_country_short,
			IP2Location_get_country_long])

		AC_CHECK_DECLS([API_VERSION])

		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
		     [[
				#include <IP2Location.h>
				IP2Location loc;
				void test() {
					loc.ipv6databaseaddr = 1;
				};
		     ]])],[
				AC_MSG_RESULT([IP2Location has full IPv6 support (API >= 7.0.0)])
				IP2LOCATION_IPV6_COMPAT="no"
			],[
				AC_MSG_WARN([IP2Location has only compat IPv6 support (API < 7.0.0) which is no longer supported])
				IP2LOCATION_IPV6_COMPAT="yes"
			]
		)

		AC_CHECK_DECLS([USAGETYPE],
			[
				IP2LOCATION_ALL_COMPAT="no"
			],
			[
				AC_MSG_WARN([IP2Location library header file misses USAGETYPE (library < 6.0.0)])
				IP2LOCATION_ALL_COMPAT="yes"
			]
		)

	],
	[
		AC_MSG_ERROR([IP2Location library header files not found])
	])

	AC_MSG_RESULT([*** IP2location db dir: $ip2location_db])
	AC_DEFINE_UNQUOTED(IP2LOCATION_DB, "$ip2location_db", Define IP2Location database directory.)

	if test "$IP2LOCATION_DYN" != "yes"; then
		if test "$IP2LOCATION_STATIC" = "yes"; then
			AC_DEFINE(SUPPORT_IP2LOCATION_STATIC, 1, Define if you want IP2Location support statically linked - requires also additional linker options.)
		fi

		CPPFLAGS="$CFLAGS"

		if test -n "$IP2LOCATION_LIB_DIR"; then
			if test -e "$IP2LOCATION_LIB_DIR/lib$IP2LOCATION_LIB_NAME.so"; then
				LDFLAGS="$LDFLAGS -L$IP2LOCATION_LIB_DIR"
				CFLAGS="$CFLAGS -L$IP2LOCATION_LIB_DIR"
				LIBS="-L$IP2LOCATION_LIB_DIR"
			else
				AC_MSG_ERROR([IP2Location library file not found: $IP2LOCATION_INCLUDE_DIR/lib$IP2LOCATION_LIB_NAME.so])
			fi
		fi

		AC_CHECK_LIB($IP2LOCATION_LIB_NAME, IP2Location_api_version_string,
		[
			AC_DEFINE(SUPPORT_IP2LOCATION_API_VERSION_STRING, 1, Define if you want IP2Location API version string support.)
			AC_MSG_RESULT([*** IP2Location library supports API version string])
		])

		AC_CHECK_LIB($IP2LOCATION_LIB_NAME, IP2Location_lib_version_string,
		[
			AC_DEFINE(SUPPORT_IP2LOCATION_LIB_VERSION_STRING, 1, Define if you want IP2Location LIB version string support.)
			AC_MSG_RESULT([*** IP2Location library supports LIB version string])
		])

		AC_MSG_RESULT([***** CPPFLAGS=$CPPFLAGS])
		AC_MSG_RESULT([***** CFLAGS  =$CFLAGS])
		AC_MSG_RESULT([***** LDFLAGS =$LDFLAGS])

		AC_CHECK_LIB($IP2LOCATION_LIB_NAME, IP2Location_open,
		[
			AC_DEFINE(SUPPORT_IP2LOCATION, 1, Define if you want IP2Location support.)
			AC_MSG_RESULT([*** IP2Location support enabled])
		],
		[
			AC_MSG_ERROR([IP2Location library header files were found but the library was not found, LDFLAGS=$LDFLAGS, CFLAGS=$CFLAGS])
		])
	else
		AC_CHECK_DECLS([IP2Location_api_version_string],
		[
			AC_DEFINE(SUPPORT_IP2LOCATION_API_VERSION_STRING, 1, Define if you want IP2Location API version string support.)
			AC_MSG_RESULT([*** IP2Location header supports API version string])
		])

		# wrapper detects by itself the real support
		AC_MSG_RESULT([*** IP2Location dyn lib: $ip2location_dyn_lib])
		AC_DEFINE_UNQUOTED(IP2LOCATION_DYN_LIB, "$ip2location_dyn_lib", Define IP2Location dynamic library.)

		AC_MSG_RESULT([*** IP2Location support will be implemented by using dynamic load of library])
		AC_DEFINE(SUPPORT_IP2LOCATION, 1, Define if you want IP2Location support.)
		AC_DEFINE(SUPPORT_IP2LOCATION_DYN, 1, Define if you want IP2Location support with dynamic loading support - requires also additional linker options.)
	fi
fi

if test "$IP2LOCATION_IPV6_COMPAT" = "yes"; then
	AC_DEFINE(SUPPORT_IP2LOCATION_IPV6_COMPAT, 1, Define if your IP2Location supports IPv6 only in old manner.)
fi

if test "$IP2LOCATION_ALL_COMPAT" = "yes"; then
	AC_DEFINE(SUPPORT_IP2LOCATION_ALL_COMPAT, 1, Define if your IP2Location supports only reduced set of databases.)
fi

IP2LOCATION_DB=$ip2location_db
AC_SUBST(IP2LOCATION_INCLUDE)
AC_SUBST(IP2LOCATION_INCLUDE_L1)
AC_SUBST(IP2LOCATION_INCLUDE_L2)
AC_SUBST(IP2LOCATION_LIB)
AC_SUBST(IP2LOCATION_LIB_L1)
AC_SUBST(IP2LOCATION_LIB_L2)
AC_SUBST(IP2LOCATION_DB)
AC_SUBST(IP2LOCATION_DYN_LIB)

if test -n "$IP2LOCATION_INCLUDE_VERSION"; then
	AC_DEFINE_UNQUOTED(IP2LOCATION_INCLUDE_VERSION, "$IP2LOCATION_INCLUDE_VERSION", IP2Location include file version.)
fi


dnl *************************************************
dnl GeoIP support
dnl *************************************************
GEOIP_LIB_NAME="GeoIP"
GEOIP_INCLUDE_VERSION=""

AC_ARG_ENABLE([geoip], 
	AS_HELP_STRING([--enable-geoip],
	               [Enable GeoIP support (default: disabled)]),
	[
		if test "$enable_geoip" != "no"; then
			GEOIP="$enable_geoip"
		fi
	],[
		GEOIP="no"
	])

AC_ARG_WITH([geoip-dynamic],
	AS_HELP_STRING([--with-geoip-dynamic],
                   [Enable use of dynamic loading of GeoIP library (default=no)]),
	[
		if test "$with_geoip_dynamic" != "no"; then
			GEOIP_DYN="yes"
		fi
	],[
		true
	])

AC_ARG_WITH([geoip-headers],
	AS_HELP_STRING([--with-geoip-headers=DIR],
		[GeoIP include files location]),
	[
		GEOIP_INCLUDE_DIR="$with_geoip_headers"
	])

AC_ARG_WITH([geoip-headers-fallback],
	AS_HELP_STRING([--with-geoip-headers-fallback],
		[GeoIP include files from internal fallback location (only usable with dynamic load option)]),
	[
		if test "$GEOIP_DYN" != "yes"; then
			AC_MSG_ERROR([GeoIP fallback headers are only usable with dynamic load option set: --with-geoip-dynamic])
		fi
	
		if test -n "$GEOIP_INCLUDE_DIR"; then
			AC_MSG_ERROR([GeoIP include files location already set by --with-geoip-headers, skip fallback])
		else
			AC_MSG_RESULT([*** GeoIP fallback headers activated])
			GEOIP_INCLUDE_DIR="external-fallback/GeoIP"
			GEOIP_INCLUDE_VERSION=$(cat external-fallback/GeoIP/VERSION-GeoIP)
		fi
	])

if test -n "$GEOIP_INCLUDE_DIR"; then
	GEOIP_INCLUDE="-I$GEOIP_INCLUDE_DIR"
	if echo "$GEOIP_INCLUDE_DIR" | grep -q "^/"; then
		# absolute path
		GEOIP_INCLUDE_L1="-I$GEOIP_INCLUDE_DIR"
		GEOIP_INCLUDE_L2="-I$GEOIP_INCLUDE_DIR"
	else
		GEOIP_INCLUDE_L1="-I../$GEOIP_INCLUDE_DIR"
		GEOIP_INCLUDE_L2="-I../../$GEOIP_INCLUDE_DIR"
	fi
fi

AC_ARG_WITH([geoip-lib],
	AS_HELP_STRING([--with-geoip-lib=DIR],
		[GeoIP library location]),
	[
		if test -d "$with_geoip_lib"; then 
			GEOIP_LIB_DIR="$with_geoip_lib"
			GEOIP_LIB="-L$GEOIP_LIB_DIR $GEOIP_LIB"
			AC_MSG_RESULT([GeoIP library directory given: $GEOIP_LIB_DIR])
		else
			AC_MSG_ERROR([GeoIP library directory not found: $with_geoip_lib])
		fi

		if echo "$GEOIP_LIB_DIR" | grep -q "^/"; then
			# absolute path
			GEOIP_LIB_L1="-L$GEOIP_LIB_DIR"
			GEOIP_LIB_L2="-L$GEOIP_LIB_DIR"
			LD_LIBRARY_PATH=$GEOIP_LIB_DIR:$LD_LIBRARY_PATH
		else
			GEOIP_LIB_L1="-L../$GEOIP_LIB_DIR"
			GEOIP_LIB_L2="-L../../$GEOIP_LIB_DIR"
			LD_LIBRARY_PATH=../$GEOIP_LIB_DIR:$LD_LIBRARY_PATH
		fi
	])

# must be tested
#AC_ARG_WITH([geoip-lib-name],
#	AS_HELP_STRING([--with-geoip-lib-name=NAME],
#		[GeoIP library name]),
#	[
#		GEOIP_LIB_NAME="$with_geoip_lib_name"
#		GEOIP_LIB="-l$GEOIP_LIB_NAME $GEOIP_LIB"
#		AC_MSG_RESULT([GeoIP library name given: $GEOIP_LIB_NAME])
#        ],[
#	])

AC_ARG_WITH([geoip-static],
	AS_HELP_STRING([--with-geoip-static],
                   [Explicitly link GeoIP statically (default=no)]),
	[
		if test "$with_geoip_static" != "no"; then 
			GEOIP_STATIC="$with_geoip_static"
			GEOIP_LIB="-Wl,-Bstatic $GEOIP_LIB -Wl,-Bdynamic"
		fi
	],[
		GEOIP_STATIC="no"
	])

AC_ARG_WITH([geoip-db],
	AS_HELP_STRING([--with-geoip-db=DIR],
		[Use specified GeoIP database directory, default: /usr/share/GeoIP]),
	[
		geoip_db="$with_geoip_db"
	],
	[
		geoip_db=$geoip_db_default
	])

AC_ARG_WITH([geoip-dyn-lib],
	AS_HELP_STRING([--with-geoip-dyn-lib=NAME],
		[Use specified GeoIP dynamic library, default: libGeoIP.so.1]),
	[
		geoip_dyn_lib="$with_geoip_dyn_lib"
	],
	[
		geoip_dyn_lib=$geoip_dyn_lib_default
	])

AC_ARG_WITH([geoip-ipv6-compat],
	AS_HELP_STRING([--with-geoip-ipv6-compat],
		[Use IPv6 interface of GeoIP in compatibility mode (supporting 1.4.5)]),
	[
		if test "$with_geoip_ipv6_compat" != "no"; then 
			GEOIP_COMPAT="yes",
		fi
	],[
		GEOIP_COMPAT="no"
	])

# Automagic enable GeoIP if dynamic load is available (TODO: enable later by default??)
#if test "$DYNAMIC_LOAD" = "yes"; then
#	if test "$GEOIP_DYN" = "no"; then
#		true
#	else
#	    AC_CHECK_HEADER(GeoIP.h,
#		    [
#			    AC_MSG_RESULT(["*** GeoIP library header files found and dynamic library support enabled, enable GeoIP"])
#			    GEOIP="yes"
#			    GEOIP_DYN="yes"
#		    ],
#		    [
#		    ])
#	fi
#fi

if test "$GEOIP" = "yes"; then
	if test "$GEOIP_DYN" != "yes"; then
		GEOIP_LIB="-l$GEOIP_LIB_NAME $GEOIP_LIB"
		GEOIP_LIB_L1="-l$GEOIP_LIB_NAME $GEOIP_LIB_L1"
		GEOIP_LIB_L2="-l$GEOIP_LIB_NAME $GEOIP_LIB_L2"
	else
		AC_MSG_RESULT([*** GeoIP dynamic load support enabled, disable GeoIP linker options])
	fi

	CPPFLAGS="$CPPLAGS $GEOIP_INCLUDE"

	AC_MSG_RESULT([*** GeoIP support requested])

	AC_MSG_RESULT([***** CPPFLAGS=$CPPFLAGS])
	AC_MSG_RESULT([***** CFLAGS  =$CFLAGS])
	AC_MSG_RESULT([***** LDFLAGS =$LDFLAGS])

	AC_CHECK_HEADER(GeoIP.h, [
		if test -n "$GEOIP_INCLUDE_DIR"; then
			if test -e "$GEOIP_INCLUDE_DIR/GeoIP.h"; then
				CPPFLAGS="$CPPFLAGS -include $GEOIP_INCLUDE_DIR/GeoIP.h"
			else
				AC_MSG_ERROR([GeoIP library header file not found: $GEOIP_INCLUDE_DIR/GeoIP.h])
			fi
		else
			CPPFLAGS="$CPPFLAGS -include GeoIP.h"
		fi

		AC_CHECK_DECL([GeoIP_open],,
			AC_MSG_ERROR([GeoIP library header file misses GeoIP_open]))

		AC_CHECK_DECLS([GeoIP_country_code_by_ipnum_v6,
			GeoIP_lib_version,
			GeoIP_country_code_by_addr_v6,
			GeoIP_country_name_by_addr_v6,
			GeoIP_cleanup])

		AC_CHECK_DECLS([GEOIP_LARGE_COUNTRY_EDITION,
			GEOIP_LARGE_COUNTRY_EDITION_V6,
			GEOIP_CITY_EDITION_REV0_V6,
			GEOIP_CITY_EDITION_REV1_V6,
			GEOIP_ASNUM_EDITION,
			GEOIP_ASNUM_EDITION_V6,
			GEOIP_COUNTRY_EDITION_V6])

		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
			     [[geoipv6_t a;]])
			],
			[
				AC_MSG_RESULT([typedef geoipv6_t defined])
				AC_DEFINE(SUPPORT_GEOIP_IPV6_STRUCT, 1, Define if GeoIP support IPv6 structure.)
			],
			[
				AC_MSG_WARN([typedef geoipv6_t missing, enable workaround])
			])

	],
	[
		AC_MSG_ERROR([GeoIP library header files not found])
	])

	AC_MSG_RESULT([*** GeoIP database directory: $geoip_db])
	AC_DEFINE_UNQUOTED(GEOIP_DB, "$geoip_db", Define GeoIP database directory.)

	if test "$GEOIP_DYN" != "yes"; then
		if test "$GEOIP_STATIC" = "yes"; then
			AC_DEFINE(SUPPORT_GEOIP_STATIC, 1, Define if you want GeoIP support statically linked - requires also additional linker options.)
		fi

		CPPFLAGS="$CFLAGS"

		if test -n "$GEOIP_LIB_DIR"; then
			if test -e "$GEOIP_LIB_DIR/lib$GEOIP_LIB_NAME.so"; then
				LDFLAGS="$LDFLAGS -L$GEOIP_LIB_DIR"
				CFLAGS="$CFLAGS -L$GEOIP_LIB_DIR"
				LIBS="-L$GEOIP_LIB_DIR"
			else
				AC_MSG_ERROR([GeoIP library file not found: $GEOIP_INCLUDE_DIR/lib$GEOIP_LIB_NAME.so])
			fi
		fi

		AC_MSG_RESULT([***** CPPFLAGS=$CPPFLAGS])
		AC_MSG_RESULT([***** CFLAGS  =$CFLAGS])
		AC_MSG_RESULT([***** LDFLAGS =$LDFLAGS])

		AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_open,
		[
			AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
			AC_MSG_RESULT([*** GeoIP support enabled])
		],
		[
			AC_MSG_ERROR([GeoIP library header files given but the library was not found, LDFLAGS=$LDFLAGS])
		])

		AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_country_code_by_ipnum_v6,
		[
			AC_DEFINE(SUPPORT_GEOIP_V6, 1, Define if you want GeoIP IPv6 support.)
			AC_MSG_RESULT([*** GeoIP IPv6 support enabled])
		],
		[
			AC_MSG_WARN([GeoIP library file were found but not supporting IPv6 (upgrade to GeoIP 1.4.5 or newer for enabling IPv6 support)])
		])

		if test "$GEOIP_COMPAT" = "no"; then
			AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_lib_version,
			[
				AC_DEFINE(SUPPORT_GEOIP_LIB_VERSION, 1, Define if your GeoIP version supports GeoIP_lib_version.)
			],
			[
		    		AC_MSG_WARN([GeoIP library header files were found but not supporting GeoIP_lib_version (upgrade to newer version for support).])
			])

			AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_country_code_by_addr_v6,
			[
				AC_DEFINE(SUPPORT_GEOIP_COUNTRY_CODE_BY_ADDR_V6, 1, Define if your GeoIP version supports GeoIP_country_code_by_addr_v6.)
			],
			[
			    AC_MSG_WARN([GeoIP library header files were found but not supporting GeoIP_country_code_by_addr_v6 (will use workaround).])
			])

			AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_country_name_by_addr_v6,
			[
				AC_DEFINE(SUPPORT_GEOIP_COUNTRY_NAME_BY_ADDR_V6, 1, Define if your GeoIP version supports GeoIP_country_name_by_addr_v6.)
			],
			[
				AC_MSG_WARN([GeoIP library header files were found but not supporting GeoIP_country_name_by_addr_v6 (will use workaround).])
			])

			AC_CHECK_LIB($GEOIP_LIB_NAME, GeoIP_cleanup,
			[
				AC_DEFINE(SUPPORT_GEOIP_CLEANUP, 1, Define if your GeoIP version supports GeoIP_cleanup.)
			],
			[
				AC_MSG_WARN([GeoIP library header files were found but not supporting GeoIP_cleanup (will use workaround).])
			])
		else
			AC_MSG_WARN([GeoIP IPv6 support compatibility mode enabled (supporting 1.4.5).])
		fi
	else
		# wrapper detects by itself the real support
		AC_MSG_RESULT([*** GeoIP dyn lib: $geoip_dyn_lib])
		AC_DEFINE_UNQUOTED(GEOIP_DYN_LIB, "$geoip_dyn_lib", Define GeoIP dynamic library.)

		AC_MSG_RESULT([*** GeoIP support will be implemented by using dynamic load of library])
		AC_DEFINE(SUPPORT_GEOIP, 1, Define if you want GeoIP support.)
		AC_DEFINE(SUPPORT_GEOIP_V6, 1, Define if you want GeoIP IPv6 support.)
		AC_DEFINE(SUPPORT_GEOIP_DYN, 1, Define if you want GeoIP support with dynamic loading support - requires also additional linker options.)
	fi
fi

GEOIP_DB=$geoip_db
AC_SUBST(GEOIP_INCLUDE)
AC_SUBST(GEOIP_INCLUDE_VERSION)
AC_SUBST(GEOIP_INCLUDE_L2)
AC_SUBST(GEOIP_INCLUDE_L1)
AC_SUBST(GEOIP_LIB)
AC_SUBST(GEOIP_LIB_L1)
AC_SUBST(GEOIP_LIB_L2)
AC_SUBST(GEOIP_DB)
AC_SUBST(GEOIP_DYN_LIB)

if test -n "$GEOIP_INCLUDE_VERSION"; then
	AC_DEFINE_UNQUOTED(GEOIP_INCLUDE_VERSION, "$GEOIP_INCLUDE_VERSION", GeoIP include file version.)
fi


dnl *************************************************
dnl Dynamic load used?
dnl *************************************************
if test "$DYNAMIC_LOAD" = "yes"; then
	if test "$GEOIP_DYN" = "yes" -o "$IP2LOCATION_DYN" = "yes"; then
		DYNAMIC_LOAD="yes"
		AC_MSG_RESULT([*** Dynamic loading of libraries is ENABLED])
		DYNLOAD_LIB="-rdynamic -ldl"
	fi
fi

AC_SUBST(DYNLOAD_LIB)


dnl *************************************************
dnl libdb required
dnl *************************************************
if test "$require_libdb" = "yes"; then
	AC_CHECK_HEADER(db.h, [
		AC_CHECK_LIB(db, db_create,
		[
			AC_MSG_RESULT([*** Berkeley DB library found and usable])
		],
		[
			AC_MSG_ERROR([Berkeley DB library file misses db_create])
		])
	],
	[
		AC_MSG_ERROR([Berkeley DB library header files not found (perhaps missing db4-devel/libdb-devel package)])
	])

	LDFLAGS_EXTRA="$LDFLAGS_EXTRA -ldb"
	AC_DEFINE(HAVE_BERKELEY_DB_SUPPORT, 1, Define if Berkeley DB support is required.)
fi


dnl *************************************************
dnl mod_ipv6calc / apxs - APache eXtension tool
dnl *************************************************
AC_ARG_ENABLE([mod_ipv6calc], 
	AS_HELP_STRING([--enable-mod_ipv6calc],
		[Enable build of mod_ipv6calc for Apache (default: disabled)]),
	[
		ENABLE_MOD_IPV6CALC="1"
	],[
		ENABLE_MOD_IPV6CALC="0"
	])

AC_SUBST(ENABLE_MOD_IPV6CALC)

AC_ARG_WITH(apxs, AC_HELP_STRING([--with-apxs=NAME],
            [name of the apxs executable (apxs)]),
            [APXS="$with_apxs"])

if test "$ENABLE_MOD_IPV6CALC" = "1"; then
	AC_MSG_RESULT([Build of mod_ipv6calc enabled])

	if test -z "$APXS"; then
		AC_PATH_PROGS(APXS, apxs2 apxs, [], [$PATH:/usr/local/apache/bin:/usr/sbin])
	fi

	if test -z "$APXS"; then
		AC_MSG_ERROR([No APXS binary found: cannot create Apache module - missing httpd-devel?])
	else
		AC_MSG_RESULT([APXS binary found: $APXS])

		# partially taken from configure.ac from mod_wsgi
		AC_MSG_CHECKING(Apache version)
		HTTPD="`${APXS} -q SBINDIR`/`${APXS} -q TARGET`"
		HTTPD_INCLUDEDIR="`${APXS} -q INCLUDEDIR`"
		if test -x ${HTTPD}; then
		    HTTPD_VERSION=`${HTTPD} -v | awk '/version/ {print $3}' \
		     | awk -F/ '{print $2}'`
		else
		    if test -f ${HTTPD_INCLUDEDIR}/ap_release.h; then
			HTTPD_VERSION=`grep '^#define AP_SERVER_MAJORVERSION_NUMBER ' \
			 ${HTTPD_INCLUDEDIR}/ap_release.h | sed -e \
			 's/^#define AP_SERVER_MAJORVERSION_NUMBER \([0-9]\).*/\1.X/'`
		    else
			if test -f ${HTTPD_INCLUDEDIR}/httpd.h; then
			    HTTPD_VERSION=`grep '^#define APACHE_RELEASE ' \
			     ${HTTPD_INCLUDEDIR}/httpd.h | sed -e \
			     's/^#define APACHE_RELEASE \([0-9]\).*/\1.X/'`
			else
			    HTTPD_VERSION="2.?"
			fi
		    fi
		fi

		HTTPD_LIBEXECDIR="`${APXS} -q libexecdir`"
		if test -z "$HTTPD_LIBEXECDIR"; then
			AC_MSG_ERROR([${APXS} cannot retrieve libexecdir])
		fi

		HTTPD_SYSCONFDIR="`${APXS} -q sysconfdir`"
		if test -z "$HTTPD_SYSCONFDIR"; then
			AC_MSG_ERROR([${APXS} cannot retrieve sysconfdir])
		fi

		if test -n "$HTTPD_SYSCONFDIR"; then
			HTTPD_SYSCONFDIR="$HTTPD_SYSCONFDIR.d"
		fi
		if test -n "$HTTPD_VERSION"; then
			HTTPD_VERSION_MAJOR_MINOR=`echo "$HTTPD_VERSION" | awk -F. '{ print $1 "." $2 }'`
		fi
	fi

	AC_SUBST(HTTPD_LIBEXECDIR)
	AC_SUBST(HTTPD_SYSCONFDIR)
	AC_SUBST(HTTPD_VERSION_MAJOR_MINOR)
	AC_SUBST(APXS)
else
	AC_MSG_WARN([Build of mod_ipv6calc NOT enabled])
fi


dnl *************************************************
dnl Files to create from <file>.in
dnl *************************************************
AC_SUBST(CFLAGS_EXTRA)
AC_SUBST(LDFLAGS_EXTRA)
AC_SUBST(LDFLAGS_EXTRA_MOD_IPV6CALC)
AC_SUBST(LDFLAGS_EXTRA_STATIC)
AC_SUBST(LD_LIBRARY_PATH)
AC_SUBST(LD_LIBRARY_PATH_BASIC)

AC_OUTPUT([
		Makefile
		md5/Makefile
		tools/Makefile
		getopt/Makefile
		ipv6calc/Makefile
		lib/Makefile
		man/Makefile
		databases/lib/Makefile
		ipv6logconv/Makefile
		ipv6loganon/Makefile
		ipv6logstats/Makefile
		ipv6calcweb/Makefile
		contrib/ipv6calc.spec
		tools/ipv6calc-db-update.sh
		tools/DBIP-update.sh
		tools/IP2Location-update.sh
		tools/GeoIP-update.sh
		mod_ipv6calc/Makefile
		VERSION
	])

AC_MSG_RESULT([***** Summary])

AC_MSG_RESULT([*** IP2LOCATION                =$IP2LOCATION])
AC_MSG_RESULT([*** IP2LOCATION_DB             =$IP2LOCATION_DB])
AC_MSG_RESULT([*** IP2LOCATION_DYN            =$IP2LOCATION_DYN])
AC_MSG_RESULT([*** IP2LOCATION_DYN_LIB        =$ip2location_dyn_lib])
AC_MSG_RESULT([*** IP2LOCATION_INCLUDE        =$IP2LOCATION_INCLUDE])
AC_MSG_RESULT([*** IP2LOCATION_INCLUDE_VERSION=$IP2LOCATION_INCLUDE_VERSION])
AC_MSG_RESULT([*** IP2LOCATION_LIB            =$IP2LOCATION_LIB])
AC_MSG_RESULT([*** IP2LOCATION_LIB_NAME       =$IP2LOCATION_LIB_NAME])
AC_MSG_RESULT([*** IP2LOCATION_LIB_DIR        =$IP2LOCATION_LIB_DIR])
AC_MSG_RESULT([*** IP2LOCATION_IPV6_COMPAT    =$IP2LOCATION_IPV6_COMPAT])
AC_MSG_RESULT([*** IP2LOCATION_ALL_COMPAT     =$IP2LOCATION_ALL_COMPAT])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** GEOIP                      =$GEOIP])
AC_MSG_RESULT([*** GEOIP_DB                   =$GEOIP_DB])
AC_MSG_RESULT([*** GEOIP_DYN                  =$GEOIP_DYN])
AC_MSG_RESULT([*** GEOIP_DYN_LIB              =$geoip_dyn_lib])
AC_MSG_RESULT([*** GEOIP_INCLUDE              =$GEOIP_INCLUDE])
AC_MSG_RESULT([*** GEOIP_INCLUDE_VERSION      =$GEOIP_INCLUDE_VERSION])
AC_MSG_RESULT([*** GEOIP_LIB                  =$GEOIP_LIB])
AC_MSG_RESULT([*** GEOIP_LIB_NAME             =$GEOIP_LIB_NAME])
AC_MSG_RESULT([*** GEOIP_LIB_DIR              =$GEOIP_LIB_DIR])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** DBIP                       =$DBIP])
AC_MSG_RESULT([*** DBIP_DB                    =$DBIP_DB])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** EXTERNAL                   =$EXTERNAL])
AC_MSG_RESULT([*** EXTERNAL_DB                =$EXTERNAL_DB])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** BUILTIN                    =$BUILTIN])
AC_MSG_RESULT([*** DB_IPV4                    =$DB_IPV4])
AC_MSG_RESULT([*** DB_IPV6                    =$DB_IPV6])
AC_MSG_RESULT([*** DB_IEEE                    =$DB_IEEE])
AC_MSG_RESULT([*** DB_AS_REG                  =$DB_AS_REG])
AC_MSG_RESULT([*** DB_CC_REG                  =$DB_CC_REG])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** CC                         =$CC])
AC_MSG_RESULT([*** CFLAGS_EXTRA               =$CFLAGS_EXTRA])
AC_MSG_RESULT([*** LDFLAGS_EXTRA              =$LDFLAGS_EXTRA])
AC_MSG_RESULT([*** LD_LIBRARY_PATH            =$LD_LIBRARY_PATH])
AC_MSG_RESULT([*** LD_LIBRARY_PATH_BASIC      =$LD_LIBRARY_PATH_BASIC])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** CPPLAGS                    =$CPPLAGS])
AC_MSG_RESULT([*** CFLAGS                     =$CFLAGS])
AC_MSG_RESULT([*** LDFLAGS                    =$LDFLAGS])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** PACKAGE_VERSION_NUMERIC    =$PACKAGE_VERSION_NUMERIC])
AC_MSG_RESULT([*** PACKAGE_VERSION_STRING     =$PACKAGE_VERSION_STRING])
AC_MSG_RESULT([*** API_VERSION_NUMERIC        =$API_VERSION_NUMERIC])
AC_MSG_RESULT([*** API_VERSION_STRING         =$API_VERSION_STRING])

AC_MSG_RESULT([])

AC_MSG_RESULT([*** ENABLE_MOD_IPV6CALC        =$ENABLE_MOD_IPV6CALC])
if test "$ENABLE_MOD_IPV6CALC" = "1"; then
	AC_MSG_RESULT([*** APXS                       =$APXS])
	AC_MSG_RESULT([*** HTTPD_SYSCONFDIR           =$HTTPD_SYSCONFDIR])
	AC_MSG_RESULT([*** HTTPD_LIBEXECDIR           =$HTTPD_LIBEXECDIR])
	AC_MSG_RESULT([*** HTTPD_VERSION              =$HTTPD_VERSION])
	AC_MSG_RESULT([*** HTTPD_VERSION_MAJOR_MINOR  =$HTTPD_VERSION_MAJOR_MINOR])
	AC_MSG_RESULT([*** LDFLAGS_EXTRA_MOD_IPV6CALC =$LDFLAGS_EXTRA_MOD_IPV6CALC])
fi