File: configure.pl

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (1916 lines) | stat: -rw-r--r-- 69,530 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
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

BEGIN {
   if ($] < 5.016) {
      print STDERR <<".";
polymake requires perl version not lower than 5.16;
your perl interpreter says it is $].

Please upgrade your perl installation;
if you already have an up-to-date perl interpreter somewhere else,
you can specify its location on the command line:

./configure PERL=/path/to/my/new/perl [other options ...]
.
      exit(1);
   } elsif ($] >= 5.042) {
      print STDERR <<".";
*************
*** ERROR ***
*************

polymake has not been checked for compatibility with perl 5.42 or newer;
your perl interpreter says it is $].

If you already have another (older) perl interpreter somewhere else, you can
specify its location on the command line:

./configure PERL=/path/to/my/new/perl [other options ...]

You can install a custom perl version in your home directory using perlbrew
(https://perlbrew.pl). Make sure to append '-Duseshrplib' to the install
command if you want to use libpolymake (e.g. for the jupyter interface) and to
install all required perl modules which are listed after running configure
again with the new perl.
.
      exit(1);
   }
}

use Config;
use Cwd;
use File::Path;

use strict 'vars', 'subs';
use lib "perllib";

my ($NeedsArchFlag);

my $Wiki="http://www.polymake.org/doku.php";

my $warning;

package FakeNoShell;
sub new { bless \(my $dummy) }
sub interactive { 0 }

# set autoflush
$| = 1;

# import some utilities and prepare the fake environment for them
package Polymake;
use vars qw( $DeveloperMode $Shell $filename_re $directory_of_cmd_re );

use Polymake::ConfigureStandalone;

$Shell=new FakeNoShell;
# we can't load regex.pl without compiled support for namespaces
$filename_re=qr{ ([^/]+) $ }x;
$directory_of_cmd_re=qr{ ^(.*) / [^/]+ (?: $ | \s)}x;

package Polymake::Configure;

@ARGV=grep { !/^PERL=/ } @ARGV;

my (%options, %vars, %allowed_options, %allowed_with, %allowed_flags, %allowed_vars);

# expected options for the core script
@allowed_options{ qw( prefix exec-prefix bindir includedir libdir libexecdir datadir docdir build build-modes ) }=();
@allowed_with{ qw( gmp mpfr boost permlib toolchain ccache ccwrapper ) }=();
@allowed_flags{ qw( prereq callable native openmp libcxx ) }=();
@allowed_vars{ qw( CC CFLAGS CXX CXXFLAGS CXXOPT CXXDEBUG LDFLAGS LIBS Arch DESTDIR ) }=();

if ($^O eq "darwin") {
  @allowed_with{ qw( fink brew ) }=();
}

my (@ext, @ext_disabled, %ext_with_config, %ext_requires, %ext_requires_opt, %ext_conflicts, %ext_failed, %ext_bad,
    @ext_ordered, %ext_survived);

my $repeating_config = early_parse_command_line();
my $root = Cwd::getcwd;
$Polymake::DeveloperMode = -d "$root/testscenarios";

my $BuildDir = $options{build} ? "build.$options{build}" : "build";
my $perlxpath = "perlx/$Config::Config{version}/$Config::Config{archname}";
my $perlextraflags = "";
my $autogold = 0;

load_enabled_bundled_extensions();
parse_command_line(\@ARGV, $repeating_config);
construct_paths();
determine_cxx_compiler();
determine_cxx_library();
if ($^O eq "darwin") {
   check_macos_package_manager();
}
determine_architecture();
collect_compiler_specific_options();
check_build_modes();
if ($options{'alt-perl'}) {
   create_alt_perl_configuration();
   exit(0);
}

my %store_versions;
locate_gmp_and_mpfr_libraries();
locate_boost_headers();
locate_permlib();

# there is no independent package for TOSimplex and Minimball, always pick the bundled headers
$ExternalHeaders .= " TOSimplex Miniball";


if ($options{prereq} ne ".none.") {
   check_prerequisite_perl_packages();
   if ($options{callable} ne ".none.") {
      check_libperl();
   }
}

# create the main build directory
File::Path::make_path("$BuildDir/$perlxpath");

my $BundledLOG;
my $BundledLOGfile="$BuildDir/bundled.log";

print "\nConfiguring bundled extensions:\n";
foreach my $ext (@ext_disabled) {
   print "bundled extension $ext ... disabled by command-line\n";
}
while (my ($ext, $err)=each %ext_bad) {
   print "bundled extension $ext ... disabled because of a fatal error\n";
   bundled_ext_error_msg($ext, $err);
}

order_enabled_bundled_extensions();
configure_enabled_bundled_extensions();
finalize_compiler_flags();
find_ninja();

File::Path::make_path($BuildDir);
write_configuration_file("$BuildDir/config.ninja");
write_perl_specific_configuration_file("$BuildDir/$perlxpath/config.ninja");
create_build_trees($root, "$root/$BuildDir", perlxpath => $perlxpath);
delete_old_and_disabled_build_trees();

if ($Polymake::DeveloperMode) {
   print <<"---";

* Configuration successful.
* You can run  'ninja -C $BuildDir/Opt'  now to build polymake with full optimization
* or  'ninja -C $BuildDir/Debug'  to build polymake with debugging support.
* To install an immutable snapshot of polymake at $InstallTop,
* run  'ninja -C $BuildDir/Opt install'.
*
* On systems with moderate amount of memory like laptops it is advisable to
* restrict the number of parallel build processes below the default ninja limit;
*   'ninja -l <NUMBERofCPUS>'  is a good approximation to start with.
* If the system still feels overloaded, take a lower hard job limit
*   'ninja -j <N>'  instead.
---
} else {
   print <<"---";

* Configuration successful.
* You can run 'ninja -C $BuildDir/Opt install' now to build and install polymake.
---
}

print $warning if defined $warning;
exit(0);

### end of main body ###

sub usage {

   print STDERR <<'---';
This is a script preparing the build and installation of polymake.
It tries to mimic well-known GNU auto-configuration scripts:

./configure [options] [VARIABLE=value ...]

Without any options, or with a sole --build option, it reuses the options specified
in the most recent run, if any; this is mostly useful for developers after an update
of the codebase.

Allowed options (and their default values) are:

 Mulitple build trees:

  --build SUFFIX      (none)  create or update one of several build directories,
                              named "build.SUFFIX".  This is primarily for developers
                              who want to test various configurations from a single code base,
                              or for packagers.
                              By default, a single "build" directory is created.

  --builddir PATH     An alternative way of specifying an existing build directory by its full path

 Installation directories:

  --prefix=PATH       ( /usr/local )                   root of the installation tree
  --exec-prefix=PATH  ( ${prefix} )                    root of the architecture-dependent tree
  --bindir=PATH       ( ${exec-prefix}/bin )           main polymake script
  --includedir=PATH   ( ${prefix}/include )            include files
  --libdir=PATH       ( ${exec-prefix}/lib )           callable library
  --libexecdir=PATH   ( ${exec-prefix}/lib/polymake )  dynamic modules loaded at the runtime
  --datadir=PATH      ( ${prefix}/share/polymake )     rules and other architecture-independent files
  --docdir=PATH       ( ${datadir}/doc )               automatically generated documentation files

 Build dependences:

  --with-toolchain=PATH      path to a full GCC or LLVM (including clang and libc++) installation;
                               overrides CC, CXX, CXXFLAGS, LDFLAGS, LIBS and --with-libcxx
  --with-ccache=PATH         use the given ccache program for compilation
  --with-ccwrapper=COMMAND   prepend the given command to every compiler, linker, and ar invocation

---
   $^O eq "darwin" and
   print STDERR <<'---';
  --with-fink=PATH         fink installation directory. You can pass "default" as argument if fink is installed into its default location ( /sw )
  --with-brew=PATH         homebrew installation directory. You can pass "default" as argument if brew is installed into its default location ( /usr/local for intel Macs or /opt/homebrew for silicon Macs)
.
---
   print STDERR <<"---";
  --with-gmp=PATH     ( /usr ) GNU MultiPrecision library installation directory
  --with-mpfr=PATH    ( =gmp-path ) GNU Multiple Precision Floating-point Reliable library installation directory

  --with-boost=PATH   installation path of boost library, if non-standard

  --with-permlib=PATH installation path of permlib headers, if non-standard,
                      polymake uses the bundled permlib by default or if 'bundled' is given.

 Bundled extensions:
---
   foreach my $ext (sort keys %ext_with_config) {
      no strict 'refs';
      print STDERR "\n  --without-$ext  disable the bundled extension $ext completely\n";
      &{"Polymake::Bundled::$ext\::usage"}();
      print STDERR "\n";
   }

   print STDERR <<'---';


 Other options:

  --with-libcxx       build against the libc++ library instead of the GNU libstdc++, useful when
                      building with LLVM/Clang. (sets -stdlib=libc++, -lc++ and -lc++abi)
                      see also --with-toolchain when using a custom LLVM installation

  --without-callable  don't build polymake callable library
                      (in the case of custom perl installations lacking libperl shared library)

  --without-prereq    don't check for availability of required libraries and perl modules
                      (to be used from within package management systems like RPM,
                       having own mechanisms for providing all prerequisites.)

  --without-openmp    disable OpenMP support for libnormaliz and to_simplex

---
   $^O ne "darwin" and
   print STDERR <<'---'; 
  --without-native    build without "-march=native" flag to allow execution on different CPU types
                      (passing one of -m{cpu,arch,tune} via CFLAGS or CXXFLAGS also disables "-march=native")

---
   print STDERR <<'---';
  --build-modes=MODE,MODE...
                      prepare for builds in non-standard modes; currently supported modes are:
                        Cov  generated code gathers coverage statistics
                        San  sanitized build detecting address violations and undefined behavior
                      Standard modes Opt and Debug are always supported and must not be listed here.

---
   $Polymake::DeveloperMode and
   print STDERR <<"---";
  --clone=PATH/config.ninja
                      Import the options stored in the given configuration file.
                      More options may follow; simple options may override the imported ones,
                      but no provisions are made for detecting more subtle contradictions.
                      Use at own risk.

---
   print STDERR <<"---";
Allowed variables are:

   Arch=       An abbreviation for the system architecture.
---
   $^O eq "darwin" and
   print STDERR <<'---';
               Allowed values are "i386" for 32bit or "x86_64" for 64bit.
---
   print STDERR <<'---';
               Default value is derived from the current system setup.
               Users' custom variables may have distinct values for different architectures.

   CC=cc       C compiler executable
   CFLAGS=     C compiler options
   CXX=c++     C++ compiler executable
   CXXFLAGS=   C++ compiler options
   CXXOPT=     C/C++ compiler optimization level (defaults to highest possible)
   LDFLAGS=    linker options, including linker choice (-fuse-ld)
   LIBS=       additional libraries to be linked with
   PERL=perl   perl executable

Options incompatible with any others:

   --defaults    perform a configuration assuming all default settings,
                 ignoring any existing configured builds

---
   $Polymake::DeveloperMode and
   print STDERR <<"---";
   --alt-perl=TAG    create a configuration for a non-standard perl interpreter;
                     the ninja files will be called build.TAG.ninja

---
   print STDERR <<"---";
For detailed installation instructions, please refer to the polymake Wiki site:
  $Wiki/howto/install

---
}

