File: configure.ac

package info (click to toggle)
freeciv 2.6.2-1~bpo10+1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 212,500 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (1777 lines) | stat: -rw-r--r-- 60,311 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
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
dnl configure.ac for freeciv
dnl Process this file with autoconf to produce a configure script.

AC_INIT([Freeciv], m4_esyscmd([./fc_version | tr -d '\n']),
        [https://www.hostedredmine.com/projects/freeciv],
        [freeciv])
AC_PREREQ(2.61)

dnl Initialize with some random file to ensure the source is here.
AC_CONFIG_SRCDIR([common/game.c])
AC_CONFIG_AUX_DIR(bootstrap) # This can't be quoted or automake will fail
AC_CONFIG_MACRO_DIR([m4])
ifdef([AC_CONFIG_MACRO_DIRS],[AC_CONFIG_MACRO_DIRS([dependencies/m4])])
AC_CONFIG_HEADERS([gen_headers/fc_config.h gen_headers/freeciv_config.h])
AC_CANONICAL_HOST
AC_USE_SYSTEM_EXTENSIONS
AC_C_BIGENDIAN

BUG_URL="$PACKAGE_BUGREPORT"
WIKI_URL="http://www.freeciv.org/"
MAIL_ADDRESS="freeciv-dev AT freelists.org"

dnl Explain fc_config.h to end users (e.g., on Windows)
AH_TOP(
[/* This header file is shipped in some binary distributions.
 * It is included purely for reference as to how the executables were built,
 * and changing it will have no functional effect on pre-built binaries. */])

AC_DEFINE(FC_CONFIG_H, 1, [Configuration autogenerated])
AC_DEFINE_UNQUOTED([BUG_URL], ["$BUG_URL"], [Bug reporting URL])
AC_DEFINE([FREECIV_META_URL], ["http://meta.freeciv.org/metaserver.php"], [Metaserver URL])
AC_DEFINE_UNQUOTED([WIKI_URL], ["$WIKI_URL"], [Informational URL])

AC_DEFINE(DEFAULT_SOCK_PORT, 5556, [Connection TCP Port])

AC_SUBST([BUG_URL])
AC_SUBST([WIKI_URL])
AC_SUBST([MAIL_ADDRESS])

dnl client/server should always have the same major and minor versions
dnl different patch versions are compatible
VERSION_SCRIPT_SILENT=yes
m4_include(fc_version)

AC_ARG_VAR([FREECIV_LABEL_FORCE], [Forced version label format])

AC_DEFINE_UNQUOTED([MAJOR_VERSION], [$MAJOR_VERSION], [Major version])
AC_DEFINE_UNQUOTED([MINOR_VERSION], [$MINOR_VERSION], [Minor version])
AC_DEFINE_UNQUOTED([PATCH_VERSION], [$PATCH_VERSION], [Patch version])
if test x$EMERGENCY_VERSION != x ; then
  AC_DEFINE_UNQUOTED([EMERGENCY_VERSION], [$EMERGENCY_VERSION], [Emergency version])
fi
AC_DEFINE_UNQUOTED([VERSION_LABEL], ["${VERSION_LABEL}"], [Version label])
AC_DEFINE_UNQUOTED([VERSION_STRING], ["${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}${EMERG_PART}${VERSION_LABEL}"], [Version string])
AC_DEFINE_UNQUOTED([IS_DEVEL_VERSION], [$IS_DEVEL_VERSION], [Is this a devel version])
AC_DEFINE_UNQUOTED([IS_FREEZE_VERSION], [$IS_FREEZE_VERSION], [Is this a frozen version])
AC_DEFINE_UNQUOTED([IS_BETA_VERSION], [$IS_BETA_VERSION], [Is this a beta version])
AC_DEFINE_UNQUOTED([NEXT_STABLE_VERSION], ["$NEXT_STABLE_VERSION"], [Version number of next release])
AC_DEFINE_UNQUOTED([FREECIV_RELEASE_MONTH], [$RELEASE_MONTH], [Month next version will be released])
AC_SUBST([MAJOR_VERSION])
AC_SUBST([MINOR_VERSION])

AC_DEFINE_UNQUOTED([NETWORK_CAPSTRING_MANDATORY],
		   ["$NETWORK_CAPSTRING_MANDATORY"],
		   [Network capability string])
AC_SUBST([NETWORK_CAPSTRING_MANDATORY])
AC_DEFINE_UNQUOTED([NETWORK_CAPSTRING_OPTIONAL],
		   ["$NETWORK_CAPSTRING_OPTIONAL"],
		   [Additional optional network capabilities])
AC_SUBST([NETWORK_CAPSTRING_OPTIONAL])

AC_DEFINE_UNQUOTED([DATASUBDIR],
                   ["$DATASUBDIR"],
                   [Version specific subdir for default data path])
AC_SUBST([DATASUBDIR])

AC_DEFINE_UNQUOTED([FREECIV_DISTRIBUTOR], ["$FREECIV_DISTRIBUTOR"],
                   [Distribution this freeciv is built for])

dnl Initialize automake stuff
AM_INIT_AUTOMAKE([subdir-objects dist-bzip2 dist-zip])

dnl Use Automake 1.11 silent rules by default if available
dnl verbose build using  make V=1
ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

UTILITY_LIBS=

AC_PROG_MKDIR_P

dnl Sed is needed for the configuration
dnl of the clients, database setting and the mapimg toolkits.
AC_PROG_SED

AC_CACHE_CHECK([for malloc(0) return value], [fc_cv_malloc_zero_ok], [
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdlib.h>

int
main()
{
  void *allocation = malloc(0);

  if (allocation != NULL) {
    free(allocation);
  }

  return (allocation == NULL);
}
]])], [fc_cv_malloc_zero_ok=true], [fc_cv_malloc_zero_ok=false], [fc_cv_malloc_zero_ok=false])])

if test "x$fc_cv_malloc_zero_ok" = "xtrue" ; then
  AC_DEFINE([MALLOC_ZERO_OK], [1], [It's ok to call malloc() for zero bytes])
fi

dnl set default values
fcdb_all=no
fcdb_mysql=no
fcdb_postgres=no
fcdb_sqlite3=no

dnl checks for databases
dnl all:                  Autodetect as many as possible [default].
dnl mysql:                use mysql database
dnl postgres:             use postgres database
dnl comma-separated-list: Detect these or abort.
AC_ARG_ENABLE([fcdb],
  AS_HELP_STRING([--enable-fcdb[=no/all/mysql/postgres/sqlite3]],
                 [database backends [no](no, or list)]),
[databases=${enableval}],
[databases=no])

for db in $(echo $databases | $SED 's/,/ /g') ; do
  if test "x$db" = "xall" ; then
    fcdb_all=yes
  elif test "x$db" = "xno" ; then
    fcdb_all=no
  elif test "x$db" = "xmysql" ; then
    fcdb_mysql=yes
  elif test "x$db" = "xpostgres" ; then
    fcdb_postgres=yes
  elif test "x$db" = "xsqlite3" ; then
    fcdb_sqlite3=yes
  else
    AC_MSG_ERROR([bad value ${db} for --enable-fcdb])
  fi
done

dnl checks for database mysql
dnl sets FCDB_MYSQL(conditional), FCDB_MYSQL_CFLAGS
FC_FCDB_MYSQL

dnl checks for database postgres
dnl sets FCDB_POSTGRES(conditional), FCDB_POSTGRES_CFLAGS
FC_FCDB_POSTGRES

dnl checks for database sqlite3
dnl sets FCDB_SQLITE3(conditional), FCDB_SQLITE3_CFLAGS
FC_FCDB_SQLITE3

dnl check if a database backend is available
if test "x$fcdb_mysql" = "xyes" || test "x$fcdb_postgres" = "xyes" \
   || test "x$fcdb_sqlite3" = "xyes"; then
  enable_fcdb=yes
  AC_DEFINE([HAVE_FCDB], [1], [Database backend available])
else
  enable_fcdb=no
fi
AM_CONDITIONAL([FCDB_DB], [test "x$enable_fcdb" = "xyes"])

dnl  no=do not compile server,  yes=compile server,  *=error
AC_ARG_ENABLE([server],
  AS_HELP_STRING([--disable-server], [do not compile the server]),
[case "${enableval}" in
  yes) server=yes ;;
  no)  server=no ;;
  *)   AC_MSG_ERROR(bad value ${enableval} for --disable-server) ;;
esac], [server=yes])
AM_CONDITIONAL(SERVER, test x$server = xyes)

dnl Host type variable defaults
MINGW=no
AMIGA=no

dnl Settings specific to host OS
case "$host_os" in

  *mingw*)
    dnl Windows-specific settings
    MINGW=yes
    FC_WINSOCK2_INCLUDE([AC_DEFINE([FREECIV_HAVE_WINSOCK2], [1], [Mingw-specific setting - winsock2])])
    AC_DEFINE([FREECIV_HAVE_WINSOCK], [1], [Mingw-specific setting - winsock])
    AC_CHECK_HEADERS([ws2tcpip.h], [AC_DEFINE([FREECIV_HAVE_WS2TCPIP_H], [1], [ws2tcpip.h available])])
    AC_CHECK_HEADERS([direct.h])

    dnl Without WINSOCK2, use: LIBS="$LIBS -lwsock32"
    LIBS="${LIBS} -lws2_32"
    ;;
esac

dnl Networking headers
AC_CHECK_HEADERS([sys/types.h], [AC_DEFINE([FREECIV_HAVE_SYS_TYPES_H], [1], [sys/types.h available])])

dnl Avoid including the unix emulation layer if we build mingw executables
dnl There would be type conflicts between winsock and bsd/unix includes
if test "x$MINGW" != "xyes"; then
  AC_CHECK_HEADERS([sys/socket.h], [AC_DEFINE([FREECIV_HAVE_SYS_SOCKET_H], [1], [sys/socket.h available])])
fi

