Codebase list icinga / debian/1.13.3-4 configure.in
debian/1.13.3-4

Tree @debian/1.13.3-4 (Download .tar.gz)

configure.in @debian/1.13.3-4raw · history · blame

   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
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
dnl Process this -*-m4-*- file with autoconf to produce a configure script.

dnl Disable caching
define([AC_CACHE_LOAD],)
define([AC_CACHE_SAVE],)

AC_INIT(base/icinga.c)
AC_CONFIG_HEADER(include/config.h)
AC_PREFIX_DEFAULT(/usr/local/icinga)

PKG_NAME=icinga-core
PKG_VERSION="1.13.3"
PKG_HOME_URL="http://www.icinga.org/"
PKG_REL_DATE="07-15-2015"

dnl Figure out how to invoke "install" and what install options to use.
AC_PROG_INSTALL
AC_SUBST(INSTALL)

dnl What OS are we running?
AC_CANONICAL_HOST

dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PATH_PROG([STRIP],[strip],[true])

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(arpa/inet.h ctype.h dirent.h errno.h fcntl.h getopt.h grp.h libgen.h limits.h math.h netdb.h netinet/in.h pthread.h pthreads.h pwd.h regex.h signal.h socket.h stdarg.h string.h strings.h sys/mman.h sys/types.h sys/time.h sys/resource.h sys/wait.h sys/socket.h sys/stat.h sys/timeb.h sys/un.h sys/ipc.h sys/msg.h sys/poll.h syslog.h uio.h unistd.h sys/select.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL
AC_TYPE_GETGROUPS


dnl Check for asprintf() and friends...
AC_CACHE_CHECK([for va_copy],ac_cv_HAVE_VA_COPY,[
AC_TRY_LINK([#include <stdarg.h>
va_list ap1,ap2;], [va_copy(ap1,ap2);],
ac_cv_HAVE_VA_COPY=yes,
ac_cv_HAVE_VA_COPY=no)])
if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then
    AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
else
    AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE___VA_COPY,[
    AC_TRY_LINK([#include <stdarg.h>
    va_list ap1,ap2;], [__va_copy(ap1,ap2);],
    ac_cv_HAVE___VA_COPY=yes,
    ac_cv_HAVE___VA_COPY=no)])
    if test x"$ac_cv_HAVE___VA_COPY" = x"yes"; then
        AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
    fi
fi

dnl base/Makefile.in
AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(snprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(asprintf,,SNPRINTF_O=../common/snprintf.o)
AC_CHECK_FUNC(vasprintf,,SNPRINTF_O=../common/snprintf.o)

dnl module/idoutils/src/Makefile.in
AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(snprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(asprintf,,SNPRINTF_O_IDO=snprintf.o)
AC_CHECK_FUNC(vasprintf,,SNPRINTF_O_IDO=snprintf.o)

AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[
AC_TRY_RUN([
#include <sys/types.h>
#include <stdarg.h>
void foo(const char *format, ...) {
       va_list ap;
       int len;
       char buf[5];

       va_start(ap, format);
       len = vsnprintf(buf, 0, format, ap);
       va_end(ap);
       if (len != 5) exit(1);

       va_start(ap, format);
       len = vsnprintf(0, 0, format, ap);
       va_end(ap);
       if (len != 5) exit(1);

       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);

       exit(0);
}
main() { foo("hello"); }
],
ac_cv_HAVE_C99_VSNPRINTF=yes,ac_cv_HAVE_C99_VSNPRINTF=no,ac_cv_HAVE_C99_VSNPRINTF=cross)])
if test x"$ac_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
    AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Define if system has C99 compatible vsnprintf])
fi

dnl AC_CHECK_FUNC(snprintf,AC_DEFINE(HAVE_SNPRINTF),SNPRINTF_O=../common/snprintf.o)
AC_SUBST(SNPRINTF_O)
AC_SUBST(SNPRINTF_O_IDO)


dnl Checks for library functions.
AC_SEARCH_LIBS([getservbyname],[nsl],
	[if test "$ac_cv_search_getservbyname" != "none required"; then
		SOCKETLIBS="$SOCKETLIBS -lnsl"
	fi])
AC_SEARCH_LIBS([connect],[socket],
	[if test "$ac_cv_search_connect" != "none required"; then
		SOCKETLIBS="$SOCKETLIBS -lsocket"
	fi])
AC_SUBST(SOCKETLIBS)
AC_CHECK_FUNCS(initgroups setenv strdup strstr strtoul unsetenv)

dnl Check for gethostbyname (requires libnsl on Solaris)
AC_SEARCH_LIBS([gethostbyname], [nsl],
	[if test "$ac_cv_search_gethostbyname" != "none required"; then
		SOCKETLIBS="$SOCKETLIBS -lnsl"
	fi])

dnl Check for getopt_long (Solaris)
AC_CHECK_FUNCS([getopt_long],,AC_CHECK_LIB([iberty],[getopt_long],OTHERLIBS="$OTHERLIBS -liberty"))
AC_SUBST(OTHERLIBS)


AC_MSG_CHECKING(for type of socket size)
AC_TRY_COMPILE([#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
],
[int a = send(1, (const void *) 0, (size_t) 0, (int) 0);],
[AC_DEFINE(SOCKET_SIZE_TYPE, size_t, [typedef for socket size]) AC_MSG_RESULT(size_t)],
[AC_DEFINE(SOCKET_SIZE_TYPE, int, [typedef for socket size]) AC_MSG_RESULT(int)])


dnl Test for pthreads support - taken from ICU FreeBSD Port configure script
THREADLIBS=""
have_pthreads="no"

dnl FreeBSD: Try ports/linuxthreads first - Mammad Zadeh <mammad@yahoo-inc.com>
dnl FreeBSD -pthread check - Jonathan McDowell <noodles@earth.li>
AC_DEFUN([AC_PTHREAD_FREEBSD],[
	AC_CHECK_LIB(lthread,pthread_create,[
		CFLAGS="-D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads -I/usr/include $CFLAGS"
		THREADLIBS="-L/usr/local/lib -llthread -llgcc_r"
		],[
		AC_MSG_CHECKING([if we need -pthread for threads])
		AC_CACHE_VAL(ac_cv_ldflag_pthread,[
			ac_save_LDFLAGS="$LDFLAGS"
			LDFLAGS="-pthread $LDFLAGS"
			AC_TRY_LINK([
				char pthread_create();
				],
				pthread_create();,
				eval "ac_cv_ldflag_pthread=yes",
				eval "ac_cv_ldflag_pthread=no"
				),
			THREADLIBS="$ac_save_LDFLAGS"
			])
		if eval "test \"`echo $ac_cv_ldflag_pthread`\" = yes"; then
			AC_MSG_RESULT(yes)
		else
			AC_MSG_RESULT(no)
		fi
		],-L/usr/local/lib)
	])

