This file is indexed.

/usr/src/gcc-5/debian/rules.defs is in gcc-5-source 5.5.0-12ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
# -*- makefile -*-
# definitions used in more than one Makefile / rules file

NJOBS :=
USE_CPUS := 1
ifneq (,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
  USE_CPUS := $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
  NJOBS := -j $(USE_CPUS)
endif

# common vars
SHELL		= /bin/bash -e	# brace expansion used in rules file
srcdir		= $(CURDIR)/src
builddir	= $(CURDIR)/build
builddir_jit	= $(CURDIR)/build-jit
builddir_hppa64	= $(CURDIR)/build-hppa64
stampdir	= stamps

distribution	:= $(shell lsb_release -is)
distrelease	:= $(shell lsb_release -cs)
derivative	:= $(shell if dpkg-vendor --derives-from Ubuntu; then echo Ubuntu; \
			elif dpkg-vendor --derives-from Debian; then echo Debian; \
			else echo Unknown; fi)

# On non official archives, "lsb_release -cs" default to "n/a". Assume
# sid in that case 
ifeq ($(distrelease),n/a)
distrelease	:= sid
endif

on_buildd := $(shell [ -f /CurrentlyBuilding -o "$$LOGNAME" = buildd ] && echo yes)

# creates {srcdir,builddir}_{hppa64,neon}
$(foreach x,srcdir builddir,$(foreach target,hppa64 neon,$(eval \
  $(x)_$(target) := $($(x))-$(target))))

# for architecture dependent variables and changelog vars
vafilt = $(subst $(2)=,,$(filter $(2)=%,$(1)))
# for rules.sonames
vafilt_defined = 1

dpkg_target_vars := $(shell (dpkg-architecture | grep -q DEB_TARGET) && echo yes)
ifeq ($(dpkg_target_vars),yes)
  DEB_TARGET_ARCH=
  DEB_TARGET_ARCH_BITS=
  DEB_TARGET_ARCH_CPU=
  DEB_TARGET_ARCH_ENDIAN=
  DEB_TARGET_ARCH_OS=
  DEB_TARGET_GNU_CPU=
  DEB_TARGET_GNU_SYSTEM=
  DEB_TARGET_GNU_TYPE=
  DEB_TARGET_MULTIARCH=
endif

DPKG_VARS		:= $(shell dpkg-architecture)
ifeq ($(dpkg_target_vars),yes)
  DPKG_VARS		:= $(filter-out DEB_TARGET_%, $(DPKG_VARS))
endif
DEB_BUILD_ARCH		?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_ARCH)
DEB_BUILD_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_GNU_TYPE)
DEB_BUILD_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_MULTIARCH)
DEB_HOST_ARCH		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH)
DEB_HOST_GNU_CPU	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_CPU)
DEB_HOST_GNU_SYSTEM	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_SYSTEM)
DEB_HOST_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

ifeq ($(derivative),Ubuntu)
  ifeq (,$(filter $(distrelease),dapper hardy lucid precise quantal raring saucy trusty))
    ifeq ($(DEB_BUILD_GNU_TYPE),i486-linux-gnu)
      DEB_BUILD_GNU_TYPE = i686-linux-gnu
    endif
    ifeq ($(DEB_HOST_GNU_TYPE),i486-linux-gnu)
      DEB_HOST_GNU_TYPE	= i686-linux-gnu
    endif
  endif
else
  ifneq (,$(filter $(distrelease),lenny etch squeeze wheezy))
    # keep dpkg defaults
  else ifneq (,$(filter $(distrelease),jessie))
    ifeq ($(DEB_BUILD_GNU_TYPE),i486-linux-gnu)
      DEB_BUILD_GNU_TYPE = i586-linux-gnu
    endif
    ifeq ($(DEB_HOST_GNU_TYPE),i486-linux-gnu)
      DEB_HOST_GNU_TYPE	= i586-linux-gnu
    endif
  else
    # stretch and newer ...
    DEB_BUILD_GNU_TYPE := $(subst i586,i686,$(DEB_BUILD_GNU_TYPE))
    DEB_HOST_GNU_TYPE := $(subst i586,i686,$(DEB_HOST_GNU_TYPE))
  endif
endif

CHANGELOG_VARS := $(shell dpkg-parsechangelog | \
	sed -n 's/ /_/g;/^[^_]/s/^\([^:]*\):_\(.*\)/\1=\2/p')

# the name of the source package
PKGSOURCE := $(call vafilt,$(CHANGELOG_VARS),Source)
# those are required here too
SOURCE_VERSION := $(call vafilt,$(CHANGELOG_VARS),Version)
DEB_VERSION := $(strip $(shell echo $(SOURCE_VERSION) | \
        sed -e 's/.*://' -e 's/ds[0-9]*//'))
# epoch used for gcc versions up to 3.3.x, now used for some remaining
# libraries: libgcc1, libobjc1
EPOCH := 1
DEB_EVERSION := $(EPOCH):$(DEB_VERSION)
BASE_VERSION := $(shell echo $(DEB_VERSION) | sed -e 's/\([1-9]\).*-.*/\1/')

# push glibc stack traces into stderr
export LIBC_FATAL_STDERR_=1

# ---------------------------------------------------------------------------
# set target
# - GNU triplet via DEB_TARGET_GNU_TYPE
# - Debian arch in debian/target
# - Debian arch via DEB_GCC_TARGET or GCC_TARGET
#
# alias
ifdef GCC_TARGET
  DEB_GCC_TARGET := $(GCC_TARGET)
endif
ifdef DEB_TARGET_GNU_TYPE
  TARGET_VARS := $(shell dpkg-architecture -f -t$(DEB_TARGET_GNU_TYPE) 2>/dev/null)
else
  # allow debian/target to be used instead of DEB_GCC_TARGET - this was requested
  # by toolchain-source maintainer
  DEBIAN_TARGET_FILE := $(strip $(if $(wildcard debian/target),$(shell cat debian/target 2>/dev/null)))
  ifndef DEB_TARGET_ARCH
    ifneq (,$(DEBIAN_TARGET_FILE))
      DEB_TARGET_ARCH := $(DEBIAN_TARGET_FILE)
    else
      ifdef DEB_GCC_TARGET
        DEB_TARGET_ARCH := $(DEB_GCC_TARGET)
      else
        DEB_TARGET_ARCH := $(DEB_HOST_ARCH)
      endif
    endif
  endif
  TARGET_VARS := $(shell dpkg-architecture -f -a$(DEB_TARGET_ARCH) 2>/dev/null)
endif
ifeq ($(dpkg_target_vars),yes)
  TARGET_VARS		:= $(filter-out DEB_TARGET_%, $(TARGET_VARS))
endif

DEB_TARGET_ARCH		:= $(call vafilt,$(TARGET_VARS),DEB_HOST_ARCH)
DEB_TARGET_ARCH_OS	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_ARCH_OS)
DEB_TARGET_ARCH_CPU	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_ARCH_CPU)
DEB_TARGET_GNU_CPU	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_GNU_CPU)
DEB_TARGET_GNU_TYPE	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_GNU_TYPE)
DEB_TARGET_GNU_SYSTEM	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_GNU_SYSTEM)
DEB_TARGET_MULTIARCH	:= $(call vafilt,$(TARGET_VARS),DEB_HOST_MULTIARCH)

ifeq ($(derivative),Ubuntu)
  ifeq (,$(filter $(distrelease),dapper lucid))
    ifeq ($(DEB_TARGET_GNU_TYPE),i486-linux-gnu)
      DEB_TARGET_GNU_TYPE = i586-linux-gnu
    endif
  endif
else
  ifneq (,$(filter $(distrelease),stretch))
    DEB_TARGET_GNU_TYPE := $(subst i586,i686,$(DEB_TARGET_GNU_TYPE))
    i586_symlinks = $(if $(findstring i686,$(DEB_TARGET_GNU_TYPE)),yes)
  endif
endif

ifeq ($(DEB_TARGET_ARCH),)
  $(error Invalid architecure.)
endif

# Force this, people get confused about the default. See #760770.
override with_deps_on_target_arch_pkgs :=

# including unversiond symlinks for binaries
#with_unversioned = yes

# ---------------------------------------------------------------------------
# cross-compiler config
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
  ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_TARGET_GNU_TYPE))
    # cross building a cross compiler, untested.
    DEB_CROSS = yes
    build_type = cross-build-cross
  else
    # cross building the native compiler
    ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid))
      with_sysroot = /
    endif
    build_type = cross-build-native
  endif
else
  ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_TARGET_GNU_TYPE))
    # cross compiler, sets WITH_SYSROOT on it's own
    DEB_CROSS = yes
    build_type = build-cross
  else ifeq ($(FORCE_CROSS_LAYOUT),yes)
    # a native build with a cross layout
    DEB_CROSS = yes
    build_type = build-cross
  else
    # native build
    # first ones are wheezy and maverick
    ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid))
      with_sysroot = /
    endif
    build_type = build-native
  endif
endif

# ---------------------------------------------------------------------------
# cross compiler support
ifeq ($(DEB_CROSS),yes)
  # TARGET: Alias to DEB_TARGET_ARCH (Debian arch name)
  # TP: Target Prefix. Used primarily as a prefix for cross tool
  #     names (e.g. powerpc-linux-gcc).
  # TS: Target Suffix. Used primarily at the end of cross compiler
  #     package names (e.g. gcc-powerpc).
  # LS: Library Suffix. Used primarily at the end of cross compiler
  #     library package names (e.g. libgcc-powerpc-cross).
  # AQ: Arch Qualifier. Used for cross-arch dependencies
  DEB_TARGET_ALIAS ?= $(DEB_TARGET_GNU_TYPE)
  TARGET := $(DEB_TARGET_ARCH)
  TP :=  $(subst _,-,$(DEB_TARGET_GNU_TYPE))-
  TS := -$(subst _,-,$(DEB_TARGET_ALIAS))
  LS := -$(subst _,-,$(DEB_TARGET_ARCH))-cross
  AQ :=

  cross_bin_arch := -$(subst _,-,$(DEB_TARGET_ALIAS))
  cross_lib_arch := -$(subst _,-,$(DEB_TARGET_ARCH))-cross
  cmd_prefix := $(DEB_TARGET_GNU_TYPE)-

  TARGET_ALIAS := $(DEB_TARGET_ALIAS)

  lib_binaries := indep_binaries
  cross_shlibdeps =  DEB_HOST_ARCH=$(TARGET) ARCH=$(DEB_TARGET_ARCH) MAKEFLAGS="CC=something"
  cross_gencontrol = DEB_HOST_ARCH=$(TARGET)
  cross_makeshlibs = DEB_HOST_ARCH=$(TARGET)
  cross_clean = DEB_HOST_ARCH=$(TARGET)