dnl Check getaddrinfo just once here, and remember the result
AC_CHECK_FUNCS([getaddrinfo], [have_getaddrinfo=yes], [
  AC_MSG_CHECKING([getaddrinfo() as a macro])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef FREECIV_HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif], [getaddrinfo(NULL, NULL, NULL, NULL);])], [
  AC_MSG_RESULT([yes])
  have_getaddrinfo=yes
  AC_DEFINE([HAVE_GETADDRINFO])], [AC_MSG_RESULT([no])])])

dnl yes     - Support for IPv6 required
dnl no      - Legacy IPv4 support
dnl test    - Try to enable IPv6 support
AC_ARG_ENABLE([ipv6],
  AS_HELP_STRING([--enable-ipv6=yes/no/test], [use IPv6 [test]]),
[case "${enableval}" in
  yes|no|test) ipv6=${enableval} ;;
  *)   AC_MSG_ERROR(bad value ${enableval} for --enable-ipv6) ;;
esac], [ipv6=test])
if test x$ipv6 != xno ; then
  if test "x$have_getaddrinfo" = "xyes" ; then
    enable_ipv6=yes
    AC_CHECK_FUNCS([inet_pton], [],
       [AC_MSG_CHECKING([inet_pton() as a macro])
      AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef FREECIV_HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif], [inet_pton(0, NULL, NULL);])], [
      AC_MSG_RESULT([yes])], [enable_ipv6=no])])
    AC_CHECK_FUNCS([inet_ntop], [],
       [AC_MSG_CHECKING([inet_ntop() as a macro])
      AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef FREECIV_HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif], [inet_ntop(0, NULL, NULL, 0);])], [
      AC_MSG_RESULT([yes])], [enable_ipv6=no])])
    AC_CHECK_FUNCS([getnameinfo], [],
       [AC_MSG_CHECKING([getnameinfo() as a macro])
      AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef FREECIV_HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif], [getnameinfo(NULL, 0, NULL, 0, NULL, 0, 0);])], [
      AC_MSG_RESULT([yes])], [enable_ipv6=no])])
  else
     enable_ipv6=no
  fi
  if test x$enable_ipv6 = xyes ; then
    AC_MSG_CHECKING([for AF_INET6])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef FREECIV_HAVE_WINSOCK2
#include <winsock2.h>
#endif
#ifdef FREECIV_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef FREECIV_HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif]], [[return AF_INET6;]])], [AC_MSG_RESULT([yes])],
       [AC_MSG_RESULT([no])
        enable_ipv6=no])
  fi
  if test x$enable_ipv6 = xno && test x$ipv6 = xyes ; then
    AC_MSG_ERROR([Cannot enable IPv6 functionality])
  fi
  if test x$enable_ipv6 = xyes ; then
    AC_DEFINE([FREECIV_IPV6_SUPPORT], [1], [IPv6 Support built in])
  else
    feature_ipv6=missing
  fi
fi

AC_ARG_WITH([readline],
  AS_HELP_STRING([--with-readline], [support fancy command line editing]),
WITH_READLINE=$withval,	dnl yes/no - required to use / never use
WITH_READLINE="maybe"	dnl maybe  - use if found [default]
)

FOLLOWTAG=${DEFAULT_FOLLOW_TAG}
AC_ARG_WITH([followtag],
  AS_HELP_STRING([--with-followtag], [version tag to follow]),
[FOLLOWTAG=${withval}])
AC_DEFINE_UNQUOTED([FOLLOWTAG], ["${FOLLOWTAG}"], [Version tag to follow])

AC_ARG_WITH([modlist],
  AS_HELP_STRING([--with-modlist], [default modlist URL]),
[modlist_url=${withval}])
if test "x$modlist_url" != "x" ; then
  AC_DEFINE_UNQUOTED([MODPACK_LIST_URL], ["${modlist_url}"], [Default modpack list URL])
fi

AC_ARG_WITH([desktopdir],
  AS_HELP_STRING([--with-desktopdir], [install desktop files to given dir]),
[ DESKTOPDIR=${withval} ], [ DESKTOPDIR="\$(prefix)/share/applications" ])
AC_SUBST([DESKTOPDIR])

AC_ARG_WITH([appdatadir],
  AS_HELP_STRING([--with-appdatadir], [install appdata files to given dir]),
[ APPDATADIR=${withval} ], [ APPDATADIR="\$(prefix)/share/appdata" ])
AC_SUBST([APPDATADIR])

dnl set default values
mapimg_all=auto
mapimg_magickwand=no

dnl map images
dnl all:                  Autodetect as many as possible [default].
dnl no:                   No additional toolkits.
dnl magickwand:           compile magickwand (imagemagick) support.
dnl comma-separated-list: Detect these or abort.
AC_ARG_ENABLE([mapimg],
  AS_HELP_STRING([--enable-mapimg=no/auto/magickwand],
                 [additional map image toolkits to compile [auto](no, or list)]),
[toolkits=${enableval}],
[enable_mapimg=auto])

for toolkit in $(echo $toolkits | $SED 's/,/ /g') ; do
  if test "x$toolkit" = "xauto" ; then
    enable_mapimg=auto
  elif test "x$toolkit" = "xno" ; then
    enable_mapimg=no
  else
    enable_mapimg=selected
  fi

  if test "x$toolkit" = "xmagickwand" ; then
    mapimg_magickwand=yes
  fi
done

dnl checks for MagickWand mapimg support
dnl sets MAPIMG_WAND_CFLAGS, MAPIMG_WAND_LIBS
FC_MAPIMG_MAGICKWAND

dnl Option not available in stable branch
fcweb=false

FC_WEB_CLIENT

FC_TESTMATIC

dnl no:   Do not compile client.
dnl auto: Autodetect one.
dnl all:  Autodetect as many as possible.
dnl comma-separated-list: Detect these or abort.
AC_ARG_ENABLE([client],
  AS_HELP_STRING([--enable-client=auto/all/gtk2/gtk3/gtk3.22/sdl/sdl2/xaw/qt/stub],
                 [clients to compile [auto](list for multiple)]),
[clients=${enableval}],
[client=auto])

if test "x$fcweb" = "xtrue" ; then
  if test "x$clients" != "x" && test "x$clients" != "xauto" &&
     test "x$clients" != "xno" ; then
    AC_MSG_ERROR([One cannot enable any clients for freeciv-web build])
  fi
  clients=no
fi

gui_gtk2=no
gui_gtk3_22=no
gui_gtk3=no
gui_sdl=no
gui_sdl2=no
gui_xaw=no
gui_qt=no
gui_stub=no

for gui in $(echo $clients | $SED 's/,/ /g') ; do
  if test "x$gui" = "xno" ; then
    client=no
  elif test "x$gui" = "xauto" || test "x$gui" = "xyes" ; then
    client=auto
  elif test "x$gui" = "xall" ; then
    client=all
  else
    if test "x$gui" = "xgtk2"   ||
       test "x$gui" = "xgtk2.0" ||
       test "x$gui" = "xgtk20"  ||
       test "x$gui" = "xgtk-2.0" ; then
      gui_gtk2=yes
    elif test "x$gui" = "xgtk3.22" ; then
      gui_gtk3_22=yes
    elif test "x$gui" = "xgtk3"   ||
         test "x$gui" = "xgtk3.0" ||
         test "x$gui" = "xgtk30"  ||
         test "x$gui" = "xgtk-3.0" ; then
      gui_gtk3=yes
    elif test "x$gui" = "xgtk" ; then
      AC_MSG_WARN([for requested client 'gtk' enabled gtk3-client, that has changed since earlier versions])
      gui_gtk3=yes
    else
      if test ! -d "${srcdir}/client/gui-$gui" ; then
        AC_MSG_ERROR(bad value ${gui} for --enable-client)
      fi
      eval "gui_$gui=yes"
    fi
    client=yes
  fi
done

AC_ARG_WITH([xaw],
  [AS_HELP_STRING([--with-xaw], [use the Xaw widget set for the xaw client])],
  [WITH_XAW=1])

AC_ARG_WITH([xaw3d],
  [AS_HELP_STRING([--with-xaw3d], [use the Xaw3d widget set for the xaw client])],
  [WITH_XAW3D=1])

if test "x$WITH_XAW" != "x" && test "x$WITH_XAW3D" != "x" ; then
  AC_MSG_ERROR([Cannot use both --with-xaw and --with-xaw3d at the same time])
fi

AC_ARG_ENABLE([gitrev],
  AS_HELP_STRING([--enable-gitrev], [get git revision to version information]),
[case "${enableval}" in
  yes) gitrev=true  ;;
  no)  gitrev=false ;;
  *)   AC_MSG_ERROR([bad value ${enableval} for --enable-gitrev]) ;;
esac], [gitrev=false])
AM_CONDITIONAL([GITREV], [test x$gitrev = xtrue])
if test x$gitrev = xtrue ; then
  AC_DEFINE([GITREV], [1], [Get git revision information to version number])
fi

AC_ARG_ENABLE([make_data],
  AS_HELP_STRING([--disable-make-data], [do not recurse make into data directories]),
[case "${enableval}" in
  yes) make_data=true ;;
  no)  make_data=false ;;
  *)   AC_MSG_ERROR(bad value ${enableval} for --disable-make-data) ;;
esac], [make_data=true])
AM_CONDITIONAL(MAKE_DATA, test x$make_data = xtrue)

AC_ARG_ENABLE([make_include],
  AS_HELP_STRING([--enable-make-include], [force make to recurse into include directory]),
[case "${enableval}" in
  yes) make_include=true ;;
  no)  make_include=false ;;
  *)   AC_MSG_ERROR(bad value ${enableval} for --enable-make-include) ;;
esac], [make_include=false])
AM_CONDITIONAL(MAKE_CLIENT_INCLUDE, test "$make_include" = "true")

AC_ARG_WITH([efence],
  AS_HELP_STRING([--with-efence], [use Electric Fence, malloc debugger]),
  WITH_EFENCE=1
)