dnl Test for HPUX cma threads first..
AC_CHECK_LIB(cma,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_cma_pthread_create = yes; then
	have_pthreads="yes"
fi

dnl special pthread handling
dnl AIX uses pthreads instead of pthread, and HP/UX uses cma
dnl FreeBSD users -pthread
AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_pthread_pthread_create = yes; then
	have_pthreads="yes"
else
	dnl For HP 11
	AC_CHECK_LIB(pthread,pthread_mutex_init,THREADLIBS="$THREADLIBS -lpthread")
	if test $ac_cv_lib_pthread_pthread_mutex_init = yes; then
		have_pthreads="yes"
	fi
fi

dnl AIX uses pthreads instead of pthread
if test $have_pthreads = "no"; then
	AC_CHECK_LIB(pthreads,pthread_create,THREADLIBS="$THREADLIBS -lpthreads")
	if test $ac_cv_lib_pthreads_pthread_create = yes; then
		have_pthreads="yes"
	fi
fi

dnl all other thread tests fail, try BSD's -pthread
if test $have_pthreads = "no"; then
	AC_PTHREAD_FREEBSD
fi

AC_SUBST(THREADLIBS)

dnl Solaris needs rt or posix4 libraries for nanosleep()
AC_SEARCH_LIBS(nanosleep,[rt posix4],,[
	echo "Error: nanosleep() needed for timing operations."
	exit 1
	])


AC_ARG_WITH(icinga_user,AC_HELP_STRING([--with-icinga-user=<user>],[sets user name to run icinga]),icinga_user=$withval,icinga_user=icinga)
AC_ARG_WITH(icinga_group,AC_HELP_STRING([--with-icinga-group=<grp>],[sets group name to run icinga]),icinga_grp=$withval,icinga_grp=icinga)
AC_SUBST(icinga_user)
AC_SUBST(icinga_grp)
AC_DEFINE_UNQUOTED(DEFAULT_ICINGA_USER,"$icinga_user",[user name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_NAGIOS_USER,"$icinga_user",[user name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_ICINGA_GROUP,"$icinga_grp",[group name to run nagios])
AC_DEFINE_UNQUOTED(DEFAULT_NAGIOS_GROUP,"$icinga_grp",[group name to run nagios])
INSTALL_OPTS="-o $icinga_user -g $icinga_grp"
AC_SUBST(INSTALL_OPTS)

AC_ARG_WITH(command_user,AC_HELP_STRING([--with-command-user=<user>],[sets user name for command access]),command_user=$withval,command_user=$icinga_user)
AC_ARG_WITH(command_group,AC_HELP_STRING([--with-command-group=<grp>] ,[sets group name for command access]),command_grp=$withval,command_grp=$icinga_grp)
AC_SUBST(command_user)
AC_SUBST(command_grp)
COMMAND_OPTS="-o $command_user -g $command_grp"
AC_SUBST(COMMAND_OPTS)


# Users for webfiles
AC_DEFUN([ACICINGA_USER_GUESS],[
   $2=$3
   for x in $1; do
    AC_MSG_CHECKING([if user $x exists])
     AS_IF([ $GREP -q "^$x:" /etc/passwd ],
           [ AC_MSG_RESULT([found]); $2=$x ; break],
           [ AC_MSG_RESULT([not found]) ])
   done
  ])

AC_DEFUN([ACICINGA_GROUP_GUESS],[
   $2=$3
   for x in $1; do
    AC_MSG_CHECKING([if group $x exists])
     AS_IF([ $GREP -q "^$x:" /etc/group ],
           [ AC_MSG_RESULT([found]); $2=$x ; break],
           [ AC_MSG_RESULT([not found]) ])
   done
])

AC_ARG_WITH([web_user],
        AS_HELP_STRING([--with-web-user=USER], [username for web writable files (default www-data)]),
        web_user=$withval,
        ACICINGA_USER_GUESS([www wwwrun www-data apache httpd nobody],[web_user],[www-data])
)

AC_ARG_WITH([web_group],
        AS_HELP_STRING([--with-web-group=GROUP], [group for web writable files (default www-data)]),
        web_group=$withval,
        ACICINGA_GROUP_GUESS([www www-data apache httpd nogroup nobody],[web_group], [www-data])
)
AC_SUBST(web_user)
AC_SUBST(web_group)

INSTALL_OPTS_WEB="-o $web_user -g $web_group"
AC_SUBST(INSTALL_OPTS_WEB)


dnl Check for location of mail program
MAIL_PROG=no
AC_ARG_WITH(mail,AC_HELP_STRING([--with-mail=<path_to_mail>],[sets path to equivalent program to mail]),MAIL_PROG=$withval,MAIL_PROG=no)
if test x$MAIL_PROG = xno; then
	AC_PATH_PROG(MAIL_PROG,mail)
fi
dnl Fix for systems that don't (yet) have mail/mailx installed...
if test x$MAIL_PROG = x; then
	MAIL_PROG="/bin/mail"
fi
AC_SUBST(MAIL_PROG)

dnl Check for location of Apache conf.d directory
HTTPD_CONF=no
APACHE24_DEBIAN=no
AC_ARG_WITH(httpd_conf,AC_HELP_STRING([--with-httpd-conf=<path_to_conf>],[sets path to Apache conf.d directory]),HTTPD_CONF=$withval,HTTPD_CONF=no)
if test x$HTTPD_CONF = xno; then
	if test -d /etc/httpd/conf.d; then
		HTTPD_CONF="/etc/httpd/conf.d"
	elif test -d /etc/apache2/conf-available; then
		dnl debian apache 2.4
		HTTPD_CONF="/etc/apache2/conf-available"
		APACHE24_DEBIAN=yes
	elif test -d /etc/apache2/conf.d; then
		HTTPD_CONF="/etc/apache2/conf.d"
	elif test -d /etc/apache/conf.d; then
		HTTPD_CONF="/etc/apache/conf.d"
	else
		HTTPD_CONF="/etc/httpd/conf.d"
	fi
fi
AC_SUBST(HTTPD_CONF)
AC_SUBST(APACHE24_DEBIAN)

dnl Location of check result path
CHECKRESULTDIR=no
AC_ARG_WITH(checkresult-dir,AC_HELP_STRING([--with-checkresult-dir=<path>],[sets path to check results spool directory]),CHECKRESULTDIR=$withval,CHECKRESULTDIR=no)
if test x$CHECKRESULTDIR = xno; then
	CHECKRESULTDIR="$localstatedir/spool/checkresults"
fi
AC_SUBST(CHECKRESULTDIR)

dnl Location of temp path
TMPDIR=no
AC_ARG_WITH(temp-dir,AC_HELP_STRING([--with-temp-dir=<path>],[sets path to temp directory path where Icinga can create temp files for service/host check results]),TMPDIR=$withval,TMPDIR=no)
if test x$TMPDIR = xno; then
	TMPDIR="/tmp"
fi
AC_SUBST(TMPDIR)

dnl Location of temp file
TMPFILE=no
AC_ARG_WITH(temp-file,AC_HELP_STRING([--with-temp-file=<filepath>],[sets path to an Icinga exclusive update temp file i.e. /tmp/icinga.tmp]),TMPFILE=$withval,TMPFILE=no)
if test x$TMPFILE = xno; then
	        TMPFILE="/tmp/icinga.tmp"
	fi
AC_SUBST(TMPFILE)


dnl Location of state dir
STATEDIR=no
AC_ARG_WITH(state-dir,AC_HELP_STRING([--with-state-dir=<filepath>],[sets path to custom localstate dir e.g. /var/spool/icinga]),STATEDIR=$withval,STATEDIR=no)
if test x$STATEDIR = xno; then
                STATEDIR="$localstatedir"
        fi
AC_SUBST(STATEDIR)


dnl Location of http auth file
HTTPAUTHFILE=no
AC_ARG_WITH(http-auth-file,AC_HELP_STRING([--with-http-auth-file=<filepath>],[sets path to an Icinga HTTP auth file]),HTTPAUTHFILE=$withval,HTTPAUTHFILE=no)
if test x$HTTPAUTHFILE = xno; then
                HTTPAUTHFILE="$sysconfdir/htpasswd.users"
        fi
AC_SUBST(HTTPAUTHFILE)

dnl Location of apache conf file
HTTPDCONFFILE=no
AC_ARG_WITH(httpd-conf-file,AC_HELP_STRING([--with-httpd-conf-file=<filepath>],[sets path to Icinga HTTPD config file]),HTTPDCONFFILE=$withval,HTTPDCONFFILE=no)
if test x$HTTPDCONFFILE = xno; then
                HTTPDCONFFILE="$HTTPD_CONF/icinga.conf"
        fi
AC_SUBST(HTTPDCONFFILE)


dnl Location of plugin path
PLUGINDIR=no
AC_ARG_WITH(plugin-dir,AC_HELP_STRING([--with-plugin-dir=<path>],[sets path to plugins directory path i.e. $prefix/libexec]),PLUGINDIR=$withval,PLUGINDIR=no)
if test x$PLUGINDIR = xno; then
	        PLUGINDIR="$libexecdir"
	fi
AC_SUBST(PLUGINDIR)

dnl Location of eventhandler path
EVENTHANDLERDIR=no
AC_ARG_WITH(eventhandler-dir,AC_HELP_STRING([--with-eventhandler-dir=<path>],[sets path to eventhandlers directory path i.e. $prefix/libexec/eventhandlers]),EVENTHANDLERDIR=$withval,EVENTHANDLERDIR=no)
if test x$EVENTHANDLERDIR = xno; then
                EVENTHANDLERDIR="$libexecdir/eventhandlers"
        fi
AC_SUBST(EVENTHANDLERDIR)

dnl Location of downtimes scripts path
DOWNTIMESRDIR=no
AC_ARG_WITH(downtimes-dir,AC_HELP_STRING([--with-downtimes-dir=<path>],[sets path to recurring downtimes scripts directory path i.e. $prefix/libexec/downtimes]),DOWNTIMESDIR=$withval,DOWNTIMESDIR=no)
if test x$DOWNTIMESDIR = xno; then
                DOWNTIMESDIR="$libexecdir/downtimes"
        fi
AC_SUBST(DOWNTIMESDIR)

dnl enable perfdata
ENABLE_PERFDATA=no
AC_ARG_ENABLE(perfdata,AC_HELP_STRING([--enable-perfdata],[enables perfdata in icinga.cfg]),[
        if test x$enableval = xyes; then
                ENABLE_PERFDATA=yes
        fi
        ],ENABLE_PERFDATA=no)

if test x$ENABLE_PERFDATA = xyes; then
        ENABLEPERFDATA=1
else   
        ENABLEPERFDATA=0
fi
AC_SUBST(ENABLEPERFDATA)


dnl enable cgi zlib log support
DISABLE_COMPRESSED_LOGS=no
DISABLECOMPRESSEDLOGS=""
AC_ARG_ENABLE(compressed-logs,AC_HELP_STRING([--disable-compressed-logs],[disable support for gzip compressed logs]), [
	if test x$enableval = xno; then
	        DISABLE_COMPRESSED_LOGS=yes
	fi
	],DISABLE_COMPRESSED_LOGS=no)

if test x$DISABLE_COMPRESSED_LOGS = xno; then
	AC_ARG_WITH(zlib,
	[  --with-zlib[[=DIR]]       use libz in DIR],[
		if test "$withval" != "no" -a "$withval" != "yes"; then
			Z_DIR=$withval
			CFLAGS="${CPPFLAGS} -I$withval/include"
			LDFLAGS="${LDFLAGS} -L$withval/lib"
		fi
	])
	if test "$with_zlib" = "no"; then
		echo "Disabling support for gzip compressed logs"
		DISABLE_COMPRESSED_LOGS=yes
	else
		AC_CHECK_HEADERS(zlib.h,
			AC_CHECK_LIB(z, gzread,[
				AC_DEFINE(HAVE_ZLIB,[],[Do we have zlib])
				if test "x${Z_DIR}" != "x"; then
					CFLAGS="$CFLAGS -I${Z_DIR}/include"
					LIBS="$LIBS -L${Z_DIR}/lib -lz"
					[case ${host} in
						*-*-solaris*)
							LIBS="$LIBS -L${Z_DIR}/lib -R${Z_DIR}/lib -lz"
							;;
					esac]
				else
					LIBS="$LIBS -lz"
				fi], [
					echo "Disabling support for gzip compressed logs"
					DISABLE_COMPRESSED_LOGS=yes
				]
			), [
				echo "No zlib.h found, disabling support for gzip compressed logs"
				DISABLE_COMPRESSED_LOGS=yes
			]
		)
	fi
fi

if test x$DISABLE_COMPRESSED_LOGS = xyes; then
	DISABLECOMPRESSEDLOGS="THIS OPTION WAS DISABLED DURING COMPILE TIME"
fi
AC_SUBST(DISABLECOMPRESSEDLOGS)


dnl ################
dnl LOG DIRS
dnl ################
dnl Location of logging path
LOGDIR=no
AC_ARG_WITH(log-dir,AC_HELP_STRING([--with-log-dir=<path>],[sets path to logging directory]),LOGDIR=$withval,LOGDIR=no)
if test x$LOGDIR = xno; then
        LOGDIR="$localstatedir"
fi
AC_SUBST(LOGDIR)

dnl Enable cgi logging
ENABLE_CGILOG=no
AC_ARG_ENABLE(cgi-log,AC_HELP_STRING([--enable-cgi-log],[enables cgi logging - experimental!!]),[
        if test x$enableval = xyes; then
		ENABLE_CGILOG=yes
	fi
	],ENABLE_CGILOG=no)

if test x$ENABLE_CGILOG = xyes; then
        ENABLECGILOG=1
else
        ENABLECGILOG=0
fi
AC_SUBST(ENABLECGILOG)

dnl Location of cgi logging path
CGILOGDIR=no
AC_ARG_WITH(cgi-log-dir,AC_HELP_STRING([--with-cgi-log-dir=<path>],[sets path to cgi logging directory]),CGILOGDIR=$withval,CGILOGDIR=no)
if test x$CGILOGDIR = xno; then
        CGILOGDIR="$datarootdir/log"
fi
AC_SUBST(CGILOGDIR)

dnl ################
dnl OTHER DIRS
dnl ################
dnl Location of the external command file path
EXTCMDFILEDIR=no
PHPAPIEXTCMDDIR=no
AC_ARG_WITH(ext-cmd-file-dir,AC_HELP_STRING([--with-ext-cmd-file-dir=<path>],[sets path to external command file directory]),EXTCMDFILEDIR=$withval,EXTCMDFILEDIR=no)
if test x$EXTCMDFILEDIR = xno; then
        EXTCMDFILEDIR="$localstatedir/rw"
fi
PHPAPIEXTCMDDIR="$EXTCMDFILEDIR"
AC_SUBST(EXTCMDFILEDIR)
AC_SUBST(PHPAPIEXTCMDDIR)

dnl Location of the embedded perl p1.pl
P1FILELOC=no
AC_ARG_WITH(p1-file-dir,AC_HELP_STRING([--with-p1-file-dir=<path>],[sets path to embedded perl p1.pl directory]),P1FILELOC=$withval,P1FILELOC=no)
if test x$P1FILELOC = xno; then
        P1FILELOC="$libdir"
fi
AC_SUBST(P1FILELOC)



dnl Check for location of init scripts
init_dir=/etc/rc.d/init.d
if test -d /etc/rc.d/init.d; then
	init_dir="/etc/rc.d/init.d"
elif test -d /usr/local/etc/rc.d; then
	init_dir="/usr/local/etc/rc.d"
elif test -d /etc/rc.d; then
	init_dir="/etc/rc.d"
elif test -d /etc/init.d; then
	init_dir="/etc/init.d"
elif test -d /sbin/init.d; then
	init_dir="/sbin/init.d"
fi

dnl User can override init script location
AC_ARG_WITH(init_dir,AC_HELP_STRING([--with-init-dir=<path>],[sets directory to place init script into]),init_dir=$withval)
AC_SUBST(init_dir)

dnl Check for location of systemd unit files
systemd_unit_dir=/usr/lib/systemd/system
if test -d /usr/lib/systemd/system; then
       systemd_unit_dir=/usr/lib/systemd/system
elif test -d /lib/systemd/system; then
       systemd_unit_dir=/lib/systemd/system
fi

systemd_sysconfig_dir=/etc/sysconfig

dnl User can override unit file directory location
AC_ARG_WITH(systemd_unit_dir,AC_HELP_STRING([--with-systemd-unit-dir=<path>],[sets directory to place systemd service file into]),systemd_unit_dir=$withval)
AC_SUBST(systemd_unit_dir)

dnl User can override sysconfig file directory location
AC_ARG_WITH(systemd_sysconfig_dir,AC_HELP_STRING([--with-systemd-sysconfig-dir=<path>],[sets directory to place systemd service configuration file]),systemd_sysconfig_dir=$withval)
AC_SUBST(systemd_sysconfig_dir)

dnl User can override lock file location
AC_ARG_WITH(lockfile,AC_HELP_STRING([--with-lockfile=<path>],[sets path and file name for lock file]),lockfile=$withval,lockfile=$localstatedir/icinga.lock)
AC_SUBST(lockfile)


dnl Location of icinga.chk (error log on initscript)
ICINGACHKFILE=no
AC_ARG_WITH(icinga-chkfile,AC_HELP_STRING([--with-icinga-chkfile=<path>],[sets path and file name for icinga initscript error file]),ICINGACHKFILE=$withval,ICINGACHKFILE=no)
if test x$ICINGACHKFILE = xno; then
        ICINGACHKFILE="$localstatedir/icinga.chk"
fi
AC_SUBST(ICINGACHKFILE)

dnl Location of ido2db.lock
IDO2DBLOCKFILE=no
AC_ARG_WITH(ido2db-lockfile,AC_HELP_STRING([--with-ido2db-lockfile=<path>],[sets path and file name for ido2db lock file]),IDO2DBLOCKFILE=$withval,IDO2DBLOCKFILE=no)
if test x$IDO2DBLOCKFILE = xno; then
        IDO2DBLOCKFILE="$localstatedir/ido2db.lock"
fi
AC_SUBST(IDO2DBLOCKFILE)


dnl Location of ido.sock
IDOSOCKFILE=no
AC_ARG_WITH(ido-sockfile,AC_HELP_STRING([--with-ido-sockfile=<path>],[sets path and file name for ido sock file]),IDOSOCKFILE=$withval,IDOSOCKFILE=no)
if test x$IDOSOCKFILE = xno; then
        IDOSOCKFILE="$localstatedir/ido.sock"
fi
AC_SUBST(IDOSOCKFILE)

dnl Location of idomod.tmp
IDOMODTMPFILE=no
AC_ARG_WITH(idomod-tmpfile,AC_HELP_STRING([--with-idomod-tmpfile=<path>],[sets path and file name for idomod tmp file]),IDOMODTMPFILE=$withval,IDOMODTMPFILE=no)
if test x$IDOMODTMPFILE = xno; then
        IDOMODTMPFILE="$localstatedir/idomod.tmp"
fi
AC_SUBST(IDOMODTMPFILE)


dnl Default xdata routines...
XSDTYPE=default
XRDTYPE=default
XODTYPE=template
XPDTYPE=default

XSDCOMMENT=
XRDCOMMENT=
XODCOMMENT=
XPDCOMMENT=

USE_MYSQL=no
USE_PGSQL=no

dnl Status data
AC_DEFINE_UNQUOTED(USE_XSDDEFAULT,,[use default routines (in xdata/xsddefault.*) for status data I/O...])
XSDC="xsddefault.c"
XSDH="xsddefault.h"
XSDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xsddefault.*) for status data I/O..."
AC_SUBST(XSDC)
AC_SUBST(XSDH)


dnl Retention data
AC_DEFINE_UNQUOTED(USE_XRDDEFAULT,,[use default routines (in xdata/xrddefault.*) for retention data I/O...])
XRDC="xrddefault.c"
XRDH="xrddefault.h"
XRDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xrddefault.*) for retention data I/O..."
AC_SUBST(XRDC)
AC_SUBST(XRDH)