else
  TARGET_ALIAS := $(DEB_TARGET_GNU_TYPE)

  ifeq ($(TARGET_ALIAS),i386-gnu)
    TARGET_ALIAS := i586-gnu
  endif

  cmd_prefix :=

  #ifeq ($(TARGET_ALIAS),i486-linux-gnu)
  #  TARGET_ALIAS := i686-linux-gnu
  #endif

  TARGET_ALIAS := $(subst i386,i486,$(TARGET_ALIAS))

  # configure as linux-gnu, not linux
  #ifeq ($(findstring linux,$(TARGET_ALIAS))/$(findstring linux-gnu,$(TARGET_ALIAS)),linux/)
  #  TARGET_ALIAS := $(TARGET_ALIAS)-gnu
  #endif

  # configure as linux, not linux-gnu
  #TARGET_ALIAS := $(subst linux-gnu,linux,$(TARGET_ALIAS))

  lib_binaries := arch_binaries
  cross_shlibdeps :=
  cross_gencontrol :=
  cross_makeshlibs :=
  cross_clean :=
endif

printarch:
	@echo DEB_TARGET_ARCH: $(DEB_TARGET_ARCH)
	@echo DEB_TARGET_ARCH_OS: $(DEB_TARGET_ARCH_OS)
	@echo DEB_TARGET_ARCH_CPU: $(DEB_TARGET_ARCH_CPU)
	@echo DEB_TARGET_GNU_SYSTEM: $(DEB_TARGET_GNU_SYSTEM)
	@echo DEB_TARGET_MULTIARCH: $(DEB_TARGET_MULTIARCH)
	@echo MULTIARCH_CONFARG: $(MULTIARCH_CONFARG)
	@echo TARGET_ALIAS: $(TARGET_ALIAS)
	@echo TP: $(TP)
	@echo TS: $(TS)

# -------------------------------------------------------------------
# bootstrap options
ifdef WITH_BOOTSTRAP
  # "yes" is the default and causes a 3-stage bootstrap.
  # "off" runs a complete build with --disable-bootstrap
  # "no" means to just build the first stage, and not create the stage1
  # directory.
  # "lean" means a lean 3-stage bootstrap, i.e. delete each stage when no
  # longer needed.
  with_bootstrap = $(WITH_BOOTSTRAP)
endif
ifneq ($(findstring nostrap, $(DEB_BUILD_OPTIONS)),)
  with_bootstrap := off
endif

ifneq ($(findstring gccdebug, $(DEB_BUILD_OPTIONS)),)
  with_bootstrap := off
  DEB_BUILD_OPTIONS := $(DEB_BUILD_OPTIONS) nostrip
  export DEB_BUILD_OPTIONS
endif

# -------------------------------------------------------------------
# stage options
ifdef DEB_STAGE
  with_cdev := yes
  separate_lang := yes
  # "stage1" is minimal compiler with static libgcc
  # "stage2" is minimal compiler with shared libgcc
  # "rtlibs" is a subset of target libraries, without compilers
  ifeq ($(DEB_STAGE),stage1)
    with_shared_libgcc := no
  endif
  ifeq ($(DEB_STAGE),stage2)
    with_libgcc := yes
    with_shared_libgcc := yes
  endif
  ifeq ($(DEB_STAGE),rtlibs)
    with_rtlibs := libgcc libgomp libstdc++ libgfortran libquadmath
    ifeq ($(DEB_CROSS),yes)
      LS :=
      TS :=
      cross_lib_arch :=
    endif
  endif
endif

ifeq ($(BACKPORT),true)
  with_dev := no
  with_source := yes
  with_base_only := yes
endif

# -------------------------------------------------------------------
# sysroot options
ifdef WITH_SYSROOT
  with_sysroot = $(WITH_SYSROOT)
endif
ifdef WITH_BUILD_SYSROOT
  with_build_sysroot = $(WITH_BUILD_SYSROOT)
endif

# -------------------------------------------------------------------
# for components configuration

COMMA = ,
SPACE = $(EMPTY) $(EMPTY)

# lang= overwrites all of nolang=, overwrites all of WITHOUT_LANG

DEB_LANG_OPT	:= $(filter lang=%,$(DEB_BUILD_OPTIONS))
DEB_LANG	:= $(strip $(subst $(COMMA), ,$(patsubst lang=%,%,$(DEB_LANG_OPT))))
DEB_NOLANG_OPT	:= $(filter nolang=%,$(DEB_BUILD_OPTIONS))
DEB_NOLANG	:= $(strip $(subst $(COMMA), ,$(patsubst nolang=%,%,$(DEB_NOLANG_OPT))))
lfilt	= $(strip $(if $(DEB_LANG), \
		$(if $(filter $(1) $(2),$(DEB_LANG)),yes),$(3)))
nlfilt	= $(strip $(if $(DEB_NOLANG), \
		$(if $(filter $(1) $(2),$(DEB_NOLANG)),disabled by $(DEB_NOLANG_OPT),$(3))))
wlfilt	= $(strip $(if $(filter $(1) $(2), $(subst $(COMMA), ,$(WITHOUT_LANG))), \
		disabled by WITHOUT_LANG=$(WITHOUT_LANG),$(3)))
envfilt	= $(strip $(or $(call lfilt,$(1),$(2)),$(call nlfilt,$(1),$(3)),$(call wlfilt,$(1),$(3)),$(4)))

# -------------------------------------------------------------------
# architecture specific config

# FIXME: libjava is not ported for thumb, this hack only works for
# separate gcj builds
ifeq (,$(findstring gcj,$(PKGSOURCE)))
  ifeq ($(DEB_TARGET_ARCH),armhf)
    ifeq ($(distribution),Raspbian)
      with_arm_thumb := no
    else
      with_arm_thumb := yes
    endif
  else
    ifeq ($(derivative)-$(DEB_TARGET_ARCH),Ubuntu-armel)
      ifneq (,$(filter $(distrelease),lucid maverick natty oneiric precise))
        with_arm_thumb := yes
      endif
    endif
  endif
endif

# build using fsf or linaro
ifeq ($(distribution),Ubuntu)
  ifneq (,$(findstring $(DEB_TARGET_ARCH),arm64 armel armhf))
    with_linaro_branch = yes
  endif
endif

# build using fsf or the ibm branch
ifeq ($(distribution),Ubuntu)
  ifneq (,$(findstring $(DEB_TARGET_ARCH),ppc64el))
    with_ibm_branch = yes
  endif
endif

# check if we're building for armel or armhf
ifeq ($(DEB_TARGET_ARCH),armhf)
  float_abi := hard
else ifneq (,$(filter $(distribution)-$(DEB_TARGET_ARCH), Ubuntu-armel))
  ifneq (,$(filter $(distrelease),lucid maverick natty oneiric precise))
    float_abi := softfp
  else
    float_abi := soft
  endif
else ifneq (,$(filter $(DEB_TARGET_ARCH), arm armel))
  float_abi := soft
endif

# -------------------------------------------------------------------
# basic config

# allows to wrote backtraces for ICEs
#unstripped_exe = yes

# common things ---------------
# build common packages, where package names don't differ in different
# gcc versions (fixincludes, libgcj-common) ...
#with_common_pkgs := yes
# ... and some libraries, which do not change (libgcc1, libssp0).
#with_common_libs := yes
# XXX: should with_common_libs be "yes" only if this is the default compiler
# version on the targeted arch?

# is this a multiarch-enabled build?
ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid maverick))
  with_multiarch_lib := yes
endif

ifeq ($(with_multiarch_lib),yes)
  ifneq ($(single_package),yes)
    ifneq ($(DEB_CROSS),yes)
      with_multiarch_cxxheaders := yes
    endif
  endif
endif

ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid maverick))
  multiarch_stage1 := yes
endif

# mapping for the non-default biarch multilib / multiarch names
multiarch_xarch_map = \
	amd64=i386-linux-gnu,x86_64-linux-gnux32 \
	armel=arm-linux-gnueabi \
	armhf=arm-linux-gnueabihf \
	i386=x86_64-linux-gnu,x86_64-linux-gnux32 \
	powerpc=powerpc64-linux-gnu \
	ppc64=powerpc-linux-gnu \
	sparc=sparc64-linux-gnu \
	sparc64=sparc-linux-gnu \
	s390=s390x-linux-gnu \
	s390x=s390-linux-gnu \
	mips=mips64-linux-gnuabin32,mips64-linux-gnuabi64 \
	mipsel=mips64el-linux-gnuabin32,mips64el-linux-gnuabi64 \
	mipsn32=mips-linux-gnu,mips64-linux-gnuabi64 \
	mipsn32el=mipsel-linux-gnu,mips64el-linux-gnuabi64 \
	mips64=mips-linux-gnu,mips64-linux-gnuabin32 \
	mips64el=mipsel-linux-gnu,mips64el-linux-gnuabin32 \
	mipsr6=mipsisa64r6-linux-gnuabin32,mipsisa64r6-linux-gnuabi64 \
	mipsr6el=mipsisa64r6el-linux-gnuabin32,mipsisa64r6el-linux-gnuabi64 \
	mipsn32r6=mipsisa32r6-linux-gnu,mipsisa64r6-linux-gnuabi64 \
	mipsn32r6el=mipsisa32r6el-linux-gnu,mipsisa64r6el-linux-gnuabi64 \
	mips64r6=mipsisa32r6-linux-gnu,mipsisa64r6-linux-gnuabin32 \
	mips64r6el=mipsisa32r6el-linux-gnu,mipsisa64r6el-linux-gnuabin32 \
	x32=x86_64-linux-gnu,i386-linux-gnu \
	kfreebsd-amd64=i386-kfreebsd-gnu
