File: configure.ac

package info (click to toggle)
groonga 9.0.0-1+deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (1807 lines) | stat: -rw-r--r-- 54,577 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
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
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
AC_PREREQ(2.59)
m4_define([groonga_version], m4_include(base_version))
AC_INIT([groonga], groonga_version, [groonga@razil.jp])
AC_CONFIG_MACRO_DIR([m4])
AM_CONFIG_HEADER(config.h)

GRN_VERSION_MAJOR=`echo groonga_version | cut -d. -f1`
AC_SUBST(GRN_VERSION_MAJOR)
GRN_VERSION_MINOR=`echo groonga_version | cut -d. -f2`
AC_SUBST(GRN_VERSION_MINOR)
GRN_VERSION_MICRO=`echo groonga_version | cut -d. -f3`
AC_SUBST(GRN_VERSION_MICRO)

GRN_VERSION_RC=`echo groonga_version | sed -e 's/\./,/g'`
AC_SUBST(GRN_VERSION_RC)

AM_INIT_AUTOMAKE([foreign tar-pax subdir-objects])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

PACKAGE_LABEL=Groonga
AC_SUBST(PACKAGE_LABEL)
AC_DEFINE_UNQUOTED(PACKAGE_LABEL, ["$PACKAGE_LABEL"], [Label of package])

# for Autoconf 2.60 or earlier.
if test -z "${datarootdir}"; then
   datarootdir="\${prefix}/share"
   AC_SUBST(datarootdir)
fi

# for Autoconf 2.59 or earlier.
if test -z "${docdir}"; then
   docdir="\${datarootdir}/doc/\${PACKAGE_TARNAME}"
   AC_SUBST(docdir)
fi

AC_CANONICAL_HOST
AC_DEFINE_UNQUOTED(HOST_CPU, ["$host_cpu"], [host CPU])
AC_DEFINE_UNQUOTED(HOST_OS, ["$host_os"], [host OS])

AC_MSG_CHECKING([for native Win32])
case "$host_os" in
  mingw*)
    os_win32=yes
    ;;
  *)
    os_win32=no
    ;;
esac
AC_MSG_RESULT([$os_win32])

AC_MSG_CHECKING([for some Win32 platform])
case "$host_os" in
  mingw*|cygwin*)
    platform_win32=yes
    ;;
  *)
    platform_win32=no
    ;;
esac
AC_MSG_RESULT([$platform_win32])

AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")

AC_MSG_CHECKING([for NetBSD.])
case "$host_os" in
  netbsd*)
    netbsd=yes
    ;;
  *)
    netbsd=no
    ;;
esac
AC_MSG_RESULT([$netbsd])

AC_MSG_CHECKING([for Solaris.])
case "$host_os" in
  solaris*)
    solaris=yes
    ;;
  *)
    solaris=no
    ;;
esac
AC_MSG_RESULT([$solaris])

AC_C_BIGENDIAN
AC_PROG_CXX
m4_ifdef([AX_CXX_COMPILE_STDCXX_11],
         [AX_CXX_COMPILE_STDCXX_11([ext], [optional])])
AC_PROG_CC
m4_ifdef([AC_PROG_CC_C99],
         [AC_PROG_CC_C99])
AM_PROG_CC_C_O
m4_ifdef([PKG_PROG_PKG_CONFIG],
         [PKG_PROG_PKG_CONFIG([0.19])
          m4_pattern_allow(PKG_CONFIG_LIBDIR)])

AC_MSG_CHECKING([for clang])
if test "$CC" = "clang"; then
  CLANG=yes
else
  CLANG=no
fi
AC_MSG_RESULT([$CLANG])

AC_DEFUN([CHECK_CFLAG], [
  AC_MSG_CHECKING([if gcc supports $1])
  old_CFLAGS=$CFLAGS
  flag=`echo '$1' | sed -e 's,^-Wno-,-W,'`
  CFLAGS="$CFLAGS $flag -Werror"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
    [check_cflag=yes],
    [check_cflag=no])
  CFLAGS="$old_CFLAGS"
  if test "x$check_cflag" = "xyes"; then
    CFLAGS="$CFLAGS $1"
  fi
  AC_MSG_RESULT([$check_cflag])
])

AC_DEFUN([CHECK_CXXFLAG], [
  AC_MSG_CHECKING([if g++ supports $1])
  old_CXXFLAGS=$CXXFLAGS
  flag=`echo '$1' | sed -e 's,^-Wno-,-W,'`
  CXXFLAGS="$CXXFLAGS $flag -Werror"
  AC_LANG_PUSH([C++])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
    [check_cxxflag=yes],
    [check_cxxflag=no])
  AC_LANG_POP([C++])
  CXXFLAGS="$old_CXXFLAGS"
  if test "x$check_cxxflag" = "xyes"; then
    CXXFLAGS="$CXXFLAGS $1"
  fi
  AC_MSG_RESULT([$check_cxxflag])
])

AC_DEFUN([CHECK_BUILD_FLAG], [
  CHECK_CFLAG([$1])
  CHECK_CXXFLAG([$1])
])

AC_DEFUN([REMOVE_CXXFLAG], [
  AC_MSG_CHECKING([whether g++ option $1 is needed to be removed])
  if echo "$CXXFLAGS" | grep -q -- "$1"; then
    CXXFLAGS=`echo "$CXXFLAGS" | sed -e 's,$1,,'`
    remove_cxxflag=yes
  else
    remove_cxxflag=no
  fi
  AC_MSG_RESULT([$remove_cxxflag])
])

TEST_CFLAGS=""
TEST_CXXFLAGS=""
NO_STRICT_ALIASING_CFLAGS=""
NO_FLOAT_EQUAL_CFLAGS=""
NO_BAD_FUNCTION_CAST_CFLAGS=""
if test "$GCC" = "yes"; then
  CHECK_BUILD_FLAG([-Wall])
  if test "x$check_cflag" = "xno"; then
    CHECK_BUILD_FLAG([-W])
  fi
  CHECK_BUILD_FLAG([-Wno-unused-but-set-variable]) # FIXME: enable it.
  CHECK_CFLAG([-Wno-pointer-sign])
  CHECK_CFLAG([-Wno-declaration-after-statement])

  CHECK_BUILD_FLAG([-Wformat])
  CHECK_BUILD_FLAG([-Wno-format-truncation])
  CHECK_BUILD_FLAG([-Wstrict-aliasing=2])
  if test "x$check_cflag" = "xyes"; then
    NO_STRICT_ALIASING_CFLAGS="-fno-strict-aliasing"
  fi
  CHECK_BUILD_FLAG([-Wdisabled-optimization])
  CHECK_BUILD_FLAG([-Wfloat-equal])
  if test "x$check_cflag" = "xyes"; then
    NO_FLOAT_EQUAL_CFLAGS="-Wno-float-equal"
  fi
  CHECK_BUILD_FLAG([-Wpointer-arith])
  CHECK_CFLAG([-Wbad-function-cast])
  if test "x$check_cflag" = "xyes"; then
    NO_BAD_FUNCTION_CAST_CFLAGS="-Wno-bad-function-cast"
  fi
#  if test "$CLANG" = "no"; then
#   CHECK_BUILD_FLAG([-Wcast-align])
#  fi
#  CHECK_BUILD_FLAG([-Wredundant-decls])
#  CHECK_BUILD_FLAG([-Wunsafe-loop-optimizations])
#  CHECK_BUILD_FLAG([-Wunreachable-code])
#  CHECK_BUILD_FLAG([-Wswitch-enum])
#  CHECK_BUILD_FLAG([-Wshadow])
#  CHECK_BUILD_FLAG([-Wconversion])
  CHECK_BUILD_FLAG([-Wwrite-strings])
#  CHECK_BUILD_FLAG([-Winline])

  CHECK_CXXFLAG([-fexceptions])
  CHECK_CXXFLAG([-fimplicit-templates])
fi
AC_SUBST(TEST_CFLAGS)
AC_SUBST(TEST_CXXFLAGS)
AC_SUBST(NO_STRICT_ALIASING_CFLAGS)
AC_SUBST(NO_FLOAT_EQUAL_CFLAGS)
AC_SUBST(NO_BAD_FUNCTION_CAST_CFLAGS)

LT_INIT([dlopen win32-dll])
LT_LANG([Windows Resource])
LT_OUTPUT

LT_CURRENT=0
LT_REVISION=0
LT_AGE=0
LT_VERSION_INFO="\$(LT_CURRENT):\$(LT_REVISION):\$(LT_AGE)"
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
AC_SUBST(LT_VERSION_INFO)

GRN_DLL_FILENAME="libgroonga-\$(LT_CURRENT).dll"
AC_SUBST(GRN_DLL_FILENAME)

if test "$srcdir/version.sh"; then
  . "$srcdir/version.sh"
  AC_SUBST(GRN_VERSION)
  AC_DEFINE_UNQUOTED(GRN_VERSION, ["$GRN_VERSION"], [groonga version])
fi

