This file is indexed.

/usr/src/binutils/debian/rules is in binutils-source 2.30-15ubuntu1.

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

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
#!/usr/bin/make -f
# debian/rules file - for binutils (2.29)
# Based on sample debian/rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# Copyright 1998-2007 James Troup.
# Portions Copyright 2008-2017 Canonical Ltd.
# Portions Copyright 2008-2017 Matthias Klose.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

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

vafilt = $(subst $(2)=,,$(filter $(2)=%,$(1)))
DPKG_VARS := $(shell dpkg-architecture)
DEB_BUILD_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_GNU_TYPE)
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_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

ifeq (,$(filter $(distrelease),lenny etch squeeze wheezy jessie))
  ifeq ($(DEB_HOST_GNU_TYPE),i586-linux-gnu)
    DEB_BUILD_GNU_TYPE	= i686-linux-gnu
    DEB_HOST_GNU_CPU	= i686
    DEB_HOST_GNU_TYPE	= i686-linux-gnu
    TRIPLET_SYMLINK	= i586-linux-gnu
  else ifeq ($(DEB_HOST_GNU_TYPE),i586-kfreebsd-gnu)
    DEB_BUILD_GNU_TYPE	= i686-kfreebsd-gnu
    DEB_HOST_GNU_CPU	= i686
    DEB_HOST_GNU_TYPE	= i686-kfreebsd-gnu
    TRIPLET_SYMLINK	= i586-kfreebsd-gnu
  else ifeq ($(DEB_HOST_GNU_TYPE),i586-gnu)
    DEB_BUILD_GNU_TYPE	= i686-gnu
    DEB_HOST_GNU_CPU	= i686
    DEB_HOST_GNU_TYPE	= i686-gnu
    TRIPLET_SYMLINK	= i586-gnu
  endif
endif

p_bin = binutils
p_com = $(p_bin)-common
p_lib = lib$(p_bin)
p_nat = $(p_bin)-$(subst _,-,$(DEB_HOST_GNU_TYPE))
p_dev = $(p_bin)-dev
p_mul = $(p_bin)-multiarch
p_mdev = $(p_mul)-dev
p_doc = $(p_bin)-doc
p_hppa64 = $(p_bin)-hppa64-linux-gnu
p_src = $(p_bin)-source

p_hst = $(p_bin)-for-host
p_bld = $(p_bin)-for-build

p_cross = $(p_bin)-$(subst _,-,$(TARGET))

# version used for p_bld/p_hst dependencies
min_ver = 2.30-2

distribution := $(shell lsb_release -is)
distrelease  := $(shell lsb_release -cs)
ifeq ($(distrelease),n/a)
  distrelease     := sid
endif

# BACKPORT is used for cross builds for a -source package not conflicting
# with the source package of the native package.
ifeq ($(BACKPORT),true)
  p_src = $(p_bin)-$(VERSION)-source
else
  p_src = $(p_bin)-source
endif

pwd   := $(shell pwd)
d     = debian/tmp
d_bin = $(d)
d_com = debian/$(p_com)
d_lib = debian/$(p_lib)
d_nat = debian/$(p_nat)
d_dev = debian/$(p_dev)
d_mul = debian/$(p_mul)
d_mdev = debian/$(p_mdev)
d_doc = debian/$(p_doc)
d_hppa64 = debian/$(p_hppa64)
d_src = debian/$(p_src)

d_hst = debian/$(p_hst)
d_bld = debian/$(p_bld)

d_cross = debian/$(p_cross)

install_dir    = install -d -m 755
install_file   = install -m 644
install_script = install -m 755
install_binary = install -m 755 -s --strip-program="$(STRIP)"

NATIVE_ARCHS ?= amd64 i386 arm64 armhf armel mips mipsel mips64el \
	ppc64el s390x
NATIVE_ARCHS += alpha hppa ia64 m68k mips64 powerpc powerpcspe ppc64 \
	riscv64 sh4 sparc64 x32
NATIVE_ARCHS += hurd-i386 kfreebsd-amd64 kfreebsd-i386
NATIVE_ARCHS += mipsn32 mipsn32el
NATIVE_ARCHS += mipsn32r6 mipsn32r6el mipsr6 mipsr6el mips64r6 mips64r6el
#NATIVE_ARCHS += nios2 or1k s390 sparc

src_name := $(shell dpkg-parsechangelog -S Source)
ifeq ($(src_name),binutils)
  with_native	= yes
  with_cross	= yes
  same_source	= yes
  ifeq (,$(CROSS_ARCHS))
    ifneq (,$(filter $(DEB_HOST_ARCH), amd64 i386 x32))
      CROSS_ARCHS =  s390x ppc64el arm64 armhf armel
      CROSS_ARCHS += mips mipsel mips64el
      CROSS_ARCHS += alpha hppa m68k
      CROSS_ARCHS += mips64 mipsn32 mipsn32el
      CROSS_ARCHS += powerpc powerpcspe ppc64 sh4 sparc64
      CROSS_ARCHS += mipsr6 mipsr6el mipsn32r6 mipsn32r6el mips64r6 mips64r6el
      CROSS_ARCHS += ia64 riscv64
      CROSS_ARCHS += kfreebsd-amd64 kfreebsd-i386 hurd-i386
      ifneq (,$(filter $(DEB_HOST_ARCH), i386 x32))
        CROSS_ARCHS += amd64
      endif
      ifneq (,$(filter $(DEB_HOST_ARCH), amd64 x32))
        CROSS_ARCHS += i386
      endif
      ifneq (,$(filter $(DEB_HOST_ARCH), amd64 i386))
        CROSS_ARCHS += x32
      endif
    else ifeq ($(DEB_HOST_ARCH),arm64)
      CROSS_ARCHS = armel armhf amd64 i386 x32
    else ifeq ($(DEB_HOST_ARCH),ppc64)
      CROSS_ARCHS = ppc64el
    else ifeq ($(DEB_HOST_ARCH),ppc64el)
      CROSS_ARCHS = powerpc ppc64 amd64 i386 x32
    else
      CROSS_ARCHS =
    endif
  else
    # c-t-b passes this one ...
    CROSS_ARCHS := $(filter-out $(DEB_HOST_ARCH),$(CROSS_ARCHS))
  endif
else
  # binutils-ports ...
  with_cross	= yes
  ifeq (,$(CROSS_ARCHS))
    CROSS_ARCHS ?= m68k sh4 mips64 mips64el
  endif
endif

ifneq (,$(filter $(DEB_HOST_ARCH),amd64 i386 x32 hppa))
  with_hppa64 = yes
endif

with_multiarch := yes

# only build the basic package when running the autopkg tests
ifneq (,$(ADT_TEST_TRIGGERS))
  CROSS_ARCHS :=
  with_hppa64 =
  with_multiarch =
endif

HOST_ARCHS_armhf = amd64 i386 x32 arm64
HOST_ARCHS_armel = amd64 i386 x32 arm64
HOST_ARCHS_arm64 = amd64 i386 x32
HOST_ARCHS_mips = amd64 i386 x32
HOST_ARCHS_mipsel = amd64 i386 x32
HOST_ARCHS_powerpc = amd64 i386 x32 ppc64el
HOST_ARCHS_ppc64el = amd64 i386 x32 ppc64
HOST_ARCHS_s390x = amd64 i386 x32
HOST_ARCHS_amd64 = arm64 i386 ppc64el x32
HOST_ARCHS_i386 = amd64 arm64 ppc64el x32
HOST_ARCHS_ia64 = amd64 i386 x32
HOST_ARCHS_riscv64 = amd64 i386 x32

HOST_ARCHS_alpha = amd64 i386 x32
HOST_ARCHS_hppa = amd64 i386 x32
HOST_ARCHS_m68k = amd64 i386 x32
HOST_ARCHS_mips64 = amd64 i386 x32
HOST_ARCHS_mips64el = amd64 i386 x32
HOST_ARCHS_powerpcspe = amd64 i386 x32
HOST_ARCHS_ppc64 = amd64 i386 x32 ppc64el
HOST_ARCHS_sh4 = amd64 i386 x32
HOST_ARCHS_sparc64 = amd64 i386 x32
HOST_ARCHS_x32 = amd64 arm64 i386 ppc64el

HOST_ARCHS_mipsn32 = amd64 i386 x32
HOST_ARCHS_mipsn32el = amd64 i386 x32

HOST_ARCHS_mipsr6 = amd64 i386 x32
HOST_ARCHS_mipsr6el = amd64 i386 x32
HOST_ARCHS_mipsn32r6 = amd64 i386 x32
HOST_ARCHS_mipsn32r6el = amd64 i386 x32
HOST_ARCHS_mips64r6 = amd64 i386 x32
HOST_ARCHS_mips64r6el = amd64 i386 x32

HOST_ARCHS_kfreebsd-amd64 = amd64 i386 x32
HOST_ARCHS_kfreebsd-i386 = amd64 i386 x32
HOST_ARCHS_hurd-i386 = amd64 i386 x32

CROSS_ARCH	= $(subst .,,$(suffix $@))
_gnu_type	= $(shell dpkg-architecture -a$(1) -qDEB_HOST_GNU_TYPE -f 2>/dev/null)
_multiarch	= $(shell dpkg-architecture -a$(1) -qDEB_HOST_MULTIARCH -f 2>/dev/null)
CROSS_GNU_TYPE	= $(subst i586,i686,$(call _gnu_type,$(CROSS_ARCH)))
P_CROSS		= binutils-$(subst _,-,$(CROSS_GNU_TYPE))
D_CROSS		= debian/binutils-$(subst _,-,$(CROSS_GNU_TYPE))

# If $(TARGET) is not set, try reading debian/target
ifeq (,$(TARGET))
  ifneq (,$(wildcard debian/target))
    TARGET := $(shell cat debian/target 2>/dev/null)
  endif
endif

ifneq (,$(TARGET))
  with_native	=
  with_cross	=
  same_source	=
  # Support TARGET both as Debian architecture specification (e.g. arm),
  # and as the target name (e.g. arm-linux-gnu).
  try_convert := $(shell dpkg-architecture -f -a$(TARGET) -qDEB_HOST_GNU_TYPE 2>/dev/null)
  ifneq ($(try_convert),)
    override TARGET := $(try_convert)
  endif
  DPKG_TARGET_VARS := $(shell dpkg-architecture -f -t$(TARGET))
  DEB_TARGET_MULTIARCH = $(call vafilt,$(DPKG_TARGET_VARS),DEB_HOST_MULTIARCH)
  DEB_TARGET_ARCH      = $(call vafilt,$(DPKG_TARGET_VARS),DEB_HOST_ARCH)
  for_target           = dpkg-architecture -f -t$(TARGET) -c
else
  DEB_TARGET_MULTIARCH = $(DEB_HOST_MULTIARCH)
  DEB_TARGET_ARCH      = $(DEB_HOST_ARCH)
  for_target           =