dnl Object data
AC_DEFINE_UNQUOTED(USE_XODTEMPLATE,,[use template-based routines (in xdata/xodtemplate.*) for object data I/O...])
XODC="xodtemplate.c"
XODH="xodtemplate.h"
XODCOMMENT="Template-based (text file)"
echo "We'll use template-based routines (in xdata/xodtemplate.*) for object data I/O..."
AC_SUBST(XODC)
AC_SUBST(XODH)



dnl Performance data
AC_DEFINE_UNQUOTED(USE_XPDDEFAULT,,[use default routines (in xdata/xpddefault.*) for performance data I/O...])
XPDC="xpddefault.c"
XPDH="xpddefault.h"
XPDCOMMENT="Default (external commands)"
echo "We'll use default routines (in xdata/xpddefault.*) for performance data I/O..."
AC_SUBST(XPDC)
AC_SUBST(XPDH)



dnl Optional GD library and include paths
AC_ARG_WITH(gd-lib,AC_HELP_STRING([--with-gd-lib=DIR],[sets location of the gd library]),[
	LDFLAGS="${LDFLAGS} -L${withval}"
	LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"
	])
AC_ARG_WITH(gd-inc,AC_HELP_STRING([--with-gd-inc=DIR],[sets location of the gd include files]),[
	CFLAGS="${CFLAGS} -I${withval}"
	])