###################################################################################
# * sieve out disabled extensions so that their configuration scripts are not loaded
# * process --build, --builddir, --build-modes, and --defaults
# * restore options from previous runs if desired
sub early_parse_command_line {
   my (@other_args, $enforce_defaults);
   while (defined(my $arg = shift @ARGV)) {
      if ($arg eq "--defaults") {
         $enforce_defaults = 1;
      } elsif (my ($flag, $value) = $arg =~ /^--(build(?:-modes|dir)?|alt-perl)(?:=(\S+))?$/) {
         $value //= @ARGV && $ARGV[0] =~ /^\w/ ? shift @ARGV : die "option --$flag requires a value\n";
         $options{$flag} = $value;
      } elsif ($arg =~ /^--without-(\w+)$/  &&  -d "bundled/$1") {
         push @ext_disabled, $1;
         $options{$1} = ".none.";
      } else {
         push @other_args, $arg;
      }
   }

   if (my $builddir = delete $options{'builddir'}) {
      if ($options{build}) {
         die "--build and --builddir may not be specified together\n"
      }
      if (-f "$builddir/config.ninja" && $builddir =~ s{/build(?:\.([^/]+))?(?:/\w+)?$}{}) {
         chdir $builddir or die "can't change into $builddir: $!\n";
         if (defined($1)) {
            $options{build} = $1;
         }
      } else {
         die "$builddir does not look like a configured polymake build directory\n";
      }
   }

   if ($options{'alt-perl'}) {
      if ($enforce_defaults || @other_args || @ext_disabled) {
         die "option --alt-perl can't be combined with any other configuration option\n";
      }
   }

   if ($enforce_defaults) {
      if (@other_args || @ext_disabled) {
         die "option --defaults can't be combined with any other configuration option\n";
      }

   } elsif (@other_args) {
      @ARGV=splice @other_args;

   } elsif (!@ext_disabled) {
      # no configuration options means we should reuse the options from the previous run

      if ($options{build}) {
         # want to keep several architectures in parallel
         if ($^O eq "darwin") {
            $options{build} =~ s/^(?!darwin\.)/darwin./;
         }
         if (-f "build.$options{build}/config.ninja") {
            retrieve_config_command_line("build.$options{build}/config.ninja", \@ARGV);
            return 1;
         } elsif (-f "build.$options{build}/conf.make") {
            retrieve_config_command_line("build.$options{build}/conf.make", \@ARGV);
            return 1;
         }
      } elsif (-f "build/config.ninja") {
         retrieve_config_command_line("build/config.ninja", \@ARGV);
         return 1;
      } elsif (my @ninja_configs=glob("build.*/config.ninja")) {
         die "polymake has been configured for several build architectures: ", (map { m{/build\.([^/]+)/} } @ninja_configs),
              "\nPlease specify the desired one with --build option or enforce default configuration with --defaults option.\n";
      } elsif (my @old_configs=glob("build.*/conf.make")) {
         if (@old_configs==1) {
            my ($old_build)=$old_configs[0] =~ m{(build.[^/])};
            retrieve_config_command_line($old_configs[0], \@ARGV);
            rename $old_build, "build";
            return 1;
         } else {
            die "polymake has been configured for several build architectures: ", (map { m{/build\.([^/]+)/} } @old_configs),
                "\nPlease specify the one to be migrated to ninja build system with --build option.\n",
                "If you want to preserve just one of them, delete all other build.XXX directories and re-run the configure command without any options.\n";
         }
      }
   }
   0
}

###########################w######################################
sub parse_command_line {
   my ($arglist, $repeating_config, $ignore_unknown)=@_;
   while (defined (my $arg=shift @$arglist)) {
      # trim and allow empty arguments
      $arg =~ s/^\s+//;
      $arg =~ s/\s+$//;
      next if length($arg)==0;
      $arg =~ s/^--with-libc\K\+\+$/xx/;
      if ($arg eq "--help") {
         usage();
         exit(0);
      } elsif (my ($with, $out, $name, $value)= $arg =~ /^--(with(out)?-)?(\w[-\w]+)(?(2)|=(.*))?$/) {
         if ($with and exists $allowed_flags{$name} and !defined($value)) {
            if (defined($out)) {
               $options{$name}=".none.";
            } else {
               $options{$name}=".true.";
            }
            next;
         } elsif ($with ? exists $allowed_with{$name}
                        : exists $allowed_options{$name}
                    and
                  defined($out) || defined($value) || @$arglist) {
            if (defined($out)) {
               $value=".none.";
            } else {
               $value //= shift(@$arglist);
               $value =~ s{^~/}{$ENV{HOME}/};
               $value =~ s{/+$}{};
            }
            if ($repeating_config && $name =~ /^build/) {
               $options{$name} //= $value;
            } elsif ($value eq "default" && $name ne "fink" && $name ne "brew") {
               delete $options{$name};
            } else {
               $options{$name}=$value;
            }
            next;
         } elsif ($Polymake::DeveloperMode and
                  $arg eq "--clone" && @$arglist  ||
                  $arg =~ s/^--clone=(?=.)//) {
            # used in testscenarios
            my @other_command_line;
            retrieve_config_command_line($arg eq "--clone" ? shift(@$arglist) : $arg, \@other_command_line);
            parse_command_line(\@other_command_line, 0, 1);
            next;
         }
      } elsif ($arg =~ /^([A-Z]\w+)=(.*)/) {
         if (exists $allowed_vars{$1}) {
            $vars{$1}=$2;
            next;
         }
      }
      if (!$ignore_unknown) {
         die "Unrecognized option $arg\nTry ./configure --help for detailed information\n";
      }
   }

   if (!$repeating_config) {
      # inherit some variables which haven't appeared on the command line from the environment
      foreach my $varname (grep { !exists $vars{$_} } keys %allowed_vars) {
         if (defined (my $value=$ENV{$varname})) {
            $vars{$varname}=$value;
         }
      }
   }

   $CXXOPT   =$vars{CXXOPT}   // "-O3";
   $CXXDEBUG =$vars{CXXDEBUG} // "-g";
   $CFLAGS   =$vars{CFLAGS}   // "";
   $CXXFLAGS =$vars{CXXFLAGS} // $CFLAGS;
   $LDFLAGS  =$vars{LDFLAGS}  // "";
   $LIBS     =$vars{LIBS}     // "";
   $DESTDIR  =$vars{DESTDIR};

   $Arch = $vars{Arch} =~ s/^darwin\.//r;
}