xarch_multiarch_names = $(subst $(COMMA),$(SPACE),$(patsubst $(DEB_TARGET_ARCH)=%,%, \
		$(filter $(DEB_TARGET_ARCH)=%,$(multiarch_xarch_map))))

multilib_multiarch_map = \
	$(DEB_TARGET_ARCH)/=$(DEB_TARGET_MULTIARCH) \
	amd64/32=i386-linux-gnu \
	amd64/x32=x86_64-linux-gnux32 \
	armel/hf=arm-linux-gnueabihf \
	armhf/sf=arm-linux-gnueabi \
	i386/64=x86_64-linux-gnu \
	i386/x32=x86_64-linux-gnux32 \
	powerpc/64=powerpc64-linux-gnu \
	ppc64/32=powerpc-linux-gnu \
	sparc/64=sparc64-linux-gnu \
	sparc64/32=sparc-linux-gnu \
	s390/64=s390x-linux-gnu \
	s390x/32=s390-linux-gnu \
	mips/n32=mips64-linux-gnuabin32 \
	mips/64=mips64-linux-gnuabi64 \
	mipsel/n32=mips64el-linux-gnuabin32 \
	mipsel/64=mips64el-linux-gnuabi64 \
	mipsn32/32=mips-linux-gnu \
	mipsn32/64=mips64-linux-gnuabi64 \
	mipsn32el/32=mipsel-linux-gnu \
	mipsn32el/64=mips64el-linux-gnuabi64 \
	mips64/32=mips-linux-gnu \
	mips64/n32=mips64-linux-gnuabin32 \
	mips64el/32=mipsel-linux-gnu \
	mips64el/n32=mips64el-linux-gnuabin32 \
	mipsr6/n32=mipsisa64r6-linux-gnuabin32 \
	mipsr6/64=mipsisa64r6-linux-gnuabi64 \
	mipsr6el/n32=mipsisa64r6el-linux-gnuabin32 \
	mipsr6el/64=mipsisa64r6el-linux-gnuabi64 \
	mipsn32r6/32=mipsisa32r6-linux-gnu \
	mipsn32r6/64=mipsisa64r6-linux-gnuabi64 \
	mipsn32r6el/32=mipsisa32r6el-linux-gnu \
	mipsn32r6el/64=mipsisa64r6el-linux-gnuabi64 \
	mips64r6/32=mipsisa32r6-linux-gnu \
	mips64r6/n32=mipsisa64r6-linux-gnuabin32 \
	mips64r6el/32=mipsisa32r6el-linux-gnu \
	mips64r6el/n32=mipsisa64r6el-linux-gnuabin32 \
	x32/32=i386-linux-gnu \
	x32/64=x86_64-linux-gnu \
	kfreebsd-amd64/32=i386-kfreebsd-gnu
# $(call mlib_to_march,<empty>|32|64|n32|x32|hf|sf)
mlib_to_march = $(patsubst $(DEB_TARGET_ARCH)/$(1)=%,%, \
		   $(filter $(DEB_TARGET_ARCH)/$(1)=%,$(multilib_multiarch_map)))

# build -base packages
with_gccbase := yes
ifeq ($(build_type),build-cross)
  ifneq ($(DEB_STAGE),rtlibs)
    with_gcclbase := yes
  endif
endif

# build dev packages.
ifneq ($(DEB_STAGE),rtlibs)
  with_dev := yes
endif

with_cpp := yes

# set lang when built from a different source package.
separate_lang := no

ifneq (,$(findstring gcc-snapshot, $(PKGSOURCE)))
  single_package = yes
  trunk_build = yes
  with_linaro_branch =
else ifneq (,$(findstring gcc-linaro, $(PKGSOURCE)))
  single_package = yes
  trunk_build = no
else
  # --program-suffix=-$(BASE_VERSION)
  versioned_packages := yes
endif

#no_dummy_cpus := ia64 i386 hppa s390 sparc
#ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(no_dummy_cpus)))
#  with_base_only	:= no
#  with_common_libs	:= yes
#  with_common_pkgs	:= yes
#else
#  with_base_only	:= yes
#  with_common_libs	:= no
#  with_common_pkgs	:= no
#  with_dev		:= no
#endif

ifeq ($(versioned_packages),yes)
  pkg_ver := -$(BASE_VERSION)
  PV := $(pkg_ver)
endif

# -------------------------------------------------------------------
# configure languages

# C ---------------------------
enabled_languages := c

with_jit = yes

# FIXME: compiler bug
jit_no_cpus	:= ia64

ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(jit_no_cpus)))
  with_jit := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifneq (,$(with_rtlibs))
  with_jit := disabled for rtlibs stage
endif
with_jit := $(call envfilt, jit, , , $(with_jit))

ifeq (,$(findstring gcc-,$(PKGSOURCE)))
  with_jit :=
endif

ifneq (,$(findstring build-cross, $(build_type)))
  with_jit := disabled for cross builds
endif

ifeq ($(with_jit),yes)
    ifeq ($(with_common_libs),yes)
      with_libgccjit := yes
    endif
endif

with_cc1 := yes
with_cc1 := $(call envfilt, cc1, , , $(with_cc1))
ifeq ($(with_cc1),yes)
  ifneq ($(DEB_CROSS),yes)
    ifeq ($(with_common_libs),yes)
      with_libcc1 := yes
    endif
  endif
endif
ifneq (,$(with_rtlibs))
  with_libcc1 := disabled for rtlibs stage
endif

# Build all packages needed for C development
ifneq ($(with_base_only),yes)
  ifeq ($(with_dev),yes)
    with_cdev := yes
  endif
endif

ifeq (,$(filter $(DEB_STAGE),stage1 stage2))
# Ada --------------------
ada_no_cpus	:= m32r sh3 sh3eb sh4eb
# no Debian builds ... some of these should exist
ada_no_cpus += powerpcspe
ada_no_cpus += mips64 # see https://gcc.gnu.org/PR65337
ada_no_cpus += x32 # see https://gcc.gnu.org/PR61954
ada_no_systems	:= 
ada_no_cross	:= no
ada_no_snap	:= no
ifeq ($(single_package),yes)
  ada_no_cpus += m68k powerpcspe sh4 sparc64
  ada_no_cpus += alpha
  ifneq (,$(filter $(DEB_TARGET_ARCH),m68k mips mipsel powerpcspe sh4 sparc64 hurd-i386 kfreebsd-i386 kfreebsd-amd64))
    ada_no_cpus += mips mipsel
    ada_no_cpus += hurd-i386 kfreebsd-i386 kfreebsd-amd64
    ada_no_snap := yes
  endif
endif

ifeq ($(with_dev),yes)
  ifneq ($(separate_lang),yes)
    with_ada := yes
  endif
endif
ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(ada_no_cpus)))
  with_ada := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifneq (,$(filter $(DEB_TARGET_ARCH),powerpcspe x32))
  with_ada := disabled for architecture $(DEB_TARGET_ARCH)
endif
ifneq (,$(findstring cross,$(build_type)))
  ifneq (,$(filter $(DEB_BUILD_ARCH),m68k powerpcspe sh4 x32))
    with_ada := no gnat host compiler on $(DEB_BUILD_ARCH)
  endif
endif
ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(ada_no_systems)))
  with_ada := disabled for system $(DEB_TARGET_GNU_SYSTEM)
endif
ifeq ($(ada_no_cross)-$(DEB_CROSS),yes-yes)
  with_ada := disabled for cross compiler package
endif
ifeq ($(ada_no_snap)-$(single_package),yes-yes)
  with_ada := disabled for snapshot build
endif
ifneq (,$(findstring gccgo,$(PKGSOURCE)))
  with_ada :=
endif
ifneq (,$(filter $(distrelease),lucid))
  with_ada :=
endif
with_ada := $(call envfilt, ada, , , $(with_ada))


ifeq ($(DEB_STAGE)-$(filter libgnat, $(with_rtlibs)),rtlibs-)
  with_ada := disabled for rtlibs stage
endif

#ifneq ($(single_package),yes)
#  with_separate_gnat := yes
#endif

ifneq ($(with_separate_gnat),yes)
  ifeq ($(with_ada),yes)
    ifneq (,$(filter $(distrelease),squeeze lucid))
      with_ada :=
    endif
  endif
endif

ifeq ($(with_ada)-$(with_separate_gnat),yes-yes)
  ifneq (,$(findstring gnat,$(PKGSOURCE)))
    languages := c
    separate_lang := yes
    with_mudflap := no
    with_gccbase := no
    with_cdev := no
    with_cc1 := no
    with_libcc1 := no
  else
    debian_extra_langs += ada
    with_ada := built from separate source
    with_libgnat := built from separate source
  endif
endif

ifeq ($(with_ada),yes)
  enabled_languages += ada
  with_libgnat := yes
  with_gnatsjlj := yes
endif

# C++ -------------------------
cxx_no_cpus := avr
ifneq ($(with_base_only),yes)
  ifneq ($(separate_lang),yes)
    with_cxx := yes
  endif
endif
ifneq (,$(findstring $(DEB_TARGET_ARCH_CPU),$(cxx_no_cpus)))
  with_cxx := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
with_cxx := $(call envfilt, c++, obj-c++ java, , $(with_cxx))

# Set the default libstdc++ ABI. libstdc++ provides both ABI's.
# Existing code still runs with the new c++11 ABI, however link
# errors are seen when one object is compiled with the new std::string in scope,
# another object is compiled with the old std::string in scope. both can link
# to libstdc++.so but not to each other.
# two objects (which might be some system library and a user's program) need to
# agree on the version of std::string they're using

libstdcxx_abi = new
# backports default to the old ABI
ifneq (,$(filter $(distrelease),squeeze wheezy jessie lucid precise trusty utopic vivid))
  libstdcxx_abi = gcc4-compatible