AC_ARG_ENABLE([aimodules],
  AS_HELP_STRING([--enable-aimodules=yes/no/experimental], [support for ai modules [no]]),
[case "${enableval}" in
  yes) enable_aimodules=yes ;;
  no)  enable_aimodules=no ;;
  experimental) enable_aimodules=yes
                exp_aimodules=yes ;;
  *)   AC_MSG_ERROR([bad value ${enable_aimodules} for --enable-aimodules]) ;;
esac], [enable_aimodules=no])
aimoduledir="${libdir}/fcai"
AC_SUBST(aimoduledir)
AM_CONDITIONAL(AI_MODULES, test "x$enable_aimodules" = "xyes")
if test $enable_aimodules = yes ; then
  if test x$enable_shared != xyes ; then
    AC_MSG_ERROR([cannot enable ai module support if also build of shared libraries is not enabled with --enable-shared])
  fi
  LIBS_TMP="$LIBS"
  LIBS="$LIBS -lltdl"
  AC_MSG_CHECKING([whether can build modules])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ltdl.h>]],
     [[lt_dlopenext(NULL);]])],
     [AC_MSG_RESULT([yes])],
     [AC_MSG_RESULT([no])
      AC_MSG_ERROR([cannot build loadable AI modules as requested])])
  LIBS="$LIBS_TMP"
  SERVER_LIBS="${SERVER_LIBS} -lltdl"
  AC_DEFINE([AI_MODULES], [1], [Enable ai modules])
  CPPFLAGS="${CPPFLAGS} -DAI_MODULEDIR=\"\\\"${aimoduledir}\\\"\""
  ai_mod_default_needed=yes
fi
AM_CONDITIONAL(EXP_AI_MODULES, test "x$exp_aimodules" = "xyes")

AC_ARG_ENABLE([ai-static],
  AS_HELP_STRING([--enable-ai-static], [statically link listed modules to server]),
[static_modules="${enableval}"],
[static_modules="classic"])

ai_mod_static_classic=no
ai_mod_static_threaded=no
ai_mod_static_stub=no

for module in $(echo $static_modules | $SED 's/,/ /g') ; do
  if test "x$module" = "xclassic" ; then
    ai_mod_static_classic=yes
    ai_mod_default_needed=yes
    AC_DEFINE([AI_MOD_STATIC_CLASSIC], [1],
              [classic ai module statically linked])
  elif test "x$module" = "xthreaded" ; then
    ai_mod_static_threaded=yes
    ai_mod_default_needed=yes
    AC_DEFINE([AI_MOD_STATIC_THREADED], [1],
              [threaded ai module statically linked])
  elif test "x$module" = "xstub" ; then
    ai_mod_static_stub=yes
    AC_DEFINE([AI_MOD_STATIC_STUB], [1],
              [stub ai module statically linked]) 
  else
    AC_MSG_ERROR([bad value ${module} for --enable-ai-static])
  fi
  if test "x$default_ai_set" = "x" ; then
    dnl Make first static module default ai type
    default_ai_set="${module}"
  fi
done
AM_CONDITIONAL([AI_MOD_STATIC_CLASSIC],
[test "x$ai_mod_static_classic" = "xyes" || test "x$enable_aimodules" != "xyes"])
AM_CONDITIONAL([AI_MOD_STATIC_THREADED],
[test "x$ai_mod_static_threaded" = "xyes"])
AM_CONDITIONAL([AI_MOD_STATIC_STUB],
[test "x$ai_mod_static_stub" = "xyes"])

AC_ARG_WITH([default-ai],
  AS_HELP_STRING([--with-default-ai], [default ai type [first_static]]),
  [default_ai_set="${withval}"],
  [])

AC_ARG_WITH([ai-lib],
  AS_HELP_STRING([--with-ai-lib], [build in default AI code [if_needed]]),
  [ai_mod_default_needed=yes], [])

AM_CONDITIONAL([AI_MOD_DEFAULT_NEEDED],
[test  "x${ai_mod_default_needed}" = "xyes" || test "x${default_ai_set}" = "x"])

if test "x${default_ai_set}" = "x" ; then
  default_ai_set="classic"
fi

fc_ai_last=0
if test "x$ai_mod_static_classic" = "xyes" ; then
  fc_ai_last=$fc_ai_last+1
fi
if test "x$ai_mod_static_threaded" = "xyes" ; then
  fc_ai_last=$fc_ai_last+1
fi
if test "x$ai_mod_static_stub" = "xyes" ; then
  fc_ai_last=$fc_ai_last+1
fi
if test "x$enable_aimodules" = "xyes" ; then
  dnl Dynamic modules allowed, give slots for them
  fc_ai_last=$fc_ai_last+3
fi
AC_DEFINE_UNQUOTED([FREECIV_AI_MOD_LAST], [(${fc_ai_last})], [Max number of AI modules])

AC_DEFINE_UNQUOTED([AI_MOD_DEFAULT], ["${default_ai_set}"], [Default ai type name])

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_LN_S
AC_DISABLE_SHARED
dnl Replace AC_PROG_LIBTOOL with LT_INIT when minimum libtool
dnl version 2.2
m4_ifdef([AM_PROG_AR], [AM_PROG_AR], [AC_CHECK_TOOL([AR], [ar])])
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL)
if test -z $AR; then
	AC_MSG_ERROR([*** 'ar' missing.  Install binutils, fix your \$PATH, or set \$AR manually. ***])
fi

AM_PROG_CC_C_O
AC_PROG_CXX
FC_WORKING_CXX
FC_C99_TOKEN_CONCENATION

AC_CHECK_PROG(UNAME,uname,uname,:)

AC_CHECK_SIZEOF([int])

dnl Programs already checked by AM_INIT_AUTOMAKE:
dnl
dnl AC_PROG_MAKE_SET required with automake-ng
AC_PROG_MAKE_SET

dnl Check for libiconv (which is usually included in glibc, but may be
dnl distributed separately).  The libcharset check must come after the
dnl iconv check.  This whole thing must come before the gettext check below.
AM_ICONV
FC_LIBCHARSET
AM_LANGINFO_CODESET
if test "$am_cv_func_iconv" != yes; then
  AC_MSG_ERROR([Iconv is missing. You can get libiconv from http://gnu.org/, \
or try using --with-libiconv-prefix.])
fi
LIBS="$LIBS $LIBICONV"

dnl I18n support
ALL_LINGUAS="ar bg cs ca da de el en_GB eo es et fa fi fr ga gd he hu id it ja 
ko lt nl nb pl pt pt_BR ro ru sr sv tr uk zh_CN zh_TW"
PODOMAINS="freeciv nations ruledit"

AM_GNU_GETTEXT([external], [need-ngettext])

if test "x$USE_NLS" = "xyes" ; then
  AC_DEFINE([FREECIV_ENABLE_NLS], [1], [Native language support enabled])
fi

AM_XGETTEXT_OPTION([--keyword=Q_])
AM_XGETTEXT_OPTION([--keyword=PL_:1,2])
AM_XGETTEXT_OPTION([--language=C])
AM_XGETTEXT_OPTION([--escape])
AM_XGETTEXT_OPTION([--add-comments="TRANS:"])
AM_XGETTEXT_OPTION([--from-code=UTF-8])

PKG_PROG_PKG_CONFIG
if test "x$PKG_CONFIG" = "x" ; then
  AC_MSG_ERROR([pkg-config not found])
fi
PKG_CHECK_MODULES([CURL], [libcurl >= 7.12.1],,
    [AC_MSG_ERROR([libcurl development files required])])
UTILITY_CFLAGS="${UTILITY_CFLAGS} ${CURL_CFLAGS}"
UTILITY_LIBS="${UTILITY_LIBS} ${CURL_LIBS}"

AC_ARG_ENABLE([xml-registry],
  AS_HELP_STRING([--enable-xml-registry], [build xml-backend for registry (WIP)]),
[case "${enableval}" in
  yes) XMLREGISTRY=yes ;;
  no)  XMLREGISTRY=no  ;;
  *)   AC_MSG_ERROR([bad value ${enableval} for --enable-xml-registry]) ;;
esac], [XMLREGISTRY=no])

if test "x$XMLREGISTRY" = "xyes" ; then
  PKG_CHECK_MODULES([LIBXML2], [libxml-2.0],,
      [AC_MSG_ERROR([libxml2 development files required])])
  UTILITY_CFLAGS="${UTILITY_CFLAGS} ${LIBXML2_CFLAGS}"
  UTILITY_LIBS="${UTILITY_LIBS} ${LIBXML2_LIBS}"
  AC_DEFINE([FREECIV_HAVE_XML_REGISTRY], [1], [Build xml-backend for registry])
fi

dnl Set debug flags supported by compiler
EXTRA_DEBUG_CFLAGS=""
EXTRA_DEBUG_CXXFLAGS=""
EXTRA_DEBUG_LDFLAGS=""
dnl check debugging
FC_DEBUG
dnl check profiling
FC_GPROF

AC_C99_VARIADIC_MACROS
AC_C99_VARIABLE_ARRAYS
AC_C99_INITIALIZERS
AC_C99_STDINT_H

FC_C99_INITIALIZER_BRACES

FC_C11_STATIC_ASSERT
FC_C11_AT_QUICK_EXIT

FC_CXX11_STATIC_ASSERT
FC_CXX11_NULLPTR

dnl BeOS-specific settings
if test x`$UNAME -s` = xBeOS ; then
  AC_DEFINE([FREECIV_SOCKET_ZERO_NOT_STDIN], [1], [BeOS-specific setting])
  CFLAGS="$CFLAGS -Wno-multichar"
  LDFLAGS="$LDFLAGS -x none"
  if test x$enable_debug = xyes ; then
    CFLAGS="$CFLAGS -gdwarf-2"
    LDFLAGS="$LDFLAGS -gdwarf-2"
  fi
  # We used to set ARFLAGS here, but under recent versions of automake this
  # broke compilation on other systems.  Setting ARFLAGS shouldn't be
  # necessary with a working automake.