#################################################################
sub load_enabled_bundled_extensions {
   @ext=grep { $options{$_} ne ".none." } map { m{bundled/(.*)} } glob("bundled/*");

   my @prereq_sections=qw(REQUIRE REQUIRE_OPT);

   foreach my $ext (@ext) {
      eval {
         if (-f "bundled/$ext/polymake.ext") {
            open my $MF, "bundled/$ext/polymake.ext"
              or die "unreadable\n";
            local $/;
            local $_=<$MF>;
            s/^\s*\#.*\n//mg;
            my @sections=split /(?:\A\n*|\n{2,})([A-Z_]+)(?=\s)/m;  shift @sections;
            my %sections=@sections;
            if ($sections{URI}) {
               die "bundled extensions have implict URIs; URI section not allowed\n";
            }

            my @prereq;
            foreach my $is_optional (0..1) {
               if (my $section=$sections{$prereq_sections[$is_optional]}) {
                  foreach ($section =~ /(\S+)/g) {
                     if (/^bundled:(\w+)$/) {
                        push @prereq, $1;
                        $ext_requires_opt{$ext}->{$1}=$is_optional;
                     } else {
                        die "invalid reference to a prerequisite extension: $_\n"
                     }
                  }
               }
            }
            $ext_requires{$ext}=\@prereq;

            my @confl;
            if ($sections{CONFLICT}) {
               @confl=map { /^bundled:(\w+)$/ ? $1 : die "invalid reference to a conflicting extension: $_\n" } $sections{CONFLICT} =~ /(\S+)/g;
            }
            $ext_conflicts{$ext}=\@confl;
         } else {
            die "missing\n";
         }
      };
      if ($@) {
         $options{$ext}=".none.";
         $ext_bad{$ext}= $@ =~ /^(missing|unreadable)$/ ? "$1 description file bundled/$ext/polymake.ext" : "invalid description file bundled/$ext/polymake.ext\n$@";

      } elsif (-f (my $ext_config="bundled/$ext/support/configure.pl")) {
         my $err;
         eval <<"---";
         { package Polymake::Bundled::$ext;
           do "./$ext_config";
           unless (\$err=\$\@) {
             allowed_options(\\%allowed_options, \\%allowed_with);
           }
         }
---
         if ($err) {
            $options{$ext}=".none.";
            $ext_bad{$ext}="broken configuration script $ext_config:\n$err";
         } else {
            $ext_with_config{$ext}=1;
         }
      }
   }
}

#####################################################
sub construct_paths {
   my $prefix=$options{prefix} || "/usr/local";
   my $exec_prefix=$options{'exec-prefix'} || $prefix;

   $InstallBin=$options{bindir} || "$exec_prefix/bin";
   $InstallLib=$options{libdir} || "$exec_prefix/lib";
   $InstallTop=$options{datadir} || "$prefix/share/polymake";
   $InstallArch=$options{libexecdir} || "$exec_prefix/lib/polymake";
   $InstallInc=$options{includedir} || "$prefix/include";
}

#####################################################
sub determine_cxx_compiler {
   print "checking C++ compiler ... ";
   $CXX=$vars{CXX};
   $CC=$vars{CC};

   if ($options{toolchain}) {
      if (-x $options{toolchain}."/bin/clang++") {
         $CXX ||= $options{toolchain}."/bin/clang++";
         $CC  ||= $options{toolchain}."/bin/clang";
      } elsif (-x $options{toolchain}."/bin/g++") {
         $CXX ||= $options{toolchain}."/bin/g++";
         $CC  ||= $options{toolchain}."/bin/gcc";
      } else {
         die <<"---"
Unsupported toolchain given, only GCC or LLVM/Clang are supported.
Make sure $options{toolchain}/bin/clang++ or $options{toolchain}/bin/g++ exists and is executable.
---
      }
   }

   check_program($CXX, "g++", "c++", "icpc", "clang++")
     or die "no supported C++ compiler found; please reconfigure with CXX=name\n";

   my $cxx_tell_version=<<"---";
#include <iostream>
int main() {
#if defined(__APPLE__)
   std::cout << "apple";
#endif
#if defined(__clang__)
   std::cout << "clang " << __clang_major__ << '.' << __clang_minor__ << '.' << __clang_patchlevel__ << std::endl;
   return 0;
#elif defined(__GNUC__)
   std::cout << "gcc " << __GNUC__ << '.' << __GNUC_MINOR__ << '.' << __GNUC_PATCHLEVEL__ << std::endl;
   return 0;
#elif defined(__INTEL_COMPILER)
   std::cout << "icc " << __INTEL_COMPILER << std::endl;
   return 0;
#else
   return 1;
#endif
}
---
   my $build_error;

   # try to use gold linker unless another linker has been prescribed by the user
   unless ($^O eq "darwin" or $Config::Config{archname} =~ /^mips/ or "$CXXFLAGS $LDFLAGS" =~ /(?:^|\s)-fuse-ld[=\s]/) {
      $build_error = build_test_program($cxx_tell_version, LDFLAGS => "-fuse-ld=gold");
      if ($?) {
         # did not work out, maybe gold is missing?
         undef $build_error;
      } else {
         $LDFLAGS .= " -fuse-ld=gold";
         $autogold = 1;
      }
   }
   $build_error //= build_test_program($cxx_tell_version);

   if ($?) {
      die "C++ compiler $CXX could not compile a test program for version recognition:\n",
          $build_error,
          "\nPlease investigate and reconfigure with CXX=<appropriate C++ compiler>\n";
   }

   local $_=run_test_program();  chomp;
   if (/^(apple)?clang /) {
      if ($1 eq "apple") {
         $XcodeVersion=$';
         $CLANGversion=xcode2clang_version();
      } else {
         $CLANGversion=$';
         if (v_cmp($CLANGversion, "3.4") < 0) {
            die "C++ compiler $CXX says its version is $CLANGversion, while the minimal required version is 3.4\n";
         }
      }

   } elsif (/icc (\d+)(\d\d)$/) {
      $ICCversion="$1.$2";
      if (v_cmp($ICCversion, "16.0") < 0) {
        die "C++ compiler $CXX says its version is $ICCversion, while the minimal required version is 16.0\n";
      }
      # untested but since version 16 most of C++14 should be supported
      print "warning: probably unsupported C++ compiler Intel $ICCversion.\n";
   } elsif (/(apple)?gcc /) {
      $GCCversion=$';
      # decide whether we use the gcc provided by apple, in that case we need the -arch flags, otherwise we probably don't
      $NeedsArchFlag=defined($1);
      if (v_cmp($GCCversion, "5.1") < 0) {
         die "C++ compiler $CXX says its version is $GCCversion, while the minimal required version is 5.1\n";
      }
   } else {
      die "$CXX is an unsupported C++ compiler.  Please choose one of the supported: Intel, clang, or GCC.\n";
   }

   if (defined $CC) {
      check_program($CC);
   } else {
      $CC=$CXX;
      unless (defined($CLANGversion)
              ? $CC =~ s{clang\+\+$}{clang} :
              defined($ICCversion)
              ? $CC =~ s{\b([ei])cp?c$}{${1}cc} :
              defined($GCCversion)
              ? $CC =~ s{g\+\+(?=[^/]*)$}{gcc}
                  ||
                $CC =~ s{(?:c\+\+|CC)(?=[^/]*)$}{cc}
              : 0
              and find_program($CC)) {
         $CC=$Config::Config{cc};
      }
   }
   if (defined($GCCversion) or defined($CLANGversion)) {
      print "ok ($CXX is ",
            defined($GCCversion)
            ? "GCC $GCCversion" :
            defined($XcodeVersion)
            ? "Apple CLANG (roughly $CLANGversion) from Xcode $XcodeVersion"
            : "CLANG $CLANGversion",
            ")\n";
   }
}
#####################################################
sub determine_cxx_library {
   print "checking C++ library ... ";

   if ($options{toolchain}) {
      my $libdir;
      # CC/CXX was set earlier, the else case already died at that point
      if (-x $options{toolchain}."/bin/clang++") {
         $libdir = get_libdir($options{toolchain}, "clang");
         $options{libcxx} = ".true.";
      } elsif (-x $options{toolchain}."/bin/g++") {
         $libdir = get_libdir($options{toolchain}, "gcc_s");
      }
      $CFLAGS   .= " -I$options{toolchain}/include";
      $CXXFLAGS .= " -I$options{toolchain}/include";
      $LDFLAGS  .= " -L$libdir -Wl,-rpath,$libdir";
   }

   if ($options{libcxx} eq ".true.") {
      $CXXFLAGS .= " -stdlib=libc++";
      $LDFLAGS  .= " -stdlib=libc++";
      $LIBS     .= " -lc++";
      $LIBS     .= " -lc++abi" if ($^O eq "linux");
   }

   # All polymake releases after 3.0 require C++14,
   # but if someone explicitly requests another standard version go along with it,
   # if it is too old we will generate a warning / an error later on.
   if ($CXXFLAGS !~ /(?:^|\s)-std=/) {
      if (defined($CLANGversion) and v_cmp($CLANGversion, "3.5") < 0) {
         $CXXFLAGS .= ' -std=c++1y';
      } else {
         $CXXFLAGS .= ' -std=c++14';
      }
   }

   my $build_error = build_test_program(<<"---");
#include <cstddef>
#include <cstdio>
#include <iostream>
int main() {
   std::cout << "cplusplus " << __cplusplus << std::endl;
#if defined(_LIBCPP_VERSION)
   std::cout << "libc++ " << _LIBCPP_VERSION << std::endl;
   return 0;
#elif defined(__GLIBCXX__)
   std::cout << "GNU libstdc++ " << __GLIBCXX__ << std::endl;
   return 0;
#elif defined(__INTEL_CXXLIB_ICC)
   std::cout << "Intel " << __INTEL_CXXLIB_ICC << std::endl;
   return 0;
#else
   return 1;
#endif
}
---
   if ($?) {
      die <<"---";
C++ compiler $CXX could not compile a test program for C++ library recognition:
$build_error
Please investigate and reconfigure.
---
   }
   local $_=run_test_program();  chomp;
   my ($cppver, $cpplib) = $_ =~ m/^cplusplus (\d+)\n(.+)$/;

   unless ($cppver >= 201402 or
           $cppver >= 201305 and
               defined($CLANGversion) and v_cmp($CLANGversion, "3.5") < 0
          ) {
      # C++ standard older than C++14 won't work (C++1y from clang 3.4 is also ok)
      die "C++ standard version ($cppver) too old, C++14 or later is required. Please omit any '-std=' options.\n";
   }

   # see http://sourceforge.net/p/predef/wiki/Libraries/
   if ($cpplib =~ /^GNU libstdc\+\+ /) {
      # this is some more or less useful date
      my $stdlibversion=$';
      $CPPStd = $cppver;
      print "ok ($cpplib, C++ $CPPStd)\n";
   } elsif ($cpplib =~ /^libc\+\+ /) {
      $CPPStd = $cppver;
      if ($LIBS !~ /-lc\+\+/) {
         $LIBS .= " -lc++";
         $LIBS .= " -lc++abi" if ($^O eq "linux");
      }
      print "ok ($cpplib, C++ $CPPStd)\n";
   } elsif ($cpplib =~ /^Intel /) {
      my $intelcxxversion=$';
      $CPPStd = $cppver;
      print "warning: probably unsupported C++ library Intel $intelcxxversion.\n";
      # not tested in a long time
   } else {
      die "Unsupported C++ library, use -stdlib to specify libstdc++ or libc++.\n";
   }

   if ($LDFLAGS !~ /-stdlib=/ and $CXXFLAGS =~ /(-stdlib=\S+)/) {
      $LDFLAGS .= " $1";
   }
}