AC_CONFIG_FILES([
  Makefile
  build/Makefile
  build/cmake_modules/Makefile
  src/Makefile
  src/suggest/Makefile
  src/httpd/Makefile
  lib/Makefile
  lib/dat/Makefile
  lib/mrb/Makefile
  lib/mrb/scripts/Makefile
  lib/mrb/scripts/command_line/Makefile
  lib/mrb/scripts/context/Makefile
  lib/mrb/scripts/expression_rewriters/Makefile
  lib/mrb/scripts/expression_tree/Makefile
  lib/mrb/scripts/initialize/Makefile
  lib/mrb/scripts/logger/Makefile
  lib/mrb/scripts/query_logger/Makefile
  lib/proc/Makefile
  lib/ts/Makefile
  include/Makefile
  include/groonga/Makefile
  plugins/Makefile
  plugins/tokenizers/Makefile
  plugins/suggest/Makefile
  plugins/query_expanders/Makefile
  plugins/ruby/Makefile
  plugins/token_filters/Makefile
  plugins/sharding/Makefile
  plugins/functions/Makefile
  examples/Makefile
  examples/dictionary/Makefile
  examples/dictionary/edict/Makefile
  examples/dictionary/eijiro/Makefile
  examples/dictionary/gene95/Makefile
  examples/dictionary/jmdict/Makefile
  packages/Makefile
  packages/apt/Makefile
  packages/ubuntu/Makefile
  packages/rpm/Makefile
  packages/rpm/centos/Makefile
  packages/yum/Makefile
  packages/source/Makefile
  packages/windows/Makefile
  packages/windows/patches/Makefile
  packages/windows/language-files/Makefile
  packages/windows/setup-x64.nsi
  data/Makefile
  data/html/Makefile
  data/munin/Makefile
  data/init.d/Makefile
  data/init.d/centos/Makefile
  data/init.d/centos/sysconfig/Makefile
  data/logrotate.d/Makefile
  data/logrotate.d/centos/Makefile
  data/systemd/Makefile
  data/systemd/centos/Makefile
  data/systemd/centos/sysconfig/Makefile
  data/scripts/Makefile
  data/tmpfiles.d/Makefile
  tools/Makefile
  doc/Makefile
  doc/locale/Makefile
  doc/locale/en/Makefile
  doc/locale/en/LC_MESSAGES/Makefile
  doc/locale/ja/Makefile
  doc/locale/ja/LC_MESSAGES/Makefile
  test/Makefile
  test/unit/Makefile
  test/unit/lib/Makefile
  test/unit/fixtures/Makefile
  test/unit/fixtures/inverted-index/Makefile
  test/unit/fixtures/stress/Makefile
  test/unit/fixtures/plugins/Makefile
  test/unit/fixtures/geo/Makefile
  test/unit/fixtures/story/Makefile
  test/unit/fixtures/story/taiyaki/Makefile
  test/unit/util/Makefile
  test/unit/core/Makefile
  test/unit/core/dat/Makefile
  test/unit/story/Makefile
  test/command/Makefile
  benchmark/Makefile
  benchmark/fixtures/Makefile
  benchmark/fixtures/geo-select/Makefile
  benchmark/lib/Makefile
  vendor/Makefile
  vendor/lz4/Makefile
  vendor/onigmo/Makefile
  vendor/mecab/Makefile
  vendor/message_pack/Makefile
  vendor/mruby/Makefile
  vendor/groonga-log/Makefile
])

if test "$GCC" = "yes"; then
  AC_DEFINE(_GNU_SOURCE, [1], [Define to 1 if you use GCC.])
fi

if test "$netbsd" = "yes"; then
  AC_DEFINE(_NETBSD_SOURCE, [1], [Define to 1 if you are on NetBSD.])
fi

if test "$solaris" = "yes"; then
  AC_DEFINE(_XPG4_2, [1],
            [Define to 1 for msghdr.msg_control if you are on Solaris.])
  AC_DEFINE(__EXTENSIONS__, [1],
            [Define to 1 for singal.h with _XPG4_2 if you are on Solaris.])
fi

# For debug
AC_ARG_ENABLE(debug,
  [AS_HELP_STRING([--enable-debug],
                  [use debug flags (default=no)])],
  [grn_debug="$enableval"],
  [grn_debug="no"])
if test "x$grn_debug" != "xno"; then
  grn_debug="yes"
  if test "$CLANG" = "yes"; then
    CFLAGS="$CFLAGS -O0 -g"
    CXXFLAGS="$CXXFLAGS -O0 -g"
  elif test "$GCC" = "yes"; then
    CFLAGS="$CFLAGS -O0 -g3"
    CXXFLAGS="$CXXFLAGS -O0 -g3"
  fi
fi
AC_SUBST(grn_debug)

AC_SEARCH_LIBS(log, m, [], [AC_MSG_ERROR("No libm found")])
AC_MSG_CHECKING([for fpclassify])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
    [#include <math.h>],
    [if (fpclassify(0.0)) {return 0;}]
   )],
  [
    AC_DEFINE(HAVE_FPCLASSIFY, [1], [use fpclassify])
    AC_MSG_RESULT(yes)
  ],
  [
    AC_LINK_IFELSE(
      [AC_LANG_PROGRAM(
        [#define _ISOC99_SOURCE
         #include <math.h>],
        [if (fpclassify(0.0)) {return 0;}]
       )],
      [
        AC_DEFINE(_ISOC99_SOURCE, [1], [Define to 1 for fpclassify])
        AC_DEFINE(HAVE_FPCLASSIFY, [1], [use fpclassify with _ISOC99_SOURCE])
        AC_MSG_RESULT(yes)
      ],
      [
        AC_MSG_RESULT(no)
      ])
  ])

m4_include(build/ac_macros/check_headers.m4)
m4_include(build/ac_macros/check_functions.m4)