endif

# Build all packages needed for C++ development
ifeq ($(with_cxx),yes)
  ifeq ($(with_dev),yes)
    with_cxxdev := yes
    with_libcxxdbg := yes
  endif
  ifeq ($(with_common_libs),yes)
    with_libcxx := yes
  endif

  # debugging versions of libstdc++
  ifneq (,$(findstring gcc-, $(PKGSOURCE)))
  ifeq ($(with_cxxdev),yes)
    with_cxx_debug := yes
    debug_no_cpus :=
    ifneq (,$(findstring $(DEB_TARGET_ARCH_CPU),$(debug_no_cpus)))
      with_cxx_debug := disabled for cpu $(DEB_TARGET_GNU_CPU)
    endif
  endif
  endif
  with_cxx_debug := $(call envfilt, debug, , , $(with_cxx_debug))

  enabled_languages += c++
endif

# Java --------------------
# - To build a standalone gcj package (with no corresponding gcc
#   package): with_separate_libgcj=yes, with_standalone_gcj=yes
# - To build the java packages from the gcc source package:
#   with_separate_libgcj=no, with_standalone_gcj=no
# - To build gcc and java from separate sources:
#   with_separate_libgcj=yes, with_standalone_gcj=no

java_no_cpus := # arm64 mips mipsel
java_no_systems :=

ifneq ($(single_package),yes)
  with_separate_libgcj := yes
endif
with_separate_libgcj := no
with_standalone_gcj := no

ifneq ($(separate_lang),yes)
  with_java := yes
endif

# java converted for V3 C++ ABI for some archs
ifeq ($(with_base_only),yes)
  with_java := no
endif
ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(java_no_cpus)))
  with_java := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifneq (,$(filter $(DEB_TARGET_GNU_SYSTEM),$(java_no_systems)))
  with_java := disabled for system $(DEB_TARGET_GNU_SYSTEM)
endif
ifeq ($(java_no_cross)-$(DEB_CROSS),yes-yes)
  with_java := disabled for cross compiler package
endif
with_java := $(call envfilt, java, , c++, $(with_java))

ifeq ($(DEB_STAGE)-$(filter libgcj, $(with_rtlibs)),rtlibs-)
  with_java := disabled for rtlibs stage
endif

ifeq (,$(filter $(distrelease),squeeze wheezy jessie stretch precise trusty xenial yakkety zesty artful))
  with_java := disabled for recent distro releases
endif

ifneq (,$(findstring gccgo, $(PKGSOURCE)))
  with_java :=
endif

ifeq ($(with_java)-$(with_separate_libgcj),yes-yes)
  ifneq (,$(findstring gcj, $(PKGSOURCE)))
    languages := c c++
    separate_lang := yes
  else
    debian_extra_langs += java
    with_java := built from separate source
    with_gcj := built from separate source
    with_libgcj := buit from separate source
  endif
endif

with_java_plugin := no

ifeq ($(with_java),yes)
  # use the same names as OpenJDK
  java_cpu_map = armel=arm armhf=arm arm64=aarch64 hppa=parisc \
	i686=i386 i586=i386 i486=i386 x32=x32 \
	mipsel=mips mips64=mips mips64el=mips mipsn32=mips mipsn32el=mips \
	mipsr6=mips mipsr6el=mips mips64r6=mips mips64r6el=mips mipsn32r6=mips mipsn32r6el=mips \
	powerpc=ppc ppc64el=ppc64le sh4=sh x32=x32
  java_cpu = $(patsubst $(DEB_TARGET_ARCH_CPU)=%,%, \
                         $(filter $(DEB_TARGET_ARCH_CPU)=%,$(java_cpu_map)))
  ifeq (,$(java_cpu))
    java_cpu = $(DEB_TARGET_ARCH_CPU)
  endif
  java_priority = 10$(subst .,,$(BASE_VERSION))0

  with_libgcj := yes
  with_libgcjbc := no

  ifneq (,$(findstring gcj-4,$(PKGSOURCE)))
    ifneq (,$(filter $(DEB_TARGET_ARCH), arm))
      with_gcj_base_only := yes
    endif
  endif

  ifeq ($(single_package),yes)
    with_ecj := yes
  endif

  #ifneq (,$(filter $(DEB_TARGET_ARCH),hppa))
  #  with_native_ecj := yes
  #endif

  ifneq (,$(filter $(DEB_TARGET_ARCH),arm armel))
    with_external_ecj1 := yes
  endif
  ifeq (,$(filter $(distrelease),squeeze wheezy jessie lucid precise trusty xenial))
    with_external_ecj1 := yes
  endif

  with_java_maintainer_mode := no

  # used as well in debian/rules.conf to determine the build deps
  java_awt_peers = gtk # qt # xlib

  ifeq ($(with_common_libs),yes)
    with_libgcj_doc := yes
  endif

  # Build all packages needed for Java development (gcj, libgcj-dev)
  ifeq ($(with_dev),yes)
    with_javadev := yes
    with_gcj := yes
  endif

  with_java_alsa := yes
  ifeq (,$(filter $(DEB_TARGET_GNU_SYSTEM),linux-gnu))
    with_java_alsa := no
  endif

  # Just build the cross compiler to be able to cross build a native build.
  ifeq ($(DEB_CROSS),yes)
    with_libgcj :=
  endif

  enabled_languages += java
endif

# Go -------------------
# - To build a standalone gccgo package (with no corresponding gcc
#   package): with_separate_libgo=yes, with_standalone_go=yes
# - To build the go packages from the gcc source package:
#   with_separate_libgo=no, with_standalone_go=no
# - To build gcc and go from separate sources:
#   with_separate_libgo=yes, with_standalone_go=no

go_no_cross := yes
go_no_cross := no

ifneq (,$(findstring gccgo, $(PKGSOURCE)))
  with_separate_libgo := yes
  with_standalone_go := yes
endif

go_no_cpus := avr arm hppa m68k sh4
ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid maverick natty oneiric))
  go_no_cpus := $(filter-out arm, $(go_no_cpus))
endif
go_no_systems := gnu kfreebsd-gnu

ifneq ($(with_base_only),yes)
  ifneq ($(separate_lang),yes)
    with_go := yes
  endif
endif
ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(go_no_cpus)))
  with_go := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(go_no_systems)))
  with_go := disabled for system $(DEB_TARGET_GNU_SYSTEM)
endif
ifeq ($(go_no_cross)-$(DEB_CROSS),yes-yes)
  with_go := disabled for cross compiler package
endif
ifeq ($(DEB_STAGE)-$(filter libgo, $(with_rtlibs)),rtlibs-)
  with_go := disabled for rtlibs stage
endif
with_go := $(call envfilt, go, , , $(with_go))

# Build all packages needed for Go development
ifneq (,$(findstring gcc, $(PKGSOURCE)))
  ifeq ($(with_go),yes)
    with_libgo := yes
    enabled_languages += go
  endif
endif

ifeq ($(with_go)-$(with_separate_libgo),yes-yes)
  ifneq (,$(findstring gccgo, $(PKGSOURCE)))
    languages := c c++ go
    separate_lang := yes
    with_libgcc := yes
    with_shared_libgcc := yes
  else
    debian_extra_langs += go
    with_go := built from separate source
    with_libgo := buit from separate source
  endif
endif

# D ---------------------------
d_no_cross := yes
d_no_snap := yes
d_no_cpus := s390

ifneq ($(single_package),yes)
  with_separate_gdc := yes
endif
with_separate_gdc := no

ifneq ($(separate_lang),yes)
  with_d := yes
endif

ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(d_no_cpus)))
  with_d := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifeq ($(d_no_snap)-$(single_package),yes-yes)
  with_d := disabled for snapshot build
endif
ifeq ($(DEB_STAGE)-$(filter libphobos, $(with_rtlibs)),rtlibs-)
  with_d := disabled for rtlibs stage
endif
with_d := $(call envfilt, d, , , $(with_d))

ifeq ($(with_base_only),yes)
  with_d := no
endif

ifeq ($(with_d)-$(with_separate_gdc),yes-yes)
  ifneq (,$(findstring gdc,$(PKGSOURCE)))
    languages := c c++
    separate_lang := yes

    # FIXME: language selection needs improvement.
    with_go := disabled for d
  else
    debian_extra_langs += d
    with_d := built from separate source
  endif
endif

ifeq ($(with_d),yes)
  libphobos_archs = amd64 armel armhf i386 x32 kfreebsd-amd64 kfreebsd-i386
  ifneq (,$(filter $(DEB_TARGET_ARCH), $(libphobos_archs)))
    with_libphobos := yes
  endif

  libphobos_no_cpus := alpha avr arm64 hppa ia64 m68k \
	mips mipsel mips64 mips64el mipsn32 mipsn32el \
	powerpc powerpcspe ppc64 s390 s390x sh4 sparc sparc64
  libphobos_no_systems := gnu kfreebsd-gnu
  ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(libphobos_no_cpus)))
    with_libphobos := disabled for cpu $(DEB_TARGET_ARCH_CPU)
  endif
  ifneq (,$(filter $(DEB_TARGET_GNU_SYSTEM),$(libphobos_no_systems)))
    with_libphobos := disabled for system $(DEB_TARGET_GNU_SYSTEM)
  endif

  enabled_languages += d
endif

# Fortran 95 -------------------
fortran_no_cross := yes
fortran_no_cross := no

ifneq ($(with_base_only),yes)
  ifneq ($(separate_lang),yes)
    with_fortran := yes
  endif
endif
ifeq ($(fortran_no_cross)-$(DEB_CROSS),yes-yes)
  with_fortran := disabled for cross compiler package
endif
ifeq ($(DEB_STAGE)-$(filter libgfortran libquadmath, $(with_rtlibs)),rtlibs-)
  with_fortran := disabled for rtlibs stage
endif

with_fortran := $(call envfilt, fortran, , , $(with_fortran))