#####################################################
sub check_fink {
   $FinkBase=$options{fink};
   if ( $FinkBase eq "default" ) {
      # Fink location not specified, look for it at plausible places
      (undef, my ($fink, $error))=find_program_in_path("fink", sub {
         !($FinkBase=$_[0] =~ s|/bin/fink$||r && -f "$FinkBase/etc/fink.conf") && "!"
      });
      if ($fink) {
         if ($error) {
            die <<"---";
Found the fink program at $fink, but the corresponding configuration file is missing;
Please specify the top installation directory using option --with-fink=PATH
---
         }
      } elsif (-f "/sw/etc/fink.conf") {
         $FinkBase="/sw";
      } else {
         die <<"---";
The Fink package system cannot be found at a default location on your computer.
Please refer to $Wiki/howto/mac for installation instructions and other options to install polymake on a Mac.
If you have Fink installed at a non-standard location, please specify it using option --with-fink=PATH
---
      }  
   } elsif (-d $FinkBase) {
      unless (-f "$FinkBase/etc/fink.conf") {
         die "option --with-fink does not point to the fink installation tree: $FinkBase/etc/fink.conf not found\n";
      }
   } elsif (-x $FinkBase && $FinkBase =~ s|/bin/fink$||) {
      unless (-f "$FinkBase/etc/fink.conf") {
         die "option --with-fink points to a broken fink installation: $FinkBase/etc/fink.conf not found\n";
      }
   } else {
      die <<'---';
option --with-fink points to a wrong program: something like /path/bin/fink expected.
If you have renamed the main fink program, please specify the top directory: --with-fink=PATH
---
   }

   if (defined (my $anylib=(glob("$FinkBase/lib/*.dylib"))[0])) {
      my ($fink_arch)= `lipo -info $anylib` =~ /architecture: (\S+)/;
      if (defined $Arch) {
         if ($Arch ne $fink_arch) {
            die "Required architecture $Arch does not match installed Fink architecture $fink_arch\n";
         }
      } else {
         $Arch=$fink_arch;
      }
   } else {
      die "Fink installation seems corrupt: no shared libraries found in $FinkBase/lib\n";
   }

   print "ok ($FinkBase)\n";
}
#####################################################
sub check_brew {
   $BrewBase=$options{brew};
   my $local_arch = `uname -m`;
   chomp $local_arch;
   if ( $BrewBase eq "default" || ( $local_arch == "x86_64" && $BrewBase eq "/usr/local" ) || ( $local_arch == "arm64" && $BrewBase eq '/opt/homebrew' ) ) {
      $BrewBase = $local_arch eq "x86_64" ? '/usr/local' : '/opt/homebrew';
      unless (-f "$BrewBase/bin/brew") {
         die "brew installation corrupt: $BrewBase/bin/brew not found\n";
      }
   } elsif( $BrewBase eq "bottle" ) {
      $ADDITIONAL_PERL_INCLUDES = "";
      my @perl_paths = split(/:/, "$ENV{PERL5LIB}");
      foreach (@perl_paths) {
         $ADDITIONAL_PERL_INCLUDES .= " -I$_";
      }
      $BrewBase = '#{HOMEBREW_PREFIX}';
   } else {
      if (-d $BrewBase) {
         unless (-f "$BrewBase/bin/brew") {
            die "option --with-brew does not point to the brew installation tree: $BrewBase/bin/brew not found\n";
         }
      } elsif (-x $BrewBase && $BrewBase =~ s|/bin/brew$||) {
         unless (-f "$BrewBase/bin/brew") {
            die "option --with-brew points to a broken brew installation: $BrewBase/bin/brew not found\n";
         }
      } else {
         die <<'---';
option --with-brew points to a wrong program: something like --with-brew=/path/bin/brew expected.
You can also pass --with-brew=PATH,  where PATH is the base directory of your homebrew installation. 
If you installed into the default location (/usr/local/), then you can also pass -with-brew=default or omit the option completely.
---
      }

      $CFLAGS .= " -I$BrewBase/include";
      $CXXFLAGS .= " -I$BrewBase/include";
      $LDFLAGS .= " -L$BrewBase/lib";
   }
   
   if (defined (my $anylib=(glob("$BrewBase/lib/*.dylib"))[0])) {
      my ($brew_arch)= `lipo -info $anylib` =~ /architecture: (\S+)/;
      if (defined $Arch) {
         if ($Arch ne $brew_arch) {
            die "Required architecture $Arch does not match installed brew architecture $brew_arch\n";
         }
      } else {
         $Arch=$brew_arch;
      }
   } else {
      die "Homebrew installation seems corrupt: no shared libraries found in $BrewBase/lib\n";
   }

   print "ok ($BrewBase)\n";
}
#####################################################
sub check_macos_package_manager {
   print "checking for package manager ... ";
   if (defined($options{fink}) and $options{fink} ne ".none.") {
      check_fink();
   } elsif (defined($options{brew}) and $options{brew} ne ".none.") {
      check_brew();
   } else {
      print "no package manager specified\n";
   }
}
#####################################################
sub determine_architecture {
   print "determining architecture ... ";
   if ($^O eq "darwin") {
      if ( !defined($FinkBase) && !defined($BrewBase) ) {
         $Arch //= `uname -m`;
         chomp $Arch;
         if ($Arch ne "arm64" && $Arch ne "i386" && $Arch ne "x86_64") {
            die "Invalid architecture $Arch for Mac OS: allowed values are i386, x86_64 and arm64.\n";
         }
      }
      $ARCHFLAGS= $NeedsArchFlag ? "-arch $Arch" : "";
      $Arch="darwin.$Arch";
   } else {
      unless (defined $Arch) {
         if ($^O !~ /aix|rs6000|ibm/i) {
            ($Arch)= `uname -m` =~ /(\w+)/;
         }
         $Arch //= $Config::Config{archname};
      }

      # no arch flags set
      if ($options{native} ne ".none.") {
         if ("$CFLAGS $CXXFLAGS" =~ /(?:^|\s)-m(?:arch|tune|cpu)=(\w+)/) {
            $options{native} = ".none." unless $1 eq "native";
         } else {
            $CFLAGS .= " -march=native";
            $CXXFLAGS .= " -march=native";
         }
      }
   }
   print "ok ($Arch)\n";
}