TRYGD=yep

dnl statusmap CGI enabled by default, unless users chooses not to use it
TRYSTATUSMAP=yep
AC_ARG_ENABLE(statusmap, AC_HELP_STRING([--disable-statusmap], [disables compilation of statusmap CGI]),TRYSTATUSMAP=nope)


dnl JMD_CHECK_LIB_ORDER(LIBRARY, FUNCTION, ORDER [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND
dnl              [, OTHER-LIBRARIES]]])
	AC_DEFUN([JMD_CHECK_LIB_ORDER],
	[AC_MSG_CHECKING([for $2 in -l$1 (order $3)])
	dnl Use a cache variable name containing both the library and function name,
	dnl because the test really is for library $1 defining function $2, not
	dnl just for library $1.  Separate tests with the same $1 and different $2s
	dnl may have different results.
	ac_lib_var=`echo $1['_']$2['_']$3 | sed 'y%./+-%__p_%'`
	AC_CACHE_VAL(ac_cv_lib_$ac_lib_var,
	[ac_save_LIBS="$LIBS"
	LIBS="-l$1 $6 $LIBS"
	AC_TRY_LINK(dnl
	ifelse([AC_LANG], [FORTRAN77], ,
	ifelse([$2], [main], , dnl Avoid conflicting decl of main.
[/* Override any gcc2 internal prototype to avoid an error.  */
]ifelse([AC_LANG], CPLUSPLUS, [#ifdef __cplusplus
extern "C"
#endif
])dnl
[/* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */
char $2();
])),
	            [$2()],
	            eval "ac_cv_lib_$ac_lib_var=yes",
	            eval "ac_cv_lib_$ac_lib_var=no")
	LIBS="$ac_save_LIBS"
	])dnl
	if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
	  AC_MSG_RESULT(yes)
	  ifelse([$4], ,
	[changequote(, )dnl
	  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
	    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
	changequote([, ])dnl
	  AC_DEFINE_UNQUOTED($ac_tr_lib)
	  LIBS="-l$1 $LIBS"
	], [$4])
	else
	  AC_MSG_RESULT(no)
	ifelse([$5], , , [$5
	])dnl
	fi
	])



dnl Should we try and detect the GD libs?
if test x$TRYGD = xyep; then

	dnl libiconv is required on some systems - tack it on if found
	AC_CHECK_LIB(iconv,main,ICONV=-liconv,)

	dnl See if the GD lib is available and supports PNG images...

	dnl GD > 1.8.3 requires the TrueType library to be present as well, so test for that first...
	JMD_CHECK_LIB_ORDER(gd,gdImagePng,1,[
			GDLIBFOUND=yep
			GDLIBS="-lgd -lttf -lpng -ljpeg -lz -lm"
			],:,[-lttf -lpng -ljpeg -lz -lm])

	dnl GD > 1.8.1 requires the jpeg library to be present as well, so test for that...
	if test x$GDLIBFOUND = x; then
		JMD_CHECK_LIB_ORDER(gd,gdImagePng,2,[
			GDLIBFOUND=yep
			GDLIBS="-lgd $ICONV -lpng -ljpeg -lz -lm"
        		],:,[$ICONV -lpng -ljpeg -lz -lm])
	fi

	dnl If we failed the first test, try without jpeg library
	if test x$GDLIBFOUND = x; then
		JMD_CHECK_LIB_ORDER(gd,gdImagePng,3,[
			GDLIBFOUND=yep
			GDLIBS="-lgd $ICONV -lz -lm -lpng"
		        ],:,[$ICONV -lz -lm -lpng])
	fi

	dnl We failed again, so try a different library ordering (without jpeg libs)
	if test x$GDLIBFOUND = x; then
		JMD_CHECK_LIB_ORDER(gd,gdImagePng,4,[
			GDLIBFOUND=yep
			GDLIBS="-lgd $ICONV -lpng -lz -lm"
	        	],:,[$ICONV -lpng -lz -lm])
	fi

	dnl Did we find the necessary GD libraries?
	if test x$GDLIBFOUND = x; then
		echo ""
		echo ""
		echo "*** GD, PNG, and/or JPEG libraries could not be located... *********"
		echo ""
		echo "Boutell's GD library is required to compile the statusmap, trends"
		echo "and histogram CGIs.  Get it from http://www.boutell.com/gd/, compile"
		echo "it, and use the --with-gd-lib and --with-gd-inc arguments to specify"
		echo "the locations of the GD library and include files."
		echo ""
		echo "NOTE: In addition to the gd-devel library, you'll also need to make"
		echo "      sure you have the png-devel and jpeg-devel libraries installed"
		echo "      on your system."
		echo ""
		echo "NOTE: After you install the necessary libraries on your system:"
		echo "      1. Make sure /etc/ld.so.conf has an entry for the directory in"
		echo "         which the GD, PNG, and JPEG libraries are installed."
		echo "      2. Run 'ldconfig' to update the run-time linker options."
		echo "      3. Run 'make clean' in the Icinga distribution to clean out"
		echo "         any old references to your previous compile."
		echo "      4. Rerun the configure script."
		echo ""
		echo "NOTE: If you can't get the configure script to recognize the GD libs"
		echo "      on your system, get over it and move on to other things.  The"
		echo "      CGIs that use the GD libs are just a small part of the entire"
		echo "      Icinga package.  Get everything else working first and then"
		echo "      revisit the problem.  Make sure to check the icinga-users"
		echo "      mailing list archives for possible solutions to GD library"
		echo "      problems when you resume your troubleshooting."
		echo ""
		echo "********************************************************************"
		echo ""
		echo ""

	dnl We found the GD lib!
	else
		echo "GD library was found!"
		if test x$TRYSTATUSMAP = xyep; then
			AC_DEFINE_UNQUOTED(USE_STATUSMAP,,[defined if the user chose to include status map])
			CGIEXTRAS="$CGIEXTRAS statusmap.cgi"
			AC_CHECK_LIB(gd,gdImageCreateTrueColor,
				AC_DEFINE(HAVE_GDIMAGECREATETRUECOLOR,1,
					[Define if your gd library has gdImageCreateTrueColor]))
		fi

		dnl compile trends CGI
		AC_DEFINE_UNQUOTED(USE_TRENDS,,[compile trends CGI])
		CGIEXTRAS="$CGIEXTRAS trends.cgi"

		dnl compile histogram CGI
		AC_DEFINE_UNQUOTED(USE_HISTOGRAM,,[compile histogram CGI])
	        CGIEXTRAS="$CGIEXTRAS histogram.cgi"
	fi