# Build all packages needed for Fortran development
ifeq ($(with_fortran),yes)
  ifeq ($(with_dev),yes)
    ifneq ($(DEB_STAGE)-$(filter libgfortran libquadmath, $(with_rtlibs)),rtlibs-)
      with_fdev := yes
    endif
  endif
  ifeq ($(with_common_libs),yes)
    with_libgfortran := yes
  endif
  enabled_languages += fortran
endif

# libquadmath -------------------

ifneq (,$(findstring $(DEB_TARGET_ARCH_CPU), ia64 i386 i486 i586 i686 amd64))
  # FIXME: upstream build tied to gfortran build
  ifeq ($(with_fortran),yes)
    with_qmath := yes
    ifneq (,$(findstring gcc-5,$(PKGSOURCE)))
      ifeq ($(with_common_libs),yes)
        with_libqmath := yes
      endif
    endif
  endif
endif

# ObjC ------------------------
objc_no_cross := no

ifneq ($(with_base_only),yes)
  ifneq ($(separate_lang),yes)
    with_objc := yes
    objc_no_archs =
    ifneq (,$(filter $(DEB_TARGET_ARCH),$(objc_no_archs)))
      with_objc :=
    endif
  endif
endif
ifeq ($(objc_no_cross)-$(DEB_CROSS),yes-yes)
  with_objc := disabled for cross compiler package
endif
ifeq ($(DEB_STAGE)-$(filter libobjc, $(with_rtlibs)),rtlibs-)
  with_objc := disabled for rtlibs stage
endif
with_objc := $(call envfilt, objc, obj-c++, , $(with_objc))

ifeq ($(with_objc),yes)
  # the ObjC runtime with garbage collection enabled needs the Boehm GC
  with_objc_gc := yes

  # disable ObjC garbage collection library (needs libgc)
  libgc_no_cpus := arm64 avr mips mipsel # alpha amd64 arm armel armhf hppa i386 ia64 m68k mips mipsel powerpc ppc64 s390 s390x sparc
  libgc_no_systems := knetbsd-gnu
  ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(libgc_no_cpus)))
    with_objc_gc := disabled for cpu $(DEB_TARGET_ARCH_CPU)
  endif
  ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(libgc_no_systems)))
    with_objc_gc := disabled for system $(DEB_TARGET_GNU_SYSTEM)
  endif
  ifneq (,$(findstring build-cross, $(build_type)))
    with_objc_gc := disabled for cross builds
  endif
  # Build all packages needed for Objective-C development
  ifeq ($(with_dev),yes)
    with_objcdev := yes
  endif
  ifeq ($(with_common_libs),yes)
    with_libobjc := yes
  endif

  enabled_languages += objc
endif

# ObjC++ ----------------------
objcxx_no_cross := no

ifeq ($(with_objc),yes)
  ifneq ($(with_base_only),yes)
    ifneq ($(separate_lang),yes)
      with_objcxx := yes
    endif
  endif
endif
ifeq ($(objcxx_no_cross)-$(DEB_CROSS),yes-yes)
  with_objcxx := disabled for cross compiler package
endif
with_objcxx := $(call envfilt, obj-c++, , c++ objc, $(with_objcxx))

ifeq ($(with_objcxx),yes)
  enabled_languages += obj-c++
endif

# -------------------------------------------------------------------
# other config

# not built from the main source package
ifeq (,$(findstring gcc-,$(PKGSOURCE)))
  extra_package := yes
endif

with_nls := yes
ifeq ($(trunk_build),yes)
  with_nls := no
endif
with_nls := $(call envfilt, nls, , , $(with_nls))

# powerpc nof libraries -----
with_libnof := no

ifneq (,$(findstring gcc-5,$(PKGSOURCE)))
  ifeq (,$(with_rtlibs))
    with_source := yes
  endif
endif
with_source := $(call envfilt, source, , , $(with_source))

ifeq ($(with_cdev),yes)

# ssp & libssp -------------------------
with_ssp := yes
ssp_no_archs = alpha hppa ia64 m68k
ifneq (, $(filter $(DEB_TARGET_ARCH),$(ssp_no_archs) $(ssp_no_archs:%=uclibc-%)))
  with_ssp := not available on $(DEB_TARGET_ARCH)
endif
with_ssp := $(call envfilt, ssp, , , $(with_ssp))

ifeq ($(with_ssp),yes)
  ifneq ($(derivative),Debian)
    ifneq (,$(findstring gcc-5, $(PKGSOURCE)))
      with_ssp_default := yes
    endif
  endif
endif

# gomp --------------------
with_gomp := yes
with_gomp := $(call envfilt, gomp, , , $(with_gomp))
gomp_no_archs =
ifneq (,$(filter $(DEB_TARGET_ARCH),$(gomp_no_archs)))
  with_gomp :=
endif

# itm --------------------
itm_archs = alpha amd64 arm64 i386 x32 ppc64 ppc64el s390x sh4 sparc64
ifneq (,$(filter $(DEB_TARGET_ARCH),$(itm_archs)))
  with_itm := yes
endif
with_itm := $(call envfilt, itm, , , $(with_itm))

# atomic --------------------
with_atomic := yes
atomic_no_archs =
ifneq (,$(filter $(DEB_TARGET_ARCH),$(atomic_no_archs)))
  with_atomic :=
endif

# backtrace --------------------
with_backtrace := yes
backtrace_no_archs = m68k
ifneq (,$(filter $(DEB_TARGET_ARCH),$(backtrace_no_archs)))
  with_backtrace :=
endif

# asan / sanitizer --------------------
with_asan :=
with_asan := $(call envfilt, asan, , , $(with_asan))
asan_archs = amd64 armel armhf arm64 i386 powerpc ppc64 ppc64el x32 sparc sparc64
ifneq (,$(filter $(DEB_TARGET_ARCH),$(asan_archs)))
  with_asan := yes
endif

# lsan / sanitizer --------------------
with_lsan :=
with_lsan := $(call envfilt, lsan, , , $(with_lsan))
lsan_archs = amd64
ifneq (,$(filter $(DEB_TARGET_ARCH),$(lsan_archs)))
  with_lsan := yes
endif

# tsan / sanitizer --------------------
with_tsan :=
with_tsan := $(call envfilt, tsan, , , $(with_tsan))
tsan_archs = amd64
ifneq (,$(filter $(DEB_TARGET_ARCH),$(tsan_archs)))
  with_tsan := yes
endif

endif # with_cdev

# ubsan / sanitizer --------------------
with_ubsan :=
with_ubsan := $(call envfilt, ubsan, , , $(with_ubsan))
ubsan_archs = amd64 armel armhf arm64 i386 powerpc ppc64 ppc64el x32 sparc sparc64
ifneq (,$(filter $(DEB_TARGET_ARCH),$(ubsan_archs)))
  with_ubsan := yes
endif

# libvtv --------------------
with_vtv :=
with_vtv := $(call envfilt, vtv, , , $(with_vtv))
vtv_archs = amd64 i386 x32
ifneq (,$(filter $(DEB_TARGET_ARCH),$(vtv_archs)))
  with_vtv := yes
  with_libvtv := yes
endif
# libvtv builds a modified libstdc++, don't enable it by default
with_vtv :=
with_libvtv :=

# libcilkrts --------------------
with_cilkrts :=
with_cilkrts := $(call envfilt, cilkrts, , , $(with_cilkrts))
cilkrts_archs = amd64 i386 x32
ifneq (,$(filter $(DEB_TARGET_ARCH),$(cilkrts_archs)))
  with_cilkrts := yes
endif

# libmpx --------------------
with_mpx :=
with_mpx := $(call envfilt, mpx, , , $(with_mpx))
mpx_archs = amd64 i386
ifneq (,$(filter $(DEB_TARGET_ARCH),$(mpx_archs)))
  # requires newer binutils, or else libmpxwrappers isn't built
  ifeq (,$(filter $(distrelease),squeeze lucid precise))
    with_mpx := yes
    ifneq (,$(findstring gcc-, $(PKGSOURCE)))
      with_libmpx := yes
    endif
  endif
endif

# pie by default --------------------
with_pie :=
ifeq ($(distribution),Ubuntu)
  ifeq (,$(filter $(distrelease),lucid precise trusty utopic vivid wily))
    pie_archs = s390x
  endif
  ifeq (,$(filter $(distrelease),lucid precise trusty utopic vivid wily xenial))
    pie_archs += amd64 ppc64el
  endif
  ifeq (,$(filter $(distrelease),lucid precise trusty utopic vivid wily xenial yakkety zesty))
    pie_archs += armhf arm64 # i386 FIXME: bootstrap error on i386
  endif
  ifneq (,$(filter $(DEB_TARGET_ARCH),$(pie_archs)))
    with_pie := yes
  endif
endif

# gold --------------------
# armel with binutils 2.20.51 only
gold_archs = amd64 armel armhf i386 powerpc powerpcspe ppc64 ppc64el sparc sparc64 x32 hurd-i386
ifneq (,$(filter $(DEB_TARGET_ARCH),$(gold_archs)))
  with_gold := yes
endif

# plugins --------------------
with_plugins := yes
ifneq (,$(with_rtlibs))
  with_plugins := disabled for rtlibs stage
endif

endif # ifeq (,$(filter $(DEB_STAGE),stage1 stage2))

# Don't include docs with GFDL invariant sections
GFDL_INVARIANT_FREE := yes
ifeq ($(derivative),Ubuntu)
  GFDL_INVARIANT_FREE := no
endif

# -------------------------------------------------------------------
# non-extra config
ifeq ($(extra_package),yes)
  ifeq ($(with_separate_libgcj)-$(with_standalone_gcj),yes-no)
    # package stuff
    with_gccbase := no
    with_cdev := no
    with_cxx := no
    with_cxxdev := no

    ifneq ($(DEB_CROSS),yes)
      with_gcjbase := yes
    else
      with_gcjxbase := yes
    endif
  endif
  ifeq ($(with_separate_libgo),yes)
    # package stuff
    with_gccbase := yes
    with_cdev := no
    with_cxx := no
    with_cxxdev := no
  endif