#####################################################
sub collect_compiler_specific_options {
   print "determining compiler flags ... ";
   if (defined($GCCversion)) {
      # avoid using temp files, they grow indeterminately during debug builds
      $CsharedFLAGS="-fPIC -pipe";
      # TODO: remove -fno-strict-aliasing when the core library is free from reintepret_casts
      $CXXFLAGS .= " -ftemplate-depth-200 -fno-strict-aliasing";
      if ($options{openmp} ne ".none.") {
         $CXXFLAGS .= " -fopenmp";
         $LDFLAGS .= " -fopenmp";
      }
      $CXXCOV="--coverage -O1";
      $CXXSANITIZE="-fno-omit-frame-pointer -O1 " . ($CXXDEBUG =~ /(?:^|\s)-g0/ ? "-g1" : $CXXDEBUG);
      # external libraries might be somehow dirtier
      $CflagsSuppressWarnings="-Wno-unused-result";
      # gcc-specific flags
      $CXXFLAGS .= " -Wshadow -Wlogical-op -Wconversion -Wzero-as-null-pointer-constant -Wno-parentheses -Wno-error=unused-function";
      if (v_cmp($GCCversion, "8") < 0) {
         $CXXFLAGS .= " -Wno-float-conversion -Wno-strict-overflow";
      }
      if (v_cmp($GCCversion, "6.3") >= 0 && v_cmp($GCCversion, "7") < 0) {
         $CXXFLAGS .= " -Wno-maybe-uninitialized";
      }
      if (v_cmp($GCCversion, "9.1") >= 0) {
         $CXXFLAGS .= " -Wno-stringop-overflow";
         $CflagsSuppressWarnings.=" -Wno-stringop-overflow";
      }
      if (v_cmp($GCCversion, "10") >= 0) {
         $CXXFLAGS .= " -Wno-array-bounds";
      }
      if (v_cmp($GCCversion, "11") >= 0) {
         $CXXFLAGS .= " -Wno-maybe-uninitialized -Wno-free-nonheap-object";
      }
      if (v_cmp($GCCversion, "14") >= 0) {
         # due to false positives
         $CXXFLAGS .= " -Wno-dangling-reference";
      }

   } elsif (defined($ICCversion)) {
      $CsharedFLAGS="-fPIC";
      $CXXDEBUG !~ /(?:^|\s)-O/ and $CXXDEBUG =~ s/-g(?!0)\K/ -Ob0/;
      $CXXFLAGS .= " -wd193,383,304,981,1419,279,810,171,1418,488,1572,561";
      $CFLAGS .= " -wd193,1572,561";

   } elsif (defined($CLANGversion)) {
      # avoid using temp files, they grow indeterminately during debug builds
      $CsharedFLAGS="-fPIC -pipe";
      $CXXFLAGS .= " -Wno-logical-op-parentheses -Wno-shift-op-parentheses -Wno-mismatched-tags";
      $CflagsSuppressWarnings="-Wno-unused -Wno-empty-body -Wno-format-extra-args";
      if (v_cmp($CLANGversion, "3.6") >= 0) {
         $CXXFLAGS .= " -Wno-unused-local-typedef -Wno-error=unneeded-internal-declaration";
      }
      if (v_cmp($CLANGversion, "5") >= 0) {
         $CXXFLAGS .= " -Wshadow -Wconversion -Wno-sign-conversion -Wzero-as-null-pointer-constant";
      } elsif (v_cmp($CLANGversion, "4") >= 0) {
         $CXXFLAGS .= " -Wno-unknown-pragmas -Wno-unknown-warning-option";
      } else {
         $CXXFLAGS .= " -Wno-unknown-pragmas";
      }
      # verify openmp support which is available starting with 3.7 but depends on the installation,
      # but 3.7 seems to crash when compiling libnormaliz so we skip that version
      # version 3.8 is tested to work with openmp
      if (v_cmp($CLANGversion, "3.8") >= 0 && $options{openmp} ne ".none.") {
         my $ompflag = "-fopenmp";
         my $build_error=build_test_program(<<'---', CXXFLAGS => "$ompflag", LDFLAGS => "$ompflag");
#include <stdio.h>
#include <omp.h>

int main() {
#pragma omp parallel
    printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
    return 0;
}
---
         if ($? == 0) {
            my $openmpout = run_test_program();
            my ($nthr) = $openmpout =~ /Hello from thread \d+, nthreads (\d+)/;
            if ($? == 0) {
               $CXXFLAGS .= " $ompflag";
               $LDFLAGS .= " $ompflag";
            }
         }
      }

      if (v_cmp($CLANGversion, "3.8") >= 0) {
         # stick to the gcov-compatible coverage tool for now
         # let's experiment with -fcoverage-mapping -fprofile-instr-generate later
         $CXXCOV="--coverage -O1";
      }
      if (v_cmp($CLANGversion, "3.9") >= 0) {
         $CXXSANITIZE="-fno-omit-frame-pointer -O1 " . ($CXXDEBUG =~ /(?:^|\s)-g0/ ? "-g1" : $CXXDEBUG);
      }
   }

   $LDsharedFLAGS=$Config::Config{lddlflags};

   if ($^O eq "darwin") {
      # MacOS magic again: remove multi-architecture options for fat binaries
      my $allarch=qr/ -arch \s+ \S+ (?: \s+ -arch \s+ \S+)* /x;
      $CFLAGS =~ s/$allarch//;
      $CXXFLAGS =~ s/$allarch//;
      $LDsharedFLAGS =~ s/$allarch//;
      if ($options{callable} ne ".none.") {
         $LDcallableFLAGS = $Config::Config{ldflags} =~ s/$allarch//r;
         $LDcallableFLAGS = "$LDsharedFLAGS $LDcallableFLAGS";
         $LDcallableFLAGS =~ s/-bundle/-dynamiclib/;
         $LDsonameFLAGS = "-install_name $InstallLib/";
      } else {
         $LDcallableFLAGS="none";
      }
   } else {
      # enforce lazy binding unless it's already explicitly enabled or disabled by the user
      # (there are few strange Linux distributions where it's not enabled by default contradicting the ld manual)
      if ("$LDFLAGS $LDsharedFLAGS" !~ /-z(?:,|\s+)(?:lazy|now)\b/) {
         $LDsharedFLAGS .= " -Wl,-z,lazy";
      }

      # prevent early loading of third-party shared modules which are used only in few applications
      if ("$LDFLAGS $LDsharedFLAGS" !~ /-as-needed/) {
         $LDsharedFLAGS .= " -Wl,--as-needed";
      }

      if ($options{callable} ne ".none.") {
         $LDcallableFLAGS="$LDsharedFLAGS $Config::Config{ldflags}";
         $LDsonameFLAGS = "-Wl,-soname,";
      } else {
         $LDcallableFLAGS="none";
      }
   }

   if (defined($CLANGversion) && v_cmp($CLANGversion, "3.5") < 0) {
      # old clangs do not have this option which is actively used in newer perls
      s/-fstack-protector\K-strong//g for $LDsharedFLAGS, $LDcallableFLAGS;
   }

   print <<"---";
ok
   CFLAGS=$CFLAGS
   CXXFLAGS=$CXXFLAGS
   LDFLAGS=$LDFLAGS
---
}

#####################################################
sub check_build_modes {
   $BuildModes="Opt Debug";
   if ($options{'build-modes'}) {
      # might want to use a non-standard perl just with one build mode
      $BuildModes="" if $options{'alt-perl'};
      add_build_modes($options{'build-modes'});
   }
}