fi

dnl Defaults to override with host specific values
HOST_PATH_SEPARATOR=":"
HOST_DIR_SEPARATOR="/"

dnl Settings specific to host OS
case "$host_os" in

  *mingw*)
    dnl Windows-specific settings
    AC_CHECK_TOOL([WINDRES], [windres])
    if test -z $WINDRES; then
	  AC_MSG_ERROR([*** 'windres' missing.  Install binutils, fix your \$PATH, or set \$WINDRES manually. ***])
    fi

    HOST_PATH_SEPARATOR=";"
    HOST_DIR_SEPARATOR="\\"

    AC_DEFINE([FREECIV_SOCKET_ZERO_NOT_STDIN], [1], [Mingw-specific setting - stdin])
    AC_DEFINE([ALWAYS_ROOT], [1], [Can execute program as root - Mingw])
    AC_DEFINE([FREECIV_MSWINDOWS], [1], [Windows build])

    dnl Backward compatibility macro, FREECIV_MSWINDOWS is the preferred one, and
    dnl one that must be used in public headers.
    AC_DEFINE([WIN32_NATIVE], [1], [Mingw-specific setting - native])
    AC_DEFINE([NONBLOCKING_SOCKETS], [1], [nonblocking sockets support])
    ;;

  *skyos*)
    dnl SkyOS specific settings
    AC_DEFINE([ALWAYS_ROOT], [1], [Can execute program as root - SkyOS])
    ;;

  *haiku*)
    dnl Haiku specific settings
    AC_DEFINE([ALWAYS_ROOT], [1], [Can execute program as root - Haiku])
    LIBS="$LIBS -lnetwork"
    ;;

  *amigaos*)
    AMIGA=yes
    AC_DEFINE([ALWAYS_ROOT], [1], [Can execute program as root - Amiga])
    ;;

esac

dnl Autoconf provides path separator for build system.
dnl Use that instead of our own guess in case of native build.
dnl Actually; Don't, since at least with autoconf-2.69 msys2 builds got wrong separator this way
dnl if test x$build = x$host ; then
dnl   HOST_PATH_SEPARATOR=$PATH_SEPARATOR
dnl fi

dnl note this has to match the path installed by translations/freeciv/Makefile
if test x"$MINGW" != "xyes"; then
  CPPFLAGS="$CPPFLAGS -DLOCALEDIR=\"\\\"$localedir\\\"\""
else
  AC_DEFINE_UNQUOTED([LOCALEDIR], [".\\\\share\\\\locale"], [Locale directory (windows)])
fi

CPPFLAGS="$CPPFLAGS -DBINDIR=\"\\\"$bindir\\\"\""

COMMON_LIBS=-lm

dnl Check for zlib
AC_CHECK_LIB([z], [gzgets],
  [AC_DEFINE([FREECIV_HAVE_LIBZ], [1], [zlib is available])
UTILITY_LIBS="${UTILITY_LIBS} -lz"
COMMON_LIBS="$COMMON_LIBS -lz"], 
  AC_MSG_ERROR([Could not find zlib library.]))

AC_CHECK_HEADER(zlib.h, , 
  AC_MSG_ERROR([zlib found but not zlib.h.
You may need to install a zlib devel package.]))

AC_PATH_PROG(GZIP, gzip, "no")
if test "$GZIP" = "no"; then
  AC_MSG_ERROR([You need the gzip program for compilation.])
fi

dnl Check for bzip2 compression
AC_ARG_WITH([libbz2],
  AS_HELP_STRING([--with-libbz2], [support bzip2 compressed files [if_possible]]),
[WITH_BZ2="${withval}"],
[WITH_BZ2="test"])

if test "x$WITH_BZ2" != xno ; then
  AC_CHECK_LIB([bz2], [BZ2_bzReadOpen],
    [AC_CHECK_HEADERS([bzlib.h],
     [AC_DEFINE([FREECIV_HAVE_LIBBZ2], [1], [libbzip2 is available])
  UTILITY_LIBS="${UTILITY_LIBS} -lbz2"
  libbz2_available=true])])
  if test "x$libbz2_available" != "xtrue" ; then
    if test "x$WITH_BZ2" = "xyes" ; then
      AC_MSG_ERROR([Could not find libbz2 devel files])
    fi
    feature_bz2=missing
  fi
fi

dnl Check for xz compression
AC_ARG_WITH([liblzma],
  AS_HELP_STRING([--with-liblzma], [support xz compressed files [if_possible]]),
[WITH_XZ="${withval}"],
[WITH_XZ="test"])

if test "x$WITH_XZ" != xno ; then
  AC_CHECK_LIB([lzma], [lzma_code],
    [AC_CHECK_HEADERS([lzma.h],
     [AC_DEFINE([FREECIV_HAVE_LIBLZMA], [1], [liblzma is available])
  UTILITY_LIBS="${UTILITY_LIBS} -llzma"
  libxz_available=true])])
  if test "x$libxz_available" != "xtrue" ; then
    if test "x$WITH_XZ" = "xyes" ; then
      AC_MSG_ERROR([Could not find liblzma devel files])
    fi
    feature_xz=missing
  fi
fi

UTILITY_LIBS="${UTILITY_LIBS} ${LTLIBINTL}"

AC_SUBST([UTILITY_CFLAGS])
AC_SUBST([UTILITY_LIBS])
AC_SUBST([COMMON_LIBS])

AC_ARG_ENABLE([crosser],
  AS_HELP_STRING([--enable-crosser], [build version to be used with crosser environment]),
[case "${enableval}" in
  yes) crosser=yes
       AC_DEFINE([CROSSER], [1], [this is crosser based build]) ;;
  no)  crosser=no ;;
  *)   AC_MSG_ERROR([bad value ${enableval} for --enable-crosser]) ;;
esac], [crosser=no])
if test x$crosser = xyes && test x$MINGW != xyes ; then
  AC_MSG_ERROR([--enable-crosser is Windows build specific option])
fi

AC_ARG_WITH([cacert-path],
  AS_HELP_STRING([--with-cacert-path], [path to ca cert bundle]),
[case "${withval}" in
 yes) AC_MSG_ERROR([Path must be given for --with-cacert-path]) ;;
 *)   custom_cacert_path="${withval}" ;;
esac])

if test "x$custom_cacert_path" != "x" ; then
  AC_DEFINE_UNQUOTED([CUSTOM_CACERT_PATH], ["$custom_cacert_path"], [Path to CA cert bundle])
fi

dnl Check thread implementation
AC_MSG_CHECKING([for threads implementation])
thread_impl=none

CFLAGS_SAVE="${CFLAGS}"
LIBS_SAVE="${LIBS}"

if test x$crosser != xyes ; then
  FC_C_FLAGS([-pthread], [], [CFLAGS])
  FC_LD_FLAGS([-pthread], [], [LIBS])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
    [[return pthread_create(NULL, NULL, NULL, NULL);]])],
    [AC_DEFINE([FREECIV_HAVE_PTHREAD], [1], [Use pthreads as thread implementation])
    thread_impl=pthreads
    AC_MSG_RESULT([pthreads])
    AC_DEFINE([FREECIV_HAVE_THREAD_COND], [1], [Has thread condition variable implementation])])
    thread_cond=true
fi

if test "x$thread_impl" = "xnone" ; then
  CFLAGS="$CFLAGS_SAVE"
  LDFLAGS="$LDFLAGS_SAVE"

  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <windows.h>]],
    [[CreateThread(NULL, 0, NULL, NULL, 0, NULL);]])],
    [AC_DEFINE([FREECIV_HAVE_WINTHREADS], [1], [Use Windows threads as thread implementation])
    thread_impl=windows
    AC_MSG_RESULT([windows])])
fi

if test "x$thread_impl" = "xnone" ; then
  AC_MSG_ERROR([No usable thread implementation available])
fi

if test "x$thread_cond" != "xtrue" ; then
  feature_thr_cond=missing
fi

dnl Check and choose clients
if test "x$client" != "xno"; then

  dnl Check for sound support, sets SOUND_CFLAGS, SOUND_LIBS, AUDIO_SDL
  dnl Client gui checks need to know which mixer version this has selected
  FC_CHECK_SOUND()

  dnl if specified --with-xaw or --with-xaw3d, assume --enable-client=xaw
  if test -n "$WITH_XAW" || test -n "$WITH_XAW3D"; then
    if test "x$client" = "xauto" ; then
      gui_xaw=yes
      client=yes
    elif test "x$client" = "xall" ; then
      gui_xaw=yes
    fi
  fi

  dnl if need to guess client, announce checking
  if test "x$client" = "xauto"; then
    AS_MESSAGE([checking for which client to compile:...])
  elif test "x$client" = "xall" ; then
    AS_MESSAGE([checking for which clients to compile:...])
  fi

  dnl Gtk-3.0-specific overrides
  FC_GTK3_CLIENT

  dnl Gtk-3.22-specific overrides
  FC_GTK3_22_CLIENT

  dnl Gtk-2.0-specific overrides
  FC_GTK2_CLIENT

  dnl QT-specific overrides
  FC_QT_CLIENT

  dnl SDL-specific overrides
  FC_SDL_CLIENT

  dnl SDL2-specific overrides
  FC_SDL2_CLIENT

  dnl Xaw-specific overrides
  FC_XAW_CLIENT

  dnl Stub-specific overrides
  if test "x$gui_stub" = "xyes" || test "x$client" = "xall" ; then
    gui_stub=yes
    if test "x$client" = "xauto" ; then
      client=yes
    fi
    gui_stub_libs="-lm"
  fi

  dnl If client still "auto", error out since we couldn't select any of them
  if test "x$client" = "xauto" ; then
    AC_MSG_ERROR([can not build any of the supported clients])
  fi
fi