AC_SEARCH_LIBS(backtrace, execinfo,
               [AC_DEFINE(HAVE_BACKTRACE, [1],
                          [Define to 1 if you have the `backtrace' function.])])
AC_SEARCH_LIBS(clock_gettime, rt,
               [AC_DEFINE(HAVE_CLOCK_GETTIME, [1], [use clock_gettime])])
AC_SYS_LARGEFILE
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF(off_t)
AC_CHECK_MEMBERS(
  [struct tm.tm_gmtoff],
  ,
  ,
  [
#include <time.h>
  ])

# MAP_HUGETLB
AC_ARG_ENABLE(map-hugetlb,
  [AS_HELP_STRING([--enable-map-hugetlb],
                  [use MAP_HUGETLB. [default=no]])],
  ,
  [enable_map_hugetlb="no"])
if test "x$enable_map_hugetlb" != "xno"; then
  AC_MSG_CHECKING([for MAP_HUGETLB])
  AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM(
       [
#ifdef HAVE_SYS_MMAN_H
#  include <sys/mman.h>
#endif /* HAVE_SYS_MMAN_H */
       ],
       [MAP_HUGETLB;]
     )],
    [
     AC_DEFINE(USE_MAP_HUGETLB, [1], [use MAP_HUGETLB])
     AC_MSG_RESULT(yes)
    ],
    [
     AC_MSG_RESULT(no)
     AC_MSG_ERROR("MAP_HUGETLB isn't available.")
    ]
  )
fi

# log path
AC_ARG_WITH(log_path,
  [AS_HELP_STRING([--with-log-path=PATH],
    [specify groonga log path.])],
  grn_log_path="$withval",
  grn_log_path="\$(localstatedir)/log/\$(PACKAGE_NAME)/\$(PACKAGE_NAME).log")
AC_SUBST(grn_log_path)

# default encoding
AC_ARG_WITH(default_encoding,
  [AS_HELP_STRING([--with-default-encoding=ENCODING],
    [specify groonga default encoding(euc_jp/sjis/utf8/latin1/koi8r/none)])],
  GRN_DEFAULT_ENCODING="$withval",
  GRN_DEFAULT_ENCODING="utf8")
AC_DEFINE_UNQUOTED(GRN_DEFAULT_ENCODING, "$GRN_DEFAULT_ENCODING", "specified default encoding")

# default match escalation threshold
AC_ARG_WITH(match_escalation_threshold,
  [AS_HELP_STRING([--with-match-escalation-threshold=NUMBER],
    [specify groonga default match escalation threshold])],
  GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD="$withval",
  GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD="0")
AC_DEFINE_UNQUOTED(GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD, $GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD, "specified match escalation threshold")

# default DB key management algorithm
AC_ARG_WITH(default_db_key,
  [AS_HELP_STRING([--with-default-db-key=ALGORITHM],
    [specify groonga default DB key (pat/dat/auto)])],
  GRN_DEFAULT_DB_KEY="$withval",
  GRN_DEFAULT_DB_KEY="auto")
AC_DEFINE_UNQUOTED(GRN_DEFAULT_DB_KEY, "$GRN_DEFAULT_DB_KEY",
                   "specified default DB key management algorithm")

# DANGER!!!: stack size
GRN_STACK_SIZE=1024
AC_ARG_WITH(stack_size,
  [AS_HELP_STRING([--with-stack-size=SIZE],
    [DANGER!!!
     This option specifies stack size. (default=$GRN_STACK_SIZE)
     Normally, you should not use this option.])],
  GRN_STACK_SIZE="$withval")
AC_DEFINE_UNQUOTED(GRN_STACK_SIZE, [$GRN_STACK_SIZE], [stack size])

# lock timeout
GRN_LOCK_TIMEOUT=900000
AC_ARG_WITH(lock_timeout,
  [AS_HELP_STRING([--with-lock-timeout=N],
    [This option specifies how many times Groonga tries to acquire a lock.
     Each try waits --with-lock-wait-time nanoseconds to acquire a lock.
     It means that Groonga gives up after
     (--with-lock-wait-time * --with-lock-timeout) nanoseconds.
     (default=$GRN_LOCK_TIMEOUT)])],
  GRN_LOCK_TIMEOUT="$withval")
AC_DEFINE_UNQUOTED(GRN_LOCK_TIMEOUT,
                   [$GRN_LOCK_TIMEOUT],
                   [lock timeout])

# lock wait time
GRN_LOCK_WAIT_TIME_NANOSECOND=1000000
AC_ARG_WITH(lock_wait_time,
  [AS_HELP_STRING([--with-lock-wait-time=NANOSECONDS],
    [This option specifies wait time in nanosecond to acquire a lock.
     (default=$GRN_LOCK_WAIT_TIME_NANOSECOND)])],
  GRN_LOCK_WAIT_TIME_NANOSECOND="$withval")
AC_DEFINE_UNQUOTED(GRN_LOCK_WAIT_TIME_NANOSECOND,
                   [$GRN_LOCK_WAIT_TIME_NANOSECOND],
                   [lock wait time in nanosecond])

if test "$os_win32" != "yes"; then
  AC_CHECK_HEADERS(pthread.h)
  AC_SEARCH_LIBS(pthread_create, pthread,
                 [],
                 [AC_MSG_ERROR("No libpthread found")])
  AC_CHECK_FUNCS(pthread_mutexattr_setpshared)
  AC_CHECK_FUNCS(pthread_condattr_setpshared)
fi
AC_SEARCH_LIBS(gethostbyname, nsl)
AC_SEARCH_LIBS(socket, socket)
AC_SEARCH_LIBS(dlopen, dl)

# nfkc
AC_ARG_ENABLE(nfkc,
  [AS_HELP_STRING([--enable-nfkc],
    [use nfkc based utf8 normalization. [default=yes]])],,
  [enable_nfkc="yes"])
if test "x$enable_nfkc" = "xyes"; then
  AC_DEFINE(GRN_WITH_NFKC, [1], [compile with nfkc.c])
fi

# coverage
m4_ifdef([AC_CHECK_COVERAGE], [AC_CHECK_COVERAGE])
GENHTML_OPTIONS="--title 'groonga Code Coverage'"

# microyield
AC_MSG_CHECKING([whether enable uyield])
AC_ARG_ENABLE(uyield,
  [AS_HELP_STRING([--enable-uyield],
    [build for detecting race conditions. [default=no]])],
  ,
  [enable_uyield="no"])
AC_MSG_RESULT($enable_uyield)

# exact-alloc-count
AC_MSG_CHECKING([whether enable exact-alloc-count])
AC_ARG_ENABLE(exact-alloc-count,
  [AS_HELP_STRING([--enable-exact-alloc-count],
    [atomic counting for memory alloc count. [default=yes]])],,
  [enable_exact_alloc_count="yes"])
if test "x$enable_exact_alloc_count" != "xno"; then
  AC_DEFINE(USE_EXACT_ALLOC_COUNT, [1], [alloc_count with atomic])
fi
AC_MSG_RESULT($enable_exact_alloc_count)

# memory debug
AC_MSG_CHECKING([whether debug memory management])
AC_ARG_ENABLE(memory-debug,
  [AS_HELP_STRING([--enable-memory-debug],
    [debug memory management. [default=no]])],
  ,
  [enable_memory_debug="no"])
AC_MSG_RESULT([$enable_memory_debug])

if test "x$enable_memory_debug" = "xyes"; then
  AC_DEFINE(USE_MEMORY_DEBUG, [1],
            [Define to 1 if you enable debuging memory management])
fi

# epoll/kqueue/poll/select check
AC_CHECK_HEADER(sys/epoll.h, [
  AC_CHECK_FUNC(epoll_create, [
    AC_TRY_RUN([
#include <sys/epoll.h>
int main(int argc, char **argv) { return (epoll_create(16) < 0); }
    ],
    [
      have_epoll="yes"
      AC_DEFINE(USE_EPOLL, [1], [use epoll])
    ]
    )
  ])
])

if test "x$have_epoll" != "xyes"; then
  AC_CHECK_HEADER(sys/event.h, [
    AC_CHECK_FUNC(kevent, [
      have_kqueue="yes"
      AC_DEFINE(USE_KQUEUE, [1], [use kqueue])
    ])
  ])
  if test "x$have_kqueue" != "xyes"; then
    AC_CHECK_HEADER(poll.h, [
      AC_CHECK_FUNC(poll, [
        have_poll="yes"
        AC_DEFINE(USE_POLL, [1], [use poll])
      ])
    ])
    if test "x$have_poll" != "xyes"; then
      if test "$os_win32" = "yes"; then
        AC_CHECK_HEADER(winsock2.h, [have_select="yes"])
      else
        AC_CHECK_FUNC(select, [
          have_select="yes"
          AC_CHECK_HEADERS(sys/select.h)
        ])
      fi
      if test "x$have_select" = "xyes"; then
        AC_DEFINE(USE_SELECT, [1], [use select])
      else
        AC_MSG_ERROR([epoll/kqueue/poll/select is missing.])
      fi
    fi
  fi
fi

# check MSG_MORE defined
AC_MSG_CHECKING([whether MSG_MORE defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <sys/types.h>
#include <sys/socket.h>

int main(int argc, char **argv)
{
  return MSG_MORE;
}
    ])],
    [
      AC_MSG_RESULT(yes)
      AC_DEFINE(USE_MSG_MORE, [1], [use MSG_MORE])
    ],
    [
      AC_MSG_RESULT(no)
    ])

# check MSG_NOSIGNAL defined
AC_MSG_CHECKING([whether MSG_NOSIGNAL defined])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <sys/types.h>
#include <sys/socket.h>

int main(int argc, char **argv)
{
  return MSG_NOSIGNAL;
}
    ])],
    [
      AC_MSG_RESULT(yes)
      AC_DEFINE(USE_MSG_NOSIGNAL, [1], [use MSG_NOSIGNAL])
    ],
    [
      AC_MSG_RESULT(no)
    ])

# MinGW
if test "$os_win32" = "yes"; then
  WINDOWS_LDFLAGS="-mwindows"
  WINDOWS_LIBS="-ladvapi32 -lws2_32 -ldbghelp"
else
  WINDOWS_LDFLAGS=
  WINDOWS_LIBS=
fi
AC_SUBST(WINDOWS_LDFLAGS)
AC_SUBST(WINDOWS_LIBS)

# groonga binary path
GROONGA="${ac_pwd}/src/groonga"
AC_SUBST(GROONGA)

# groonga-benchmark binary path
GROONGA_BENCHMARK="${ac_pwd}/src/groonga-benchmark"
AC_SUBST(GROONGA_BENCHMARK)

# groonga-suggest-create-dataset binary path
GROONGA_SUGGEST_CREATE_DATASET="${ac_pwd}/src/suggest/groonga-suggest-create-dataset"
AC_SUBST(GROONGA_SUGGEST_CREATE_DATASET)

# groonga-mruby binary path
GROONGA_MRUBY="${ac_pwd}/src/groonga-mruby"
AC_SUBST(GROONGA_MRUBY)

# check Cutter with GLib support if available
REQUIRED_MINIMUM_CUTTER_VERSION=1.1.6
REQUIRED_MINIMUM_CPPCUTTER_VERSION=1.2.0
m4_ifdef([AC_CHECK_GCUTTER],
         [AC_CHECK_GCUTTER(>= $REQUIRED_MINIMUM_CUTTER_VERSION)],
         [cutter_use_cutter="no"])
m4_ifdef([AC_CHECK_CPPCUTTER],
         [AC_CHECK_CPPCUTTER(>= $REQUIRED_MINIMUM_CPPCUTTER_VERSION)],
         [cutter_use_cppcutter="no"])

AM_CONDITIONAL([WITH_CUTTER], [test "$cutter_use_cutter" = "yes"])
AM_CONDITIONAL([WITH_CPPCUTTER], [test "$cutter_use_cppcutter" = "yes"])
if test "$cutter_use_cutter" = "yes"; then
  AC_DEFINE(GRN_WITH_CUTTER, 1, [Define to 1 if you use Cutter])
fi

# check for benchmark
AC_ARG_ENABLE(benchmark,
  [AS_HELP_STRING([--disable-benchmark],
    [don't build benchmark programs.])],,
  [enable_benchmark="yes"])
if test "x$enable_benchmark" = "xno"; then
  benchmark_available="no"
else
  REQUIRED_GLIB_VERSION=2.14.0
  m4_ifdef([AM_PATH_GLIB_2_0],
           [AM_PATH_GLIB_2_0($REQUIRED_GLIB_VERSION,
                             [benchmark_available="yes"],
                             [benchmark_available="no"],
                             [gobject gthread])],
           [benchmark_available="no"])
  AC_MSG_CHECKING(for benchmark availablity)
  AC_MSG_RESULT($ac_benchmark_available)
fi
if test "$benchmark_available" = "yes"; then
  AC_DEFINE(GRN_WITH_BENCHMARK, 1, [Define to 1 if benchamrk is available])
fi
AM_CONDITIONAL([WITH_BENCHMARK], [test "$benchmark_available" = "yes"])

# check Ruby for HTTP test
ac_cv_ruby_available="no"
AC_ARG_WITH([ruby],
            AS_HELP_STRING([--with-ruby=PATH],
                           [Ruby interpreter path (default: no)]),
            [RUBY="$withval"],
            [RUBY="no"])

if test "x$RUBY" = "xno"; then
  RUBY=
else
  if test "x$RUBY" = "xyes"; then
    AC_PATH_PROGS(RUBY,
                  [ dnl
                    ruby2.5 ruby25 dnl
                    ruby2.4 ruby24 dnl
                    ruby2.3 ruby23 dnl
                    ruby2.2 ruby22 dnl
                    ruby2.1 ruby21 dnl
                    ruby dnl
                  ],
                  ruby-not-found)
    if test "$RUBY" != "ruby-not-found"; then
      ruby_version="`$RUBY --version`"
      if echo "$ruby_version" | grep -q -- 'ruby \(2\.\)'; then
        ac_cv_ruby_available="yes"
      else
        AC_MSG_WARN([$RUBY isn't Ruby 2.0 or later ($ruby_version)])
      fi
    fi
  else
    ruby_not_found_warning_message="$RUBY is not found."
    case "$RUBY" in
    /*)
      AC_CHECK_FILE([$RUBY],
                    [ac_cv_ruby_available="yes"],
                    [AC_MSG_WARN([$ruby_not_found_warning_message])
                     RUBY="$RUBY-not-found"])
      ;;
    *)
      ruby_not_found="$RUBY-not-found"
      AC_PATH_PROGS(RUBY, "$RUBY", "$ruby_not_found")
      if test "$RUBY" = "$ruby_not_found"; then
        AC_MSG_WARN([$ruby_not_found_warning_message])
      else
        ac_cv_ruby_available="yes"
      fi
      ;;
    esac
  fi
fi
AC_SUBST(RUBY)
AM_CONDITIONAL([WITH_RUBY], [test "$ac_cv_ruby_available" = "yes"])

AM_CONDITIONAL([WITH_UNIT_TEST],
               [test "$cutter_use_cutter" = "yes" -o \
                     "$ac_cv_ruby_available" = "yes"])

AM_CONDITIONAL([WITH_COMMAND_TEST],
               [test "$ac_cv_ruby_available" = "yes"])

# check Lemon for generating .c and .h files from .y file
lemon_available="no"
AC_ARG_WITH([lemon],
            AS_HELP_STRING([--with-lemon=PATH],
                           [Lemon path (default: auto)]),
            [LEMON="$withval"],
            [: ${LEMON:=auto}])

if test "$LEMON" = "no"; then
  LEMON=
else
  if test "$LEMON" = "auto"; then
    AC_PATH_PROGS(LEMON, [lemon], none)
    if test "$LEMON" != "none"; then
      lemon_available="yes"
    fi
  elif test "$LEMON" = "yes"; then
    AC_PATH_PROGS(LEMON, [lemon], none)
    if test "$LEMON" = "none"; then
      AC_MSG_WARN([lemon is not found. Disable .y compilation.])
    else
      lemon_available="yes"
    fi
  else
    AC_CHECK_FILE([$LEMON],
                  [lemon_available="yes"],
                  [AC_MSG_WARN([$LEMON is not found. Disable .y compilation.])])
  fi
fi
AC_SUBST(LEMON)
AM_CONDITIONAL([WITH_LEMON], [test "$lemon_available" = "yes"])

# libedit
AC_ARG_ENABLE(libedit,
  [AS_HELP_STRING([--disable-libedit],
    [use libedit for console. [default=auto-detect]])],
  [enable_libedit="$enableval"],
  [enable_libedit="auto"])
if test "x$enable_libedit" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([LIBEDIT], [libedit >= 3.0],
      [LIBS_SAVE="$LIBS"
       LDFLAGS_SAVE="$LDFLAGS"
       LDFLAGS="$LIBEDIT_LIBS $LDFLAGS"
       AC_SEARCH_LIBS(el_wline, edit,
                      [libedit_available=yes],
                      [libedit_available=no])
       LIBS="$LIBS_SAVE"
       LDFLAGS="$LDFLAGS_SAVE"],
      [libedit_available=no])
    ],
    [libedit_available=no])
  if test "x$libedit_available" = "xyes"; then
    AC_DEFINE(GRN_WITH_LIBEDIT, [1], [Use libedit with multibyte support.])
  else
    if test "x$enable_editline" = "xyes"; then
      AC_MSG_ERROR("No libedit found")
    fi
  fi
fi

# zlib
AC_ARG_WITH(zlib,
  [AS_HELP_STRING([--with-zlib],
    [Support data compression by zlib. [default=auto]])],
  [with_zlib="$withval"],
  [with_zlib="auto"])
GRN_WITH_ZLIB=no
if test "x$with_zlib" != "xno"; then
  # TODO: Support custom zlib include and lib directory by --with-zlib.
  AC_SEARCH_LIBS(compress, z,
                 [
                   GRN_WITH_ZLIB=yes
                   AC_DEFINE(GRN_WITH_ZLIB, [1],
                             [Support data compression by zlib.])
                 ],
                 [
                   if test "x$with_zlib" != "xauto"; then
                     AC_MSG_ERROR("No libz found")
                   fi
                 ])
fi
AC_SUBST(GRN_WITH_ZLIB)

# LZ4
AC_ARG_WITH(lz4,
  [AS_HELP_STRING([--with-lz4],
    [Support data compression by LZ4. [default=auto]])],
  [with_lz4="$withval"],
  [with_lz4="auto"])
if test "x$with_lz4" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([LIBLZ4],
                      [liblz4],
                      [GRN_WITH_LZ4=yes],
                      [GRN_WITH_LZ4=no])
  ],
  [GRN_WITH_LZ4=no])
  if test "$GRN_WITH_LZ4" = "yes"; then
    AC_DEFINE(GRN_WITH_LZ4, [1],
              [Support data compression by LZ4.])
  else
    if test "x$with_lz4" != "xauto"; then
      AC_MSG_ERROR("No liblz4 found")
    fi
  fi
else
  GRN_WITH_LZ4=no
fi

# Zstandard
AC_ARG_WITH(zstd,
  [AS_HELP_STRING([--with-zstd],
    [Support data compression by Zstandard. [default=auto]])],
  [with_zstd="$withval"],
  [with_zstd="auto"])
if test "x$with_zstd" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([LIBZSTD],
                      [libzstd],
                      [GRN_WITH_ZSTD=yes],
                      [GRN_WITH_ZSTD=no])
  ],
  [GRN_WITH_ZSTD=no])
  if test "$GRN_WITH_ZSTD" = "yes"; then
    AC_DEFINE(GRN_WITH_ZSTD, [1],
              [Support data compression by Zstandard.])
  else
    if test "x$with_zstd" != "xauto"; then
      AC_MSG_ERROR("No libzstd found")
    fi
  fi
else
  GRN_WITH_ZSTD=no
fi

# jemalloc
AC_ARG_WITH(jemalloc,
  [AS_HELP_STRING([--with-jemalloc],
    [Use jemalloc for memory allocation. [default=no]])],
  [with_jemalloc="$withval"],
  [with_jemalloc="no"])
jemalloc_available="no"
if test "x$with_jemalloc" != "xno"; then
  if test "x$with_jemalloc" != "xyes"; then
    LDFLAGS="-L$with_jemalloc $LDFLAGS"
  fi
  AC_SEARCH_LIBS(malloc_conf, jemalloc,
                 [jemalloc_available="yes"],
                 [AC_MSG_ERROR("No libjemalloc found")])
fi

# Apache Arrow
AC_ARG_ENABLE(arrow,
  [AS_HELP_STRING([--disable-arrow],
    [enable Apache Arrow support. [default=auto-detect]])],
  [enable_arrow="$enableval"],
  [enable_arrow="auto"])
if test "x$enable_arrow" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([ARROW],
                      [arrow >= 0.8.0],
                      [arrow_available=yes],
                      [arrow_available=no])
  ],
  [arrow_available=no])
  if test "x$arrow_available" = "xyes"; then
    AC_DEFINE(GRN_WITH_ARROW, [1], [Enable Apache Arrow support.])
  else
    if test "x$enable_arrow" = "xyes"; then
      AC_MSG_ERROR("No Apache Arrow found")
    fi
  fi
fi
AM_CONDITIONAL([GRN_WITH_ARROW], [test "$arrow_available" = "yes"])

# MeCab
# NOTE: MUST be checked last

BUNDLED_MECAB_VERSION=m4_include([bundled_mecab_version])
AC_SUBST(BUNDLED_MECAB_VERSION)
BUNDLED_MECAB_NAIST_JDIC_VERSION=m4_include([bundled_mecab_naist_jdic_version])
AC_SUBST(BUNDLED_MECAB_NAIST_JDIC_VERSION)

AC_ARG_WITH(mecab,
  [AS_HELP_STRING([--with-mecab],
    [use MeCab for morphological analysis. [default=yes]])],
  [with_mecab="$withval"],
  [with_mecab="yes"])
AC_MSG_CHECKING([whether enable MeCab])
AC_MSG_RESULT($with_mecab)
if test "x$with_mecab" = "xyes"; then
  # mecab-config
  AC_ARG_WITH(mecab-config,
    [AS_HELP_STRING([--with-mecab-config=PATH],
      [set mecab-config location. [default=auto-detect]])],
    [if test "$cross_compiling" = "yes"; then
       MECAB_CONFIG="$withval"
     else
       AC_CHECK_FILE("$withval", MECAB_CONFIG="$withval", MECAB_CONFIG=no)
     fi],
    [AC_PATH_PROG(MECAB_CONFIG, mecab-config, no)])
  if test "x$MECAB_CONFIG" = "xno"; then
    with_mecab="no"
  else
    MECAB_CPPFLAGS="-I`$MECAB_CONFIG --inc-dir`"
    MECAB_LDFLAGS="-L`$MECAB_CONFIG --libs-only-L`"
    _SAVE_LIBS="$LIBS"
    _SAVE_LDFLAGS="$LDFLAGS"
    LDFLAGS="$LDFLAGS $MECAB_LDFLAGS"
    AC_SEARCH_LIBS(mecab_new,
                   mecab,
                   [MECAB_LIBS="-lmecab $PTHREAD_LIBS"],
                   [AC_MSG_ERROR("No libmecab found")],
                   $PTHREAD_LIBS)
    LDFLAGS="$_SAVE_LDFLAGS"
    LIBS="$_SAVE_LIBS"
    _SAVE_CPPFLAGS="$CPPFLAGS"
    CPPFLAGS="$CPPFLAGS $MECAB_CPPFLAGS"
    AC_CHECK_HEADER(mecab.h, , [AC_MSG_ERROR("No mecab.h found")])
    AC_CHECK_TYPE([mecab_dictionary_info_t],
                  [AC_DEFINE([HAVE_MECAB_DICTIONARY_INFO_T],
                             [1],
                             [Define to 1 if MeCab has the type `mecab_dictionary_info_t'.])],
                  [],
                  [[#include <mecab.h>]])
    CPPFLAGS="$_SAVE_CPPFLAGS"
    AC_SUBST(MECAB_CPPFLAGS)
    AC_SUBST(MECAB_LDFLAGS)
    AC_SUBST(MECAB_LIBS)
  fi
fi
if test "x$with_mecab" = "xyes"; then
  AC_DEFINE(GRN_WITH_MECAB, [1], [use MeCab])
fi
AM_CONDITIONAL(WITH_MECAB, test "x$with_mecab" = "xyes")

# KyTea
REQUIRED_MINIMUM_KYTEA_VERSION=0.4.2
AC_ARG_WITH(kytea,
  [AS_HELP_STRING([--with-kytea],
    [use KyTea for morphological analysis. [default=auto]])],
  [with_kytea="$withval"],
  [with_kytea="auto"])
AC_MSG_CHECKING([whether enable KyTea])
AC_MSG_RESULT($with_kytea)
if test "x$with_kytea" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([KYTEA],
                      [kytea >= $REQUIRED_MINIMUM_KYTEA_VERSION],
                      [kytea_exists=yes],
                      [kytea_exists=no])
    ],
    [kytea_exists=no])
  if test "$kytea_exists" = "no" -a "x$with_kytea" = "xyes"; then
    AC_MSG_ERROR("No KyTea found.")
  fi
  with_kytea="$kytea_exists"
fi
if test "x$with_kytea" = "xyes"; then
  AC_DEFINE(GRN_WITH_KYTEA, [1], [use KyTea])
fi
AM_CONDITIONAL(WITH_KYTEA, test "x$with_kytea" = "xyes")

# libstemmer
AC_ARG_WITH(libstemmer,
  [AS_HELP_STRING([--with-libstemmer],
    [use libstemmer for stemming. [default=auto]])],
  [with_libstemmer="$withval"],
  [with_libstemmer="auto"])
AC_ARG_WITH(libstemmer-include,
  [AS_HELP_STRING([--with-libstemmer-include],
    [path to libstemmer.h. [default=auto]])])
AC_ARG_WITH(libstemmer-lib,
  [AS_HELP_STRING([--with-libstemmer-lib],
    [path to libstemmer.so. [default=auto]])])
AC_MSG_CHECKING([whether enable libstemmer])
AC_MSG_RESULT($with_libstemmer)
if test "x$with_libstemmer" != "xno"; then
  LIBSTEMMER_CFLAGS=""
  LIBSTEMMER_LDFLAGS=""
  LIBSTEMMER_LIBS=""

  CFLAGS_save="${CFLAGS}"
  LDFLAGS_save="${LDFLAGS}"
  if test "x$with_libstemmer" != "xauto"; then
    if test -z "${with_libstemmer_include}"; then
      with_libstemmer_include="${with_libstemmer}/include"
    fi
    LIBSTEMMER_CFLAGS="-I${with_libstemmer_include}"
    if test -z "${with_libstemmer_lib}"; then
      with_libstemmer_lib="${with_libstemmer}/lib"
    fi
    LIBSTEMMER_LDFLAGS="-L${with_libstemmer_lib}"
    CFLAGS="${CFLAGS} ${LIBSTEMMER_CFLAGS}"
    LDFLAGS="${LDFLAGS} ${LIBSTEMMER_LDFLAGS}"
  fi
  AC_CHECK_HEADERS(libstemmer.h,
                   [libstemmer_exists=yes],
                   [libstemmer_exists=no])
  if test "$libstemmer_exists" = "yes"; then
    AC_CHECK_LIB(stemmer, sb_stemmer_list,
                 [LIBSTEMMER_LIBS="-lstemmer"],
                 [libstemmer_exists=no])
  fi
  CFLAGS="${CFLAGS_save}"
  LDFLAGS="${LDFLAGS_save}"

  if test "$libstemmer_exists" = "no" -a "x$with_libstemmer" != "xauto"; then
    AC_MSG_ERROR("No libstemmer found at ${with_libstemmer_include} and ${with_libstemmer_lib}.")
  fi
  with_libstemmer="$libstemmer_exists"
fi
if test "x$with_libstemmer" = "xyes"; then
  AC_SUBST(LIBSTEMMER_CFLAGS)
  AC_SUBST(LIBSTEMMER_LDFLAGS)
  AC_SUBST(LIBSTEMMER_LIBS)
  AC_DEFINE(GRN_WITH_LIBSTEMMER, [1], [use libstemmer])
fi
AM_CONDITIONAL(WITH_LIBSTEMMER, test "x$with_libstemmer" = "xyes")

# futex check
AC_ARG_ENABLE(futex,
  [AS_HELP_STRING([--enable-futex],
    [use futex. [default=no]])],
  ,
  [enable_futex="no"])
if test "x$enable_futex" != "xno"; then
  AC_CHECK_HEADERS(linux/futex.h sys/syscall.h, [
    AC_DEFINE(USE_FUTEX, [1], [use futex])
  ], [
    AC_MSG_ERROR("linux/futex.h or sys/syscall.h not found")
  ])
fi
AC_MSG_CHECKING([whether enable futex])
AC_MSG_RESULT($enable_futex)

# ZeroMQ
AC_ARG_ENABLE(zeromq,
  [AS_HELP_STRING([--disable-zeromq],
    [Disable ZeroMQ used for suggestion. [default=auto-detect]])],
  [enable_zeromq="$enableval"],
  [enable_zeromq="auto"])
if test "x$enable_zeromq" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([LIBZMQ],
                      [libzmq],
                      [zeromq_available=yes],
                      [zeromq_available=no])
    ],
    [zeromq_available=no])
  if test "x$zeromq_available" = "xyes"; then
    AC_DEFINE(GRN_WITH_ZEROMQ, [1], [Define to 1 if ZeroMQ is available.])
  else
    if test "x$enable_zeromq" = "xyes"; then
      AC_MSG_ERROR("No ZeroMQ found")
    fi
  fi
fi

# libevent
AC_ARG_WITH(libevent,
  [AS_HELP_STRING([--without-libevent],
    [Disable libevent used for suggestion. [default=auto]])],
  [with_libevent="$withval"],
  [with_libevent="auto"])

# workaround for bundled groonga in MariaDB.
if test "x$with_libevent" = "xbundled"; then
  with_libevent=no
fi

if test "x$with_libevent" != "xno"; then
  if test "x$with_libevent" = "xyes" -o "x$with_libevent" = "xauto"; then
    libevent_cflags=""
    libevent_ldflags="-levent"
  else
    libevent_include_dir="$with_libevent/include"
    libevent_lib_dir="$with_libevent/lib"
    if ! test -d "$libevent_include_dir" -a -d "$libevent_lib_dir"; then
      AC_MSG_ERROR("No libevent found in $with_libevent.")
    fi
    libevent_cflags="-I$libevent_include_dir"
    libevent_ldflags="-L$libevent_lib_dir -levent"
  fi

  _SAVE_CFLAGS="$CFLAGS"
  _SAVE_LDFLAGS="$LDFLAGS"
  _SAVE_LIBS="$LIBS"
  CFLAGS="$CFLAGS $libevent_cflags"
  LDFLAGS="$LDFLAGS $libevent_ldflags"
  AC_SEARCH_LIBS(event_init, event,
                 [libevent_available=yes],
                 [libevent_available=no])
  CFLAGS="$_SAVE_CFLAGS"
  LDFLAGS="$_SAVE_LDFLAGS"
  LIBS="$_SAVE_LIBS"
  if test "$libevent_available" = "yes"; then
    AC_DEFINE(GRN_WITH_LIBEVENT, [1], [Define to 1 if libevent is available.])
    LIBEVENT_CFLAGS="$libevent_cflags"
    LIBEVENT_LIBS="$libevent_ldflags"
  else
    if test "$enable_option_checking" != "no" -a "x$with_libevent" = "xyes"; then
      AC_MSG_ERROR("No libevent found")
    fi
  fi
fi
AC_SUBST(LIBEVENT_CFLAGS)
AC_SUBST(LIBEVENT_LIBS)

# MessagePack
BUNDLED_MESSAGE_PACK_VERSION=m4_include([bundled_message_pack_version])
AC_SUBST(BUNDLED_MESSAGE_PACK_VERSION)

AC_ARG_ENABLE(message-pack,
  [AS_HELP_STRING([--disable-message-pack],
    [Disable MessagePack support. [default=auto-detect]])],
  [enable_message_pack="$enableval"],
  [enable_message_pack="auto"])
if test "x$enable_message_pack" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([MESSAGE_PACK], [msgpack],
      [message_pack_available=yes],
      [message_pack_available=no])
    ],
    [message_pack_vailable=no])

  if test "$message_pack_available" = "no"; then
    AC_ARG_WITH(message-pack,
      [AS_HELP_STRING([--with-message-pack],
        [Specify prefix where MessagePack is installed. [default=/usr]])],
      [with_message_pack="$withval"],
      [with_message_pack="/usr"])
    _SAVE_CFLAGS="$CFLAGS"
    _SAVE_LDFLAGS="$LDFLAGS"
    _SAVE_LIBS="$LIBS"
    CFLAGS="$CFLAGS -I$with_message_pack/include"
    LDFLAGS="$LDFLAGS -L$with_message_pack/lib"
    AC_SEARCH_LIBS(msgpack_version, msgpackc,
                   [message_pack_available=yes],
                   [message_pack_available=no])
    CFLAGS="$_SAVE_CFLAGS"
    LDFLAGS="$_SAVE_LDFLAGS"
    LIBS="$_SAVE_LIBS"

    if test "x$message_pack_available" = "xyes"; then
      MESSAGE_PACK_CFLAGS="-I$with_message_pack/include"
      MESSAGE_PACK_LIBS="-L$with_message_pack/lib -lmsgpackc"
    fi
  fi

  if test "x$message_pack_available" = "xyes"; then
    AC_DEFINE(GRN_WITH_MESSAGE_PACK, [1],
              [Define to 1 if MessagePack is available.])
  else
    if test "x$enable_message_pack" = "xyes"; then
      AC_MSG_ERROR("No MessagePack found")
    fi
  fi
fi
AC_SUBST(MESSAGE_PACK_CFLAGS)
AC_SUBST(MESSAGE_PACK_LIBS)

AM_CONDITIONAL([ENABLE_SUGGEST_LEARNER],
               [test "$zeromq_available" = "yes" -a \
                     "$libevent_available" = "yes" -a \
                     "$message_pack_available" = "yes"])

# Check built-in atomic
case "$host" in
  i*86*|x86_64*)
    ;;
  *)
    AC_MSG_CHECKING([for platform which requires libatomic])
    AC_CHECK_LIB(atomic, __atomic_store_8, [ATOMIC_LIBS="-latomic"])
    AC_SUBST(ATOMIC_LIBS)
    ;;
esac

# Document
AC_MSG_CHECKING([whether enable document])
AC_ARG_ENABLE(document,
  [AS_HELP_STRING([--enable-document],
    [enable document generation by Sphinx. [default=auto]])],
  [enable_document="$enableval"],
  [enable_document="auto"])
AC_MSG_RESULT($enable_document)

document_available=no
document_buildable=no
have_built_document=no
if test x"$enable_document" != x"no"; then
  if test -f "$srcdir/doc/build-stamp"; then
    document_available=yes
    have_built_document=yes
  fi

  if test x"$enable_document" = x"yes"; then
    AC_PATH_PROG(SPHINX_BUILD, sphinx-build, [])
    if test -n "$SPHINX_BUILD"; then
      document_available=yes
      document_buildable=yes
    else
      AC_MSG_ERROR([
No sphinx-build found.
Install it and try again.

How to install sphinx-build:

For Debian GNU/Linux based system like Ubuntu:
  % sudo apt-get install -y python-sphinx

For Red Hat based system like CentOS:
  % sudo yum install -y python-pip
  % sudo pip install sphinx

For OS X with Homebrew:
  % brew install python
  % brew install gettext
  % export PATH="`brew --prefix gettext`/bin:\$PATH"
  % pip install sphinx])
    fi
    AC_SUBST(SPHINX_BUILD)
  fi
fi

# Check for misc.
AC_ARG_WITH([cutter-source-path],
            AS_HELP_STRING([--with-cutter-source-path=PATH],
                           [Specify Cutter source path for
                            groonga's release manager.]),
                           [CUTTER_SOURCE_PATH="$withval"])
case "$CUTTER_SOURCE_PATH" in
  ""|/*)
    : # do nothing
    ;;
  *)
    CUTTER_SOURCE_PATH="\$(top_builddir)/${CUTTER_SOURCE_PATH}"
    ;;
esac
AC_SUBST(CUTTER_SOURCE_PATH)

AM_CONDITIONAL([DOCUMENT_AVAILABLE],
               [test "${document_available}" = "yes"])
AC_MSG_CHECKING([whether document available])
AC_MSG_RESULT($document_available)

AM_CONDITIONAL([DOCUMENT_BUILDABLE],
               [test "${document_buildable}" = "yes"])
AC_MSG_CHECKING([whether document buildable])
AC_MSG_RESULT($document_buildable)

AM_CONDITIONAL([HAVE_BUILT_DOCUMENT],
               [test "${have_built_document}" = "yes"])
AC_MSG_CHECKING([whether having built document])
AC_MSG_RESULT($have_built_document)

DOCUMENT_VERSION=groonga_version
DOCUMENT_VERSION_FULL="$GRN_VERSION"
AC_SUBST(DOCUMENT_VERSION)
AC_SUBST(DOCUMENT_VERSION_FULL)

# Munin plugins
AC_MSG_CHECKING([whether install munin plugins])
AC_ARG_WITH(munin-plugins,
  [AS_HELP_STRING([--with-munin-plugins],
    [install Munin plugins. [default=no]])],
  [install_munin_plugins="$withval"],
  [install_munin_plugins="no"])
AC_MSG_RESULT($install_munin_plugins)

AM_CONDITIONAL([INSTALL_MUNIN_PLUGINS],
               [test "${install_munin_plugins}" = "yes"])

# platform
AC_MSG_CHECKING([whether package platform])
AC_ARG_WITH(package-platform,
  [AS_HELP_STRING([--with-package-platform=PLATFORM],
    [install package platform related files. [default=no]
     (supported package platforms: centos, centos5, centos6, centos7, fedora)])],
  [package_platform="$withval"],
  [package_platform="no"])
if test "$package_platform" = "centos"; then
  distribution=$(cut -d " " -f 1 /etc/redhat-release | tr "A-Z" "a-z")
  if grep -q Linux /etc/redhat-release; then
    distribution_version=$(cut -d " " -f 4 /etc/redhat-release)
  else
    distribution_version=$(cut -d " " -f 3 /etc/redhat-release)
  fi
  distribution_version=$(echo ${distribution_version} | sed -e 's/\..*$//g')
  package_platform="${package_platform}${distribution_version}"
fi
AC_MSG_RESULT($package_platform)

AM_CONDITIONAL([CENTOS_PLATFORM],
               [test "${package_platform}" != "no"])
AM_CONDITIONAL([CENTOS_INIT_PLATFORM],
               [test "${package_platform}" = "centos5" ||
                test "${package_platform}" = "centos6"])
AM_CONDITIONAL([CENTOS_SYSTEMD_PLATFORM],
               [test "${package_platform}" = "centos7" ||
                test "${package_platform}" = "fedora"])

# plugins check
relative_pluginsdir_base="\$(PACKAGE)/plugins"
AC_SUBST(relative_pluginsdir_base)
expanded_relative_pluginsdir_base="${PACKAGE}/plugins"
AC_SUBST(expanded_relative_pluginsdir_base)

relative_pluginsdir="lib/\$(relative_pluginsdir_base)"
AC_SUBST(relative_pluginsdir)

pluginsdir="\${libdir}/\$(relative_pluginsdir_base)"
AC_SUBST(pluginsdir)
expanded_pluginsdir="\${libdir}/${expanded_relative_pluginsdir_base}"
AC_SUBST(expanded_pluginsdir)

tokenizer_pluginsdir="\${pluginsdir}/tokenizers"
AC_SUBST(tokenizer_pluginsdir)

query_expander_pluginsdir="\${pluginsdir}/query_expanders"
AC_SUBST(query_expander_pluginsdir)

suggest_pluginsdir="\${pluginsdir}/suggest"
AC_SUBST(suggest_pluginsdir)

ruby_pluginsdir="\${pluginsdir}/ruby"
AC_SUBST(ruby_pluginsdir)

token_filter_pluginsdir="\${pluginsdir}/token_filters"
AC_SUBST(token_filter_pluginsdir)

sharding_pluginsdir="\${pluginsdir}/sharding"
AC_SUBST(sharding_pluginsdir)

function_pluginsdir="\${pluginsdir}/functions"
AC_SUBST(function_pluginsdir)

expression_rewriter_pluginsdir="\${pluginsdir}/expression_rewriters"
AC_SUBST(expression_rewriter_pluginsdir)

AC_MSG_CHECKING(for the suffix of plugin shared libraries)
shrext_cmds=$(./libtool --config | grep '^shrext_cmds=')
eval $shrext_cmds
module=yes eval suffix="$shrext_cmds"
AC_MSG_RESULT($suffix)
if test -z "$suffix"; then
  AC_MSG_ERROR([can't detect plugin suffix])
fi
AC_DEFINE_UNQUOTED(GRN_PLUGIN_SUFFIX, ["$suffix"], "plugin suffix")

# for query expanders
GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE_BASE="synonyms.tsv"
GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE="etc/${PACKAGE}/${GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE_BASE}"
AC_DEFINE_UNQUOTED(GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE,
                   ["$GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE"],
                   "The relative synonyms file for TSV query expander")
GRN_QUERY_EXPANDER_TSV_SYNONYMS_PATH="`
  eval echo ${sysconfdir}/${PACKAGE}/${GRN_QUERY_EXPANDER_TSV_RELATIVE_SYNONYMS_FILE_BASE}
`"
AC_DEFINE_UNQUOTED(GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE,
                   ["$GRN_QUERY_EXPANDER_TSV_SYNONYMS_PATH"],
                   "The default synonyms file for TSV query expander")

# for examples
examplesdir="\$(pkgdatadir)/examples"
AC_SUBST(examplesdir)

examples_dictionarydir="\$(examplesdir)/dictionary"
AC_SUBST(examples_dictionarydir)

# for ruby scripts
relative_ruby_scriptsdir_base="\$(PACKAGE)/scripts/ruby"
AC_SUBST(relative_ruby_scriptsdir_base)
relative_ruby_scriptsdir="lib/\$(relative_ruby_scriptsdir_base)"
AC_SUBST(relative_ruby_scriptsdir)
ruby_scriptsdir="\${libdir}/\$(relative_ruby_scriptsdir_base)"
AC_SUBST(ruby_scriptsdir)

# for document root
GRN_DEFAULT_DOCUMENT_ROOT_BASE="html/admin"
GRN_DEFAULT_DOCUMENT_ROOT="\${pkgdatadir}/\${GRN_DEFAULT_DOCUMENT_ROOT_BASE}"
GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT="\${datadir}/${PACKAGE}/${GRN_DEFAULT_DOCUMENT_ROOT_BASE}"
GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT="share/\$(PACKAGE)/\$(GRN_DEFAULT_DOCUMENT_ROOT_BASE)"
AC_SUBST(GRN_DEFAULT_DOCUMENT_ROOT_BASE)
AC_SUBST(GRN_DEFAULT_DOCUMENT_ROOT)
AC_SUBST(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT)
AC_SUBST(GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT)

# flags for compile groonga
GRN_CFLAGS=""
AC_SUBST(GRN_CFLAGS)
GRN_DEFS=""
GRN_DEFS="$GRN_DEFS -DGRN_DLL_FILENAME=L\\\"\"\$(GRN_DLL_FILENAME)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_PLUGINS_DIR=\\\"\"\$(pluginsdir)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_RELATIVE_PLUGINS_DIR=\\\"\"\$(relative_pluginsdir)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_RUBY_SCRIPTS_DIR=\\\"\"\$(ruby_scriptsdir)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_RELATIVE_RUBY_SCRIPTS_DIR=\\\"\"\$(relative_ruby_scriptsdir)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_LOG_PATH=\\\"\"\$(grn_log_path)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_DEFAULT_DOCUMENT_ROOT=\\\"\"\$(GRN_DEFAULT_DOCUMENT_ROOT)\"\\\""
GRN_DEFS="$GRN_DEFS -DGRN_DEFAULT_RELATIVE_DOCUMENT_ROOT=\\\"\"\$(GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT)\"\\\""
AC_SUBST(GRN_DEFS)
CFLAGS="$CFLAGS $OPT_CFLAGS "
LIBS="$LIBS $WINDOWS_LIBS"
AC_DEFINE_UNQUOTED(CONFIGURE_OPTIONS, "$ac_configure_args", "specified configure options")

# For groonga.org
AC_ARG_WITH(groonga-org-path,
            [AS_HELP_STRING([--with-groonga-org-path=PATH],
              [specify a path of the groonga.org repository to update groonga.org.])],
            [GROONGA_ORG_PATH="$withval"],
            [GROONGA_ORG_PATH=""])
AC_SUBST(GROONGA_ORG_PATH)

# groonga-httpd
NGINX_VERSION=m4_include([nginx_version])
AC_SUBST(NGINX_VERSION)

# groonga-httpd binary path
GROONGA_HTTPD="${ac_pwd}/vendor/nginx-${NGINX_VERSION}/objs/nginx"
AC_SUBST(GROONGA_HTTPD)

AC_ARG_ENABLE(groonga_httpd,
  [AS_HELP_STRING([--enable-groonga-httpd],
    [enable nginx used for groonga-httpd. [default=yes]])],
  [enable_groonga_httpd="$enableval"],
  [enable_groonga_httpd="yes"])
if test "x$enable_groonga_httpd" != "xno"; then
  enable_groonga_httpd="yes"
  AC_CONFIG_SUBDIRS([src/httpd])
else
  enable_groonga_httpd="no"
fi
AM_CONDITIONAL(WITH_GROONGA_HTTPD, test "$enable_groonga_httpd" = "yes")

GROONGA_HTTPD_PID_PATH="`
  test \"$prefix\" = NONE && prefix=/usr/local
  eval echo ${localstatedir}/run/groonga/groonga-httpd.pid
`"
AC_SUBST(GROONGA_HTTPD_PID_PATH)

# mruby
AC_ARG_ENABLE(mruby,
  [AS_HELP_STRING([--enable-mruby],
    [enable mruby. [default=no]])],
  [enable_mruby="$enableval"],
  [enable_mruby="no"])

AC_MSG_CHECKING([whether enable mruby])
if test "x$enable_mruby" != "xyes"; then
  enable_mruby="no"
fi
AC_MSG_RESULT($enable_mruby)

if test "$enable_mruby" = "yes"; then
  if test ! -f "$srcdir/vendor/mruby/mruby_build.timestamp" -a \
          "$ac_cv_ruby_available" != "yes"; then
    AC_MSG_ERROR(--enable-mruby requires --with-ruby)
  fi
  AC_DEFINE(GRN_WITH_MRUBY, [1], [Define to 1 if mruby is enabled.])
  MRUBY_CFLAGS="-I\$(top_srcdir)/vendor/mruby-source/include"
  GRN_WITH_MRUBY="yes"
else
  MRUBY_CFLAGS=""
fi
AC_SUBST(GRN_WITH_MRUBY)
AC_SUBST(MRUBY_CFLAGS)
AM_CONDITIONAL(WITH_MRUBY, test "$enable_mruby" = "yes")

MRUBY_CPPFLAGS="-DMRB_INT64"
AC_SUBST(MRUBY_CPPFLAGS)

# For mruby-file-stat
if test "$os_win32" = "yes"; then
  HAVE_SYS_SYSMACROS_H=no
else
  AC_CHECK_HEADERS(sys/sysmacros.h,
                   [HAVE_SYS_SYSMACROS_H=yes],
                   [HAVE_SYS_SYSMACROS_H=no])
fi
AM_CONDITIONAL(HAVE_SYS_SYSMACROS_H, test "$HAVE_SYS_SYSMACROS_H" = "yes")

# This option is used in vendor/onigmo/configure
AC_ARG_ENABLE(shared-onigmo,
  [AS_HELP_STRING([--enable-shared-onigmo],
    [use Onigmo as shared library instead of static library. [default=no]])],
  [enable_shared_onigmo="$enableval"],
  [enable_shared_onigmo="no"])
AM_CONDITIONAL(WITH_SHARED_ONIGMO, test "$enable_shared_onigmo" = "yes")

AC_ARG_WITH(onigmo,
  [AS_HELP_STRING([--without-onigmo],
    [Don't Use Onigmo. [default=bundled]])],
  [with_onigmo="$withval"],
  [with_onigmo="bundled"])
if test "x$with_onigmo" != "xno"; then
  GRN_WITH_ONIGMO="yes"
  if test "x$with_onigmo" != "xbundled"; then
    m4_ifdef([PKG_CHECK_MODULES], [
      PKG_CHECK_MODULES([ONIGMO], [onigmo],
        [have_onigmo=yes],
        [have_onigmo=no])
      ],
      [have_onigmo=no])
  fi
  if test "x$with_onigmo" = "xsystem" -a "$have_onigmo" = "no"; then
    AC_MSG_ERROR("No Onigmo found")
  fi
  if test "x$with_onigmo" = "xbundled" -o "$have_onigmo" = "no"; then
    AC_CONFIG_SUBDIRS([vendor/onigmo])
    ONIGMO_CFLAGS="-I\$(top_srcdir)/vendor/onigmo-source"
    ONIGMO_LIBS="\$(top_builddir)/vendor/onigmo-source/libonigmo.la"
  fi
  AC_DEFINE(GRN_WITH_ONIGMO, [1], [Use Onigmo.])
else
  GRN_WITH_ONIGMO="no"
fi
AC_SUBST(GRN_WITH_ONIGMO)
AC_SUBST(ONIGMO_CFLAGS)
AC_SUBST(ONIGMO_LIBS)
AM_CONDITIONAL(WITH_BUNDLED_ONIGMO, test "$with_onigmo" != "no" -a "x$have_onigmo" != "xyes")

# PCRE
GRN_WITH_PCRE=no
AC_ARG_WITH(pcre,
  [AS_HELP_STRING([--without-pcre],
    [Don't use PCRE for groonga-httpd. [default=auto-detect]])],
  [with_pcre="$withval"],
  [with_pcre="auto"])
if test "x$with_pcre" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([PCRE], [libpcre],
      [_PKG_CONFIG(PCRE_LIBS_ONLY_L, [libs-only-L], [libpcre])
       PCRE_LIBS_ONLY_L="$pkg_cv_PCRE_LIBS_ONLY_L"
       GRN_WITH_PCRE=yes],
      [GRN_WITH_PCRE=no])
    ],
    [GRN_WITH_PCRE=no])
  if test "x$with_pcre" = "xyes" -a "$GRN_WITH_PCRE" != "yes"; then
    AC_MSG_ERROR("No PCRE found")
  fi
fi
AC_SUBST(GRN_WITH_PCRE)
AC_SUBST(PCRE_CFLAGS)
AC_SUBST(PCRE_LIBS_ONLY_L)

# SSL
GRN_WITH_SSL=no
AC_ARG_WITH(ssl,
  [AS_HELP_STRING([--without-ssl],
    [Don't use SSL module for groonga-httpd. [default=auto-detect]])],
  [with_ssl="$withval"],
  [with_ssl="auto"])
if test "x$with_ssl" != "xno"; then
  m4_ifdef([PKG_CHECK_MODULES], [
    PKG_CHECK_MODULES([SSL], [libssl],
      [_PKG_CONFIG(SSL_LIBS_ONLY_L, [libs-only-L], [libssl])
       SSL_LIBS_ONLY_L="$pkg_cv_SSL_LIBS_ONLY_L"
       GRN_WITH_SSL=yes],
      [GRN_WITH_SSL=no])
    ],
    [GRN_WITH_SSL=no])
  if test "x$with_ssl" = "xyes" -a "$GRN_WITH_SSL" != "yes"; then
    AC_MSG_ERROR("No SSL found")
  fi
fi
AC_SUBST(GRN_WITH_SSL)
AC_SUBST(SSL_CFLAGS)
AC_SUBST(SSL_LIBS_ONLY_L)

# For package
AC_ARG_WITH(rsync-path,
            [AS_HELP_STRING([--with-rsync-path=PATH],
            [specify rsync path to upload groonga packages.])],
            [RSYNC_PATH="$withval"],
            [RSYNC_PATH="packages@packages.groonga.org:public"])
AC_SUBST(RSYNC_PATH)

AC_ARG_WITH(launchpad-ppa,
            [AS_HELP_STRING([--with-launchpad-ppa=PPA],
            [specify Launchpad Personal Package Archive. [default=groonga-ppa]])],
            [LAUNCHPAD_PPA="$withval"],
            [LAUNCHPAD_PPA="groonga-ppa"])
AC_SUBST(LAUNCHPAD_PPA)

AC_ARG_WITH(launchpad-uploader-pgp-key,
            [AS_HELP_STRING([--with-launchpad-uploader-pgp-key=KEY],
            [specify PGP key UID to upload Groonga packages to Launchpad.])],
            [LAUNCHPAD_UPLOADER_PGP_KEY="$withval"],
            [LAUNCHPAD_UPLOADER_PGP_KEY=""])
AC_SUBST(LAUNCHPAD_UPLOADER_PGP_KEY)

GPG_UID=m4_include(gpg_uid)
AC_SUBST(GPG_UID)

GPG_UID_RSA4096=m4_include(gpg_uid_rsa4096)
AC_SUBST(GPG_UID_RSA4096)

pkgsysconfdir="\${sysconfdir}/$PACKAGE_NAME"
AC_SUBST(pkgsysconfdir)

GRN_CONFIG_PATH="`
  test \"$prefix\" = NONE && prefix=/usr/local
  eval echo ${sysconfdir}/groonga/groonga.conf
`"
AC_DEFINE_UNQUOTED(GRN_CONFIG_PATH, ["$GRN_CONFIG_PATH"],
  [Default command line option configuration file.])

GROONGA_HTTPD_DOCUMENT_ROOT="`
  test \"$prefix\" = NONE && prefix=/usr/local
  eval eval eval echo ${GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT}
`"
AC_SUBST(GROONGA_HTTPD_DOCUMENT_ROOT)

GROONGA_HTTPD_DEFAULT_DATABASE_PATH="`
  test \"$prefix\" = NONE && prefix=/usr/local
  eval eval eval echo ${localstatedir}/lib/${PACKAGE}/db/db
`"
AC_SUBST(GROONGA_HTTPD_DEFAULT_DATABASE_PATH)

AC_OUTPUT([
  include/groonga/version.h
  lib/metadata.rc
  packages/rpm/centos/groonga.spec
  packages/apt/env.sh
  packages/yum/env.sh
  groonga.pc
  groonga-arrow.pc
  config.sh
  groonga-httpd-conf.sh
  data/groonga-httpd.conf
  data/logrotate.d/centos/groonga-httpd
  data/scripts/groonga-httpd-restart
  data/systemd/centos/groonga-httpd.service
  ])

echo "$PACKAGE_NAME $PACKAGE_VERSION configuration:"
echo "-----------------------"
echo "  Compiler:              ${CC}"
echo "  CFLAGS:                ${CFLAGS}"
echo "  CXXFLAGS:              ${CXXFLAGS}"
echo "  Libraries:             ${LIBS}"
echo "  Stack size:            ${GRN_STACK_SIZE}"
echo "  Document:              ${document_available}"
echo "    buildable:           ${document_buildable}"
echo "    built:               ${have_built_document}"
echo "  Munin plugins:         ${install_munin_plugins}"
echo "  Package platform:      ${package_platform}"
echo
echo "Paths:"
echo "  Install path prefix:   ${prefix}"
echo "  Configuration file:    ${GRN_CONFIG_PATH}"
echo

echo "Tokenizers:"
echo "  MeCab:                 $with_mecab"
if test "x$with_mecab" = "xyes"; then
  echo "    CPPFLAGS:            $MECAB_CPPFLAGS"
  echo "    LDFLAGS:             $MECAB_LDFLAGS"
  echo "    LIBS:                $MECAB_LIBS"
fi
echo "  KyTea:                 $with_kytea"
if test "x$with_kytea" = "xyes"; then
  echo "    CFLAGS:              $KYTEA_CFLAGS"
  echo "    LIBS:                $KYTEA_LIBS"
fi
echo

echo "Token filters:"
echo "  libstemmer:            $with_libstemmer"
if test "x$with_libstemmer" = "xyes"; then
  echo "    CFLAGS:              $LIBSTEMMER_CFLAGS"
  echo "    LIBS:                $LIBSTEMMER_LIBS"
fi
echo

echo "Libraries:"
echo "  ZeroMQ:                $zeromq_available"
if test "x$zeromq_available" = "xyes"; then
  echo "    CFLAGS:              ${LIBZMQ_CFLAGS}"
  echo "    LIBS:                ${LIBZMQ_LIBS}"
fi
echo "  libevent:              $libevent_available"
if test "x$libevent_available" = "xyes"; then
  echo "    CFLAGS:              ${LIBEVENT_CFLAGS}"
  echo "    LIBS:                ${LIBEVENT_LIBS}"
fi
echo "  MessagePack:           $message_pack_available"
if test "x$message_pack_available" = "xyes"; then
  echo "    CFLAGS:              ${MESSAGE_PACK_CFLAGS}"
  echo "    LIBS:                ${MESSAGE_PACK_LIBS}"
fi
echo "  LZ4:                   $GRN_WITH_LZ4"
if test "x$GRN_WITH_LZ4" = "xyes"; then
  echo "    CFLAGS:              ${LIBLZ4_CFLAGS}"
  echo "    LIBS:                ${LIBLZ4_LIBS}"
fi
echo "  Zstandard:             $GRN_WITH_ZSTD"
if test "x$GRN_WITH_ZSTD" = "xyes"; then
  echo "    CFLAGS:              ${LIBZSTD_CFLAGS}"
  echo "    LIBS:                ${LIBZSTD_LIBS}"
fi
echo "  mruby:                 $enable_mruby"
echo "  jemalloc:              $jemalloc_available"
echo

echo "groonga-httpd:"
echo "  enable:                $enable_groonga_httpd"
if test "$enable_groonga_httpd" = "yes"; then
  echo "  default database path: $GROONGA_HTTPD_DEFAULT_DATABASE_PATH"
  echo "  PCRE:                  $GRN_WITH_PCRE"
  if test "$GRN_WITH_PCRE" = "yes"; then
    echo "    CFLAGS:              $PCRE_CFLAGS"
    echo "    LIBS only -L:        $PCRE_LIBS_ONLY_L"
  fi
  echo "   SSL:                  $GRN_WITH_SSL"
  if test "$GRN_WITH_SSL" = "yes"; then
    echo "    CFLAGS:              $SSL_CFLAGS"
    echo "    LIBS only -L:        $SSL_LIBS_ONLY_L"
  fi
fi
echo

echo "Tools:"
echo "  Sphinx:                ${SPHINX_BUILD}"
echo "  lemon:                 ${LEMON}"
echo "  Ruby:                  ${RUBY}"
echo "  Cutter:                ${CUTTER}"
echo

echo "For packages:"
echo "  rsync path:            ${RSYNC_PATH}"
echo "  Launchpad PGP key:     ${LAUNCHPAD_UPLOADER_PGP_KEY}"
echo "  GPG UID:               ${GPG_UID}"
echo

echo "Now type 'make' to build $PACKAGE_NAME $PACKAGE_VERSION!"