fi


ENABLE_DEBUG=no
AC_ARG_ENABLE(debug,AC_HELP_STRING([--enable-debug],[enables debug mode]),ENABLE_DEBUG=$enableval,ENABLE_DEBUG=no)
if test x$ENABLE_DEBUG = xyes; then
	AC_DEFINE_UNQUOTED(ENABLE_DEBUG,,[enables debug mode])
fi

AC_ARG_WITH(cgiurl,AC_HELP_STRING([--with-cgiurl=<local-url>],[sets URL for cgi programs (do not use a trailing slash)]),cgiurl=$withval,cgiurl=/icinga/cgi-bin)
AC_SUBST(cgiurl)
AC_ARG_WITH(htmurl,AC_HELP_STRING([--with-htmurl=<local-url>],[sets URL for public html]),htmurl=$withval,htmurl=/icinga)
AC_SUBST(htmurl)
AC_ARG_WITH(mainurl,AC_HELP_STRING([--with-mainurl=<local-url>],[sets URL for default main frame in index.html (use quotes if special chars like & used)]),mainurl=$withval,mainurl=$cgiurl/status.cgi?allunhandledproblems)
AC_SUBST(mainurl)

USE_NANOSLEEP=yes
AC_ARG_ENABLE(nanosleep,AC_HELP_STRING([--enable-nanosleep],[enables use of nanosleep (instead sleep) in event timing]),USE_NANOSLEEP=$enableval,USE_NANOSLEEP=yes)
if test x$USE_NANOSLEEP = xyes; then
	AC_DEFINE_UNQUOTED(USE_NANOSLEEP,,[enables use of nanosleep (instead of sleep)])
fi

USE_EVENTBROKER=yes
AC_ARG_ENABLE(event-broker,AC_HELP_STRING([--enable-event-broker],[enables integration of event broker routines]),USE_EVENTBROKER=$enableval,USE_EVENTBROKER=yes)

BROKER_LDFLAGS=""
BROKERLIBS="";
some_dl_found="no";
if test x$USE_EVENTBROKER = xyes; then

	dnl Which loader library should we use? libtdl or dl?
	dnl Hopefully this will be portable and not give us headaches...
	AC_CHECK_HEADER(ltdl.h,[
		AC_CHECK_LIB(ltdl,lt_dlinit,[
			AC_DEFINE(HAVE_LTDL_H,,[Which loader library should we use? libtdl or dl?])
			some_dl_found="yes"
			BROKERLIBS="$BROKERLIBS -lltdl"
			])
	        ])
	if test "x$some_dl_found" != xyes; then
	AC_CHECK_HEADER(dlfcn.h,[
		AC_CHECK_LIB(dl,dlopen,[
			AC_DEFINE(HAVE_DLFCN_H,,[Which loader library should we use? libtdl or dl?])
			some_dl_found="yes"
			BROKERLIBS="$BROKERLIBS -ldl"
			])
	        ])
	fi

	dnl - Modified from www.erlang.org
	# Check how to export functions from the broker executable, needed
	# when dynamically loaded drivers are loaded (so that they can find
	# broker functions).
	# OS'es with ELF executables using the GNU linker (Linux and recent *BSD,
	# in rare cases Solaris) typically need '-Wl,-export-dynamic' (i.e. pass
	# -export-dynamic to the linker - also known as -rdynamic and some other
	# variants); some sysVr4 system(s) instead need(s) '-Wl,-Bexport'.
	# AIX 4.x (perhaps only for x>=2) wants -Wl,-bexpall,-brtl and doesn't
	# reliably return an error for others, thus we separate it out.
	# Otherwise we assume that if the linker accepts the flag, it is needed.
	AC_MSG_CHECKING(for extra flags needed to export symbols)
	case $host_os in
		aix4*|aix5*|aix6*|aix7*)
			BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-bexpall,-brtl"
		;;
		bsdi*)
    			BROKER_LDFLAGS="$BROKER_LDFLAGS -rdynamic"
	    	;;
		*)
			save_ldflags="$LDFLAGS"
			LDFLAGS=-Wl,-export-dynamic
			AC_TRY_LINK(,,[BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-export-dynamic"], [
				LDFLAGS=-Wl,-Bexport
				AC_TRY_LINK(,,[BROKER_LDFLAGS="$BROKER_LDFLAGS -Wl,-Bexport"],
					AC_MSG_RESULT(none))])
			LDFLAGS="$save_ldflags"
		;;
	esac
	AC_SUBST(BROKER_LDFLAGS)
	AC_SUBST(BROKERLIBS)
	test "x$BROKER_LDFLAGS" != x && AC_MSG_RESULT([$BROKER_LDFLAGS])


	dnl - Modified version from www.erlang.org
	dnl - Some 12/15/05 mods made after reading http://xaxxon.slackworks.com/phuku/dl.html
	AC_MSG_CHECKING(for linker flags for loadable modules)
	case $host_os in
		solaris2*|sysv4*)
			MOD_LDFLAGS="-G -fPIC"
			MOD_CFLAGS="-fPIC"
			INIT_OPTS="-o root -g root"
			SNPRINTF_BROKEN="yes"
		;;
		aix4*|aix5*|aix6*|aix7*)
			#MOD_LDFLAGS="-G -bnoentry -bexpall"
			MOD_LDFLAGS="-G -bM:SRE -bnoentry -bexpall"
			INIT_OPTS="-o root -g root"
		;;
		freebsd2*)
			# Non-ELF GNU linker
			MOD_LDFLAGS="-Bshareable"
			INIT_OPTS="-o root -g wheel"
		;;
		darwin*)
			# Mach-O linker, a shared lib and a loadable
			# object file is not the same thing.
			MOD_LDFLAGS="-bundle -flat_namespace -undefined suppress"
			MOD_CFLAGS="$MOD_CFLAGS -fno-common"
			INIT_OPTS="-o root -g root"
		;;
		linux* | k*bsd*-gnu*)
			# assume GNU linker and ELF
			MOD_LDFLAGS="-shared"
			MOD_CFLAGS="-fPIC"
			INIT_OPTS="-o root -g root"
		;;
		freebsd*)
			MOD_LDFLAGS="-shared"
			MOD_CFLAGS="-fPIC"
			INIT_OPTS="-o root -g wheel"
		;;
		*)
			# assume GNU linker and ELF
			MOD_LDFLAGS="-shared"
			INIT_OPTS="-o root -g root"
		;;
	esac
	AC_MSG_RESULT([$MOD_LDFLAGS])
	AC_SUBST(MOD_CFLAGS)
	AC_SUBST(MOD_LDFLAGS)


	AC_DEFINE_UNQUOTED(USE_EVENT_BROKER,,[defined to bring in the event broker objects])
	BROKER_O="broker.o nebmods.o"
	AC_SUBST(BROKER_O)
	BROKER_H="../include/broker.h ../include/nebmods.h ../include/nebmodules.h ../include/nebcallbacks.h ../include/neberrors.h"
	AC_SUBST(BROKER_H)
fi

dnl workaround for broken printf implementations (like solaris)
if test x$SNPRINTF_BROKEN = xyes; then
	AC_DEFINE(SNPRINTF_BROKEN,"1")
	SNPRINTF_O=../common/snprintf.o
	SNPRINTF_O_IDO=snprintf.o
	AC_SUBST(SNPRINTF_O)
	AC_SUBST(SNPRINTF_O_IDO)
fi

dnl Classic UI Standalone
CLASSICUI_STANDALONE=no
AC_ARG_ENABLE(classicui-standalone,AC_HELP_STRING([--enable-classicui-standalone],[enables standalone Classic UI (default: disabled)]),CLASSICUI_STANDALONE=$enableval,CLASSICUI_STANDALONE=no)
if test x$CLASSICUI_STANDALONE = xyes; then
	CLASSICUI_STANDALONE_FLAG="1"
fi
if test x$CLASSICUI_STANDALONE = xno; then
	CLASSICUI_STANDALONE_FLAG="0"
fi
AC_SUBST(CLASSICUI_STANDALONE_FLAG)


if test x$CLASSICUI_STANDALONE = xno; then
dnl Configure IDOUtils

dnl set dummy for ocilib
OCILIB_LIB=""