if test "x$client" = "xall" ; then
  if test "x$gui_gtk2" = "xyes" ||
     test "x$gui_gtk3_22" = "xyes" ||
     test "x$gui_gtk3" = "xyes" ||
     test "x$gui_sdl" = "xyes" ||
     test "x$gui_sdl2" = "xyes" ||
     test "x$gui_xaw" = "xyes" ||
     test "x$gui_qt" = "xyes" ||
     test "x$gui_stub" = "xyes" ; then
    client=yes
  else
    client=no
  fi
fi

FC_LD_FLAGS(["-Wl,-rpath=${lib_prefix}"], [], [LDFLAGS])

AM_CONDITIONAL([CLIENT], [test "x$client" = "xyes"])

AC_ARG_ENABLE([freeciv-manual],
  AS_HELP_STRING([--enable-freeciv-manual=no/yes/wiki/html], [build freeciv-manual [wiki]]),
[case "${enableval}" in
  yes|wiki) fcmanual=wiki ;;
  no)       fcmanual=no ;;
  html)     fcmanual=html ;;
  *) AC_MSG_ERROR([bad value ${enableval} for --enable-freeciv-manual]) ;;
esac], [fcmanual=wiki])

AM_CONDITIONAL([FCMANUAL], [test "x$fcmanual" != "xno"])

if test x$fcmanual = xhtml ; then
  AC_DEFINE([MANUAL_USE_HTML], [1], [Build freeciv-manual with html formatting])
fi

dnl freeciv-modpack checks
AC_ARG_ENABLE([fcmp],
  AS_HELP_STRING([--enable-fcmp=no/yes/gtk2/gtk3/qt/cli/all/auto], [build freeciv-modpack-program [auto]]),
[fc_mp=${enableval}],
[fc_mp=auto])

fcmp_cli=no
fcmp_gtk2=no
fcmp_gtk3=no
fcmp_qt=no
fcmp_list=

if test "x$fc_mp" = "xcli" ; then
  dnl Only cli requested -> no gui needed
  modinst=cli
fi

for mp in $(echo $fc_mp | $SED 's/,/ /g') ; do
  if test "x$mp" = "xno" ; then
    modinst=no
  elif test "x$mp" = "xauto" || test "x$mp" = "xyes" ; then
    modinst=auto
  elif test "x$mp" = "xall" ; then
    modinst=all
  else if test "x$mp" = "xgtk2"   ||
          test "x$mp" = "xgtk2.0" ||
          test "x$mp" = "xgtk20"  ||
          test "x$mp" = "xgtk-2.0" ; then
      req_fcmp_gtk2=yes
    elif test "x$mp" = "xgtk3"   ||
         test "x$mp" = "xgtk3.0" ||
         test "x$mp" = "xgtk30"  ||
         test "x$mp" = "xgtk-3.0" ; then
      req_fcmp_gtk3=yes
    elif test "x$mp" = "xqt" ; then
      req_fcmp_qt=yes
    elif test "x$mp" = "xcli" ; then
      req_fcmp_cli=yes
    elif test "x$mp" != "xyes" ; then
      AC_MSG_ERROR([bad value ${mp} for --enable-fcmp])
    fi
  fi
done

if test "x$req_fcmp_gtk3" = "xyes" ||
   test "x$modinst" = "xall" || test "x$modinst" = "xauto" ; then
  PKG_CHECK_MODULES([GTK3MP], [gtk+-3.0 >= 3.8.0],
[
  GTK3MP_CFLAGS="$GTK3MP_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_8 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_8"
  GTK3MP_CFLAGS="$GTK3MP_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36"
  PKG_CHECK_MODULES([GTHREAD_GTK3], [gthread-2.0],
[
  fcmp_gtk3=yes
  fcmp_list="$fcmp_list gtk3"
  mp_gtk3_cflags="$GTK3MP_CFLAGS $GTHREAD_GTK3_CFLAGS"
  mp_gtk3_libs="$GTK3MP_LIBS $GTHREAD_GTK3_LIBS"
  if test "x$MINGW" = "xyes"; then
    dnl Required to compile gtk3 on Windows platform
    mp_gtk3_cflags="$mp_gtk3_cflags -mms-bitfields"
    mp_gtk3_ldflags="$mp_gtk3_ldflags -mwindows"
  fi

  if test "x$modinst" = "xauto" ; then
    modinst=found
  fi
], [fcmp_gtk3=no])], [fcmp_gtk3=no])
fi

if test "x$req_fcmp_gtk3" = "xyes" && test "x$fcmp_gtk3" != "xyes" ; then
  AC_MSG_ERROR([Cannot build gtk3-version of freeciv-modpack as requested])
fi

if test "x$req_fcmp_gtk2" = "xyes" ||
   test "x$modinst" = "xauto" || test "x$modinst" = "xall" ; then
  AM_PATH_GTK_2_0([2.12.0],
[
  PKG_CHECK_MODULES([GTHREAD_GTK2], [gthread-2.0],
[
  fcmp_gtk2=yes
  fcmp_list="$fcmp_list gtk2"
  mp_gtk2_cflags="$GTK2_CFLAGS $GTHREAD_GTK2_CFLAGS"
  mp_gtk2_libs="$GTK2_LIBS $GTHREAD_GTK2_LIBS"
  if test "x$MINGW" = "xyes"; then
     dnl Required to compile gtk2 on Windows platform
     mp_gtk2_cflags="$mp_gtk2_cflags -mms-bitfields"
     mp_gtk2_ldflags="$mp_gtk2_ldflags -mwindows"
  fi

  if test "x$modinst" = "xauto" ; then
    modinst=found
  fi
], [])], [])
fi

if test "x$req_fcmp_gtk2" = "xyes" && test "x$fcmp_gtk2" != "xyes" ; then
  AC_MSG_ERROR([Cannot build gtk2-version of freeciv-modpack as requested])
fi

if test "x$req_fcmp_qt" = "xyes" ||
   test "x$modinst" = "xauto" || test "x$modinst" = "xall" ; then

   if test "x$cxx_works" = "xyes" ; then
     FC_QT5

     if test "x$fc_qt5_usable" = "xtrue" ; then
       fcmp_qt=yes
       fcmp_list="$fcmp_list qt"

       mp_qt_cppflags=$FC_QT5_CPPFLAGS
       mp_qt_cxxflags=$FC_QT5_CXXFLAGS
       mp_qt_libs=$FC_QT5_LIBS

       if test "x$modinst" = "xauto" ; then
         modinst=found
       fi
     fi
   fi

fi

if test "x$req_fcmp_qt" = "xyes" && test "x$fcmp_qt" != "xyes" ; then
  AC_MSG_ERROR([Cannot build Qt-version of freeciv-modpack as requested])
fi

dnl Cli does not satisfy --enable-fcmp=auto as it's not an gui.
if test "x$req_fcmp_cli" = "xyes" || test "x$modinst" = "xall" ; then
  fcmp_cli=yes
  fcmp_list="$fcmp_list cli"
fi

if test "x$modinst" != "xfound" &&
   test "x$modinst" != "xno" &&
   test "x$modinst" != "xcli" &&
   test "x$fcmp_gtk3" != "xyes" &&
   test "x$fcmp_gtk2" != "xyes" &&
   test "x$fcmp_qt" != "xyes" ;then
  AC_MSG_ERROR([Cannot build modpack installer with any gui])
fi 

if test "x$modinst" != "xno" && test "x$MINGW" != "xyes" ; then
  dnl Hack to get a run-time icon -- not needed on Windows
  mp_gtk2_cflags="$mp_gtk2_cflags -DMPICON_PATH=\"\\\"$datadir/freeciv/misc/mpicon.png\\\"\""
  mp_gtk3_cflags="$mp_gtk3_cflags -DMPICON_PATH=\"\\\"$datadir/freeciv/misc/mpicon.png\\\"\""
fi

if test "x$fcmp_list" = "x" ; then
  fcmp_list="none"
fi

AM_CONDITIONAL([MODINST], [test "x$modinst" != "xno"])
AM_CONDITIONAL([MODINST_GTK3], [test "x$fcmp_gtk3" = "xyes"])
AM_CONDITIONAL([MODINST_GTK2], [test "x$fcmp_gtk2" = "xyes"])
AM_CONDITIONAL([MODINST_QT], [test "x$fcmp_qt" = "xyes"])
AM_CONDITIONAL([MODINST_CLI], [test "x$fcmp_cli" = "xyes"])

AC_ARG_ENABLE([ruledit],
  AS_HELP_STRING([--enable-ruledit], [build freeciv-ruledit (WIP)]),
[case "${enableval}" in
  yes)  ruledit=yes ;;
  no)   ruledit=no ;;
  test) ruledit=test ;;
  *)   AC_MSG_ERROR([bad value ${enableval} for --enable-ruledit]) ;;
esac], [ruledit=test])
if test "x$ruledit" = "xyes" || test "x$ruledit" = "xtest" ; then
  if test "x$cxx_works" = "xyes" ; then
    FC_QT5

    if test "x$fc_qt5_usable" = "xtrue" ; then
      ruledit_cppflags=$FC_QT5_CPPFLAGS
      ruledit_cxxflags=$FC_QT5_CXXFLAGS
      ruledit_libs=$FC_QT5_LIBS
      ruledit=yes
    elif test "x$ruledit" = "xyes" ; then
      AC_MSG_ERROR([Qt5 not found for building freeciv-ruledit])
    fi
  elif test "x$ruledit" = "xyes" ; then
    AC_MSG_ERROR([No working C++ compiler found for building freeciv-ruledit])
  fi
fi
if test "x$ruledit" = "xtest" ; then
  dnl Still not set to 'yes' so failed tests
  ruledit=no
  feature_ruledit=missing
fi
AM_CONDITIONAL([RULEDIT], [test "x$ruledit" = "xyes"])