endif

ifneq (,$(TARGET))
  APPEND_TOOLLIBDIR=yes
  export APPEND_TOOLLIBDIR
endif

ifeq (,$(DEB_HOST_MULTIARCH))
  ifeq ($(DEB_HOST_ARCH),i386)
    DEB_HOST_MULTIARCH = i386-linux-gnu
  else
    DEB_HOST_MULTIARCH = $(DEB_HOST_GNU_TYPE)
  endif
endif

SHELL  = /bin/bash

gold_targets = \
	amd64 arm64 armel armhf i386 \
	mips mipsel mipsn32 mipsn32el mips64 mips64el \
	mipsr6 mipsr6el mipsn32r6 mipsn32r6el mips64r6 mips64r6el \
	powerpc powerpcspe ppc64 ppc64el sparc sparc64 s390x \
	x32 kfreebsd-amd64 kfreebsd-i386 hurd-i386

ifneq (,$(filter $(DEB_HOST_ARCH), $(gold_targets)))
  with_gold = yes
  gold_provides = -Vgold:Provides=binutils-gold
endif

CFLAGS = -g -O2 -Wno-format-security
CXXFLAGS = -g -O2
LDFLAGS =
CROSS := $(DEB_HOST_GNU_TYPE)-
CC     = $(CROSS)gcc
CXX    = $(CROSS)g++
STRIP  = $(CROSS)strip --remove-section=.comment --remove-section=.note

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS = -g -O0
endif

# this outputs 0 or 1 depending on whether a macro appears in the *default* cpp
# -dM -P output; this is used to test the toolchain *default* configuration
check_cpp = $(shell $(CROSS)cpp -dM -P /dev/null | grep -q '^\#define $(1)' && echo 1 || echo 0)

# testsuite doesn't expect to be built with -mthumb
# TODO if the testsuite is only broken with Thumb-2 (and not with "Thumb-1"),
# we should test for __thumb2__ instead
ifneq (,$(filter $(DEB_HOST_ARCH), armel armhf))
  ifeq ($(call check_cpp,__thumb__),1)
    CFLAGS += -marm
  endif
endif

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

DEB_VERSION	:= $(call vafilt,$(CHANGELOG_VARS),Version)
DEB_SVERSION	:= $(shell echo $(DEB_VERSION) | sed 's/+b[0-9][0-9]*$$//')
DEB_UPSTREAM	:= $(firstword $(subst -,$(SPACE),$(DEB_VERSION)))