###############################################################
sub locate_gmp_and_mpfr_libraries {
   my $GMP=$options{gmp};

   unless (defined $GMP) {
      if ($^O eq "freebsd") {
         if (-f "/usr/local/include/gmp.h") {
            $GMP="/usr/local";
         }
      } elsif ($FinkBase) {
         $GMP=$FinkBase;
      }
   }
   if (defined $GMP) {
      $CFLAGS .= " -I$GMP/include";
      $CXXFLAGS .= " -I$GMP/include";
      my $libdir=get_libdir($GMP, "gmp");
      $LDFLAGS .= " -L$libdir";
      if (!$FinkBase) {
         # non-standard location
         $LDFLAGS .= " -Wl,-rpath,$libdir";
      }
   }

   my $MPFR=$options{mpfr};
   if (defined($MPFR) && $MPFR ne $GMP) {
      $CFLAGS .= " -I$MPFR/include";
      $CXXFLAGS .= " -I$MPFR/include";
      my $libdir=get_libdir($MPFR, "mpfr");
      $LDFLAGS .= " -L$libdir";
      if (!$FinkBase) {
         # non-standard location
         $LDFLAGS .= " -Wl,-rpath,$libdir";
      }
   } elsif ($FinkBase) {
      $MPFR=$FinkBase;
   }

   if ($options{prereq} ne ".none.") {
      if ($FinkBase) {
         print "checking fink gmp and mpfr packages ... ";
         -f "$FinkBase/lib/libgmp.dylib"
           or die <<"---";
Fink package gmp-shlibs seems to be missing.
Please install the packages gmp and gmp-shlibs and repeat the configure run.
---
         -f "$FinkBase/lib/libmpfr.dylib"
           or die <<"---";
Fink package mpfr-shlibs seems to be missing.
Please install the packages mpfr and mpfr-shlibs and repeat the configure run.
---
         print "ok\n";
      }

      print "checking gmp installation ... ";
      my $build_error=build_test_program(<<'---', LIBS => "$ARCHFLAGS -lgmp");
#include <cstddef>
#include <gmp.h>
#include <iostream>
int main() {
   mpz_t a;
   mpz_init(a);
   std::cout << __GNU_MP_VERSION << '.' << __GNU_MP_VERSION_MINOR << '.' << __GNU_MP_VERSION_PATCHLEVEL << std::flush;
   return 0;
}
---
      if ($?==0) {
         my $is_version=run_test_program();
         if ($?==0) {
            if (v_cmp($is_version, "4.2.0") < 0) {
               die <<"---";
The GNU Multiprecision Library (GMP) installed at your site is of version $is_version
while 4.2.0 is the minimal required version.
---
            }
            $store_versions{GMP}=$is_version;
         } else {
            die <<"---";
Could not run a test program linked to the GNU Multiprecision Library (GMP).
Probably the shared library libgmp.$Config::Config{so} is missing or of an incompatible machine type.
---
         }
      } else {
         die <<"---", $build_error;
Could not compile a test program checking for the GNU Multiprecision Library (GMP).
The most probable reasons are that the library is installed at a non-standard location,
lacking developer's subpackage or missing at all.
Please refer to the installation instructions at $Wiki/howto/install.
The complete error log follows:
---
      }
      print "ok", defined($GMP) && " ($GMP)", "\n";

      print "checking mpfr installation ... ";
      $build_error=build_test_program(<<'---', LIBS => "$ARCHFLAGS -lmpfr -lgmp");
#include <cstddef>
#include <mpfr.h>
#include <iostream>
int main() {
   mpfr_t a;
   mpfr_init(a);
   std::cout << MPFR_VERSION_MAJOR << '.' << MPFR_VERSION_MINOR << '.' << MPFR_VERSION_PATCHLEVEL << std::flush;
   return 0;
}
---
      if ($?==0) {
         my $is_version=run_test_program();
         if ($?==0) {
            if (v_cmp($is_version, "3.0.0") < 0) {
               die <<"---";
The Multiple Precision Floating-Point Reliable Library (MPFR) installed at your site is of version $is_version
while 3.0.0 is the minimal required version.
---
            }
            $store_versions{MPFR}=$is_version;
         } else {
            die <<"---";
Could not run a test program linked to the Multiple Precision Floating-Point Reliable Library (MPFR).
Probably the shared library libmpfr.$Config::Config{so} is missing or of an incompatible machine type.
---
         }
      } else {
         die <<"---", $build_error;
Could not compile a test program checking for the Multiple Precision Floating-Point Reliable Library (MPFR).
The most probable reasons are that the library is installed at a non-standard location,
lacking developer's subpackage or missing at all.
Please refer to the installation instructions at $Wiki/howto/install.
The complete error log follows:
---
      }
      print "ok", defined($MPFR) && " ($MPFR)", "\n";
   }
}

sub check_gmpxx {
   # check GMP C++ bindings
   my $build_error=build_test_program(<<'---', LIBS => "-lgmpxx -lgmp");
#include <cstddef>
#include <gmpxx.h>
int main() {
   mpz_class z(7);
   mpz_class y(z-z);
   return y.get_si();
}
---
   if ($?==0) {
      my $run_error = run_test_program();
      if ($?) {
         die "Could not run a test program linked to the C++ version of the GNU Multiprecision Library (GMP).\n",
             "Probably the shared library libgmpxx.$Config::Config{dlext} is missing or of an incompatible machine type:\n$run_error\n";
      }
   } else {
      die "Could not compile a test program checking for C++ bindings of the GNU Multiprecision Library (GMP).\n",
          "The most probable reasons are that a gmpxx package is missing, lacking the developer's subpackage \n",
          "or GMP was configured without C++ support (--enable-cxx).\n",
          "Please refer to the installation instructions at $Wiki/howto/install.\n",
          "The complete error log follows:\n", $build_error;
   }
}

sub check_gmpxx_ostream {
   my $extraflags = "";
   # check GMP C++ library
OSTREAM_CHECK:
   my $build_error=build_test_program(<<'---', CXXFLAGS => "$extraflags", LIBS => "$ARCHFLAGS -lgmpxx -lgmp");
#include <cstddef>
#include <gmpxx.h>
#include <iostream>

#ifdef PM_MIXED_OSTREAM
std::ostream& operator<< (std::ostream &s, mpq_srcptr r) {
   return s << 1;
}
#endif
int main() {
   mpq_class x(7,3);
   std::cout << x << std::endl;
   return 0;
}
---
      my $run_error = run_test_program() if $? == 0;
      if ($?!=0) {
         if ($extraflags) {
            die "Could not build and run a test program checking the C++ library used by the GNU Multiprecision Library (GMP):\nbuild: $build_error\nrun:$run_error\n";
         } else {
            $extraflags = " -DPM_MIXED_OSTREAM";
            goto OSTREAM_CHECK;
         }
      } elsif ($extraflags) {
         $CXXFLAGS .= $extraflags;
      }
}

##########################################################
sub locate_boost_headers {
   my $boost_path=$options{boost};

   if (defined $boost_path) {
      $boost_path .= '/include' if (-d "$boost_path/include/boost");
      $CXXFLAGS .= " -I$boost_path";
   } elsif ($FinkBase) {
      print "checking fink boost package ... ";
      ($boost_path) = glob("$FinkBase/opt/boost-*/include/boost");
      $boost_path =~ s{/include/boost$}{};
      unless (-d $boost_path) {
         die <<"---";
Fink package boost-<some version>_nopython seems to be missing.
Please install the package boost-<some version>_nopython and repeat the configure run.
---
      }
      $CXXFLAGS .= " -I$boost_path/include";
      print "ok\n";
   }

   if ($options{prereq} ne ".none.") {
      print "checking boost installation ... ";
      my $build_error=build_test_program(<<'---');
#include <boost/shared_ptr.hpp>
#include <boost/iterator/counting_iterator.hpp>
int main() {
  return 0;
}
---
      if ($?) {
         die <<"---";
Could not compile a test program checking for boost library.
The most probable reasons are that the library is installed at a non-standard location,
or missing at all.
The complete error log follows:
$build_error

Please install the library and specify its location using --with-boost option, if needed.
---
      }
      print "ok", defined($boost_path) && " ($boost_path)", "\n";
   }
}


###############################################################