AC_SUBST([gui_gtk2_cflags])
AC_SUBST([gui_gtk2_libs])
AC_SUBST([gui_gtk2_ldflags])
AC_SUBST([gui_gtk3_22_cflags])
AC_SUBST([gui_gtk3_22_libs])
AC_SUBST([gui_gtk3_22_ldflags])
AC_SUBST([gui_gtk3_cflags])
AC_SUBST([gui_gtk3_libs])
AC_SUBST([gui_gtk3_ldflags])
AC_SUBST([gui_sdl_cflags])
AC_SUBST([gui_sdl_libs])
AC_SUBST([gui_sdl_ldflags])
AC_SUBST([gui_sdl2_cflags])
AC_SUBST([gui_sdl2_libs])
AC_SUBST([gui_sdl2_ldflags])
AC_SUBST([gui_xaw_cflags])
AC_SUBST([gui_xaw_libs])
AC_SUBST([gui_xaw_ldflags])
AC_SUBST([gui_qt_cppflags])
AC_SUBST([gui_qt_cflags])
AC_SUBST([gui_qt_cxxflags])
AC_SUBST([gui_qt_libs])
AC_SUBST([gui_qt_ldflags])
AC_SUBST([gui_stub_cflags])
AC_SUBST([gui_stub_libs])
AC_SUBST([gui_stub_ldflags])
AC_SUBST([mp_cli_cflags])
AC_SUBST([mp_cli_libs])
AC_SUBST([mp_cli_ldflags])
AC_SUBST([mp_gtk2_cflags])
AC_SUBST([mp_gtk2_libs])
AC_SUBST([mp_gtk2_ldflags])
AC_SUBST([mp_gtk3_cflags])
AC_SUBST([mp_gtk3_libs])
AC_SUBST([mp_gtk3_ldflags])
AC_SUBST([mp_qt_cppflags])
AC_SUBST([mp_qt_cxxflags])
AC_SUBST([mp_qt_libs])
AC_SUBST([ruledit_cppflags])
AC_SUBST([ruledit_cxxflags])
AC_SUBST([ruledit_libs])
AC_SUBST([SOUND_CFLAGS])
AC_SUBST([SOUND_LIBS])
AC_SUBST([VERSION_LABEL])
AC_SUBST([HOST_PATH_SEPARATOR])
AC_SUBST([HOST_DIR_SEPARATOR])
AM_CONDITIONAL(AUDIO_SDL, test "x$SDL_mixer" != "xno")
AM_CONDITIONAL(CLIENT_GUI_SDL, test "x$gui_sdl" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_SDL2, test "x$gui_sdl2" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_GTK_2_0, test "x$gui_gtk2" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_GTK_3_22, test "x$gui_gtk3_22" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_GTK_3_0, test "x$gui_gtk3" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_XAW, test "x$gui_xaw" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_QT, test "x$gui_qt" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_STUB, test "x$gui_stub" = "xyes")
AM_CONDITIONAL(MINGW, test x"$MINGW" = "xyes")

dnl Additional client libraries:
if test "x$client" = "xyes"; then
    CLIENT_LIBS=" -lm "
    AC_SUBST(CLIENT_LIBS)
fi

dnl Checks for additional server libraries:
if test "x$server" = "xyes"; then
    SERVER_LIBS="-lm ${SERVER_LIBS}"

    dnl Some systems (e.g., BeOS) need this lib
    AC_CHECK_LIB(bind, gethostbyaddr, SERVER_LIBS="-lbind $SERVER_LIBS")

    dnl Readline library and header files.
    FC_HAS_READLINE()
    AC_SUBST([SERVER_LIBS])
    AC_SUBST([SRV_LIB_LIBS])
fi

AC_CHECK_LIB(nls,main)

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([fcntl.h sys/utsname.h \
                  sys/file.h signal.h strings.h execinfo.h \
                  libgen.h])
AC_CHECK_HEADERS([sys/time.h], [AC_DEFINE([FREECIV_HAVE_SYS_TIME_H], [1], [sys/time.h available])])
AC_CHECK_HEADERS([unistd.h], [AC_DEFINE([FREECIV_HAVE_UNISTD_H], [1], [unistd.h available])])
AC_CHECK_HEADERS([locale.h], [AC_DEFINE([FREECIV_HAVE_LOCALE_H], [1], [locale.h available])])
AC_CHECK_HEADERS([libintl.h], [AC_DEFINE([FREECIV_HAVE_LIBINTL_H], [1], [libint.h available])])
AC_HEADER_STDBOOL
if test $ac_cv_header_stdbool_h = yes; then
  AC_DEFINE([FREECIV_HAVE_STDBOOL_H], [1], [Have standard compliant stdbool.h])
fi

AC_CHECK_HEADERS([pwd.h])

dnl Avoid including the unix emulation layer if we build mingw executables
dnl There would be type conflicts between winsock and bsd/unix includes
if test "x$MINGW" != "xyes"; then
  AC_CHECK_HEADERS([arpa/inet.h netdb.h sys/ioctl.h \
                    sys/signal.h sys/termio.h \
                    sys/uio.h termios.h])
  AC_CHECK_HEADERS([sys/select.h], [AC_DEFINE([FREECIV_HAVE_SYS_SELECT_H], [1], [sys/select.h available])])
  AC_CHECK_HEADERS([netinet/in.h], [AC_DEFINE([FREECIV_HAVE_NETINET_IN_H], [1], [netinet/in.h available])])
fi
if test "x$gui_xaw" = "xyes" ; then
  dnl Want to get appropriate -I flags:
  fc_save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$CPPFLAGS $gui_xaw_cflags"
  AC_CHECK_HEADER(X11/xpm.h, ,
    AC_MSG_ERROR(need X11/xpm.h header; perhaps try/adjust --with-xpm-include))
  CPPFLAGS="$fc_save_CPPFLAGS"
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_TIME
AC_STRUCT_TM
AC_CHECK_TYPES([socklen_t], [AC_DEFINE([FREECIV_HAVE_SOCKLEN_T], [1], [Have socklen_t type defined])],
[],
[#ifdef FREECIV_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef FREECIV_HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef FREECIV_HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif
])
AC_TYPE_INTPTR_T
dnl Headers that might contain the intptr_t definition found earlier
AC_CHECK_HEADERS([inttypes.h],
  [AC_DEFINE([FREECIV_HAVE_INTTYPES_H], [1], [inttypes.h available])])
AC_CHECK_HEADERS([stdint.h],
  [AC_DEFINE([FREECIV_HAVE_STDINT_H], [1], [stdint.h available])])

dnl Checks for library functions.
AC_FUNC_FORK
AC_FUNC_STRCOLL
AC_FUNC_VPRINTF
AC_FUNC_FSEEKO

dnl Windows vsnprintf doesn't support argument reordering (see PR#12932)
if test "x$MINGW" != "xyes"; then
dnl The use of both FC_FUNC_VSNPRINTF and AC_CHECK_FUNCS(vsnprintf) is
dnl deliberate.
FC_FUNC_VSNPRINTF
AC_CHECK_FUNCS([vsnprintf])
fi

AC_CHECK_FUNCS([bind connect fileno flock ftime gethostbyname gethostname \
		getpwuid inet_aton select snooze strcasecmp strcasestr \
		strerror strlcat strlcpy strncasecmp strstr uname usleep \
                getline _strcoll stricoll _stricoll strcasecoll \
                backtrace])

dnl Possible "-Wmissing-declarations" and "-Werror" will prune out
dnl cases where we should not use _mkdir() even if it's possible to link against it
fc_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -Werror $EXTRA_DEBUG_CFLAGS"
AC_CHECK_FUNCS([_mkdir])
CPPFLAGS="$fc_save_CPPFLAGS"

AC_MSG_CHECKING(for working gettimeofday)
  FC_CHECK_GETTIMEOFDAY_RUNTIME(,AC_DEFINE([HAVE_GETTIMEOFDAY], [1],
	[Define if the gettimeofday function works and is sane.]),)

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netinet/in.h>]],
[[struct ip_mreqn req; req.imr_ifindex = 0;]])],
[AC_DEFINE([HAVE_IP_MREQN], [1], [struct ip_mreqn available])])

dnl Check for extra socket libraries.
dnl If the AC_CHECK_FUNCS check finds the function, we don't look any
dnl further.  This is rumoured to prevent choosing the wrong libs on IRIX.
if test $ac_cv_func_gethostbyname = no; then
  AC_CHECK_LIB(nsl, gethostbyname, LIBS="-lnsl $LIBS")
fi
if test $ac_cv_func_connect = no; then
  AC_CHECK_LIB(socket, connect, LIBS="-lsocket $LIBS")
fi
if test $ac_cv_func_bind = no; then
  AC_CHECK_LIB(bind, gethostbyaddr, LIBS="-lbind $LIBS")
fi

dnl Windows fdopen does not work with sockets.
if test "x$MINGW" != "xyes"; then
  AC_CHECK_FUNCS(fdopen)
fi

dnl We would AC_CHECK_FUNCS for socket as well, except it is complicated
dnl by the fact that the -lsocket is in X_EXTRA_LIBS and/or SERVER_LIBS,
dnl and not in LIBS.

dnl Now check if non blocking sockets are possible
dnl (if fcntl or ioctl exists)

AC_CHECK_FUNC([fcntl],
              [AC_DEFINE([HAVE_FCNTL], [1], [fcntl support])
               AC_DEFINE([NONBLOCKING_SOCKETS], [1], [nonblocking sockets support])],
               [AC_CHECK_FUNC([ioctl], 
                             [AC_DEFINE([HAVE_IOCTL], [1], [ioctl support])
                              AC_DEFINE([NONBLOCKING_SOCKETS], [1], [nonblocking sockets support])])])

dnl Checks if SIGPIPE is usable
AC_MSG_CHECKING([for SIGPIPE])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>]], [[signal (SIGPIPE, SIG_IGN)]])],[AC_MSG_RESULT([yes])
                AC_DEFINE([HAVE_SIGPIPE], [1], [sigpipe support])],[AC_MSG_RESULT([no])])

dnl export where the datadir is going to be installed
FC_EXPAND_DIR(FREECIV_DATADIR, "$datadir/freeciv")