USE_IDOUTILS=yes
USE_IDOUTILS_ORACLE=no
AC_ARG_ENABLE(idoutils,AC_HELP_STRING([--enable-idoutils],[enables database connectivity using idoutils (default: enabled)]),USE_IDOUTILS=$enableval,USE_IDOUTILS=yes)
if test x$USE_IDOUTILS = xyes; then
	if test x$USE_EVENTBROKER = xno; then
		AC_MSG_ERROR([--enable-idoutils needs also --enable-event-broker])
	fi

	dnl instance name
	IDO_INSTANCE_NAME=no
	AC_ARG_WITH(ido-instance-name,AC_HELP_STRING([--with-ido-instance-name=<instancename>],[sets instance_name for IDOUtils in idomod.cfg]),IDO_INSTANCE_NAME=$withval,IDO_INSTANCE_NAME=no)
	if test x$IDO_INSTANCE_NAME = xno; then
	        IDO_INSTANCE_NAME="default"
	fi
	AC_SUBST(IDO_INSTANCE_NAME)

	dnl check if oracle enabled, then require ocilib
	dnl check if pgsql enabled, then require libpq
	dnl else require libpq

	dnl ocilib is to be expected in /usr/local/lib and /usr/local/include
	dnl libpq is to be expected in /usr/lib and /usr/include check with $ pg_config --libdir|--includedir
	dnl libdbi is to be expected in /usr/lib and /usr/include

	dnl Check for optional ocilib 
	USE_OCILIB=no
	USE_LIBPQ=no

	AC_ARG_ENABLE(oracle,AC_HELP_STRING([--enable-oracle],[enables idoutils with ocilib and oracle]),USE_OCILIB=$enableval,USE_OCILIB=no)
	AC_ARG_ENABLE(pgsql,AC_HELP_STRING([--enable-pgsql],[!use libdbis pgsql support instead, libpq not yet implemented! enables idoutils with libpq and pgsql]),USE_LIBPQ=$enableval,USE_LIBPQ=no)

	if test x$USE_OCILIB = xyes; then

		dnl set marker for output
		USE_IDOUTILS_ORACLE=yes
		OCILIB_INC="/usr/local/include"
		OCILIB_LIB="/usr/local/lib"

	        dnl Optional ocilib library and include paths
	        AC_ARG_WITH(ocilib-lib,AC_HELP_STRING([--with-ocilib-lib=DIR],[sets location of the ocilib library]),[
	                OCILIB_LIB="${withval}"
	                ])
	        AC_ARG_WITH(ocilib-inc,AC_HELP_STRING([--with-ocilib-inc=DIR],[sets location of the ocilib include files,]),[
	                OCILIB_INC="${withval}"
        	        ])

		ORACLE_LIB=""
                AC_ARG_WITH(oracle-lib,AC_HELP_STRING([--with-oracle-lib=DIR],[sets location of the oracle library]),[
                        ORACLE_LIB="${withval}"
                        ])

		if test "$ORACLE_LIB" = ""; then
			IDO2DB_RUNTIME="$OCILIB_LIB"
		else
			IDO2DB_RUNTIME="$OCILIB_LIB:$ORACLE_LIB"
		fi


		CFLAGS="$CFLAGS -I$OCILIB_INC -DOCI_IMPORT_RUNTIME -DOCI_CHARSET_ANSI"
		LDFLAGS="$LDFLAGS -L$OCILIB_LIB"

		dnl check and include ocilib.h
		AC_CHECK_HEADERS(ocilib.h)

		dnl check and include ocilib library, at runtime

		AC_DEFINE(HAVE_OCILIB_H,"1")
                dnl check libs
                AC_MSG_CHECKING(for ocilib)
                AC_CHECK_LIB([ocilib], [main],DBLIBS_OCI="${DBCFLAGS} -locilib" , [AC_MSG_ERROR([ERROR - We really need a ocilib to link against])] )
		DBLIBS="${DBLIBS} ${DBLIBS_OCI}"
		AC_SUBST(DBLIBS)

		dnl #define USE_ORACLE
		AC_DEFINE_UNQUOTED(USE_ORACLE)

	fi

	dnl Check for optional libpq
	if test x$USE_LIBPQ = xyes; then

		LIBPQ_INC=""
		LIBPQ_LIB=""

                dnl Optional libpq library and include paths
                AC_ARG_WITH(pgsql-lib,AC_HELP_STRING([--with-pgsql-lib=DIR],[!use libdbis pgsql support instead, libpq not yet implemented! sets location of the pgsql library]),[
                        LIBPQ_LIB="-L${withval}"
                        ])
                AC_ARG_WITH(psql-inc,AC_HELP_STRING([--with-pgsql-inc=DIR],[!use libdbis pgsql support instead, libpq not yet implemented! sets location of the pgsql include files,]),[
                        LIBPQ_INC="-I${withval}"
                        ])

                CFLAGS="$CFLAGS $LIBPQ_INC"
                LDFLAGS="$LDFLAGS $LIBPQ_LIB"

                AC_CHECK_HEADERS(libpq-fe.h)
                AC_DEFINE(HAVE_LIBPQ_FE_H,"1")
                AC_MSG_CHECKING(for lpq)
                AC_CHECK_LIB([pq], [main],DBLIBS_PQ="${DBCFLAGS} -lpq" , [AC_MSG_ERROR([ERROR - We really need a libpq to link against])] )
                DBLIBS="${DBLIBS} ${DBLIBS_PQ}"
                AC_SUBST(DBLIBS)

		dnl #define USE_PGSQL
		AC_DEFINE_UNQUOTED(USE_PGSQL)
	fi

	if test x$USE_LIBPQ = xno && test x$USE_OCILIB = xno; then

	        dnl Checks for libdbi
		dnl LIBDBI_INC="-I/usr/include"
		LIBDBI_INC=""
		dnl LIBDBI_LIB="-L/usr/lib"
		LIBDBI_LIB=""

	        dnl Optional libdbi library and include paths
	        AC_ARG_WITH(dbi-lib,AC_HELP_STRING([--with-dbi-lib=DIR],[sets location of the libdbi library]),[
			LIBDBI_LIB="-L${withval}"
	                ])
	        AC_ARG_WITH(dbi-inc,AC_HELP_STRING([--with-dbi-inc=DIR],[sets location of the libdbi include files,]),[
	                LIBDBI_INC="-I${withval}"
			])

                CFLAGS="$CFLAGS $LIBDBI_INC"
                LDFLAGS="$LDFLAGS $LIBDBI_LIB"

	        AC_CHECK_HEADERS(dbi/dbi.h)
	        AC_DEFINE(HAVE_DBI_DBI_H,"1")
	        AC_MSG_CHECKING(for libdbi)
	        AC_CHECK_LIB([dbi], [main],DBLIBS_DBI="${DBCFLAGS} -ldbi" , [AC_MSG_ERROR([ERROR - We really need a libdbi to link against])] )
		DBLIBS="${DBLIBS} ${DBLIBS_DBI}"
	        AC_SUBST(DBLIBS)

		dnl #define USE_LIBDBI
		AC_DEFINE_UNQUOTED(USE_LIBDBI)

	fi
fi
dnl classic ui standalone
fi


dnl Location of temp path
LIBDBIDRIVERDIR=no
AC_ARG_WITH(libdbi-driver-dir,AC_HELP_STRING([--with-libdbi-driver-dir=<path>],[sets path to libdbi driver directory path (only valid with libdbi, not oracle ocilib)]),LIBDBIDRIVERDIR=$withval,LIBDBIDRIVERDIR=no)
if test x$LIBDBIDRIVERDIR = xno; then
        LIBDBIDRIVERDIR="/usr/local/lib/dbd"
fi
AC_SUBST(LIBDBIDRIVERDIR)


USEPERL=no;
INSTALLPERLSTUFF=no;
AC_ARG_ENABLE(embedded-perl,AC_HELP_STRING([--enable-embedded-perl],[will enable embedded Perl interpreter]),[
	USEPERL=$enableval
	]
	,USEPERL=no)

PERLCACHE=yes;
AC_ARG_WITH(perlcache,AC_HELP_STRING([--with-perlcache],[turns on cacheing of internally compiled Perl scripts]),[
	PERLCACHE=$withval
	]
	,[
	AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
	PERLCACHE=yes;
	])

dnl Is embedded Perl being compiled in?
if test x$USEPERL = xyes; then

	AC_DEFINE_UNQUOTED(EMBEDDEDPERL,,[Is embedded Perl being compiled in?])
	PERLLIBS="`perl -MExtUtils::Embed -e ldopts`"
	PERLDIR="`perl -MConfig -e 'print $Config{installsitearch}'`"
	CFLAGS="${CFLAGS} `perl -MExtUtils::Embed -e ccopts`"
	USEPERL=yes
	INSTALLPERLSTUFF=yes;
	PERLXSI_O=perlxsi.o
	OBJS="${OBJS} ${PERLXSI_O}"
	echo "creating base/perlxsi.c"
	perl -MExtUtils::Embed -e xsinit -- -o base/perlxsi.c

	echo "Embedded Perl interpreter will be compiled in..."

	dnl Is caching enabled?
	if test x$PERLCACHE = xyes; then
		AC_DEFINE(DO_CLEAN,"0",[whether to clean cached compiled perl])
		PERLCACHE=yes;
		echo "Internally compiled Perl scripts will be cached..."
	else
		AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
		echo "Internally compiled Perl scripts will NOT be cached..."
	fi