sub locate_permlib {
   my $permlib_path = $options{permlib};
   if (defined($permlib_path) and $permlib_path ne "bundled") {
      $permlib_path .= '/include' if (-d "$permlib_path/include/permlib");
      $CXXFLAGS .= " -I$permlib_path";
   } else {
      if (!-e "external/permlib/include/permlib/permlib_api.h") {
         # bundled permlib seems to be missing
         # will try to use a systemwide permlib as fallback unless explicitly requested
         die "Bundled PermLib was requested but is missing in the distribution.\n" if $permlib_path eq "bundled";
         $permlib_path = "";
      } else {
         $ExternalHeaders .= " permlib";
      }
   }

   if ($options{prereq} ne ".none.") {
      # this includes the case $permlib_path eq "" where we try to use a systemwide installation
      if (defined($permlib_path) and $permlib_path ne "bundled") {
         print "checking permlib installation ... ";
         # check permlib installation
         my $build_error=build_test_program(<<'---');
#include <permlib/permlib_api.h>
int main() {
   // from permlibs api example
   using namespace permlib;
   const unsigned long n = 10;
   // group generators
   std::list<Permutation::ptr> groupGenerators;
   Permutation::ptr gen1(new Permutation(n, std::string("1 3 5 7 9 10 2 4 6 8")));
   groupGenerators.push_back(gen1);
   Permutation::ptr gen2(new Permutation(n, std::string("1 5")));
   groupGenerators.push_back(gen2);
   boost::shared_ptr<PermutationGroup> group = construct(n, groupGenerators.begin(), groupGenerators.end());
   return 0;
}
---
         if ($?) {
            die <<"---";
Could not compile a test program checking for permlib.
The most probable reasons are that the library is installed at a non-standard location,
or missing at all.
The complete error log follows:
$build_error

Please install the library and specify its location using --with-permlib option, if needed.
Alternatively, you may leave out the --with-permlib option to use the bundled version.
---
         }
         print "ok", " (", $permlib_path eq "" ? "system" : ($permlib_path // "bundled"), ")\n";
      }
   }
}

##############################################################
sub check_libperl {
   print "checking shared perl library ... ";
   my $libperl=$Config::Config{libperl};

   my $error = "";
   if (length($libperl)==0) {
      $error = <<"---";
Your perl installation seems to lack the libperl.$Config::Config{so} shared library.
On some systems it is contained in a separate package named like
perl-devel or libperl-dev.  Please look for such a package and install it.

If your perl installation has been configured by hand, please make sure that
you have answered with "yes" to the question about the libperl shared library
(it is not the default choice!), or that you have passed '-Duseshrplib=true'
to the ./Configure script.
Otherwise, reconfigure and reinstall your perl.
---
   }

   # We also build a test program for libperl since e.g. on Debian based systems the
   # check for Config::Config{libperl} will not detect a missing libperl-dev package
   require ExtUtils::Embed;
   chomp(my $perlcflags = ExtUtils::Embed::ccopts());
   chomp(my $perlldflags = ExtUtils::Embed::ldopts());
   if (defined($CLANGversion)) {
      if (v_cmp($CLANGversion, "3.5") < 0) {
         s/-fstack-protector\K-strong//g for $perlcflags, $perlldflags;
      }
      if (defined($XcodeVersion) && v_cmp($XcodeVersion, "10.0") >= 0) {
         # from XCode 10.0.0 on, 32-bit builds are deprecated
         $_ =~ s/(?:^|\s+)-arch\s+\w+//g for $perlcflags, $perlldflags; 
      }
   }
RETRYLIBPERL:
   my $build_error=build_test_program(<<'---', CXXFLAGS => (defined($CLANGversion) && "-Wno-reserved-user-defined-literal ")."$perlcflags $perlextraflags", LDFLAGS => "$ARCHFLAGS $perlldflags" );
#include <EXTERN.h>
#include <perl.h>

int main(int argc, char **argv, char **env)
{
   const char* embedding[] = { "", "-e", "print $];", 0 };
   PERL_SYS_INIT3(&argc, &argv, &env);
   pTHXx = perl_alloc();
   perl_construct(aTHXx);
   PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
   perl_parse(aTHXx_ nullptr, 3, (char**)embedding, nullptr);
   perl_run(aTHXx);
   perl_destruct(aTHXx);
   perl_free(aTHXx);
   PERL_SYS_TERM();
}
---
   if ($?==0) {
      chomp(my $version = run_test_program());
      if ($? == 0) {
         if ($version ne $]) {
            $error = <<"---";
The shared perl library claims to be of a different version ($version) than
your perl interpreter ($]). Please choose a different perl installation with
PERL=/some/path/to/bin/perl or try to reinstall perl (including libperl).
---
         }
      } else {
         $error = <<"---";
Could not run a test program checking for libperl.$Config::Config{so}.
The error is as follows:
$!

On some systems the library is contained in a separate package named like
perl-devel or libperl-dev.  Please look for such a package and install it.
---
      }
   } else {
      if (defined($GCCversion) && $perlextraflags !~ /-D_Thread_local/ && $build_error =~ /error:.+_Thread_local.+does not name a type/s) {
         # The PERL_THREAD_LOCAL macro might be set to _Thread_local (since perl 5.35.5).
         # This is defined in the C11 standard and supported by all relevant gcc versions.
         # But g++ (gcc in C++ mode) does not accept _Thread_local so we define that to thread_local instead.
         # clang and clang++ both accept _Thread_local.
         $perlextraflags .= " -D_Thread_local=thread_local";
         goto RETRYLIBPERL;
      }
      if ($autogold && $LDFLAGS =~ /-fuse-ld=gold/ && $build_error =~ /ld\.gold.*unknown -z option/s) {
         # some distributions have extra flags in the perl settings that the gold linker
         # doesn't understand, so switch back to the default linker in that case
         $LDFLAGS =~ s/-fuse-ld=gold//g;
         goto RETRYLIBPERL;
      }
      $error = <<"---";
Could not compile a test program for the libperl.$Config::Config{so} shared library.
The build error is as follows:
$build_error

On some systems the library is contained in a separate package named like
perl-devel or libperl-dev.  Please look for such a package and install it.
---
   }

   if ($error) {
      print "failed\n\n";
      die <<"---";
$error
As a last resort, you can configure polymake with the option --without-callable .
You won't be able to build the callable library any more, but at least you get
polymake compiled.
---
   }

   print "ok\n";
}