if test x"$MINGW" = xyes; then
  DEFAULT_SAVE_PATH=".;~\\\\\\\\.freeciv\\\\\\\\saves"
  if test x$crosser = xyes ; then
    FC_CONF_PATH="../etc/freeciv"
    DEFAULT_DATA_PATH=".;data;~/.freeciv/$DATASUBDIR;$datadir/freeciv;../share/freeciv"
    DEFAULT_SCENARIO_PATH=".;data/scenarios;~/.freeciv/$DATASUBDIR/scenarios;~/.freeciv/scenarios;$datadir/freeciv/scenarios;../share/freeciv/scenarios"
  else
    FC_CONF_PATH="etc\\\\\\\\freeciv"
    DEFAULT_DATA_PATH=".;data;~\\\\\\\\.freeciv\\\\\\\\$DATASUBDIR;$datadir\\\\\\\\freeciv"
    DEFAULT_SCENARIO_PATH=".;data\\\\\\\\scenarios;~\\\\\\\\.freeciv\\\\\\\\$DATASUBDIR\\\\\\\\scenarios;~\\\\\\\\.freeciv\\\\\\\\scenarios;$datadir\\\\\\\\freeciv\\\\\\\\scenarios"
  fi
else
  FC_CONF_PATH="$sysconfdir/freeciv"
  DEFAULT_DATA_PATH=".:data:~/.freeciv/$DATASUBDIR:$datadir/freeciv"
  DEFAULT_SAVE_PATH=".:~/.freeciv/saves"
  DEFAULT_SCENARIO_PATH=".:data/scenarios:~/.freeciv/$DATASUBDIR/scenarios:~/.freeciv/scenarios:$datadir/freeciv/scenarios"
fi
CPPFLAGS="$CPPFLAGS -DFC_CONF_PATH=\"\\\"$FC_CONF_PATH\\\"\""
CPPFLAGS="$CPPFLAGS -DDEFAULT_DATA_PATH=\"\\\"$DEFAULT_DATA_PATH\\\"\""
CPPFLAGS="$CPPFLAGS -DDEFAULT_SAVE_PATH=\"\\\"$DEFAULT_SAVE_PATH\\\"\""
CPPFLAGS="$CPPFLAGS -DDEFAULT_SCENARIO_PATH=\"\\\"$DEFAULT_SCENARIO_PATH\\\"\""

dnl This has to be last library
if test -n "$WITH_EFENCE"; then
  AC_CHECK_LIB(efence, malloc, [ 
  if test "x$LIBS" = "x"; then
    LIBS = -lefence
  else
    LIBS="$LIBS -lefence"
  fi])
fi

AC_ARG_ENABLE([sys-lua],
  AS_HELP_STRING([--enable-sys-lua], [use lua from system instead of one from freeciv tree [test]]),
[case "${enableval}" in
  yes)
    sys_lua=true ;;
  no)
    sys_lua=false ;;
  test)
    sys_lua=test ;;
  *)   AC_MSG_ERROR([bad value ${enableval} for --enable-sys-lua]) ;;
esac], [sys_lua=test])

dnl There's wide divergence on what the pkg-config file for Lua is called
dnl See http://lua-users.org/lists/lua-l/2008-09/msg00184.html
if test "x$sys_lua" = "xtrue" || test "x$sys_lua" = "xtest" ; then
  PKG_CHECK_MODULES([LUA], [lua5.3], [sys_lua=true],
    [PKG_CHECK_MODULES([LUA], [lua-5.3], [sys_lua=true],
      [PKG_CHECK_MODULES([LUA], [lua >= 5.3 lua < 5.4], [sys_lua=true],
[if test "x$sys_lua" = "xtrue" ; then
  AC_MSG_ERROR([Use of included lua disabled, and no lua found from system])
fi
feature_syslua=missing
sys_lua=false])])])
fi

if test "x$sys_lua" != "xtrue" ; then
  dnl Checks needed for included lua.
  gl_FUNC_MKSTEMP
  if test "x$gl_cv_func_working_mkstemp" = xyes ; then
    dnl if only "guessing yes", do not try to use mkstemp, but fallback
    AC_DEFINE([HAVE_MKSTEMP], [1], [Have working mkstemp])
  fi
  AC_CHECK_FUNCS([popen pclose _longjmp _setjmp gmtime_r localtime_r])

  LUA_CFLAGS="-I\$(top_srcdir)/dependencies/lua-5.3/src"
  LUA_LIBS="\$(top_builddir)/dependencies/lua-5.3/src/liblua.la"
fi

AC_SUBST([LUA_CFLAGS])
AC_SUBST([LUA_LIBS])
AM_CONDITIONAL([SYS_LUA], [test "x$sys_lua" = "xtrue"])

if test x$enable_fcdb = xyes ; then
  LUASQL_CFLAGS="-I\$(top_srcdir)/dependencies/luasql/src"
  LUASQL_LIBS="\$(top_builddir)/dependencies/luasql/src/libluasql_base.la"
  if test x$fcdb_mysql = xyes ; then
    LUASQL_LIBS="$LUASQL_LIBS \$(top_builddir)/dependencies/luasql/src/libluasql_mysql.la"
  fi
  if test x$fcdb_postgres = xyes ; then
    LUASQL_LIBS="$LUASQL_LIBS \$(top_builddir)/dependencies/luasql/src/libluasql_postgres.la"
  fi
  if test x$fcdb_sqlite3 = xyes ; then
    LUASQL_LIBS="$LUASQL_LIBS \$(top_builddir)/dependencies/luasql/src/libluasql_sqlite3.la"
  fi
  LUASQL_AS_DEPENDENCY="$LUASQL_LIBS"
  LUASQL_LIBS="$LUASQL_LIBS $FCDB_MYSQL_LIBS $FCDB_POSTGRES_LIBS $FCDB_SQLITE3_LIBS"

  AC_SUBST([LUASQL_CFLAGS])
  AC_SUBST([LUASQL_LIBS])
  AC_SUBST([LUASQL_AS_DEPENDENCY])
fi

AC_ARG_ENABLE([sys-tolua-cmd],
  AS_HELP_STRING([--enable-sys-tolua-cmd], [use tolua command from build system instead of one from freeciv tree [true_when_cross-compiling]]),
[case "${enableval}" in
  yes)
    sys_tolua_cmd=true ;;
  no)
    if test "x$cross_compiling" = "xyes" ; then
      AC_MSG_ERROR([Must use external build system tolua command when cross-compiling])
    fi
    sys_tolua_cmd=false ;;
  *)
    sys_tolua_cmd=${enableval} ;;
esac], [
if test "x$cross_compiling" = "xyes" ; then
  sys_tolua_cmd=true
else
  sys_tolua_cmd=test
fi])

if test "x$sys_tolua_cmd" = "xtrue" || test "x$sys_tolua_cmd" = "xtest" ; then
  AC_PATH_PROG([TOLUA], [tolua], [notfound])
  if test "x$TOLUA" = "xnotfound" ; then
    if test "x$sys_tolua_cmd" = "xtest" ; then
      TOLUA="\$(top_builddir)/dependencies/tolua-5.2/src/bin/tolua$EXEEXT"
      sys_tolua_cmd=false
    else
      AC_MSG_WARN([tolua command not found])
      TOLUA="unavailable"
    fi
    feature_systolua_cmd=missing
  else
    sys_tolua_cmd=true
  fi
elif test "x$sys_tolua_cmd" != "xfalse" ; then
  TOLUA=$sys_tolua_cmd
else
  TOLUA="\$(top_builddir)/dependencies/tolua-5.2/src/bin/tolua$EXEEXT"
fi

AC_SUBST([TOLUA])

TOLUA_CFLAGS="-I\$(top_srcdir)/dependencies/tolua-5.2/include"
TOLUA_LIBS="\$(top_builddir)/dependencies/tolua-5.2/src/lib/libtolua.la"
AC_SUBST([TOLUA_CFLAGS])
AC_SUBST([TOLUA_LIBS])

AM_CONDITIONAL([SYS_TOLUA_CMD], [test "x$sys_tolua_cmd" != "xfalse"])

dnl The BeOS sys/uio.h is broken.  This kludges it out of existence.
dnl (This still causes lots of spurious changes to fc_config.h on BeOS.)
AC_CONFIG_COMMANDS([fc_default-5],[[if test x`uname -s` = xBeOS ; then
     if grep '#define HAVE_SYS_UIO_H 1' fc_config.h >/dev/null 2>&1 ; then
       echo kluging fc_config.h
       mv -f fc_config.h fc_config.h.tmp
       sed -e 's/#define HAVE_SYS_UIO_H 1/#undef HAVE_SYS_UIO_H/g' fc_config.h.tmp > fc_config.h
       rm fc_config.h.tmp
     fi
   fi]],[[]])

CFLAGS="$EXTRA_DEBUG_CFLAGS $CFLAGS"
CXXFLAGS="$EXTRA_DEBUG_CXXFLAGS $CXXFLAGS"
LDFLAGS="$EXTRA_DEBUG_LDFLAGS $LDFLAGS"

dnl Rebuild 'configure' whenever fc_version changes, if maintainer mode enabled.
AC_SUBST([CONFIGURE_DEPENDENCIES], ["$CONFIGURE_DEPENDENCIES \$(top_srcdir)/fc_version"])

dnl Make sure that fc_config.h changes when ever CPPFLAGS, CFLAGS or CXXFLAGS
dnl change so everything gets rebuilt. LDFLAGS is not handled here
dnl since change in it should not cause recompilation, only relinking.
dnl Note: Variables are named FC_STORE_* instead of FC_*_STORE in order to
dnl make them appear next to each other in fc_config.h.
FC_STORE_CPPFLAGS="$(echo $CPPFLAGS | $SED 's/\\/\\\\/g' | $SED 's/\"/\\\"/g')"
AC_DEFINE_UNQUOTED([FC_STORE_CPPFLAGS], ["$FC_STORE_CPPFLAGS"],
                   [These are the CPPFLAGS used in compilation])