fi

dnl Test if we're using threaded Perl (patch by Chip Ach)
if test x$USEPERL = xyes; then
	if (perl -e 'use Config;exit -1 unless ($Config{'usethreads'});'); then
		echo "Using threaded perl"
		AC_DEFINE_UNQUOTED(THREADEDPERL,,[defined if we're using threaded Perl])
	fi
fi


dnl Option for compiling under CYGWIN
icinga_name=icinga
icingastats_name=icingastats
ido2db_name=ido2db
cygwin=no
AC_ARG_ENABLE(cygwin,AC_HELP_STRING([--enable-cygwin],[enables building under the CYGWIN environment]),[
	cygwin=$enableval
	])
if test x$cygwin = xyes; then
	CFLAGS="${CFLAGS} -DCYGWIN"
	icinga_name=icinga.exe;
	icingastats_name=icingastats.exe;
fi
AC_SUBST(icinga_name)
AC_SUBST(icingastats_name)
AC_SUBST(ido2db_name)

dnl create ido2db_runtime for rc.ido2db.in
ido2db_runtime="$IDO2DB_RUNTIME"
AC_SUBST(ido2db_runtime)

dnl Should predictive failure routines be compiled in?
dnl AC_ARG_ENABLE(failure-prediction,AC_HELP_STRING([--enable-failure-prediction],[will enable integration with failure prediction module (NOT HERE YET!)]),[
dnl	AC_DEFINE_UNQUOTED(PREDICT_FAILURES)
dnl	BASEEXTRALIBS="$BASEEXTRALIBS \$(FDATALIBS)"
dnl	echo "Failure prediction routines (incomplete!) will be compiled in..."
dnl	])


dnl Package directory for Solaris pkgmk (and other OSs, eventually)
dnl VERSION=`grep 1.0 include/common.h | cut -d ' ' -f 3 | sed 's/"//g'`
VERSION=$PKG_VERSION
PACKDIR=`pwd`/solaris_pkg
SOL_PKG_NAME=Icinga
ARCH=`uname -p`
AC_SUBST(PACKDIR)
AC_SUBST(VERSION)
AC_SUBST(ARCH)
AC_SUBST(SOL_PKG_NAME)

AC_MSG_CHECKING(for type va_list)
AC_TRY_COMPILE([#ifdef __STDC__
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#else
#include <sys/types.h>
#include <stdio.h>
#include <varargs.h>
#endif],
[va_list args;],
[AC_MSG_RESULT(yes)],
[AC_DEFINE(NEED_VA_LIST,,[defined if va_list fails to compile]) AC_MSG_RESULT(no)])

dnl Environment Prefix
env_prefix="ICINGA_"
AC_ARG_ENABLE(nagiosenv,
 	AC_HELP_STRING([--enable-nagiosenv],[expose Icinga Environment variables as NAGIOS_*)]))
AS_IF([ test "x$enable_nagiosenv" = "xyes"],[
 	env_prefix="NAGIOS_"
 	AC_DEFINE(USE_NAGIOS_ENV,"1",[use NAGIOS_ as EnvVar Prefix])
 	])
 

AC_SUBST(CGIEXTRAS)
AC_SUBST(GDLIBS)
AC_SUBST(PERLLIBS)
AC_SUBST(PERLDIR)
AC_SUBST(PERLXSI_O)
AC_SUBST(BASEEXTRALIBS)
AC_SUBST(INITDIR)
AC_SUBST(INIT_OPTS)
AC_SUBST(INSTALLPERLSTUFF)
AC_SUBST(USE_EVENTBROKER)
AC_SUBST(USE_IDOUTILS)
AC_SUBST(USE_IDOUTILS_ORACLE)
AC_SUBST(ENABLE_DEBUG)

AC_PATH_PROG(PERL,perl)

dnl create perl bin path for idoutils *db scripts
ido2db_perl="$PERL"
AC_SUBST(ido2db_perl)

dnl Does user want to check for SSL?
AC_ARG_ENABLE(ssl,AC_HELP_STRING([--enable-ssl],[enables native SSL support]),[
	if test x$enableval = xyes; then
		check_for_ssl=yes
	else
		check_for_ssl=no
	fi
	],check_for_ssl=no)

dnl Optional SSL library and include paths
ssl_dir=
ssl_inc_dir=
ssl_lib_dir=
AC_ARG_WITH(ssl,AC_HELP_STRING([--with-ssl=DIR],[sets location of the SSL installation]),[
	ssl_dir=$withval
	])
AC_ARG_WITH(ssl-inc,AC_HELP_STRING([--with-ssl-inc=DIR],[sets location of the SSL include files]),[
	ssl_inc_dir=$withval
	])
AC_ARG_WITH(ssl-lib,AC_HELP_STRING([--with-ssl-lib=DIR],[sets location of the SSL libraries]),[
	ssl_lib_dir=$withval
	])
AC_ARG_WITH(kerberos-inc,AC_HELP_STRING([--with-kerberos-inc=DIR],[sets location of the Kerberos include files]),[
	kerberos_inc_dir=$withval
	])

dnl Check for SSL support
dnl Modified version of Mark Ethan Trostler's macro <trostler@juniper.net>
if test x$check_for_ssl = xyes; then
	AC_MSG_CHECKING(for SSL headers)
	found_ssl=no
	for dir in $ssl_inc_dir $ssl_dir /usr/local/openssl /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr /usr/freeware/lib/openssl; do
		ssldir="$dir"
		if test -f "$dir/include/openssl/ssl.h"; then
			found_ssl=yes
			CFLAGS="$CFLAGS -I$dir/include/openssl -I$ssldir/include"
			sslincdir="$dir/include/openssl"
		        break
		fi
		if test -f "$dir/include/ssl.h"; then
			found_ssl=yes
			CFLAGS="$CFLAGS -I$dir/include"
			sslincdir="$dir/include"
		        break
		fi
		if test -f "$dir/ssl.h"; then
			found_ssl=yes
			CFLAGS="$CFLAGS -I$dir"
			sslincdir="$dir"
			ssldir="$dir/.."
		        break
		fi
		if test -f "$dir/openssl/ssl.h"; then
			found_ssl=yes
			CFLAGS="$CFLAGS -I$dir/openssl"
			sslincdir="$dir/openssl"
			ssldir="$dir/.."
		        break
		fi
	done

	if test x_$found_ssl != x_yes; then
        	AC_MSG_ERROR(Cannot find ssl headers)
	else

	        printf "SSL headers found in $ssldir\n";

		dnl Now try and find SSL libraries
		AC_MSG_CHECKING(for SSL libraries)
		found_ssl=no
		for dir in $ssl_lib_dir $ssl_dir /usr/lib/*-linux-gnu /usr/lib64 /usr/lib /usr/local/lib /usr/lib/ssl /usr/ssl/lib /usr/openssl/lib /usr/pkg/lib  /usr/freeware/lib/openssl; do
			ssllibdir="$dir"
			if test -f "$dir/libssl.so"; then
				found_ssl=yes
			        break
			fi
			if test -f "$dir/lib/libssl.so"; then
				found_ssl=yes
				ssllibdir="$dir/lib"
			        break
			fi
		done

		if test x_$found_ssl != x_yes; then
        		AC_MSG_ERROR(Cannot find ssl libraries)
		else
		        printf "SSL libraries found in $ssllibdir\n";

			LDFLAGS="$LDFLAGS -L$ssllibdir";
		        LIBS="$LIBS -lssl -lcrypto";

			AC_DEFINE_UNQUOTED(HAVE_SSL)
			AC_SUBST(HAVE_SSL)

			dnl if ssl dir provided, thake this instead
			if test "ssl_dir" != ""; then
				ssldir="$ssl_dir"
			fi

			dnl Generate DH parameters
			echo ""
			echo "*** Generating DH Parameters for SSL/TLS ***"
			if test -f "$ssldir/sbin/openssl"; then
				sslbin=$ssldir/sbin/openssl
			else
				if test -f "$ssldir/bin/openssl"; then
                                        sslbin=$ssldir/bin/openssl
                                else
                                        sslbin=openssl
                                fi
			fi
			# awk to strip off meta data at bottom of dhparam output
			$sslbin dhparam -C 512 | awk '/^-----/ {exit} {print}' > include/dh.h
		fi
	fi

	dnl RedHat 8.0 and 9.0 include openssl compiled with kerberos, so we must include header file
	AC_MSG_CHECKING(for Kerberos include files)
	found_kerberos=no
	for dir in $kerberos_inc_dir /usr/kerberos/include; do
		kerbdir="$dir"
		if test -f "$dir/krb5.h"; then
			found_kerberos=yes
			CFLAGS="$CFLAGS -I$kerbdir"
			AC_DEFINE_UNQUOTED(HAVE_KRB5_H)
			dnl AC_CHECK_HEADERS(krb5.h)
			break
		fi
	done

	if test x_$found_kerberos != x_yes; then
		printf "could not find include files\n";
	else
		printf "found Kerberos include files in $kerbdir\n";
	fi
fi


TESTS_CFLAGS="$CFLAGS"
AC_SUBST(TESTS_CFLAGS)

dnl set -Wall based on os/compiler
AC_MSG_CHECKING(for -Wall based on os/compiler)
        case $host_os in
                solaris2*|sysv4*)
                ;;
                aix4*|aix5*|aix6*|aix7*)
			CFLAGS="-Wall $CFLAGS"
                ;;
                freebsd2*)
                ;;
                darwin*)
                ;;
                linux* | k*bsd*-gnu*)
			CFLAGS="-Wall $CFLAGS"
		;;
                freebsd*)
			CFLAGS="-Wall $CFLAGS"
                ;;
                *)
                ;;
        esac


dnl OUTPUT
AC_OUTPUT(Makefile subst solaris/pkginfo solaris/icinga.xml base/Makefile common/Makefile contrib/Makefile cgi/Makefile html/Makefile module/Makefile module/idoutils/Makefile xdata/Makefile daemon-init rc.ido2db icinga-systemd sysconfig-env ido2db-systemd module/idoutils/src/Makefile t/Makefile module/idoutils/db/scripts/installdb module/idoutils/db/scripts/upgradedb module/idoutils/db/scripts/prepsql p1.pl)

perl subst $srcdir/include/locations.h

perl subst $srcdir/contrib/eventhandlers/submit_check_result
perl subst $srcdir/contrib/eventhandlers/disable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/disable_notifications
perl subst $srcdir/contrib/eventhandlers/enable_active_service_checks
perl subst $srcdir/contrib/eventhandlers/enable_notifications

perl subst $srcdir/html/index.html
perl subst $srcdir/html/menu.html
perl subst $srcdir/html/js/autocomplete.js

echo ""
echo "Creating sample config files in sample-config/ ..."

perl subst $srcdir/sample-config/icinga.cfg
perl subst $srcdir/sample-config/cgi.cfg
perl subst $srcdir/sample-config/cgiauth.cfg
perl subst $srcdir/sample-config/resource.cfg
perl subst $srcdir/sample-config/httpd.conf
perl subst $srcdir/sample-config/mrtg.cfg

perl subst $srcdir/sample-config/template-object/templates.cfg
perl subst $srcdir/sample-config/template-object/commands.cfg
perl subst $srcdir/sample-config/template-object/timeperiods.cfg
perl subst $srcdir/sample-config/template-object/contacts.cfg
perl subst $srcdir/sample-config/template-object/notifications.cfg

perl subst $srcdir/sample-config/template-object/localhost.cfg
perl subst $srcdir/sample-config/template-object/windows.cfg
perl subst $srcdir/sample-config/template-object/printer.cfg
perl subst $srcdir/sample-config/template-object/switch.cfg

perl subst $srcdir/sample-config/modules/livestatus.cfg
perl subst $srcdir/sample-config/modules/mod_gearman.cfg
perl subst $srcdir/sample-config/modules/pnp4nagios.cfg
perl subst $srcdir/sample-config/modules/flapjack.cfg

echo ""
echo "Creating sample config files in module/idoutils/config/ ..."

perl subst $srcdir/module/idoutils/config/idoutils.cfg-sample
perl subst $srcdir/module/idoutils/config/ido2db.cfg-sample
perl subst $srcdir/module/idoutils/config/idomod.cfg-sample

dnl Create IDOUtils Perl Scripts for DB Handling
dnl perl subst module/idoutils/db/installdb
dnl perl subst module/idoutils/db/prepsql
dnl perl subst module/idoutils/db/upgradedb


dnl Review options
echo ""
echo ""
AC_MSG_RESULT([*** Configuration summary for $PKG_NAME $PKG_VERSION $PKG_REL_DATE ***:])

echo ""
echo " General Options:"
echo " -------------------------"

AC_MSG_RESULT([        Icinga executable:  $icinga_name])
AC_MSG_RESULT([        Icinga user/group:  $icinga_user,$icinga_grp])
AC_MSG_RESULT([       Command user/group:  $command_user,$command_grp])
AC_MSG_RESULT([        Apache user/group:  $web_user,$web_group])
if test x$ENABLE_DEBUG = xyes; then
AC_MSG_RESULT([               Debug Mode:  yes])
fi
if test x$USEPERL = xyes; then
if test x$PERLCACHE = xyes; then
AC_MSG_RESULT([            Embedded Perl:  yes, with caching])
else
AC_MSG_RESULT([            Embedded Perl:  yes, without caching])
fi
else
AC_MSG_RESULT([            Embedded Perl:  no])
fi
if test x$USE_EVENTBROKER = xyes; then
AC_MSG_RESULT([             Event Broker:  yes])
else
AC_MSG_RESULT([             Event Broker:  no])
fi
if test x$DISABLE_COMPRESSED_LOGS = xno; then
AC_MSG_RESULT([   Enable compressed logs:  yes])
else
AC_MSG_RESULT([   Enable compressed logs:  no])
fi
if test x$ENABLE_PERFDATA = xyes; then
AC_MSG_RESULT([  Enable Performance Data:  yes])
else
AC_MSG_RESULT([  Enable Performance Data:  no])
fi
if test x$USE_IDOUTILS = xyes; then
AC_MSG_RESULT([          ido2db lockfile:  $IDO2DBLOCKFILE])
AC_MSG_RESULT([             ido sockfile:  $IDOSOCKFILE])
AC_MSG_RESULT([          idomod tempfile:  $IDOMODTMPFILE])
if test x$USE_IDOUTILS_ORACLE = xyes; then
AC_MSG_RESULT([           Build IDOUtils:  ocilib, instance_name=$IDO_INSTANCE_NAME])
else
AC_MSG_RESULT([           Build IDOUtils:  libdbi, instance_name=$IDO_INSTANCE_NAME])
AC_MSG_RESULT([        libdbi driver dir:  $LIBDBIDRIVERDIR])
fi
else
AC_MSG_RESULT([           Build IDOUtils:  no])
fi
AC_MSG_RESULT([        Install \${prefix}:  $prefix])
AC_MSG_RESULT([                Lock file:  $lockfile])
AC_MSG_RESULT([                Temp file:  $TMPFILE])
AC_MSG_RESULT([                 Chk file:  $ICINGACHKFILE])
AC_MSG_RESULT([           HTTP auth file:  $HTTPAUTHFILE])
AC_MSG_RESULT([            Lib directory:  $libdir])
AC_MSG_RESULT([            Bin directory:  $bindir])
AC_MSG_RESULT([         Plugin directory:  $PLUGINDIR])
AC_MSG_RESULT([   Eventhandler directory:  $EVENTHANDLERDIR])
AC_MSG_RESULT([            Log directory:  $LOGDIR])
if test x$ENABLE_CGILOG = xyes; then
AC_MSG_RESULT([        cgi log directory:  $CGILOGDIR])
fi
AC_MSG_RESULT([   Check result directory:  $CHECKRESULTDIR])
AC_MSG_RESULT([           Temp directory:  $TMPDIR])
AC_MSG_RESULT([          State directory:  $STATEDIR])
AC_MSG_RESULT([   Ext Cmd file directory:  $EXTCMDFILEDIR])
AC_MSG_RESULT([           Init directory:  $init_dir])
AC_MSG_RESULT([  Apache conf.d directory:  $HTTPD_CONF])
AC_MSG_RESULT([       Apache config file:  $HTTPDCONFFILE])
AC_MSG_RESULT([             Mail program:  $MAIL_PROG])
AC_MSG_RESULT([                  Host OS:  $host_os])
AC_MSG_RESULT([       Environment Prefix:  $env_prefix])

echo ""
echo " Web Interface Options:"
echo " ------------------------"

AC_MSG_RESULT([                 HTML URL:  http://localhost$htmurl/])
AC_MSG_RESULT([                  CGI URL:  http://localhost$cgiurl/])
AC_MSG_RESULT([                 Main URL:  http://localhost$mainurl])

echo ""
echo ""
echo "Review the options above for accuracy.  If they look okay,"
echo "type 'make all' to compile the main program and CGIs."
echo ""
echo ""
echo "!!! Please take care about the upgrade documentation !!!"
echo ""