else
  # libssp ------------------
  ifeq ($(with_ssp)-$(with_common_libs),yes-yes)
    #ifneq ($(DEB_CROSS),yes)
      with_libssp := $(if $(wildcard $(builddir)/gcc/auto-host.h),$(shell if grep -qs '^\#define TARGET_LIBC_PROVIDES_SSP 1' $(builddir)/gcc/auto-host.h; then echo 'libc provides ssp'; else echo 'yes'; fi))
    #endif
    with_libssp := libc provides ssp
  endif

  # libgomp -----------------
  ifeq ($(with_gomp)-$(with_common_libs),yes-yes)
      with_libgomp := yes
  endif

  # libitm -----------------
  ifeq ($(with_itm)-$(with_common_libs),yes-yes)
      with_libitm := yes
  endif

  # libatomic -----------------
  ifeq ($(with_atomic)-$(with_common_libs),yes-yes)
      with_libatomic := yes
  endif

  # libbacktrace -----------------
  ifeq ($(with_backtrace)-$(with_common_libs),yes-yes)
      # currently not a shared library
      #with_libbacktrace := yes
  endif

  # libasan -----------------
  # asan changes soname in GCC 6
  #ifeq ($(with_asan)-$(with_common_libs),yes-yes)
    ifeq ($(with_asan),yes)
      with_libasan := yes
    endif
  #endif

  # liblsan -----------------
  ifeq ($(with_lsan)-$(with_common_libs),yes-yes)
    #ifneq ($(DEB_CROSS),yes)
      with_liblsan := yes
    #endif
  endif

  # libtsan -----------------
  ifeq ($(with_tsan)-$(with_common_libs),yes-yes)
      with_libtsan := yes
  endif

  # libubsan -----------------
  ifeq ($(with_ubsan)-$(with_common_libs),yes-yes)
      with_libubsan := yes
  endif

  # libvtv -----------------
  ifeq ($(with_vtv)-$(with_common_libs),yes-yes)
      with_libvtv := yes
  endif

  # libcilkrts -----------------
  ifeq ($(with_cilkrts)-$(with_common_libs),yes-yes)
      with_libcilkrts := yes
  endif

  # libquadmath -----------------
  ifeq ($(with_qmath)-$(with_common_libs),yes-yes)
      with_libqmath := yes
  endif

  # fixincludes -------
  ifneq ($(DEB_CROSS),yes)
    ifeq ($(with_common_pkgs),yes)
      with_fixincl	:= yes
    endif
  endif

  # Shared libgcc --------------------
  ifneq ($(DEB_STAGE),stage1)
    with_shared_libgcc := yes
    ifeq ($(with_common_libs),yes)
      with_libgcc := yes
    endif
    ifneq (,$(filter $(distrelease),xenial yakkety))
      ifneq (,$(filter $(build_type), build-native cross-build-native))
        # built from the gccgo-6 package, but not for cross builds
        with_libgcc :=
      endif
    endif
  endif

  # libgcc-math --------------------
  with_libgmath := no
  ifneq (,$(findstring i486,$(DEB_TARGET_ARCH)))
    #with_libgccmath := yes
    #with_lib64gmath := yes
    #with_libgmathdev := yes
  endif
  ifeq ($(DEB_TARGET_ARCH),amd64)
    #with_libgccmath := yes
    #with_lib32gmath := yes
    #with_libgmathdev := yes
  endif

  # hppa64 build ----------------
  hppa64_no_snap := no
  hppa64_archs := hppa
  ifneq (,$(filter $(build_type), build-native cross-build-native))
    ifeq (,$(filter $(distrelease),wheezy squeeze jessie lucid precise trusty utopic vivid wily))
      hppa64_archs += amd64 i386 x32
    endif
    ifneq (,$(filter $(DEB_TARGET_ARCH),$(hppa64_archs)))
      with_hppa64 := yes
    endif
  endif
  ifeq ($(hppa64_no_snap)-$(trunk_build),yes-yes)
    with_hppa64 := disabled for snapshot build
  endif
  with_hppa64 := $(call envfilt, hppa64, , , $(with_hppa64))

  ifeq ($(DEB_STAGE),rtlibs)
    with_libatomic := disabled for rtlibs stage
    with_libasan := disabled for rtlibs stage
    with_liblsan := disabled for rtlibs stage
    with_libtsan := disabled for rtlibs stage
    with_libubsan := disabled for rtlibs stage
    with_libcilkrts := disabled for rtlibs stage
    with_fixincl := disabled for rtlibs stage
    with_hppa64 := disabled for rtlibs stage
  endif

  # neon build -------------------
  # FIXME: build as a cross compiler to build on armv4 as well
  ifneq (,$(findstring gcc-5, $(PKGSOURCE)))
    ifeq ($(derivative),Ubuntu)
#      neon_archs = armel armhf
#      ifneq (, $(filter $(DEB_TARGET_ARCH),$(neon_archs)))
#        with_neon = yes
#      endif
    endif
  endif
endif

# run testsuite ---------------
with_check := yes
# if you don't want to run the gcc testsuite, uncomment the next line
#with_check := disabled by hand
ifeq ($(with_base_only),yes)
  with_check := no
endif
ifeq ($(DEB_CROSS),yes)
  with_check := disabled for cross compiler package
endif
ifneq (,$(findstring cross-build-,$(build_type)))
  with_check := disabled for cross building the compiler
endif
ifneq (,$(with_rtlibs))
  with_check := disabled for rtlibs stage
endif
check_no_cpus := m68k
check_no_systems := kfreebsd-gnu # gnu
ifneq (,$(filter $(DEB_TARGET_ARCH_CPU),$(check_no_cpus)))
  with_check := disabled for cpu $(DEB_TARGET_ARCH_CPU)
endif
ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(check_no_systems)))
  with_check := disabled for system $(DEB_TARGET_GNU_SYSTEM)
endif
ifeq ($(derivative)-$(DEB_HOST_ARCH),Ubuntu-hppa)
  ifneq ($(single_package),yes)
    with_check := disabled, testsuite timeouts with expect
  endif
endif
ifneq (,$(findstring gdc,$(PKGSOURCE)))
  with_check := disabled for D
endif
with_check := $(call envfilt, check, , , $(with_check))
ifdef WITHOUT_CHECK
  with_check := disabled by environment
endif
ifneq ($(findstring nocheck, $(DEB_BUILD_OPTIONS)),)
  with_check := disabled by DEB_BUILD_OPTIONS
endif
ifneq (,$(filter $(DEB_HOST_ARCH), hppa mips))
  ifneq ($(single_package),yes)
    with_check := disabled for $(DEB_HOST_ARCH), testsuite timeouts with expect
  endif
endif
with_check := disabled for this upload

# not a dependency on all archs, but if available, use it for the testsuite
ifneq (,$(wildcard /usr/bin/localedef))
  locale_data = generate
endif

ifneq (,$(filter $(build_type), build-cross cross-build-cross))
  ldconfig_arg = --noscripts
endif

all_enabled_languages := $(enabled_languages)
languages_without_lang_opt := c++ objc obj-c++

debian_extra_langs := $(subst obj-c++,objcp,$(debian_extra_langs))
export debian_extra_langs

# multilib
biarch_map := i686=x86_64 powerpc=powerpc64 sparc=sparc64 sparc64=sparc s390=s390x s390x=s390 \
		x86_64=i686 powerpc64=powerpc \
		mips=mips64 mipsel=mips64el mips64=mips mips64el=mipsel mipsn32=mips mipsn32el=mipsel \
		# mipsr6=mips64r6 mipsr6el=mips64r6el mips64r6=mipsr6 mips64r6el=mipsr6el mipsn32r6=mipsr6 mipsn32r6el=mipsr6el
ifneq (,$(filter $(derivative),Ubuntu))
  ifeq (,$(filter $(distrelease),dapper hardy jaunty karmic lucid))
    biarch_map := $(subst i686=,i486=,$(biarch_map))
  endif
else # Debian
  biarch_map := $(subst i686=,i486=,$(biarch_map))
endif

ifeq ($(derivative),Ubuntu)
  ifeq (,$(filter $(distrelease),dapper hardy jaunty karmic lucid maverick natty))
    biarch_map += arm=arm
  endif
endif
biarch_cpu := $(strip $(patsubst $(DEB_TARGET_GNU_CPU)=%,%, \
			 $(filter $(DEB_TARGET_GNU_CPU)=%,$(biarch_map))))