FC_STORE_CFLAGS="$(echo $CFLAGS | $SED 's/\\/\\\\/g' | $SED 's/\"/\\\"/g')"
AC_DEFINE_UNQUOTED([FC_STORE_CFLAGS], ["$FC_STORE_CFLAGS"],
                   [These are the CFLAGS used in compilation])
FC_STORE_CXXFLAGS="$(echo $CXXFLAGS | $SED 's/\\/\\\\/g' | $SED 's/\"/\\\"/g')"
AC_DEFINE_UNQUOTED([FC_STORE_CXXFLAGS], ["$FC_STORE_CXXFLAGS"],
                   [These are the CXXFLAGS used in compilation])

dnl If old default of AR_FLAGS is otherwise being used (because of older automake),
dnl replace it with one without 'u'
if test "x$AR_FLAGS" = "xcru" ; then
  AR_FLAGS="cr"
fi

AC_CONFIG_FILES([Makefile
          data/Makefile
	  data/hex2t/Makefile
          data/hexemplio/Makefile
	  data/amplio2/Makefile
	  data/buildings/Makefile
	  data/flags/Makefile
	  data/misc/Makefile
	  data/cimpletoon/Makefile
	  data/trident/Makefile
	  data/isophex/Makefile
	  data/isotrident/Makefile
	  data/stdsounds/Makefile
          data/stdmusic/Makefile
          data/override/Makefile
	  data/default/Makefile
	  data/classic/Makefile
	  data/multiplayer/Makefile
	  data/experimental/Makefile
          data/civ2civ3/Makefile
	  data/civ1/Makefile
	  data/civ2/Makefile
          data/sandbox/Makefile
	  data/scenarios/Makefile
	  data/nation/Makefile
	  data/themes/Makefile
	  data/themes/gui-gtk-2.0/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Arrows/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Buttons/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Check-Radio/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Combo/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Frame-Gap/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Handles/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Lines/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/ListHeaders/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Menu-Menubar/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Others/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Panel/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/ProgressBar/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Range/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Scrollbars/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Shadows/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Spin/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Tabs/Makefile
	  data/themes/gui-gtk-2.0/Freeciv/gtk-2.0/Toolbar/Makefile
	  data/themes/gui-gtk-3.0/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Arrows/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Buttons/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Check-Radio/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Combo/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Frame-Gap/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Handles/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Lines/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/ListHeaders/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Menu-Menubar/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Others/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Panel/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/ProgressBar/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Range/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Scrollbars/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Shadows/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Spin/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Tabs/Makefile
	  data/themes/gui-gtk-3.0/Freeciv/gtk-3.0/Toolbar/Makefile
	  data/themes/gui-gtk-3.22/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Arrows/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Buttons/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Check-Radio/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Combo/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Frame-Gap/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Handles/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Lines/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/ListHeaders/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Menu-Menubar/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Others/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Panel/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/ProgressBar/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Range/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Scrollbars/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Shadows/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Spin/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Tabs/Makefile
	  data/themes/gui-gtk-3.22/Freeciv/gtk-3.0/Toolbar/Makefile
	  data/themes/gui-qt/Makefile
	  data/themes/gui-qt/icons/Makefile
	  data/themes/gui-qt/Classic/Makefile
	  data/themes/gui-qt/Necrophos/Makefile
	  data/themes/gui-qt/NightStalker/Makefile
	  data/themes/gui-qt/System/Makefile
	  data/themes/gui-sdl/Makefile
	  data/themes/gui-sdl/human/Makefile
	  data/themes/gui-sdl2/Makefile
	  data/themes/gui-sdl2/human/Makefile
	  data/wonders/Makefile
	  data/icons/Makefile
	  utility/Makefile
	  dependencies/Makefile
	  dependencies/lua-5.3/Makefile
          dependencies/lua-5.3/src/Makefile
	  dependencies/tolua-5.2/Makefile
	  dependencies/tolua-5.2/src/Makefile
	  dependencies/tolua-5.2/src/lib/Makefile
          dependencies/tolua-5.2/src/bin/Makefile
          dependencies/luasql/Makefile
          dependencies/luasql/src/Makefile
          dependencies/cvercmp/Makefile  
	  common/Makefile
          common/aicore/Makefile
          common/scriptcore/Makefile
	  ai/Makefile
          ai/default/Makefile
          ai/classic/Makefile
          ai/stub/Makefile
          ai/threaded/Makefile
	  tests/Makefile
  	  win32/Makefile
	  client/Makefile
	  client/agents/Makefile
	  client/include/Makefile
	  client/gui-sdl/Makefile
          client/gui-sdl2/Makefile
	  client/gui-gtk-2.0/Makefile
	  client/gui-gtk-3.0/Makefile
          client/gui-gtk-3.22/Makefile
	  client/gui-xaw/Makefile
          client/gui-qt/Makefile
	  client/gui-stub/Makefile
          client/luascript/Makefile
	  server/Makefile
          server/advisors/Makefile
	  server/generator/Makefile
	  server/scripting/Makefile
          tools/Makefile
          tools/ruledit/Makefile
          gen_headers/Makefile
          translations/Makefile
	  translations/freeciv/Makefile.in
	  translations/nations/Makefile.in
          translations/ruledit/Makefile.in
	  doc/Makefile
	  doc/man/Makefile
          doc/man/freeciv-client.6
          doc/man/freeciv-server.6
          doc/man/freeciv-manual.6
	  doc/man/freeciv-modpack.6
	  doc/man/freeciv-ruledit.6
	  doc/ca/Makefile
	  doc/de/Makefile
	  doc/fr/Makefile
	  doc/it/Makefile
	  doc/ja/Makefile
	  doc/nl/Makefile
	  doc/sv/Makefile
          bootstrap/Makefile
	  data/Freeciv
          lua/Makefile
	  client/freeciv.desktop:bootstrap/freeciv.desktop.in
	  client/freeciv-gtk3.22.desktop:bootstrap/freeciv-gtk3.22.desktop.in
          client/freeciv-gtk2.desktop:bootstrap/freeciv-gtk2.desktop.in
          client/freeciv-sdl.desktop:bootstrap/freeciv-sdl.desktop.in
          client/freeciv-sdl2.desktop:bootstrap/freeciv-sdl2.desktop.in
          client/freeciv-qt.desktop:bootstrap/freeciv-qt.desktop.in
	  server/freeciv-server.desktop:bootstrap/freeciv-server.desktop.in
	  tools/freeciv-mp-gtk3.desktop:bootstrap/freeciv-mp-gtk3.desktop.in
	  tools/freeciv-mp-gtk2.desktop:bootstrap/freeciv-mp-gtk2.desktop.in
	  tools/freeciv-mp-qt.desktop:bootstrap/freeciv-mp-qt.desktop.in
	  tools/ruledit/freeciv-ruledit.desktop:bootstrap/freeciv-ruledit.desktop.in
          client/freeciv-gtk2.appdata.xml:bootstrap/freeciv-gtk2.appdata.xml.in
          client/freeciv-gtk3.appdata.xml:bootstrap/freeciv-gtk3.appdata.xml.in
          client/freeciv-gtk3.22.appdata.xml:bootstrap/freeciv-gtk3.22.appdata.xml.in
          client/freeciv-sdl.appdata.xml:bootstrap/freeciv-sdl.appdata.xml.in
          client/freeciv-sdl2.appdata.xml:bootstrap/freeciv-sdl2.appdata.xml.in
          client/freeciv-qt.appdata.xml:bootstrap/freeciv-qt.appdata.xml.in
          server/freeciv-server.appdata.xml:bootstrap/freeciv-server.appdata.xml.in
          tools/freeciv-mp-gtk2.appdata.xml:bootstrap/freeciv-mp-gtk2.appdata.xml.in
          tools/freeciv-mp-gtk3.appdata.xml:bootstrap/freeciv-mp-gtk3.appdata.xml.in
          tools/freeciv-mp-qt.appdata.xml:bootstrap/freeciv-mp-qt.appdata.xml.in
          tools/ruledit/freeciv-ruledit.appdata.xml:bootstrap/freeciv-ruledit.appdata.xml.in])
AC_CONFIG_FILES([fcgui:bootstrap/fcgui.in], [chmod +x fcgui])
AC_CONFIG_FILES([fcser:bootstrap/fcser.in], [chmod +x fcser])
if test "x$ruledit" = "xyes" ; then
  AC_CONFIG_FILES([fcruledit:bootstrap/fcruledit.in], [chmod +x fcruledit])
fi

AC_OUTPUT

AC_MSG_NOTICE([
****************** Configuration Summary ******************

  == General build options ==
  Shared libraries:      $enable_shared
  Debugging support:     $enable_debug
  Profiling support:     $enable_gprof
  IPv6 support:          $enable_ipv6
  Map image toolkits:    $enable_mapimg
    ppm:                   built-in
    MagickWand:            $mapimg_magickwand

  == Client ==
  Build freeciv client:  $client

  Maintained client frontends:
    Gtk-3.0:  $gui_gtk3
    Gtk-2.0:  $gui_gtk2
    Gtk-3.22: $gui_gtk3_22
    SDL:      $gui_sdl
    QT:       $gui_qt
    Stub:     $gui_stub

  In-development client frontends:
  (these are not yet ready for general use)
    SDL2:     $gui_sdl2

  Not maintained client frontends:
    Xaw:      $gui_xaw

  == Server ==
  Build freeciv server:  $server
    AI modules support:    $enable_aimodules
    Database support:      $enable_fcdb
      mysql:                 $fcdb_mysql
      postgres:              $fcdb_postgres
      sqlite3:               $fcdb_sqlite3

  == Tools ==
  Modpack installers:   $fcmp_list
  Ruleset editor:        $ruledit
  Manual generator:      $fcmanual
])

FC_MISSING_FEATURES