VERSION		:= $(shell sed -n 's/^ *VERSION=\(.*\)/\1/p' bfd/configure | head -1 | tr -d \')
DATE		:= $(shell sed -n 's/.* \([0-9]*\)$$/\1/p' bfd/version.h)
ifneq (,$(DATE))
#  DATE_EXT	:= .$(DATE)
endif
BUILD_DATE := $(shell dpkg-parsechangelog | sed -n -e 's/^Date: //p')
BUILD_DAY  := $(shell date -Idate -u -d "$(BUILD_DATE)")

is_rc = yes
is_rc =

ifneq ($(DEB_UPSTREAM),$(VERSION)$(DATE_EXT))
  $(error upstream ($(VERSION)$(DATE_EXT)) and debian ($(DEB_UPSTREAM)) version mismatch)
endif

SINGLE_VERSION= $(VERSION)-system
MULTI_VERSION = $(VERSION)-multiarch
HPPA64_VERSION= $(VERSION)-hppa64

ifeq (,$(filter $(distrelease),squeeze wheezy precise trusty))
  DPKG_DEV = dpkg-dev (>= 1.17.11),
endif
ifeq (,$(filter $(distrelease),squeeze wheezy stretch precise trusty xenial zesty artful))
  DPKG_DEV = dpkg-dev (>= 1.19.0.5),
endif

NJOBS =
# Support parallel=<n> in DEB_BUILD_OPTIONS (see #209008)
ifneq (,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
  NJOBS := -j $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
endif
ifneq (,$(findstring nogold,$(DEB_BUILD_OPTIONS)))
  with_gold = disabled in DEB_BUILD_OPTIONS
endif
ifneq (,$(findstring nomult,$(DEB_BUILD_OPTIONS)))
  with_multiarch = disabled in DEB_BUILD_OPTIONS
endif
ifneq (,$(findstring nocross,$(DEB_BUILD_OPTIONS)))
  with_cross = disabled in DEB_BUILD_OPTIONS
endif
ifneq (,$(findstring nohppa,$(DEB_BUILD_OPTIONS)))
  with_hppa64 = disabled in DEB_BUILD_OPTIONS
endif

# PF is the installation prefix for the package without the leading slash.
# It's "usr" for gcc releases, so use this if not explicitly set
ifeq ($(PF),)
  PF = usr
endif

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

gfdl_toplevel_texinfo_files = \
	bfd/doc/bfd.texinfo \
	bfd/doc/bfdint.texi \
	ld/ldint.texinfo

gfdl_generated_files = \
	bfd/doc/bfd.info

programs = addr2line ar as c++filt elfedit gprof ld ld.bfd
programs += nm objcopy objdump ranlib readelf size strings strip
ifeq ($(with_gold),yes)
programs += gold ld.gold dwp
endif

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

CONFARGS = \
	--enable-shared \
	--enable-plugins \
	--enable-threads \
	--with-system-zlib \
	--prefix=/$(PF) \
	--enable-deterministic-archives \
	--disable-compressed-debug-sections \
	--enable-new-dtags \
	--build=$(DEB_BUILD_GNU_TYPE) \
	--host=$(DEB_HOST_GNU_TYPE) \
	--with-pkgversion="GNU Binutils for $(distribution)"

# not yet ready for GCC 4.9
CONFARGS += --disable-werror

DEB_TARGET_MULTIARCH32_amd64		= i386-linux-gnu
DEB_TARGET_MULTIARCHX32_amd64		= x86_64-linux-gnux32

DEB_TARGET_MULTIARCH32_x32		= i386-linux-gnu
DEB_TARGET_MULTIARCH64_x32		= x86_64-linux-gnu

DEB_TARGET_MULTIARCH32_powerpc		= powerpc-linux-gnu

DEB_TARGET_MULTIARCH32_s390x		= s390-linux-gnu

DEB_TARGET_MULTIARCH32_sparc64		= sparc-linux-gnu

DEB_TARGET_MULTIARCH32_kfreebsd-amd64	= i386-kfreebsd-gnu

DEB_TARGET_MULTIARCH64_i386		= x86_64-linux-gnu
DEB_TARGET_MULTIARCHX32_i386		= x86_64-linux-gnux32

DEB_TARGET_MULTIARCH64_powerpc		= powerpc64-linux-gnu

DEB_TARGET_MULTIARCH64_sparc		= sparc64-linux-gnu

DEB_TARGET_MULTIARCH64_s390		= s390x-linux-gnu

DEB_TARGET_MULTIARCH64_kfreebsd-i386	= x86_64-kfreebsd-gnu

DEB_TARGET_MULTIARCH64_mips		= mips64-linux-gnuabi64
DEB_TARGET_MULTIARCHN32_mips		= mips64-linux-gnuabin32

DEB_TARGET_MULTIARCH64_mipsel		= mips64el-linux-gnuabi64
DEB_TARGET_MULTIARCHN32_mipsel		= mips64el-linux-gnuabin32

DEB_TARGET_MULTIARCH64_mipsn32		= mips64-linux-gnuabi64
DEB_TARGET_MULTIARCH32_mipsn32		= mips-linux-gnu

DEB_TARGET_MULTIARCH64_mipsn32el 	= mips64el-linux-gnuabi64
DEB_TARGET_MULTIARCH32_mipsn32el 	= mipsel-linux-gnu

DEB_TARGET_MULTIARCH32_mips64		= mips-linux-gnu
DEB_TARGET_MULTIARCHN32_mips64		= mips64-linux-gnuabin32

DEB_TARGET_MULTIARCH32_mips64el		= mipsel-linux-gnu
DEB_TARGET_MULTIARCHN32_mips64el	= mips64el-linux-gnuabin32

DEB_TARGET_MULTIARCH64_mipsr6		= mipsisa64r6-linux-gnuabi64
DEB_TARGET_MULTIARCHN32_mipsr6	= mipsisa64r6-linux-gnuabin32

DEB_TARGET_MULTIARCH64_mipsr6el	= mipsisa64r6el-linux-gnuabi64
DEB_TARGET_MULTIARCHN32_mipsr6el	= mipsisa64r6el-linux-gnuabin32

DEB_TARGET_MULTIARCH64_mipsn32r6	= mipsisa64r6-linux-gnuabi64
DEB_TARGET_MULTIARCH32_mipsn32r6	= mipsisa32r6-linux-gnu

DEB_TARGET_MULTIARCH64_mipsn32r6el 	= mipsisa64r6el-linux-gnuabi64
DEB_TARGET_MULTIARCH32_mipsn32r6el 	= mipsisa32r6el-linux-gnu

DEB_TARGET_MULTIARCH32_mips64r6		= mipsisa32r6-linux-gnu
DEB_TARGET_MULTIARCHN32_mips64r6	= mipsisa64r6-linux-gnuabin32

DEB_TARGET_MULTIARCH32_mips64r6el	= mipsisa32r6el-linux-gnu
DEB_TARGET_MULTIARCHN32_mips64r6el	= mipsisa64r6el-linux-gnuabin32

DEB_TARGET_MULTIARCH32_arm64		= aarch64_ilp32-linux-gnu

SET_MULTIARCH_ENV = \
	DEB_TARGET_MULTIARCH=$(call _multiarch,$1) \
	$(if $(DEB_TARGET_MULTIARCH32_$1) ,DEB_TARGET_MULTIARCH32=$(DEB_TARGET_MULTIARCH32_$1)) \
	$(if $(DEB_TARGET_MULTIARCH64_$1) ,DEB_TARGET_MULTIARCH64=$(DEB_TARGET_MULTIARCH64_$1)) \
	$(if $(DEB_TARGET_MULTIARCHX32_$1),DEB_TARGET_MULTIARCHX32=$(DEB_TARGET_MULTIARCHX32_$1)) \
	$(if $(DEB_TARGET_MULTIARCHN32_$1),DEB_TARGET_MULTIARCHN32=$(DEB_TARGET_MULTIARCHN32_$1))

CONFARGS_TARGET_sparc		= --enable-targets=sparc64-linux-gnu
CONFLICTS_TARGET_sparc		= -VextraConflicts="libc6-dev-sparc64 (<< 2.2.5-7)"

CONFARGS_TARGET_sparc64		= --enable-targets=sparc-linux-gnu
CONFLICTS_TARGET_sparc64	= -VextraConflicts="libc6-dev-sparc64 (<< 2.2.5-7)"

CONFARGS_TARGET_powerpc		= --enable-targets=powerpc64-linux-gnu

CONFARGS_TARGET_ppc64		= --enable-targets=powerpc-linux-gnu

CONFARGS_TARGET_ppc64el		= --enable-targets=powerpc-linux-gnu

CONFARGS_TARGET_s390		= --enable-targets=s390x-linux-gnu

CONFARGS_TARGET_s390x		= --enable-targets=s390-linux-gnu

CONFARGS_TARGET_amd64		= --enable-targets=x86_64-linux-gnux32,x86_64-pep

CONFARGS_TARGET_i386		= --enable-targets=x86_64-linux-gnu,x86_64-linux-gnux32,x86_64-pep

CONFARGS_TARGET_x32		= --enable-targets=x86_64-linux-gnu,x86_64-pep

CONFLICTS_TARGET_amd64		= -VextraConflicts="binutils-mingw-w64-i686 (<< 2.23.52.20130612-1+3), binutils-mingw-w64-x86-64 (<< 2.23.52.20130612-1+3)"
CONFLICTS_TARGET_i386 = $(CONFLICTS_TARGET_amd64)
CONFLICTS_TARGET_x32  = $(CONFLICTS_TARGET_amd64)

CONFARGS_TARGET_kfreebsd-i386	= --enable-targets=x86_64-kfreebsd-gnu

CONFARGS_TARGET_mips		= --enable-targets=mips64-linux-gnuabi64,mips64-linux-gnuabin32

CONFARGS_TARGET_mipsel		= --enable-targets=mips64el-linux-gnuabi64,mips64el-linux-gnuabin32

CONFARGS_TARGET_mipsn32		= --enable-targets=mips64-linux-gnuabi64,mips-linux-gnu

CONFARGS_TARGET_mipsn32el	= --enable-targets=mips64el-linux-gnuabi64,mipsel-linux-gnu

CONFARGS_TARGET_mips64		= --enable-targets=mips64-linux-gnuabin32,mips-linux-gnu

CONFARGS_TARGET_mips64el	= --enable-targets=mips64el-linux-gnuabin32,mipsel-linux-gnu

CONFARGS_TARGET_mipsr6	= --enable-targets=mipsisa64r6-linux-gnuabi64,mipsisa64r6-linux-gnuabin32

CONFARGS_TARGET_mipsr6el	= --enable-targets=mipsisa64r6el-linux-gnuabi64,mipsisa64r6el-linux-gnuabin32

CONFARGS_TARGET_mipsn32r6	= --enable-targets=mipsisa64r6-linux-gnuabi64,mipsisa32r6-linux-gnu

CONFARGS_TARGET_mipsn32r6el	= --enable-targets=mipsisa64r6el-linux-gnuabi64,mipsisa32r6el-linux-gnu

CONFARGS_TARGET_mips64r6	= --enable-targets=mipsisa64r6-linux-gnuabin32,mipsisa32r6-linux-gnu

CONFARGS_TARGET_mips64r6el	= --enable-targets=mipsisa64r6el-linux-gnuabin32,mipsisa32r6el-linux-gnu

CONFARGS_TARGET_aarch64		= --enable-targets=aarch64_be-linux-gnu

with_check := yes
ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  # override buildd admins to run the testsuite anyway ...
  ifeq (,$(filter $(DEB_HOST_ARCH), m68k powerpcspe sh4))
    with_check := disabled through DEB_BUILD_OPTIONS
  endif
endif
#with_check := disabled for this upload
ifneq (,$(filter $(DEB_HOST_ARCH), armel armhf mips mipsel sparc))
  ignore_regressions := regressions ignored on architecture $(DEB_HOST_ARCH)
endif
ignore_regressions := regressions ignored on architecture $(DEB_HOST_ARCH)

with_strip := yes
ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	with_strip := disabled through DEB_BUILD_OPTIONS
endif

source_files = $(addprefix $(shell basename $(pwd))/, \
		 $(filter-out stamps .pc CVS debian builddir-% test-summary%, $(wildcard *)))

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

update-patches:
	export QUILT_PATCHES=$(CURDIR)/debian/patches; \
	export QUILT_REFRESH_ARGS="--no-timestamps --no-index -pab"; \
	export QUILT_DIFF_ARGS="--no-timestamps --no-index -pab"; \
	while quilt push; do quilt refresh; done

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

################
# clean target #
################

clean:
	$(checkdir)
	rm -rf stamps
	rm -rf builddir-*
	rm -rf stamps
	find . -name \*.gmo -o -name \*~ -o -name \*.info ! -name sysroff.info | xargs -r rm -f
	rm -f test-summary*
	rm -rf $(d_bin) $(d_com) $(d_lib) $(d_lib)-dbg $(d_nat) $(d_nat)-dbg \
	  $(d_hst) $(d_dev) $(d_mul) $(d_mul)-dbg $(d_mdev) $(d_doc) \
	  $(d_hppa64) $(d_hppa64)-dbg $(d_src) $(d_bld)
	$(foreach ca,$(CROSS_ARCHS), rm -rf debian/binutils-$(shell echo $(call _gnu_type,$(ca)) | sed 's/_/-/g;s/i586/i686/'){,-dbg}; )
	rm -rf debian/tmp debian/files* debian/substvars
	rm -f debian/*.orig debian/*.rej
	rm -rf $(d_cross) debian/files debian/substvars
ifneq (,$(TARGET))
	rm -rf builddir-$(TARGET)
endif
	for i in debian/*.in; do \
	    case "$$i" in debian/control*.in) continue; esac; \
	    rm -f $${i%*.in}; \
	done

	rm -f *-stamp

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

stamps/control: debian/control.in $(if $(TARGET),debian/control.cross.in) $(if $(filter yes, $(with_cross)),debian/control.cross.in)
ifneq (,$(TARGET))
	sed -n -e 's/@dpkg_dev@/$(DPKG_DEV)/;/^Package: binutils-for-build$$/q;p' \
		< debian/control.in > debian/control
	sed -e "s/@target@/$$(echo -n $(TARGET) | sed s/_/-/g)/" \
		-e "s/@host_archs@/any/" \
		-e 's/@binutils_alt_triplet@//' \
		< debian/control.cross.in >> debian/control
else
	sed -e 's/@dpkg_dev@/$(DPKG_DEV)/' \
		debian/control.in > debian/control
	$(foreach ca,$(NATIVE_ARCHS), \
	  sed \
	    -e 's/@host_archs@/$(ca)$(if $(and $(filter yes,$(with_cross)),$(filter $(ca),$(DEB_HOST_ARCH) $(CROSS_ARCHS))), $(HOST_ARCHS_$(ca)))/g' \
	    -e 's/@target@/$(shell dpkg-architecture -a$(ca) -qDEB_HOST_GNU_TYPE 2>/dev/null | sed 's/_/-/g;s/i586/i686/')/g' \
	    -e 's/@binutils_alt_triplet@/$(if $(findstring i386,$(ca)),binutils-$(shell dpkg-architecture -a$(ca) -qDEB_HOST_GNU_TYPE 2>/dev/null | sed 's/i686/i586/g'))/g' \
	    debian/control.cross.in \
	    | $(if $(filter yes,$(same_source)), grep -v '^Built-Using', cat) \
	    >> debian/control; \
	)
  ifneq ($(DEB_HOST_ARCH),riscv64)
    ifneq ($(IGNORE_RISCV64_HACK),yes)
	sed -i -e '/^Architecture:/s/ riscv64//' debian/control
    endif
  endif
endif
	@mkdir -p stamps
	touch $@

#######################
# single-arch targets #
#######################

SINGLE_CONFARGS = $(CONFARGS) $(CONFARGS_TARGET_$(DEB_HOST_ARCH))
ifeq ($(with_gold),yes)
	SINGLE_CONFARGS += --enable-ld=default --enable-gold
endif

stamps/configure-single:
	$(checkdir)
	env
	@echo BEGIN $@
ifeq ($(with_check),yes)
	@if echo "spawn true" | /usr/bin/expect -f - >/dev/null; then \
	  : ; \
	else \
	  echo "expect is failing on your system with the above error, which means the"; \
	  echo "testsuite will fail.  Please resolve the above issues and retry the build."; \
	  echo "-----------------------------------------------------------------------------"; \
	  exit 1; \
	fi
endif

ifeq ($(DEB_HOST_ARCH),riscv64)
	rm -f stamps/control
	@mkdir -p stamps
	$(MAKE) -f debian/rules stamps/control IGNORE_RISCV64_HACK=yes
endif

	rm -rf stamps/configure-single builddir-single
	mkdir builddir-single
	cd builddir-single && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
		$(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
		../configure --with-sysroot=/ \
			--libdir=/$(PF)/lib/$(DEB_HOST_MULTIARCH) \
			$(SINGLE_CONFARGS)
	$(MAKE) -C builddir-single configure-host
	@mkdir -p stamps
	touch $@

stamps/build-single: stamps/configure-single
	$(checkdir)
	@echo BEGIN $@
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	  $(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
	    $(MAKE) -C builddir-single/bfd headers \
		LDFLAGS="-Wl,-z,relro"
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	  $(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
	    $(MAKE) $(NJOBS) -C builddir-single \
		LDFLAGS="-Wl,-z,relro"
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
ifeq ($(with_check),yes)
	-env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	  $(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
	    $(MAKE) -C builddir-single -k check
	cat builddir-single/binutils/binutils.sum \
	    builddir-single/gas/testsuite/gas.sum \
	    builddir-single/ld/ld.sum >> $(pwd)/test-summary
	set -e; \
	tsi=test-summary-installed; \
	rm -f $$tsi; \
	if [ -f /usr/share/doc/binutils/test-summary-$(DEB_HOST_ARCH).gz ]; then \
	  zcat /usr/share/doc/binutils/test-summary-$(DEB_HOST_ARCH).gz > $$tsi; \
	elif [ -f /usr/share/doc/binutils/test-summary.gz ]; then \
	  zcat /usr/share/doc/binutils/test-summary.gz > $$tsi; \
	elif [ -f /usr/share/doc/binutils/test-summary ]; then \
	  cat /usr/share/doc/binutils/test-summary > $$tsi; \
	fi; \
	if [ ! -f $$tsi ]; then \
	  echo "No test results available for the installed binutils version"; \
	elif [ -x /usr/bin/python3 ]; then \
	  echo "Test results, compared with installed binutils:"; \
	  if python3 debian/test-suite-compare.py $$tsi test-summary; then \
	    : ; \
	  elif [ -n "$(ignore_regressions)" ]; then \
	    echo "$(ignore_regressions)"; \
	  else \
	    false; \
	  fi; \
	else \
	  echo "python3 not installed, not comparing test results."; \
	fi
endif
endif
	touch $@


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

#####################
# multiarch targets #
#####################

multiarch_targets = \
	aarch64-linux-gnu \
	aarch64_be-linux-gnu \
	alpha-linux-gnu \
	arm-linux-gnueabi \
	hppa-linux-gnu \
	i686-linux-gnu \
	ia64-linux-gnu \
	m32r-linux-gnu \
	m68k-linux-gnu \
	m68k-rtems \
	mips-linux-gnu \
	mipsel-linux-gnu \
	mips64-linux-gnuabin32 \
	mips64el-linux-gnuabin32 \
	mips64-linux-gnu \
	mips64el-linux-gnu \
	mipsisa32r6-linux-gnu \
	mipsisa32r6el-linux-gnu \
	mipsisa64r6-linux-gnuabin32 \
	mipsisa64r6el-linux-gnuabin32 \
	mipsisa64r6-linux-gnuabi64 \
	mipsisa64r6el-linux-gnuabi64 \
	powerpc-linux-gnu \
	powerpc64-linux-gnu \
	powerpc64le-linux-gnu \
	riscv64-linux-gnu \
	s390-linux-gnu \
	s390x-linux-gnu \
	sh-linux-gnu \
	sparc-linux-gnu \
	sparc64-linux-gnu \
	x86_64-linux-gnu \
	x86_64-linux-gnux32 \
	m32r-linux-gnu \
	x86_64-pep

# try to work around #758830
ifeq ($(DEB_HOST_ARCH),sh4)
  multiarch_targets := $(filter-out hppa-linux-gnu, $(multiarch_targets))
endif

stamps/configure-multi:
	$(checkdir)
	@echo BEGIN $@
	rm -rf stamps/configure-multi \
		builddir-multi
	mkdir builddir-multi
	cd builddir-multi \
	    && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
	        $(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
		../configure $(CONFARGS) \
		  --with-sysroot=/ \
		  --libdir=/$(PF)/lib/$(DEB_HOST_MULTIARCH) \
		  --enable-targets=$(subst $(SPACE),$(COMMA),$(multiarch_targets))
	$(MAKE) -C builddir-multi configure-host
	@mkdir -p stamps
	touch $@

stamps/build-multi: stamps/configure-multi
	$(checkdir)
	@echo BEGIN $@
	$(MAKE) -C builddir-multi/bfd headers
	env MAKE="$(MAKE) VERSION=$(MULTI_VERSION)" \
	  $(call SET_MULTIARCH_ENV,$(DEB_HOST_ARCH)) \
	  $(MAKE) $(NJOBS) -C builddir-multi \
		LDFLAGS="-Wl,-z,relro"
	touch $@

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

#################
# cross targets #
#################

CROSS_CONFARGS = $(CONFARGS) --enable-initfini-array
ifeq ($(with_gold),yes)
	CROSS_CONFARGS += --enable-ld=default --enable-gold
endif

stamps/configure.%:
	$(checkdir)
	@echo BEGIN $@
	rm -rf $@ builddir-$*
	mkdir builddir-$*
	cd builddir-$* \
	    && env CC="$(CC)" CXX="$(CXX)" \
	       $(call SET_MULTIARCH_ENV,$*) \
		../configure \
		  $(CROSS_CONFARGS) \
		  $(CONFARGS_TARGET_$(*)) \
		  --with-sysroot=/ \
		  --libdir=/$(PF)/lib/$(call _multiarch,$*) \
		  $(if $(filter $*, $(gold_targets)),--enable-ld=default --enable-gold,--disable-gold) \
		  --target=$(CROSS_GNU_TYPE)
	@mkdir -p stamps
	touch $@

stamps/build.%: stamps/configure.%
	$(checkdir)
	@echo BEGIN $@
	env MAKE="$(MAKE) VERSION=$(VERSION)-$*" \
	  $(call SET_MULTIARCH_ENV,$*) \
	  $(MAKE) -C builddir-$* $(NJOBS) \
		CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" \
		LDFLAGS="$(LDFLAGS) -Wl,-z,relro"
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
ifeq ($(with_check),yes)
	-env MAKE="$(MAKE) VERSION=$(VERSION)-$*" \
	  $(call SET_MULTIARCH_ENV,$*) \
	    $(MAKE) -C builddir-$* -k check
	cat builddir-$*/binutils/binutils.sum \
	    builddir-$*/gas/testsuite/gas.sum \
	    builddir-$*/ld/ld.sum >> test-summary-$*
	set -e; \
	tsi=test-summary-$*-installed; \
	rm -f $$tsi; \
	if [ -f /usr/share/doc/$(P_CROSS)/test-summary.gz ]; then \
	  zcat /usr/share/doc/$(P_CROSS)/test-summary.gz > $$tsi; \
	elif [ -f /usr/share/doc/binutils/test-summary-$*.gz ]; then \
	  zcat /usr/share/doc/binutils/test-summary-$*.gz > $$tsi; \
	fi; \
	if [ ! -f $$tsi ]; then \
	  echo "No test results available for the installed $(P_CROSS) version"; \
	elif [ -x /usr/bin/python3 ]; then \
	  echo "Test results, compared with installed binutils:"; \
	  if python3 debian/test-suite-compare.py $$tsi test-summary-$*; then \
	    : ; \
	  elif [ -n "$(ignore_regressions)" ]; then \
	    echo "$(ignore_regressions)"; \
	  else \
	    false; \
	  fi; \
	else \
	  echo "python3 not installed, not comparing test results."; \
	fi
endif
endif
	touch $@

stamps/install.%: stamps/build.%
	$(checkdir)
	@echo BEGIN $@
	rm -rf $(D_CROSS)
	env MAKE="$(MAKE) VERSION=$(VERSION)-$*" \
	  $(MAKE) -C builddir-$* DESTDIR=$(CURDIR)/$(D_CROSS) install

	rm -rf \
		$(D_CROSS)/$(PF)/share/info \
		$(D_CROSS)/$(PF)/share/locale

	mkdir -p $(D_CROSS)/$(PF)/lib/$(DEB_HOST_MULTIARCH)
	set -e; \
	d_src=$(D_CROSS)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(CROSS_GNU_TYPE)/lib; \
	d_dst=$(D_CROSS)/$(PF)/lib/$(DEB_HOST_MULTIARCH); \
	for lib in libbfd libopcodes; do \
	  so=$$(basename $$(echo $$d_src/$$lib*$**.so)); \
	  mv $$d_src/$$so $$d_dst/.; \
	  ln -sf ../../../lib/$(DEB_HOST_MULTIARCH)/$$so $$d_src/$$lib.so; \
	  mv $$d_src/$$lib.a $$d_dst/$${lib}-$(VERSION)-$*.a; \
	  ln -sf ../../../lib/$(DEB_HOST_MULTIARCH)/$$lib-$(VERSION)-$*.a $$d_src/$$lib.a; \
	done

	: # replace hard links with soft links
	for i in $(D_CROSS)/usr/$(CROSS_GNU_TYPE)/bin/*; do \
	  ln -sf ../../bin/$(CROSS_GNU_TYPE)-$$(basename $$i) $$i; \
	done
	ln -sf $(CROSS_GNU_TYPE)-ld.bfd $(D_CROSS)/usr/bin/$(CROSS_GNU_TYPE)-ld

	$(call strip_package, $(P_CROSS),$(D_CROSS),.)
	chmod ugo-x $(D_CROSS)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.so

	: # Get rid of .la files since libtool obviously has no idea about transient paths
	rm -f $(D_CROSS)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(CROSS_GNU_TYPE)/lib/*.la

	if which strip-nondeterminism >/dev/null 2>&1; then \
	  find $(D_CROSS) -name '*.a' -print0 \
	    | xargs -0r strip-nondeterminism --type ar; \
	fi

	: # no spu toolchain
	rm -f $(D_CROSS)/$(PF)/bin/*embedspu

	: # Remove windows related manpages
	rm -f $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-{dlltool,nlmconv,windmc,windres}.1

	: # symlink man pages
	mv $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-ld.1 \
	  $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-ld.bfd.1
	gzip -9n $(D_CROSS)/$(PF)/share/man/man1/*
	for i in $(D_CROSS)/$(PF)/share/man/man1/*; do \
	  b=$$(basename $$i | sed 's/$(CROSS_GNU_TYPE)-//'); \
	  ln -sf $$b $$i; \
	done
	ln -sf $(CROSS_GNU_TYPE)-ld.bfd.1.gz \
	  $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-ld.1.gz

	: # gold man pages
	$(if $(filter $*, $(gold_targets)), \
	  ln -sf ld.gold.1.gz $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-ld.gold.1.gz; \
	  ln -sf dwp.1.gz $(D_CROSS)/$(PF)/share/man/man1/$(CROSS_GNU_TYPE)-dwp.1.gz; \
	)

	: # Don't want /usr/<arch>-linux to exist in any package, don't ship development files
	rm -rf $(D_CROSS)/$(PF)/$(DEB_HOST_GNU_TYPE)

	rm -f $(D_CROSS)/$(PF)/lib/*.a $(D_CROSS)/$(PF)/lib/*/*.a
	rm -f $(D_CROSS)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(CROSS_GNU_TYPE)/lib/*.a

	: # remove RPATH
	chrpath -k -d $$(file $(D_CROSS)/usr/bin/*|awk -F: '/ ELF/ {print $$1}')

ifneq (,$(filter $(distrelease),lenny etch squeeze wheezy jessie stretch))
	: # temporary i586-* symlinks for stretch
	compat=$$(echo $(CROSS_GNU_TYPE) | sed 's/i686/i586/'); \
	case "$(CROSS_GNU_TYPE)" in i686-*) \
	  for i in $(programs); do \
	    ln -sf $(CROSS_GNU_TYPE)-$$i $(D_CROSS)/$(PF)/bin/$$compat-$$i; \
	    ln -sf $(CROSS_GNU_TYPE)-$$i.1.gz $(D_CROSS)/$(PF)/share/man/man1/$$compat-$$i.1.gz; \
	  done; \
	esac
endif
	touch $@

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

#################
# hppa64 target #
#################

stamps/configure-hppa64:
	$(checkdir)
	@echo BEGIN $@
	rm -rf stamps/configure-hppa64 \
		builddir-hppa64
	mkdir builddir-hppa64
	cd builddir-hppa64 \
	    && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" ../configure \
		$(filter-out --enable-targets=%, $(CONFARGS)) \
		--libdir=/$(PF)/lib/hppa64-linux-gnu \
		--target=hppa64-linux-gnu
	$(MAKE) -C builddir-hppa64 configure-host
	@mkdir -p stamps
	touch $@

stamps/build-hppa64: stamps/configure-hppa64
	$(checkdir)
	@echo BEGIN $@
	$(MAKE) -C builddir-hppa64/bfd headers
	env MAKE="$(MAKE) VERSION=$(HPPA64_VERSION)" \
	  $(MAKE) $(NJOBS) -C builddir-hppa64 \
	    LDFLAGS="-Wl,-z,relro"
	touch $@

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

pre-build:
#ifneq (,$(filter $(DEB_HOST_ARCH), armel powerpc))
#	@echo Build it ...
#else
#	@echo Explicitely fail the build for architecture $(DEB_HOST_ARCH)
#	false
#endif

build_stamps = stamps/build-single
ifeq ($(with_multiarch),yes)
       build_stamps += stamps/build-multi
endif
ifeq ($(with_hppa64),yes)
       build_stamps += stamps/build-hppa64
endif
ifeq ($(with_cross),yes)
       build_stamps += $(foreach ca,$(CROSS_ARCHS), stamps/build.$(ca))
endif
ifneq (,$(TARGET))
   ifeq ($(TARGET),hppa64-linux-gnu)
     build_stamps = stamps/build-hppa64
   else
     build_stamps = stamps/build.$(DEB_TARGET_ARCH)
  endif
endif
ifeq ($(BACKPORT),true)
    build_stamps :=
    with_check := no
endif

build: pre-build stamps/build
build-arch: pre-build stamps/build
build-indep: pre-build stamps/build
stamps/build: $(build_stamps)
	touch $@

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

##################
# install target #
##################

install_stamps =
ifeq ($(with_hppa64),yes)
       install_stamps += stamps/install-hppa64
endif
ifeq ($(with_cross),yes)
       install_stamps += $(foreach ca,$(CROSS_ARCHS), stamps/install.$(ca))
endif

ifneq (,$(TARGET))
    ifeq ($(TARGET),hppa64-linux-gnu)
      install_stamp = stamps/install-hppa64
    else
      install_stamp = stamps/install.$(DEB_TARGET_ARCH)
  endif
else
        install_stamp = stamps/install
endif
ifeq ($(BACKPORT),true)
    install_stamps :=
endif
install: $(install_stamp)
stamps/install: checkroot stamps/build $(install_stamps)
	$(checkdir)

	rm -fr $(d_bin) $(d_com) $(d_lib) $(d_nat) $(d_dev) $(d_mul) $(d_mdev) $(d_doc) $(d_src) $(d_bld)
	$(install_dir) $(d_bin) $(d_com) $(d_lib) $(d_nat) $(d_dev) $(d_mul) $(d_mdev) $(d_doc) $(d_src) $(d_bld)

	: # install binutils and -dev stuff
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	  $(MAKE) -C builddir-single \
		CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		DESTDIR=$(CURDIR)/$(d_bin) install

	$(install_dir) $(d_com)/$(PF)/share
	mv $(d_bin)/$(PF)/share/locale $(d_com)/$(PF)/share/locale

	$(install_dir) $(d_doc)/$(PF)/share
	mv $(d_bin)/$(PF)/share/info $(d_doc)/$(PF)/share/info

	$(install_dir) $(d_nat)/$(PF)/lib/$(DEB_HOST_MULTIARCH)
	mv $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/ldscripts \
		$(d_nat)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/.

	$(install_dir) $(d_com)/$(PF)/share/man
	mv $(d_bin)/$(PF)/share/man/man1 $(d_com)/$(PF)/share/man/.
	for f in $(d_com)/$(PF)/share/man/man1/*.1; do \
	  sed -i -e '/^\.TH /s/[0-9]*-[0-9]*-[0-9]*/$(BUILD_DAY)/' $$f; \
	done

ifeq ($(with_multiarch),yes)
	: # now install binutils-multiarch stuff
	env MAKE="$(MAKE) VERSION=$(MULTI_VERSION)" \
	  $(MAKE) -C builddir-multi \
		CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		DESTDIR=$(CURDIR)/$(d_mul) install
endif

	: # fix bfd.h, removing the safety inclusion guard
	awk '/PR 14072/,/^#endif/ {next} {print}' $(d_bin)/$(PF)/include/bfd.h \
	  > $(d_bin)/$(PF)/include/bfd.h.new
	mv $(d_bin)/$(PF)/include/bfd.h.new $(d_bin)/$(PF)/include/bfd.h

	: # fix multilib conflicts of generated values by __WORDSIZE-based expressions
	sed -i -e '/^#include "ansidecl.h"/{p;s~^.*$$~#include <bits/wordsize.h>~;}' \
	    -e 's/^#define BFD_DEFAULT_TARGET_SIZE \(32\|64\) *$$/#define BFD_DEFAULT_TARGET_SIZE __WORDSIZE/' \
	    -e 's/^#define BFD_HOST_64BIT_LONG [01] *$$/#define BFD_HOST_64BIT_LONG (__WORDSIZE == 64)/' \
	    -e 's/^#define BFD_HOST_64_BIT \(long \)\?long *$$/#if __WORDSIZE == 32\
#define BFD_HOST_64_BIT long long\
#else\
#define BFD_HOST_64_BIT long\
#endif/' \
	    -e 's/^#define BFD_HOST_U_64_BIT unsigned \(long \)\?long *$$/#define BFD_HOST_U_64_BIT unsigned BFD_HOST_64_BIT/' \
	    $(d_bin)/$(PF)/include/bfd.h

	: # copy plugin-api.h ...
	cp -f include/plugin-api.h $(d_bin)/$(PF)/include

	: # We don't need to distribute everything in binutils and -dev
	rm -rf $(d_bin)/$(PF)/include/obstack.h
	rm -f $(d_doc)/$(PF)/share/info/configure.* $(d_doc)/$(PF)/share/info/standards.*

ifneq (,$(filter $(DEB_HOST_ARCH),powerpc powerpcspe ppc64 ppc64el))
	rm -f $(d_bin)/$(PF)/bin/embedspu
endif

ifeq ($(with_multiarch),yes)
	: # Now get rid of just about everything in binutils-multiarch
	rm -rf $(d_mul)/$(PF)/man $(d_mul)/$(PF)/info $(d_mul)/$(PF)/include
	rm -rf $(d_mul)/$(PF)/share/man $(d_mul)/$(PF)/share/info $(d_mul)/$(PF)/share/locale

	: # elfedit (even with its --input-mach option)
	: # is the same for all targets.
	rm -f $(d_mul)/$(PF)/bin/elfedit

	: # c++filt does not link to libbfd for anything more than
	: # the help message, and its behavior does not vary
	: # between arches aside from the --version message.
	rm -f $(d_mul)/$(PF)/bin/c++filt

	: # As gas/README points out (search for --enable-targets),
	: # multi-arch gas is not ready yet.
	rm -f $(d_mul)/$(PF)/bin/as
	rm -f $(d_mul)/$(PF)/bin/ld
	rm -f $(d_mul)/$(PF)/bin/ld.bfd
	rm -f $(d_mul)/$(PF)/bin/ld.gold

  ifneq (,$(filter $(DEB_HOST_ARCH),powerpc powerpcspe ppc64 ppc64el))
	rm -f $(d_mul)/$(PF)/bin/embedspu
  endif
	rm -rf $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/ldscripts
endif

#	rm -rf debian/binutils-*-*-*/$(PF)/lib/$(DEB_HOST_MULTIARCH)/ldscripts \
#	  debian/binutils-*-gnu/$(PF)/lib/$(DEB_HOST_MULTIARCH)/ldscripts

	$(install_dir) $(d_dev)/$(PF)/include
	mv $(d_bin)/$(PF)/include/* $(d_dev)/$(PF)/include/

	$(install_dir) $(d_lib)/$(PF)/lib/$(DEB_HOST_MULTIARCH) $(d_dev)/$(PF)/lib/$(DEB_HOST_MULTIARCH)
	mv $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.a \
	   $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libbfd.so \
	   $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libopcodes.so \
		$(d_dev)/$(PF)/lib/$(DEB_HOST_MULTIARCH)
	mv $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.so \
	   $(d_lib)/$(PF)/lib/$(DEB_HOST_MULTIARCH)

ifeq ($(with_multiarch),yes)
	$(install_dir) $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH) $(d_mdev)/$(PF)/lib/$(DEB_HOST_MULTIARCH)
	mv $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libbfd.so \
	   $(d_mdev)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libbfd-multiarch.so
	mv $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libopcodes.so \
	   $(d_mdev)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libopcodes-multiarch.so
	rm -f $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.la \
	  $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.a
	rm -f $(d_mul)/$(PF)/lib*/$(DEB_HOST_MULTIARCH)/libiberty*
endif

	: # Get rid of .la files since libtool obviously has no idea about transient paths
	rm -f $(d_bin)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.la

	chmod ugo-x $(d_lib)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.so
	$(call strip_package, $(p_lib), $(d_lib))
ifeq ($(with_multiarch),yes)
	chmod ugo-x $(d_mul)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.so
	$(call strip_package, $(p_mul), $(d_mul))
endif

	if which strip-nondeterminism >/dev/null 2>&1; then \
	  find $(d_dev) -name '*.a' -print0 \
	    | xargs -0r strip-nondeterminism --type ar; \
	fi

	: # Don't want /usr/<arch>-linux to exist in any package
	rm -rf $(d_bin)/$(PF)/$(DEB_HOST_GNU_TYPE)

	: # Remove windows related manpages
	rm -f $(d_com)/$(PF)/share/man/man1/{dlltool,nlmconv,windmc,windres}.1

ifeq ($(with_multiarch),yes)
	rm -rf $(d_mul)/$(PF)/$(DEB_HOST_GNU_TYPE)
	rm -f $(d_mul)/$(PF)/share/man/man1/{dlltool,nlmconv,windmc,windres}.1
endif

	rm -f $(d_bin)/$(PF)/bin/ld.bfd
	mv $(d_bin)/$(PF)/bin/ld $(d_bin)/$(PF)/bin/ld.bfd
	mv $(d_com)/$(PF)/share/man/man1/ld.1 \
		$(d_com)/$(PF)/share/man/man1/ld.bfd.1
	ln -sf $(DEB_HOST_GNU_TYPE)-ld.bfd $(d_bin)/$(PF)/bin/ld
	$(install_dir) $(d_com)/$(PF)/share/man/man1
	ln -sf ld.bfd.1.gz $(d_com)/$(PF)/share/man/man1/ld.1.gz
ifeq ($(with_gold),yes)
	ln -s ld.gold $(d_bin)/$(PF)/bin/gold
  ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	find debian -name '*gold' -o -name '*dwp'
	if which help2man >/dev/null 2>&1; then \
	  help2man -N -n 'The GNU ELF linker' \
	    $(d_bin)/$(PF)/bin/ld.gold \
	    | sed -e 's,debian/.*-ld.gold,ld.gold,g' \
		-e 's/$(DEB_HOST_GNU_TYPE)-//g' \
		> debian/ld.gold.1; \
	  help2man -N -n 'The DWARF packaging utility' \
	    $(d_bin)/$(PF)/bin/dwp \
	    | sed -e 's,debian/.*-dwp,dwp,g' \
		-e 's/$(DEB_HOST_GNU_TYPE)-//g' \
		> debian/dwp.1; \
	fi
  endif
	cp debian/dwp.1 $(d_com)/$(PF)/share/man/man1/
	cp debian/ld.gold.1 $(d_com)/$(PF)/share/man/man1/
	ln -s ld.gold.1.gz $(d_com)/$(PF)/share/man/man1/gold.1.gz

	: # install a symlink for the gold linker
	$(install_dir) $(d_bin)/$(PF)/lib/gold-ld
	ln -s ../../bin/ld.gold $(d_bin)/$(PF)/lib/gold-ld/ld
endif
	: # install a symlink for the bfd linker
	$(install_dir) $(d_bin)/$(PF)/lib/compat-ld
	ln -s ../../bin/ld.bfd $(d_bin)/$(PF)/lib/compat-ld/ld

	: # Remove empty directory
	rmdir $(d_bin)/$(PF)/include/

	: # Rename non-prefixed binaries to $(DEB_HOST_GNU_TYPE)- prefixed binaries
	: # and provide symlinks to the prefixed binaries.
	$(install_dir) $(d_nat)/$(PF)/bin $(d_nat)/$(PF)/share/man/man1
	for i in $(programs); do \
	  mv $(d_bin)/$(PF)/bin/$$i $(d_nat)/$(PF)/bin/$(DEB_HOST_GNU_TYPE)-$$i; \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i $(d_bin)/$(PF)/bin/$$i; \
	done
	ln -sf $(DEB_HOST_GNU_TYPE)-ld.gold $(d_nat)/usr/bin/$(DEB_HOST_GNU_TYPE)-gold
	for i in $(programs); do \
	  ln -sf $$i.1.gz $(d_nat)/$(PF)/share/man/man1/$(DEB_HOST_GNU_TYPE)-$$i.1.gz; \
	done
	$(call strip_package, $(p_nat), $(d_nat))
ifeq ($(with_multiarch),yes)
	for i in \
	  addr2line ar gprof \
	  nm objcopy objdump ranlib readelf size strings strip; \
	do \
	  mv $(d_mul)/$(PF)/bin/$$i $(d_mul)/$(PF)/bin/$(DEB_HOST_GNU_TYPE)-$$i; \
	done
	rm -f $(d_mul)/$(PF)/bin/embedspu
endif

ifneq (,$(filter $(DEB_HOST_ARCH),i386 kfreebsd-i386 hurd-i386))
# temporary i586-* symlinks for stretch/sid
  ifneq (,$(TRIPLET_SYMLINK))
	for i in $(programs); do \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i $(d_nat)/$(PF)/bin/$(TRIPLET_SYMLINK)-$$i; \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i.1.gz $(d_nat)/$(PF)/share/man/man1/$(TRIPLET_SYMLINK)-$$i.1.gz; \
	done
  endif
# temporary i486-* symlinks for jessie/sid
  ifeq ($(DEB_HOST_GNU_CPU),i586)
	gnutype=$(subst i586,i486,$(DEB_HOST_GNU_TYPE)); \
	for i in $(programs); do \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i $(d_nat)/$(PF)/bin/$$gnutype-$$i; \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i.1.gz $(d_nat)/$(PF)/share/man/man1/$$gnutype-$$i.1.gz; \
	done
  endif
# for backports to wheezy and squeeze
  ifeq ($(DEB_HOST_GNU_CPU),i486)
	gnutype=$(subst i486,i586,$(DEB_HOST_GNU_TYPE)); \
	for i in $(programs); do \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i $(d_nat)/$(PF)/bin/$$gnutype-$$i; \
	  ln -sf $(DEB_HOST_GNU_TYPE)-$$i.1.gz $(d_nat)/$(PF)/share/man/man1/$$gnutype-$$i.1.gz; \
	done
  endif
endif
	touch $@

stamps/install-hppa64: checkroot stamps/build-hppa64
	$(checkdir)

	rm -fr $(d_hppa64)
	$(install_dir) $(d_hppa64)
	$(install_dir) $(d_hppa64)/$(PF)/lib/$(DEB_HOST_MULTIARCH)

	: # install binutils-hppa64 stuff
	env MAKE="$(MAKE) VERSION=$(HPPA64_VERSION)" \
          $(MAKE) -C builddir-hppa64 \
		CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CXXFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		DESTDIR=$(CURDIR)/$(d_hppa64) install

	: # move shared libs to the standard path
	mv $(d_hppa64)/$(PF)/$(DEB_HOST_GNU_TYPE)/hppa64-linux-gnu/lib/lib*-*.so \
		$(d_hppa64)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/.

	: # Now get rid of just about everything in binutils-hppa64
	rm -rf $(d_hppa64)/$(PF)/man
	rm -rf $(d_hppa64)/$(PF)/info
	rm -rf $(d_hppa64)/$(PF)/include
	rm -rf $(d_hppa64)/$(PF)/share
	rm -rf $(d_hppa64)/$(PF)/hppa-linux-gnu
	rm -rf $(d_hppa64)/$(PF)/lib/libiberty.a

	: # replace hard links with soft links
	for i in $(d_hppa64)/usr/hppa64-linux-gnu/bin/*; do \
	  ln -sf ../../bin/hppa64-linux-gnu-$$(basename $$i) $$i; \
	done
	ln -sf hppa64-linux-gnu-ld.bfd $(d_hppa64)/usr/bin/hppa64-linux-gnu-ld

	$(call strip_package, $(p_hppa64), $(d_hppa64))
	chmod ugo-x $(d_hppa64)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/*.so

	: # remove RPATH
	chrpath -k -d $$(file $(d_hppa64)/usr/bin/*|awk -F: '/ ELF/ {print $$1}')

	: # Don't want /usr/<arch>-linux to exist in any package
	rm -rf $(d_hppa64)/$(PF)/$(DEB_HOST_GNU_TYPE)

	touch $@

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

#######################
# binary-indep target #
#######################

binary-indep: checkroot build install
	$(checkdir)

	rm -f debian/files debian/substvars

# Cross builds do not have documentation packages
ifeq (,$(TARGET))

	$(install_dir) $(d_doc)/DEBIAN

ifeq ($(GFDL_INVARIANT_FREE),yes)
	rm -f $(d_doc)/$(PF)/share/info/bfd.info*
	rm -f $(d_doc)/$(PF)/share/info/bfdint.info*
	rm -f $(d_doc)/$(PF)/share/info/ldint.info*
endif

ifneq ($(BACKPORT),true)
	$(install_dir) $(d_doc)/$(PF)/share/doc/$(p_doc)/
	$(install_file)	debian/changelog $(d_doc)/$(PF)/share/doc/$(p_doc)/changelog.Debian
	$(install_file)	debian/copyright $(d_doc)/$(PF)/share/doc/$(p_doc)/
	for i in bfd gas gprof ld; do \
	  ln -sf ../$(p_bin)/$$i $(d_doc)/$(PF)/share/doc/$(p_doc)/$$i; \
	done
	find $(d_doc)/$(PF)/share/doc/$(p_doc) -maxdepth 1 -type f ! -name copyright | xargs gzip -9n
	gzip -9n $(d_doc)/$(PF)/share/info/*

	dpkg-gencontrol -P$(d_doc) -p$(p_doc)
	chown -R root:root $(d_doc)
	chmod -R go=rX  $(d_doc)
	find $(d_doc) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_doc) ..

	$(install_dir) $(d_src)/$(PF)/share/doc/$(p_src)/
	$(install_file)	debian/changelog $(d_src)/$(PF)/share/doc/$(p_src)/changelog.Debian
	$(install_file)	debian/copyright $(d_src)/$(PF)/share/doc/$(p_src)/
	find $(d_src)/$(PF)/share/doc/$(p_src) -maxdepth 1 -type f ! -name copyright | xargs gzip -9n
endif # ifndef BACKPORT

	$(install_dir) $(d_src)/DEBIAN
	$(install_dir) $(d_src)/$(PF)/src/binutils/patches
	$(install_file) debian/patches/* $(d_src)/$(PF)/src/binutils/patches/
	cd .. && find $(source_files) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)' && \
		find $(source_files) -type f -print0 | LC_ALL=C sort -z | \
		tar --null -T - -c --xz --exclude=CVS --mode=go=rX,u+rw,a-s \
		-f $(pwd)/$(d_src)/$(PF)/src/binutils/binutils-$(VERSION).tar.xz \
		$(source_files)

	tar cf - $$(find './debian' -mindepth 1 \( \
		-path './debian/binutils*' -type d -prune -o \
		-path './debian/libbinutils' -type d -prune -o \
		-path './debian/binutils*-dbg' -type d -prune -o \
		-path './debian/libbinutils-dbg' -type d -prune -o \
		-path './debian/patches' -prune -o \
		-path './debian/tmp*' -prune -o \
		-path './debian/.bzr*' -prune -o \
		-path './debian/files' -prune -o \
		-print \) ) \
	  | tar -x -C $(d_src)/$(PF)/src/binutils -f -
	-chmod 755 $(d_src)/$(PF)/src/binutils/debian/*.{pre,post}{inst,rm}
	chmod 755 $(d_src)/$(PF)/src/binutils/debian/test-suite-compare.py

	dpkg-gencontrol -P$(d_src) -p$(p_src)
	chown -R root:root $(d_src)
	chmod -R go=rX  $(d_src)
	find $(d_src) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_src) ..


	$(install_dir) $(d_bld)/DEBIAN $(d_bld)/$(PF)/share/doc/
	ln -sf $(p_com) $(d_bld)/$(PF)/share/doc/$(p_bld)
	dpkg-gencontrol -P$(d_bld) -p$(p_bld) -Vbinutils:minver=$(min_ver)
	chown -R root:root $(d_bld)
	chmod -R go=rX $(d_bld)
	find $(d_bld) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_bld) ..
endif

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

#######################
# binary-arch target  #
#######################

binary.%: stamps/install.% install
	rm -rf $(D_CROSS)/$(PF)/share/info

	rm -rf $(D_CROSS)/DEBIAN $(D_CROSS)-dbg/DEBIAN

	: # make lintian happy
	$(install_dir) $(D_CROSS)/$(PF)/share/lintian/overrides
	sed 's/@PKG@/$(P_CROSS)/' debian/binutils-cross.overrides \
	  > $(D_CROSS)/$(PF)/share/lintian/overrides/$(P_CROSS)

	: # install maintainer scrtips
	$(install_dir) $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)
	$(install_file)	debian/changelog \
	  $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/changelog.Debian
	$(install_file)	debian/copyright debian/README.cross \
	  $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/
	gzip -9nf $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/changelog.Debian

ifeq ($(with_check),yes)
	: # remove user and date from test-summary for reproducible builds
	sed -i -e '/Test Run By/Id' test-summary-$*
	$(install_file) test-summary-$* \
	  $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/test-summary
	gzip -9nf $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/test-summary
	$(install_dir) $(D_CROSS)/$(PF)/share/doc/$(p_bin)
	ln -sf ../$(P_CROSS)/test-summary.gz \
	  $(D_CROSS)/$(PF)/share/doc/$(p_bin)/test-summary-$*.gz
endif

	for pkg in bfd gas gprof ld; do \
	  ln -sf ../binutils/$$pkg \
	    $(D_CROSS)/$(PF)/share/doc/$(P_CROSS)/$$pkg; \
	done

	$(install_dir) $(D_CROSS)/DEBIAN $(D_CROSS)-dbg/DEBIAN
	if [ "$(is_rc)" = yes ]; then \
	  nver=$$(echo $(DEB_UPSTREAM) | awk -F. '{ OFS="."; NF--; $$NF=$$NF+1; print }'); \
	else \
	  nver=$$(echo $(DEB_UPSTREAM) | awk -F. '{ OFS="."; if (NF > 2) $$NF=$$NF+1; else $$++NF=1; print }'); \
	fi; \
	date_ext=$(DATE_EXT); \
	[ "$(is_rc)" = yes ] && date_ext=; \
	$(install_file) debian/binutils.triggers $(D_CROSS)/DEBIAN/triggers

	rm -f debian/substvars
	dpkg-shlibdeps $(D_CROSS)/$(PF)/bin/*
	dpkg-gencontrol -P$(D_CROSS) -p$(P_CROSS) \
		-VBuilt-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W binutils-source)"
	cd $(D_CROSS) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	dpkg-gencontrol -P$(D_CROSS)-dbg -p$(P_CROSS)-dbg
	cd $(D_CROSS)-dbg && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	chown -R root:root $(D_CROSS) $(D_CROSS)-dbg
	chmod -R go=rX  $(D_CROSS) $(D_CROSS)-dbg
	find $(D_CROSS) $(D_CROSS)-dbg -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(D_CROSS) ..
	dpkg --build $(D_CROSS)-dbg ..

binary-for-host: checkroot
	$(checkdir)

	rm -fr $(d_hst)
	$(install_dir) $(d_hst)/DEBIAN/ $(d_hst)/$(PF)/share/doc/
	ln -sf $(p_com) $(d_hst)/$(PF)/share/doc/$(p_hst)

	rm -f debian/substvars
	$(for_target) dpkg-gencontrol -P$(d_hst) -p$(p_hst) \
		-Vbinutils:native=$(if $(TARGET),$(p_cross),$(p_nat)) \
		-Vbinutils:minver=$(min_ver)

	chown -R root:root $(d_hst)
	chmod -R go=rX $(d_hst)

	find $(d_hst) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_hst) ..

binary-arch: checkroot build install binary-for-host \
    $(if $(filter yes, $(with_cross)),$(foreach ca,$(CROSS_ARCHS), binary.$(ca)))
	$(checkdir)

ifneq ($(BACKPORT),true)
# Process the following only if $(TARGET) is set
ifneq (,$(TARGET))
	test "" != "$(TARGET)"

	rm -rf $(d_cross)/$(PF)/share/info $(d_cross)/$(PF)/share/man

	$(install_dir) $(d_cross)/DEBIAN

	$(install_dir) $(d_cross)/$(PF)/share/doc/$(p_cross)/
	$(install_file)	debian/changelog $(d_cross)/$(PF)/share/doc/$(p_cross)/changelog.Debian
	$(install_file)	debian/copyright debian/README.cross $(d_cross)/$(PF)/share/doc/$(p_cross)/
	gzip -9nf $(d_cross)/$(PF)/share/doc/$(p_cross)/changelog.Debian

	for pkg in bfd gas gprof ld; do \
	  ln -sf ../binutils/$$pkg $(d_cross)/$(PF)/share/doc/$(p_cross)/$$pkg; \
	done

	rm -f debian/substvars
	dpkg-shlibdeps $(d_cross)/$(PF)/bin/*
	dpkg-gencontrol -P$(d_cross) -p$(p_cross) \
		-VBuilt-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W binutils-source)"
	find $(d_cross) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_cross) ..

else
	: # generate some control & helper files
	if [ "$(is_rc)" = yes ]; then \
	  nver=$$(echo $(DEB_UPSTREAM) | awk -F. '{ OFS="."; NF--; $$NF=$$NF+1; print }'); \
	else \
	  nver=$$(echo $(DEB_UPSTREAM) | awk -F. '{ OFS="."; if (NF > 2) $$NF=$$NF+1; else $$++NF=1; print }'); \
	fi; \
	for i in debian/*.in; do \
	    case "$$i" in debian/control.in|debian/control.cross.in) continue; esac; \
	    date_ext=$(DATE_EXT); \
	    case "$$i" in debian/*.shlibs.in) [ "$(is_rc)" = yes ] && date_ext=; esac; \
	    sed -e 's/@VER@/$(VERSION)/g' \
		-e 's/@DEB_VER@/$(DEB_VERSION)/g' \
		-e 's/@DEB_SVER@/$(DEB_SVERSION)/g' \
		-e 's/@DEB_UVER@/$(DEB_UPSTREAM)/g' \
		-e "s/@DEB_NVER@/$$nver/g" \
		-e "s/@DATE_EXT@/$$date_ext/g" \
		-e 's/@DEB_ARCH@/$(DEB_HOST_ARCH)/g' \
		-e 's/@DEB_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' \
		-e 's/@DEB_TRIPLET@/$(DEB_HOST_GNU_TYPE)/g' \
		-e "s/@dpkg_dev@/$(DPKG_DEV)/" \
		$$i > $${i%*.in}; \
	    case "$$i" in *.post*|*.pre*) chmod 755 $${i%*.in}; esac; \
	done

	: # install bug reporting information
	$(install_file) -D debian/$(p_bin).presubj \
		$(d_bin)/$(PF)/share/bug/$(p_bin)/presubj
ifeq ($(with_multiarch),yes)
	$(install_dir) $(d_mul)/$(PF)/share/bug
	ln -sf $(p_bin) $(d_mul)/$(PF)/share/bug/$(p_mul)
endif
ifeq ($(with_hppa64),yes)
	$(install_dir) $(d_hppa64)/$(PF)/share/bug
	ln -sf $(p_bin) $(d_hppa64)/$(PF)/share/bug/$(p_hppa64)
endif

	: # make lintian happy
	$(install_file) -D debian/$(p_com).overrides \
		$(d_com)/$(PF)/share/lintian/overrides/$(p_com)
	$(install_file) -D debian/$(p_lib).overrides \
		$(d_lib)/$(PF)/share/lintian/overrides/$(p_lib)
	$(install_file) -D debian/binutils.overrides \
		$(d_bin)/$(PF)/share/lintian/overrides/$(p_bin)
	$(install_dir) $(d_nat)/$(PF)/share/lintian/overrides
	sed 's/@PKG@/$(p_nat)/' debian/binutils-triplet.overrides \
	  > $(d_nat)/$(PF)/share/lintian/overrides/$(p_nat)
ifeq ($(with_multiarch),yes)
	$(install_file) -D debian/$(p_mul).overrides \
		$(d_mul)/$(PF)/share/lintian/overrides/$(p_mul)
	$(install_file) -D debian/$(p_mdev).overrides \
		$(d_mdev)/$(PF)/share/lintian/overrides/$(p_mdev)
endif
ifeq ($(with_hppa64),yes)
	$(install_file) -D debian/$(p_hppa64).overrides \
		$(d_hppa64)/$(PF)/share/lintian/overrides/$(p_hppa64)
endif

	: # install maintainer scripts
	$(install_dir) $(d_bin)/DEBIAN

	$(install_dir) $(d_lib)/DEBIAN $(d_lib)-dbg/DEBIAN
	$(install_file) debian/binutils.triggers $(d_lib)/DEBIAN/triggers
	$(install_file) debian/libbinutils.shlibs $(d_lib)/DEBIAN/shlibs

	$(install_dir) $(d_com)/DEBIAN

	$(install_dir) $(d_nat)/DEBIAN $(d_nat)-dbg/DEBIAN

	$(install_dir) $(d_dev)/DEBIAN

ifeq ($(with_multiarch),yes)
	$(install_dir) $(d_mul)/DEBIAN $(d_mul)-dbg/DEBIAN
	$(install_script) debian/binutils-multiarch.preinst $(d_mul)/DEBIAN/preinst
	$(install_script) debian/binutils-multiarch.postinst $(d_mul)/DEBIAN/postinst
	$(install_script) debian/binutils-multiarch.prerm $(d_mul)/DEBIAN/prerm
	$(install_script) debian/binutils-multiarch.postrm $(d_mul)/DEBIAN/postrm
	$(install_file) debian/binutils-multiarch.shlibs $(d_mul)/DEBIAN/shlibs
	$(install_file) debian/binutils.triggers $(d_mul)/DEBIAN/triggers
	$(install_dir) $(d_mdev)/DEBIAN
endif

ifeq ($(with_hppa64),yes)
	$(install_dir) $(d_hppa64)/DEBIAN $(d_hppa64)-dbg/DEBIAN
	$(install_file) debian/binutils.triggers $(d_hppa64)/DEBIAN/triggers
endif

	: # install docs
	$(install_dir) $(d_bin)/$(PF)/share/doc/$(p_bin)/
	$(install_file)	debian/changelog $(d_bin)/$(PF)/share/doc/$(p_bin)/changelog.Debian
	$(install_file)	debian/copyright $(d_bin)/$(PF)/share/doc/$(p_bin)/

	$(install_dir) $(d_com)/$(PF)/share/doc/$(p_com)/
	$(install_file) debian/changelog $(d_com)/$(PF)/share/doc/$(p_com)/changelog.Debian
	$(install_file) debian/copyright $(d_com)/$(PF)/share/doc/$(p_com)/

	$(install_dir) $(d_lib)/$(PF)/share/doc/
	ln -sf $(p_com) $(d_lib)/$(PF)/share/doc/$(p_lib)

	$(install_dir) $(d_nat)/$(PF)/share/doc/
	ln -sf $(p_lib) $(d_nat)/$(PF)/share/doc/$(p_nat)

	$(install_dir) $(d_dev)/$(PF)/share/doc/
	ln -sf $(p_bin) $(d_dev)/$(PF)/share/doc/$(p_dev)
ifeq ($(with_multiarch),yes)
	$(install_dir) $(d_mul)/$(PF)/share/doc/
	ln -sf $(p_bin) $(d_mul)/$(PF)/share/doc/$(p_mul)
	$(install_dir) $(d_mdev)/$(PF)/share/doc/
	ln -sf $(p_mul) $(d_mdev)/$(PF)/share/doc/$(p_mdev)
endif
ifeq ($(with_hppa64),yes)
	$(install_dir) $(d_hppa64)/$(PF)/share/doc/
	ln -sf $(p_bin) $(d_hppa64)/$(PF)/share/doc/$(p_hppa64)
endif

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
ifeq ($(with_check),yes)
	: # remove user and date from test-summary for reproducible builds
	sed -i -e '/Test Run By/Id' $(pwd)/test-summary
	$(install_dir) $(d_nat)/$(PF)/share/doc/$(p_bin)
	$(install_file) test-summary \
	  $(d_nat)/$(PF)/share/doc/$(p_bin)/test-summary-$(DEB_HOST_ARCH)
	gzip -9nf \
	  $(d_nat)/$(PF)/share/doc/$(p_bin)/test-summary-$(DEB_HOST_ARCH)
endif
endif
	$(install_dir) $(d_com)/$(PF)/share/doc/$(p_bin)
	$(install_file) binutils/NEWS debian/README.cross \
                        $(d_com)/$(PF)/share/doc/$(p_bin)/

	$(install_file) binutils/ChangeLog $(d_com)/$(PF)/share/doc/$(p_bin)/changelog

	for pkg in bfd gas gprof ld; do \
	  $(install_dir) $(d_com)/$(PF)/share/doc/$(p_bin)/$$pkg; \
	done
	$(install_file) bfd/ChangeLog bfd/PORTING bfd/TODO \
			$(d_com)/$(PF)/share/doc/$(p_bin)/bfd/
	$(install_file) gas/ChangeLog gas/NEWS $(d_com)/$(PF)/share/doc/$(p_bin)/gas/
	$(install_file) gprof/ChangeLog gprof/TODO gprof/TEST \
			$(d_com)/$(PF)/share/doc/$(p_bin)/gprof/
	$(install_file) ld/ChangeLog ld/TODO ld/NEWS \
			$(d_com)/$(PF)/share/doc/$(p_bin)/ld/

	: # These only exist in H. J. Lu releases not GNU ones.
	for dir in binutils bfd gas gprof ld; do \
	  if [ -f $$dir/ChangeLog.linux ]; then \
	    $(install_file) $$dir/ChangeLog.linux $(d_com)/$(PF)/share/doc/$(p_bin)/$$dir/; \
	  fi; \
	done

	: # Copy bbconv.pl to the doc dir for use by interested people
	$(install_file) gprof/bbconv.pl $(d_com)/$(PF)/share/doc/$(p_bin)/gprof/.

	: # Compress stuff that needs it
	gzip -9n $(d_bin)/$(PF)/share/doc/$(p_bin)/changelog.Debian
	find $(d_com)/$(PF)/share/doc/$(p_bin)/ -type f ! -name bbconv.pl | xargs gzip -9n
	gzip -9n $(d_com)/$(PF)/share/doc/$(p_com)/changelog.Debian
	gzip -9n $(d_com)/$(PF)/share/man/man1/*.1

	: # Finish it all up
	dpkg-gencontrol -P$(d_bin) -p$(p_bin) \
		$(CONFLICTS_TARGET_$(DEB_HOST_ARCH)) $(gold_provides) \
		-Vbinutils:native=$(p_nat)
	cd $(d_bin) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	find $(d_lib) -type f | xargs file | grep ELF | cut -d: -f 1 | xargs dpkg-shlibdeps
	dpkg-gencontrol -P$(d_lib) -p$(p_lib)
	cd $(d_lib) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	dpkg-gencontrol -P$(d_lib)-dbg -p$(p_lib)-dbg
	cd $(d_lib)-dbg && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	dpkg-gencontrol -P$(d_com) -p$(p_com)
	cd $(d_com) && find -type f ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	find $(d_nat) -type f | xargs file | grep ELF | cut -d: -f 1 | xargs dpkg-shlibdeps
	dpkg-gencontrol -P$(d_nat) -p$(p_nat) -VextraDepends='libbinutils (= $${binary:Version})'
	cd $(d_nat) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	dpkg-gencontrol -P$(d_nat)-dbg -p$(p_nat)-dbg -VextraDepends='libbinutils (= $${binary:Version})'
	cd $(d_nat)-dbg && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	dpkg-gencontrol -P$(d_dev) -p$(p_dev)
	cd $(d_dev) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

ifeq ($(with_multiarch),yes)
	rm -f debian/substvars
	find $(d_mul) -type f | xargs file | grep ELF | cut -d: -f 1 | xargs dpkg-shlibdeps
	dpkg-gencontrol -P$(d_mul) -p$(p_mul)
	cd $(d_mul) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	dpkg-gencontrol -P$(d_mul)-dbg -p$(p_mul)-dbg
	cd $(d_mul)-dbg && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	mkdir -p $(d_mdev)/DEBIAN
	dpkg-gencontrol -P$(d_mdev) -p$(p_mdev)
	cd $(d_mdev) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs -r md5sum > DEBIAN/md5sums
endif

ifeq ($(with_hppa64),yes)
	rm -f debian/substvars
	find $(d_hppa64) -type f | xargs file | grep ELF | cut -d: -f 1 | xargs dpkg-shlibdeps
	dpkg-gencontrol -P$(d_hppa64) -p$(p_hppa64)
	cd $(d_hppa64) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
	dpkg-gencontrol -P$(d_hppa64)-dbg -p$(p_hppa64)-dbg
	cd $(d_hppa64)-dbg && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | LC_ALL=C sort | xargs md5sum > DEBIAN/md5sums
endif

	chown -R root:root $(d_bin) $(d_com) $(d_lib) $(d_lib)-dbg $(d_nat) $(d_nat)-dbg $(d_dev)
	chmod -R go=rX  $(d_bin) $(d_com) $(d_lib) $(d_lib)-dbg $(d_nat) $(d_nat)-dbg $(d_dev)
	find $(d_bin) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_bin) ..
	find $(d_com) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_com) ..
	find $(d_lib) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_lib) ..
	find $(d_lib)-dbg -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_lib)-dbg ..
	find $(d_nat) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_nat) ..
	find $(d_nat)-dbg -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_nat)-dbg ..
	find $(d_dev) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_dev) ..
ifeq ($(with_multiarch),yes)
	chown -R root:root $(d_mul) $(d_mul)-dbg
	chmod -R go=rX $(d_mul) $(d_mul)-dbg
	find $(d_mul) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_mul) ..
	find $(d_mul)-dbg -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_mul)-dbg ..

	chown -R root:root $(d_mdev)
	chmod -R go=rX  $(d_mdev)
	find $(d_mdev) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_mdev) ..
endif
ifeq ($(with_hppa64),yes)
	chown -R root:root $(d_hppa64)-dbg
	chmod -R go=rX  $(d_hppa64) $(d_hppa64)-dbg
	find $(d_hppa64) -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_hppa64) ..
	find $(d_hppa64)-dbg -depth -newermt '$(BUILD_DATE)' -print0 | \
		xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
	dpkg --build $(d_hppa64)-dbg ..
endif

endif # Process the following only if $(TARGET) is set
endif # ifndef BACKPORT

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

define checkdir
        test -f bfd/elf32.c -a -f debian/rules
endef

#	if which pkg_create_dbgsym >/dev/null 2>&1; then \
#	  pkg_create_dbgsym $1 $2; \
#	fi

ifeq ($(with_strip),yes)
# strip_package: <pkgname> <install-dir> <???>
define strip_package
	$(install_dir) $(strip $2)-dbg/usr/share/doc/
	ln -sf $(strip $1) $(strip $2)-dbg/usr/share/doc/$(strip $1)-dbg
	: # Strip shared libraries and binaries
	set -e; \
	for i in \
	  $(strip $2)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libbfd-*so \
	  $(strip $2)/$(PF)/lib/$(DEB_HOST_MULTIARCH)/libopcodes-*so \
	  $$(file $(strip $2)/$(PF)/bin/* |awk -F: '$$0 !~ /script/ {print $$1}'); \
	do \
	  test ! -h $$i || continue; test -f $$i || continue; \
	  files="$$files $$i"; \
	done; \
	mkdir -p $(strip $2)-dbg/usr/lib/debug/.dwz/$(DEB_HOST_MULTIARCH); \
	dwz=usr/lib/debug/.dwz/$(DEB_HOST_MULTIARCH)/$(strip $1).debug; \
	dwz -m $(strip $2)-dbg/$$dwz -M /$$dwz \
	  $$files; \
	$(CROSS)objcopy --compress-debug-sections $(strip $2)-dbg/$$dwz; \
	for i in $$files; do \
	  b_id=$$(LC_ALL=C $(CROSS)readelf -n $$i | sed -n 's/ *Build ID: *\([0-9a-f][0-9a-f]*\)/\1/p'); \
	  if [ -z "$$b_id" ]; then \
	    id=$$(echo $$i | sed -r 's,debian/[^/]+,$2-dbg/usr/lib/debug,'); \
	    echo strip $$i; \
	    mkdir -p $$(dirname $$id); \
	    $(CROSS)objcopy --only-keep-debug $$i $$id; \
	    chmod 644 $$id; \
	    $(STRIP) $$i; \
	    $(CROSS)objcopy --add-gnu-debuglink $$id $$i; \
	  else \
	    echo "ID: $${b_id} -> $$(echo $$i | sed 's,$(strip $2),,')"; \
	    d=usr/lib/debug/.build-id/$${b_id:0:2}; \
	    f=$${b_id:2}.debug; \
	    mkdir -p $(strip $2)-dbg/$$d; \
	    $(CROSS)objcopy --only-keep-debug --compress-debug-sections $$i $(strip $2)-dbg/$$d/$$f; \
	    chmod 644 $(strip $2)-dbg/$$d/$$f; \
	    $(STRIP) $$i; \
	  fi; \
	done
endef
else
define strip_package
	$(install_dir) $(strip $2)-dbg/usr/share/doc/
	ln -sf $(strip $1) $(strip $2)-dbg/usr/share/doc/$(strip $1)-dbg
endef
endif

remove-gfdl-files:
	rm -rf .git* .cvs* gdb libdecnumber readline sim
ifeq ($(GFDL_INVARIANT_FREE),yes)
	for i in $(gfdl_toplevel_texinfo_files); do \
	  if [ -f $$i ]; then \
	    sed "s/@name@/$$(basename $$i)/g" debian/gfdl.texi > $$i; \
	  fi; \
	done
	rm -f $(gfdl_generated_files)
	rm -f zlib/contrib/dotzlib/DotZLib.chm
endif

# Below here is fairly generic really

binary:         binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot

.PRECIOUS: stamps/configure.% stamps/build.% stamps/install.%