biarch64 := no
biarch32 := no
biarchn32 := no
biarchx32 := no
biarchhf := no
biarchsf := no
flavours :=
define gen_biarch
  ifneq (yes,$$(call envfilt, biarch, , ,yes))
    biarch$1archs :=
  endif
  ifneq (,$$(findstring /$$(DEB_TARGET_ARCH)/,$$(biarch$1archs)))
    biarch$1 := yes
    flavours += $1
    #biarch$1subdir = $$(biarch_cpu)-$$(DEB_TARGET_GNU_SYSTEM)
    biarch$1subdir = $1
    ifeq ($$(with_libgcc),yes)
      with_lib$1gcc := yes
    endif
    ifeq ($$(with_cdev),yes)
      with_lib$1gccdev := yes
    endif
    ifeq ($$(with_libcxx),yes)
      with_lib$1cxx := yes
    endif
    ifeq ($$(with_libcxxdbg),yes)
      with_lib$1cxxdbg := yes
    endif
    ifeq ($$(with_cxxdev),yes)
      with_lib$1cxxdev := yes
    endif
    ifeq ($$(with_libobjc),yes)
      with_lib$1objc := yes
    endif
    ifeq ($$(with_objcdev),yes)
      with_lib$1objcdev := yes
    endif
    ifeq ($$(with_libgfortran),yes)
      with_lib$1gfortran := yes
    endif
    ifeq ($$(with_fdev),yes)
      with_lib$1gfortrandev := yes
    endif
    ifeq ($$(with_libphobos),yes)
      ifeq (,$(filter $1, hf))
        with_lib$1phobosdev := yes
      endif
    endif
    ifeq ($$(with_libssp),yes)
      with_lib$1ssp := yes
    endif
    ifeq ($$(with_libgomp),yes)
      with_lib$1gomp:= yes
    endif
    ifeq ($$(with_libitm),yes)
      with_lib$1itm:= yes
    endif
    ifeq ($$(with_libatomic),yes)
      with_lib$1atomic:= yes
    endif
    ifeq ($$(with_libbacktrace),yes)
      with_lib$1backtrace:= yes
    endif
    ifeq ($$(with_libasan),yes)
      with_lib$1asan:= yes
    endif
    ifeq ($$(with_liblsan),yes)
      with_lib$1lsan := yes
    endif
    ifeq ($$(with_libtsan),yes)
      with_lib$1tsan:= yes
    endif
    ifeq ($$(with_libubsan),yes)
      with_lib$1ubsan := yes
    endif
    ifeq ($$(with_libvtv),yes)
      with_lib$1vtv := yes
    endif
    ifeq ($$(with_libcilkrts),yes)
      with_lib$1cilkrts := yes
    endif
    ifeq ($$(with_libmpx),yes)
      ifneq (,$(filter $1, 32 64))
        with_lib$1mpx := yes
      endif
    endif
    ifeq ($$(with_libqmath),yes)
      with_lib$1qmath := yes
    endif
    ifeq ($$(with_libgo),yes)
      with_lib$1go := yes
    endif

    biarch_multidir_names = libiberty libgcc libbacktrace libatomic libgomp
    ifneq (,$$(findstring gcc-, $$(PKGSOURCE)))
      biarch_multidir_names += libstdc++-v3 libobjc libgfortran libssp \
				zlib libitm libmpx \
				libsanitizer \
				libcilkrts libvtv
      ifeq ($$(with_objc_gc),yes)
        biarch_multidir_names += boehm-gc
      endif
    endif
    ifneq (,$(findstring yes, $(with_java) $(with_go)))
      biarch_multidir_names += libffi
    endif
    ifeq ($(with_fortran),yes)
      biarch_multidir_names += libquadmath
    endif
    ifeq ($(with_go),yes)
      biarch_multidir_names += libgo
    endif
    ifeq ($(with_libphobos),yes)
      ifeq (,$(filter $1, hf))
        biarch_multidir_names += libphobos
      endif
    endif
    ifneq (,$$(findstring 32,$1))
      TARGET64_MACHINE := $$(strip $$(subst $$(DEB_TARGET_GNU_CPU),$$(biarch_cpu), \
				$$(TARGET_ALIAS)))
      TARGET32_MACHINE := $$(TARGET_ALIAS)
    else
      TARGET64_MACHINE := $$(TARGET_ALIAS)
      TARGET64_MACHINE := $$(strip $$(subst $$(DEB_TARGET_GNU_CPU),$$(biarch_cpu), \
				$$(TARGET_ALIAS)))
    endif
    export TARGET32_MACHINE
    export TARGET64_MACHINE
  endif
endef
biarch32archs := /amd64/ppc64/kfreebsd-amd64/s390x/sparc64/x32/mipsn32/mipsn32el/mips64/mips64el/ # mipsn32r6/mipsn32r6el/mips64r6/mips64r6el/
biarch64archs := /i386/powerpc/sparc/s390/mips/mipsel/mipsn32/mipsn32el/x32/ # mipsr6/mipsr6el/mipsn32r6/mipsn32r6el/
biarchn32archs := /mips/mipsel/mips64/mips64el/ # mipsr6/mipsr6el/mips64r6/mips64r6el/
ifeq ($(derivative),Ubuntu)
  ifeq (,$(filter $(distrelease),dapper hardy jaunty karmic lucid maverick natty))
    biarchhfarchs := /armel/
    biarchsfarchs := /armhf/
  endif
  ifeq (,$(filter $(distrelease),dapper hardy jaunty karmic lucid maverick natty oneiric precise quantal))
    biarchx32archs := /amd64/i386/
  endif
endif
ifeq ($(derivative),Debian)
  ifeq (,$(filter $(distrelease),etch squeeze wheezy))
    biarchx32archs := /amd64/i386/
  endif
endif
$(foreach x,32 64 n32 x32 hf sf,$(eval $(call gen_biarch,$(x))))

ifeq ($(DEB_TARGET_ARCH),sh4)
  biarch_multidir_names=none
endif
export biarch_multidir_names

#ifeq ($(trunk_build),yes)
#  no_biarch_libs := yes
#endif
no_biarch_libs :=

ifeq ($(no_biarch_libs),yes)
  with_lib64gcc		:= no
  with_lib64cxx		:= no
  with_lib64cxxdbg	:= no
  with_lib64objc	:= no
  with_lib64ffi		:= no
  with_lib64gcj		:= no
  with_lib64gfortran	:= no
  with_lib64ssp		:= no
  with_lib64go		:= no
  with_lib64gomp	:= no
  with_lib64itm		:= no
  with_lib64qmath	:= no
  with_lib64atomic	:= no
  with_lib64backtrace	:= no
  with_lib64asan	:= no
  with_lib64lsan	:= no
  with_lib64tsan	:= no
  with_lib64ubsan	:= no
  with_lib64vtv		:= no
  with_lib64cilkrts	:= no
  with_lib64mpx		:= no
  with_lib64gccdev	:= no
  with_lib64cxxdev	:= no
  with_lib64objcdev	:= no
  with_lib64gfortrandev	:= no
  with_lib64phobosdev	:= no

  with_lib32gcc		:= no
  with_lib32cxx		:= no
  with_lib32cxxdbg	:= no
  with_lib32objc	:= no
  with_lib32ffi		:= no
  with_lib32gcj		:= no
  with_lib32gfortran	:= no
  with_lib32ssp		:= no
  with_lib32go		:= no
  with_lib32gomp	:= no
  with_lib32itm		:= no
  with_lib32qmath	:= no
  with_lib32atomic	:= no
  with_lib32backtrace	:= no
  with_lib32asan	:= no
  with_lib32lsan	:= no
  with_lib32tsan	:= no
  with_lib32ubsan	:= no
  with_lib32vtv		:= no
  with_lib32cilkrts	:= no
  with_lib32mpx		:= no
  with_lib32gccdev	:= no
  with_lib32cxxdev	:= no
  with_lib32objcdev	:= no
  with_lib32gfortrandev	:= no
  with_lib32phobosdev	:= no

  with_libn32gcc	:= no
  with_libn32cxx	:= no
  with_libn32cxxdbg	:= no
  with_libn32objc	:= no
  with_libn32ffi	:= no
  with_libn32gcj	:= no
  with_libn32gfortran	:= no
  with_libn32ssp	:= no
  with_libn32go		:= no
  with_libn32gomp	:= no
  with_libn32itm	:= no
  with_libn32qmath	:= no
  with_libn32atomic	:= no
  with_libn32backtrace	:= no
  with_libn32asan	:= no
  with_libn32lsan	:= no
  with_libn32tsan	:= no
  with_libn32ubsan	:= no
  with_libn32gccdev	:= no
  with_libn32cxxdev	:= no
  with_libn32objcdev	:= no
  with_libn32gfortrandev:= no
  with_libn32phobosdev	:= no

  with_libx32gcc	:= no
  with_libx32cxx	:= no
  with_libx32cxxdbg	:= no
  with_libx32objc	:= no
  with_libx32ffi	:= no
  with_libx32gcj	:= no
  with_libx32gfortran	:= no
  with_libx32ssp	:= no
  with_libx32go		:= no
  with_libx32gomp	:= no
  with_libx32itm	:= no
  with_libx32qmath	:= no
  with_libx32atomic	:= no
  with_libx32backtrace	:= no
  with_libx32asan	:= no
  with_libx32lsan	:= no
  with_libx32tsan	:= no
  with_libx32ubsan	:= no
  with_libx32vtv	:= no
  with_libx32cilkrts	:= no
  with_libx32gccdev	:= no
  with_libx32cxxdev	:= no
  with_libx32objcdev	:= no
  with_libx32gfortrandev:= no
  with_libx32phobosdev	:= no

  with_libhfgcc		:= no
  with_libhfcxx		:= no
  with_libhfcxxdbg	:= no
  with_libhfobjc	:= no
  with_libhfffi		:= no
  with_libhfgcj		:= no
  with_libhfgfortran	:= no
  with_libhfssp		:= no
  with_libhfgo		:= no
  with_libhfgomp	:= no
  with_libhfitm		:= no
  with_libhfqmath	:= no
  with_libhfatomic	:= no
  with_libhfbacktrace	:= no
  with_libhfasan	:= no
  with_libhflsan	:= no
  with_libhftsan	:= no
  with_libhfubsan	:= no
  with_libhfgccdev	:= no
  with_libhfcxxdev	:= no
  with_libhfobjcdev	:= no
  with_libhfgfortrandev	:= no
  with_libhfphobosdev	:= no

  with_libsfgcc		:= no
  with_libsfcxx		:= no
  with_libsfcxxdbg	:= no
  with_libsfobjc	:= no
  with_libsfffi		:= no
  with_libsfgcj		:= no
  with_libsfgfortran	:= no
  with_libsfssp		:= no
  with_libsfgo		:= no
  with_libsfgomp	:= no
  with_libsfitm		:= no
  with_libsfqmath	:= no
  with_libsfatomic	:= no
  with_libsfbacktrace	:= no
  with_libsfasan	:= no
  with_libsflsan	:= no
  with_libsftsan	:= no
  with_libsfubsan	:= no
  with_libsfgccdev	:= no
  with_libsfcxxdev	:= no
  with_libsfobjcdev	:= no
  with_libsfgfortrandev	:= no
  with_libsfphobosdev	:= no

  with_java_plugin := no

  ifeq ($(with_ada)-$(with_separate_gnat),yes-yes)
    biarchhf	:= disabled for Ada
    biarchsf	:= disabled for Ada
  endif

endif

ifneq (,$(filter yes,$(biarch32) $(biarch64) $(biarchn32) $(biarchx32) $(biarchhf) $(biarchsf)))
  multilib := yes
endif

multilib_archs = $(sort $(subst /, , $(biarch64archs) $(biarch32archs) $(biarchn32archs) $(biarchx32archs) $(biarchhfarchs) $(biarchsfarchs)))

biarchsubdirs := \
  $(if $(filter yes,$(biarch64)),$(biarch64subdir),) \
  $(if $(filter yes,$(biarch32)),$(biarch32subdir),) \
  $(if $(filter yes,$(biarchn32)),$(biarchn32subdir),) \
  $(if $(filter yes,$(biarchx32)),$(biarchx32subdir),) \
  $(if $(filter yes,$(biarchhf)),$(biarchhfsubdir),) \
  $(if $(filter yes,$(biarchsf)),$(biarchsfsubdir),)
biarchsubdirs := {$(strip $(shell echo $(biarchsubdirs) | tr " " ","))}

# GNU locales
force_gnu_locales := yes
locale_no_cpus :=
locale_no_systems :=
ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(locale_no_systems)))
  force_gnu_locales := disabled for system $(DEB_TARGET_GNU_SYSTEM)
endif

gcc_tarpath		:= $(firstword $(wildcard gcc-*.tar.* /usr/src/gcc-5/gcc-*.tar.*))
gcc_tarball		:= $(notdir $(gcc_tarpath))
gcc_srcdir		:= $(subst -dfsg,,$(patsubst %.tar.xz,%,$(patsubst %.tar.lzma,%,$(patsubst %.tar.gz,%,$(gcc_tarball:.tar.bz2=)))))

ifeq ($(with_d),yes)
  gdc_tarpath		:= $(firstword $(wildcard gdc-*.tar.* /usr/src/gcc-$(BASE_VERSION)/gdc-*.tar.*))
  gdc_tarball		:= $(notdir $(gdc_tarpath))
  gdc_srcdir		:= $(patsubst %.tar.xz,%,$(patsubst %.tar.lzma,%,$(patsubst %.tar.gz,%,$(gdc_tarball:.tar.bz2=))))
endif

# NOTE: This is not yet used. when building gcj, gdc or gnat using the
# gcc-source package, we don't require an exact binary dependency.
ifneq ($(dir $(gcc_tarpath)),./)
  built_using_external_source := yes
else
  built_using_external_source :=
endif
ifeq ($(DEB_CROSS),yes)
  add_built_using = yes
endif
ifeq ($(with_ada)-$(with_separate_gnat),yes-yes)
  add_built_using = yes
endif

ecj_jar := $(firstword $(wildcard ecj.jar /usr/share/java/eclipse-ecj.jar /usr/share/java/ecj.jar))

unpack_stamp		:= $(stampdir)/01-unpack-stamp
pre_patch_stamp		:= $(stampdir)/02-pre-patch-stamp
patch_stamp		:= $(stampdir)/02-patch-stamp
control_stamp		:= $(stampdir)/03-control-stamp
configure_stamp		:= $(stampdir)/04-configure-stamp
build_stamp		:= $(stampdir)/05-build-stamp
build_arch_stamp	:= $(stampdir)/05-build-arch-stamp
build_indep_stamp	:= $(stampdir)/05-build-indep-stamp
build_html_stamp	:= $(stampdir)/05-build-html-stamp
build_locale_stamp	:= $(stampdir)/05-build-locale-stamp
build_doxygen_stamp	:= $(stampdir)/05-build-doxygen-stamp
build_javasrc_stamp	:= $(stampdir)/05-build-javasrc-stamp
build_javadoc_stamp	:= $(stampdir)/05-build-javadoc-stamp
build_gnatdoc_stamp	:= $(stampdir)/05-build-gnatdoc-stamp
check_stamp		:= $(stampdir)/06-check-stamp
check_inst_stamp	:= $(stampdir)/06-check-inst-stamp
install_stamp		:= $(stampdir)/07-install-stamp
install_snap_stamp	:= $(stampdir)/07-install-snap-stamp
binary_stamp		:= $(stampdir)/08-binary-stamp

configure_dummy_stamp	:= $(stampdir)/04-configure-dummy-stamp
build_dummy_stamp	:= $(stampdir)/05-build-dummy-stamp
install_dummy_stamp	:= $(stampdir)/07-install-dummy-stamp

configure_jit_stamp	:= $(stampdir)/04-configure-jit-stamp
build_jit_stamp		:= $(stampdir)/05-build-jit-stamp
install_jit_stamp	:= $(stampdir)/07-install-jit-stamp

configure_hppa64_stamp	:= $(stampdir)/04-configure-hppa64-stamp
build_hppa64_stamp	:= $(stampdir)/05-build-hppa64-stamp
install_hppa64_stamp	:= $(stampdir)/07-install-hppa64-stamp

configure_neon_stamp	:= $(stampdir)/04-configure-neon-stamp
build_neon_stamp		:= $(stampdir)/05-build-neon-stamp
install_neon_stamp	:= $(stampdir)/07-install-neon-stamp

control_dependencies	:= $(patch_stamp)

ifeq ($(single_package),yes)
    configure_dependencies = $(configure_stamp)
    build_dependencies = $(build_stamp)
    install_dependencies = $(install_snap_stamp)
    ifeq ($(with_check),yes)
      check_dependencies += $(check_stamp)
    endif
else
  ifeq ($(with_base_only),yes)
    configure_dependencies = $(configure_dummy_stamp)
    build_dependencies = $(build_dummy_stamp)
    install_dependencies = $(install_dummy_stamp)
  else
    configure_dependencies = $(configure_stamp)
    build_dependencies = $(build_stamp)
    install_dependencies = $(install_stamp)
    ifeq ($(with_check),yes)
      check_dependencies += $(check_stamp)
    endif
  endif
endif

ifneq (,$(findstring gcj-, $(PKGSOURCE)))
  ifeq ($(with_gcj_base_only),yes)
    configure_dependencies = $(configure_dummy_stamp)
    build_dependencies = $(build_dummy_stamp)
    install_dependencies = $(install_dummy_stamp)
  endif
endif

ifeq ($(with_jit),yes)
  build_dependencies += $(build_jit_stamp)
  install_dependencies += $(install_jit_stamp)
endif

ifeq ($(with_neon),yes)
  build_dependencies += $(build_neon_stamp)
  install_dependencies += $(install_neon_stamp)
endif

ifeq ($(with_hppa64),yes)
  build_dependencies += $(build_hppa64_stamp)
  ifneq ($(trunk_build),yes)
    install_dependencies += $(install_hppa64_stamp)
  endif
endif

build_dependencies += $(check_dependencies)

build_arch_dependencies = $(build_dependencies)
build_indep_dependencies = $(build_dependencies)

ifneq (,$(findstring build-native, $(build_type)))
  ifneq ($(single_package),yes)
    build_indep_dependencies += $(build_html_stamp)
    ifeq ($(with_cxx),yes)
      build_indep_dependencies += $(build_doxygen_stamp)
    endif
    ifeq ($(with_java),yes)
      build_arch_dependencies += $(build_html_stamp)
      build_indep_dependencies += $(build_javasrc_stamp)
      build_indep_dependencies += $(build_javadoc_stamp)
    endif
    ifeq ($(with_ada),yes)
      build_indep_dependencies += $(build_gnatdoc_stamp)
    endif
  endif
endif

stamp-dir:
	mkdir -p $(stampdir)

ifeq ($(DEB_CROSS),yes)
  define cross_mangle_shlibs
	if [ -f debian/$(1)/DEBIAN/shlibs ]; then \
	  sed -i s/$(cross_lib_arch)/:$(DEB_TARGET_ARCH)/g debian/$(1)/DEBIAN/shlibs; \
	fi
  endef
  define cross_mangle_substvars
	if [ -f debian/$(1).substvars ]; then \
	  sed -i \
	    -e 's/:$(DEB_TARGET_ARCH)/$(cross_lib_arch)/g' \
	    -e 's/\(libc[.0-9]*-[^:]*\):\([a-z0-9-]*\)/\1-\2-cross/g' \
	    $(if $(filter armel,$(DEB_TARGET_ARCH)),-e 's/:armhf/-armhf-cross/g') \
	    $(if $(filter armhf,$(DEB_TARGET_ARCH)),-e 's/:armel/-armel-cross/g') \
	    debian/$(1).substvars; \
	fi
  endef
else
  define cross_mangle_shlibs
  endef
  define cross_mangle_substvars
  endef
  # precise's dh_shlibdeps doesn't work well for ARM multilibs
  # and dh_shlibdeps doesn't work well for cross builds, see #698881.
  ifneq (,$(filter $(distrelease),precise quantal raring))
    ifneq (,$(filter $(DEB_TARGET_ARCH), armel armhf arm64))
      ignshld = -
    endif
  endif
endif
ifeq ($(DEB_STAGE),rtlibs)
  define cross_mangle_shlibs
  endef
  define cross_mangle_substvars
  endef
endif

# takes a *list* of package names as $1, the multilib dirname as $2
_shlibdirs = \
	$(if $(strip $(1)), \
	  $(shell find $(foreach p,$(1),$(CURDIR)/debian/$(p)) \
		-name '*.so.*' -printf '%h ' | uniq)) \
	$(with_build_sysroot)/lib/$(call mlib_to_march,$(2)) \
	$(with_build_sysroot)/usr/lib/$(call mlib_to_march,$(2)) \
	$(with_build_sysroot)$(subst /usr,,/$(usr_lib$(2))) \
	$(with_build_sysroot)/$(usr_lib$(2)) \
	$(if $(findstring mips64,$(DEB_TARGET_ARCH)), \
	  $(with_build_sysroot)/$(usr_lib64)) \
	$(if $(findstring mipsn32,$(DEB_TARGET_ARCH)), \
	  $(with_build_sysroot)/$(usr_libn32)) \
	$(if $(filter yes,$(biarchsf) $(biarchhf)), \
	  $(with_build_sysroot)/usr/$(call mlib_to_march,$(2))/lib) \
	$(if $(filter yes, $(with_common_libs)),, \
	  $(CURDIR)/$(d)/$(usr_lib$(2)) \
	  $(CURDIR)/$(d)/usr/$(call mlib_to_march,$(2))/lib)
shlibdirs_to_search = -l$(subst $(SPACE),:,$(foreach d,$(_shlibdirs),$(d)))