######################################################################
sub check_prerequisite_perl_packages {
   if (defined $FinkBase) { 
      lib->import("$FinkBase/lib/perl5");
   }
   my @warned;
   foreach (qw(XML::SAX Term::ReadKey Term::ReadLine JSON)) {
      my $pkg=$_;
      print "checking perl module $pkg ... ";
      my $warn;
      local $SIG{__WARN__}=sub { $warn=shift };
      eval "require $pkg;";
      if (/^Term::ReadLine/) {
         $pkg.="::Gnu";
         unless ($@) {
            eval "new $pkg('polymake');";
         }
      }
      if ($@) {
         print "failed\n";
         if ($@ =~ /\ACan't locate /) {
            print STDERR <<".";
WARNING: perl module $pkg required for polymake not found on your machine.
         Please be sure to install it prior to starting to use polymake. 
         If you have installed them in a non-standard location
         please add the path to the environment variable PERL5LIB.
.
         } else {
            $@ =~ / at .*? line \d+/m;
            print STDERR <<".";
WARNING: perl module $pkg required for polymake seems to be unusable.
         An attempt to load it has failed because of the following:
         $`
         Please be sure to rectify the problem prior to starting to use polymake.
.
         }
         push @warned,$pkg;
      } elsif ($warn =~ /^(?!Use of inherited AUTOLOAD for non-method Term::ReadLine::Gnu::)./s) {
         print "\n";
         print STDERR <<".";
WARNING: perl module $pkg required for polymake might cause problems.
         An attempt to load it was successful, but was accompanied
         by the following message:
         $warn
         Please be sure to investigate it prior to starting to use polymake.
.
         push @warned,$pkg;
      } else {
         print "ok\n";
      }
   }
   if (@warned) {
      $warning .= <<'---';
WARNING: Please install/check the following perl modules prior to starting polymake: 
---
      $warning .= "         ".join(", ",@warned)."\n";
   }
}

#########################################################################
sub bundled_ext_error_msg {
   my ($ext, $msg)=@_;
   unless (defined($BundledLOG)) {
      open $BundledLOG, ">", $BundledLOGfile;
      print $BundledLOG <<"---";
Configuration of the following bundled extensions failed, proceeding without them.
If you really need them, please carefully read the following explanations,
take the suggested actions, and repeat the configuration.
---
   }
   print $BundledLOG "\n---- $ext ----\n\n$msg\n";
}

##########################################################################
sub order_enabled_bundled_extensions {
   my %ext_unordered=map { ($_ => 1) } grep { $options{$_} ne ".none." } @ext;
   while (keys %ext_unordered) {
      my $progress=@ext_ordered;
      foreach my $ext (sort keys %ext_unordered) {
         unless (grep { $ext_unordered{$_} } @{$ext_requires{$ext}}
                   or
                 grep { $ext_unordered{$_} } @{$ext_conflicts{$ext}}) {
            push @ext_ordered, $ext;
            delete $ext_unordered{$ext};
         }
      }
      last if $progress==@ext_ordered;
   }

   while ((my $ext, undef)=each %ext_unordered) {
      print "bundled extension $ext ... disabled because of cyclic dependencies on other extension(s): ",
            join(", ", (grep { $ext_unordered{$_} } @{$ext_requires{$ext}}),
                       (grep { $ext_unordered{$_} } @{$ext_conflicts{$ext}})), "\n";
   }
}

###########################################################################
sub configure_enabled_bundled_extensions {
   foreach my $ext (@ext_ordered) {
      print "bundled extension $ext ... ";
      my $enable=1;

      my @prereq;
      foreach my $prereq (@{$ext_requires{$ext}}) {
         if ($ext_survived{$prereq}) {
            push @prereq, $prereq;
         } elsif (!$ext_requires_opt{$ext}->{$prereq}) {
            if (-d "bundled/$prereq") {
               print "disabled because of unsatisfied prerequisite: $prereq";
            } else {
               print "disabled because of unknown/missing prerequisite: $prereq";
            }
            $enable=0; last;
         }
      }
      if ($enable) {
         foreach my $conflict (@{$ext_conflicts{$ext}}) {
            if ($ext_survived{$conflict}) {
               print "disabled because of conflict with other extension: $conflict";
               $enable=0; last;
            }
         }
      }

      if ($enable) {
         eval { check_extension_source_conflicts("bundled/$ext", ".", (map { "bundled/$_" } @prereq)) };
         if ($@) {
            print "disabled because of the following conflicts:\n\n$@";
            $enable=0;

         } elsif ($ext_with_config{$ext}) {
            my $result=eval { no strict 'refs'; &{"Polymake::Bundled::$ext\::proceed"}(\%options) };
            if ($@) {
               print "failed";
               bundled_ext_error_msg($ext, $@);
               $enable=0;
            } elsif ($result =~ /^disabled/) {
               $enable=0;
               print $result;
            } else {
               print "ok", $result ? " ($result)":"";
            }
         } else {
            print "ok";
         }
      }

      if ($enable) {
         $ext_requires{$ext}=\@prereq;
         $ext_survived{$ext}=1;
      } else {
         $ext_failed{$ext}=1;
         if (exists($options{$ext}) and $options{$ext} ne ".none.") {
            die << "---";


ERROR:
The bundled extension $ext was explicitly requested but failed to configure.
Please recheck your argument (--with-$ext=$options{$ext}) and ${BuildDir}/bundled.log .
You can also disable it by specifying --without-$ext instead.
---
         }
         $options{$ext}=".none.";
      }
      print "\n";
   }

   # save the list of enabled bundled extensions in proper order for the make process
   $BundledExts = join(" ", grep { $ext_survived{$_} } @ext_ordered);

   if ($options{prereq} ne ".none.") {
      my $ext_warning;

      $ext_warning .= <<"---" unless exists $ext_survived{"cdd"};

WARNING: The bundled extension for cdd was either disabled or failed to configure.
         Running polymake without cdd is deprecated and not supported!
         Please recheck your configuration and $BundledLOGfile.
---

      $ext_warning .= <<"---" unless (exists $ext_survived{"nauty"} or exists $ext_survived{"bliss"});

WARNING: The bundled extensions for bliss and nauty were both either disabled or failed to configure.
         Running polymake without a tool for graph-isomorphism tests is not supported!
         Please recheck your configuration and $BundledLOGfile.
---

      $ext_warning .= <<"---" unless exists $ext_survived{"flint"};

WARNING: The bundled extension for flint was either disabled or failed to configure.
         Running polymake without flint is not supported!
         QuadraticExtension types cannot be normalized in this configuration.
         Please recheck your configuration and $BundledLOGfile.
---

      # check for non-supported configuration:
      # failed required extensions but not disabled explicitly
      if ($ext_failed{cdd} || $ext_failed{flint} ||
          $ext_failed{bliss} && $ext_failed{nauty}) {

         print $ext_warning;
         die(<<"---");

ERROR: Configuration failed:
       At least one required bundled extension failed to configure.
       This error can be suppressed by disabling them explicitly via '--without-<ext>'.
---
      } elsif ($ext_warning) {
         $warning .= <<"---";
$ext_warning
* WARNING: Unsupported configuration:
* Some required bundled extensions were disabled explicitly.
* polymake will work but with reduced functionality.
---
      }
   }

   print "* If you want to change the configuration of bundled extensions please ",
         defined($BundledLOG) && "see $BundledLOGfile and ",
         "try configure --help.\n";

   if (defined $BundledLOG) {
      close $BundledLOG;
   } else {
      # remove an outdated logfile to avoid confusions
      unlink $BundledLOGfile;
   }
}

##############################################################################
sub finalize_compiler_flags {
   # add flags and libraries that should not appear in the test builds tried before

   if ($options{callable} ne ".none."
       and $LIBS !~ /-ldl/
       and $^O eq "linux") {
      $LIBS .= " -ldl";
   }

   $LIBS="$LIBS -lmpfr -lgmp -lpthread";

   # be rigorous about own code
   if ($Polymake::DeveloperMode) {
      $CXXFLAGS="-Wall -Werror $CXXFLAGS";
   }

   if (defined($options{ccache}) && $options{ccache} ne ".none.") {
      $CCACHE=$options{ccache};
      check_program($CCACHE);
   }
   if (defined($options{ccwrapper}) && $options{ccwrapper} ne ".none.") {
      $CCWRAPPER=$options{ccwrapper};
   }
}

##############################################################################
sub find_ninja {
   find_program_in_path("ninja")
     or die <<'---';
ERROR: The ninja program is required for building polymake.

It can usually be installed as a ready-to-use package, e.g.
on Ubuntu:
   apt-get install ninja-build
on MacOS with Homebrew:
   brew install ninja

As a fallback, you can obtain its source code from GitHub, build it yourself,
and install at a location of your choice:

INSTALL_DIR=/usr/local/bin  # or anything else reachable through your PATH

git clone https://github.com/ninja-build/ninja.git
cd ninja
./configure.py --bootstrap
sudo install -s -m 555 ninja $INSTALL_DIR

---
}

##############################################################################
sub write_configuration_file {
   my ($filename) = @_;
   open my $conf, ">", $filename
     or die "can't create $filename: $!\n";

   # preserve a copy of the command line for later reference
   print $conf "# last configured with:\n", "configure.command=$root/configure";
   write_config_command_line($conf, \%options, \%allowed_with, \%vars, \%ext_failed);

   my @external_includes=map { "-I\${root}/include/external/$_" } $ExternalHeaders =~ /(\S+)/g;
   print $conf <<"---";

root=$root
core.includes=-I\${root}/include/core-wrappers -I\${root}/include/core
app.includes=-I\${root}/include/app-wrappers -I\${root}/include/apps @external_includes

---
   write_config_vars(__PACKAGE__, "", $conf);

   print $conf <<"---";
AR = $Config::Config{ar}
---

   foreach my $pkg (sort keys %store_versions) {
      print $conf <<"---";
${pkg}.version = $store_versions{$pkg}
---
   }

   # write configuration variables for successfully configured bundled extensions
   foreach my $ext (sort keys %ext_survived) {
      write_config_vars("Polymake::Bundled::$ext", "bundled.$ext.", $conf);
      print $conf "bundled.$ext.RequireExtensions=@{$ext_requires{$ext}}\n";
   }

   close $conf;
}

#######################################################################
sub write_perl_specific_configuration_file {
   my ($filename)=@_;
   open my $conf, ">", $filename
     or die "can't create $filename: $!\n";

   my $PerlVersion=$Config::Config{version};
   $PerlVersion =~ s/\.//g;

   my $no_warn="-Wno-nonnull";
   # gcc 5 seems to not understand a #pragma ignoring -Wliteral-suffix
   if ($] < 5.020 && defined($GCCversion)) {
      $no_warn .= " -Wno-literal-suffix";
   }
   if (defined($CLANGversion) && v_cmp($CLANGversion, "10") >= 0) {
      $no_warn .= " -Wno-xor-used-as-pow";
   }

   # Xcode 10 deeply hides perl headers at unpredictable locations, it requires a special clang option to find them
   my $includePerlCore = defined($XcodeVersion) && v_cmp($XcodeVersion, "10.0") >= 0 && $Config::Config{perlpath} eq "/usr/bin/perl" ? "-iwithsysroot " : "-I";

   # fedora has ExtUtils::ParseXS in vendorlib
   my ($xsubpp) = grep { -e $_ } map { "$Config::Config{$_}/ExtUtils/xsubpp" } qw(privlib vendorlib);
   my ($typemap) = grep { -e $_ } map { "$Config::Config{$_}/ExtUtils/typemap" } qw(privlib vendorlib);

   print $conf <<"---";
PERL=$Config::Config{perlpath}
CXXglueFLAGS=$includePerlCore$Config::Config{archlibexp}/CORE $Config::Config{ccflags} $perlextraflags -DPerlVersion=$PerlVersion $no_warn
LIBperlFLAGS=-L$Config::Config{archlib}/CORE -lperl $Config::Config{ccdlflags}
ExtUtils_xsubpp=$xsubpp
ExtUtils_typemap=$typemap
---

   close $conf;
}

#######################################################################
sub delete_old_and_disabled_build_trees {
   # delete artifacts for disabled extensions, if any, and create .disabled markers
   foreach my $bundled (@ext_disabled, grep { !$ext_survived{$_} } @ext) {
      File::Path::remove_tree(grep { -d $_ } glob("$BuildDir/{Opt,Debug,Cov,San}/bundled/$bundled"));
   }

   # delete old (pre-ninja) build artifacts
   if ($Polymake::DeveloperMode && -f "$BuildDir/conf.make") {
      File::Path::remove_tree((grep { -d $_ } "$BuildDir/bundled", "$BuildDir/lib", "$BuildDir/apps", "$BuildDir/jars", "$BuildDir/java"),
                              glob("$BuildDir/perlx-*"), glob("$BuildDir/perlx/*/*/auto"));
      unlink "$BuildDir/conf.make";
   }
}

#######################################################################
sub create_alt_perl_configuration {
   -f "$BuildDir/config.ninja"
     or die "option --alt-perl can only be used on the top of an existing full configuration\n";

   File::Path::make_path("$BuildDir/$perlxpath");
   write_perl_specific_configuration_file("$BuildDir/$perlxpath/config.ninja");
   my $builddir = "$root/$BuildDir";
   foreach my $mode ($BuildModes =~ /(\S+)/g) {
      create_build_mode_subtree($builddir, $mode);
      write_build_ninja_file($builddir, $mode, "build.$options{'alt-perl'}.ninja", perlxpath => $perlxpath);
   }
}

# Local Variables:
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: