This file is indexed.

/usr/src/binutils/debian/rules is in binutils-source 2.24-5ubuntu3.

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
#!/usr/bin/make -f
# debian/rules file - for binutils (2.20)
# 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-2012 Canonical Ltd.
# Portions Copyright 2008-2013 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

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

p_bin = binutils
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
p_src = $(p_bin)-source
p_static = $(p_bin)-static
p_udeb = $(p_static)-udeb

# 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_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_static = debian/$(p_static)
d_udeb = debian/$(p_udeb)

install_dir    = install -d -m 755
install_file   = install -m 644
install_script = install -m 755
install_binary = install -m 755 -s

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_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

# 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))
  # 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)
else
  DEB_TARGET_MULTIARCH = $(DEB_HOST_MULTIARCH)
  DEB_TARGET_ARCH      = $(DEB_HOST_ARCH)
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

ifneq (,$(filter $(DEB_HOST_ARCH), amd64 armel armhf i386 powerpc powerpcspe ppc64 ppc64el sparc sparc64 x32))
  with_gold = yes
  gold_provides = -Vgold:Provides=binutils-gold
endif

with_multiarch := yes
with_static := yes

CC     = gcc
CXX    = g++
CFLAGS = -g -O2 -Wno-format-security
STRIP  = strip --remove-section=.comment --remove-section=.note
CROSS :=
ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
  CROSS := $(DEB_HOST_GNU_TYPE)-
  CC   = $(CROSS)gcc
  CXX  = $(CROSS)g++
  STRIP= $(CURDIR)/debian/strip.cross
  install_binary = install -m 755 -s --strip-program="$(STRIP)"
endif

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

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

STATIC_UDEB   = $(p_udeb)_$(DEB_VERSION)_$(DEB_HOST_ARCH).udeb

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

DISTRIBUTION := $(shell lsb_release -is)
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 nostat,$(DEB_BUILD_OPTIONS)))
  with_static = disabled in DEB_BUILD_OPTIONS
endif
ifneq (,$(findstring nomult,$(DEB_BUILD_OPTIONS)))
  with_multiarch = 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

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

CONFARGS = \
	--enable-shared \
	--enable-plugins \
	--prefix=/$(PF) \
	--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

ifeq ($(DEB_TARGET_MULTIARCH),x86_64-linux-gnu)
  DEB_TARGET_MULTIARCH32 = i386-linux-gnu
  DEB_TARGET_MULTIARCHX32 = x86_64-linux-gnux32
else ifeq ($(DEB_TARGET_MULTIARCH),x86_64-linux-gnux32)
  DEB_TARGET_MULTIARCH32 = i386-linux-gnu
  DEB_TARGET_MULTIARCH64 = x86_64-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),powerpc64-linux-gnu)
  DEB_TARGET_MULTIARCH32 = powerpc-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),s390x-linux-gnu)
  DEB_TARGET_MULTIARCH32 = s390-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),sparc64-linux-gnu)
  DEB_TARGET_MULTIARCH32 = sparc-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),x86_64-kfreebsd-gnu)
  DEB_TARGET_MULTIARCH32 = i386-kfreebsd-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),i386-linux-gnu)
  DEB_TARGET_MULTIARCH64 = x86_64-linux-gnu
  DEB_TARGET_MULTIARCHX32 = x86_64-linux-gnux32
else ifeq ($(DEB_TARGET_MULTIARCH),powerpc-linux-gnu)
  DEB_TARGET_MULTIARCH64 = powerpc64-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),sparc-linux-gnu)
  DEB_TARGET_MULTIARCH64 = sparc64-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),s390-linux-gnu)
  DEB_TARGET_MULTIARCH64 = s390x-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),i386-kfreebsd-gnu)
  DEB_TARGET_MULTIARCH64 = x86_64-kfreebsd-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),mips-linux-gnu)
  DEB_TARGET_MULTIARCH64 = mips64-linux-gnuabi64
  DEB_TARGET_MULTIARCHN32 = mips64-linux-gnuabin32
else ifeq ($(DEB_TARGET_MULTIARCH),mipsel-linux-gnu)
  DEB_TARGET_MULTIARCH64 = mips64el-linux-gnuabi64
  DEB_TARGET_MULTIARCHN32 = mips64el-linux-gnuabin32
else ifeq ($(DEB_TARGET_MULTIARCH),mips64-linux-gnuabin32)
  DEB_TARGET_MULTIARCH64 = mips64-linux-gnuabi64
  DEB_TARGET_MULTIARCH32 = mips-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),mips64el-linux-gnuabin32)
  DEB_TARGET_MULTIARCH64 = mips64el-linux-gnuabi64
  DEB_TARGET_MULTIARCH32 = mipsel-linux-gnu
else ifeq ($(DEB_TARGET_MULTIARCH),mips64-linux-gnuabi64)
  DEB_TARGET_MULTIARCH32 = mips-linux-gnu
  DEB_TARGET_MULTIARCHN32 = mips64-linux-gnuabin32
else ifeq ($(DEB_TARGET_MULTIARCH),mips64el-linux-gnuabi64)
  DEB_TARGET_MULTIARCH32 = mipsel-linux-gnu
  DEB_TARGET_MULTIARCHN32 = mips64el-linux-gnuabin32
endif
export DEB_TARGET_MULTIARCH DEB_TARGET_MULTIARCH32 DEB_TARGET_MULTIARCH64
export DEB_TARGET_MULTIARCHX32 DEB_TARGET_MULTIARCHN32

ifeq ($(DEB_TARGET_ARCH),sparc)
	CONFARGS += --enable-targets=sparc64-linux-gnu
	CONFLICTS = -VextraConflicts="libc6-dev-sparc64 (<< 2.2.5-7)"
endif
ifeq ($(DEB_TARGET_ARCH),sparc64)
	CONFARGS += --enable-targets=sparc-linux-gnu
	CONFLICTS = -VextraConflicts="libc6-dev-sparc64 (<< 2.2.5-7)"
endif
ifeq ($(DEB_TARGET_ARCH),powerpc)
	CONFARGS += --enable-targets=powerpc64-linux-gnu,spu
endif
ifeq ($(DEB_TARGET_ARCH),ppc64)
	CONFARGS += --enable-targets=powerpc-linux-gnu,spu
endif
ifeq ($(DEB_TARGET_ARCH),s390)
	CONFARGS += --enable-targets=s390x-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),s390x)
	CONFARGS += --enable-targets=s390-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),amd64)
	CONFARGS += --enable-targets=x86_64-linux-gnux32,x86_64-pep
endif
ifeq ($(DEB_TARGET_ARCH),i386)
	CONFARGS += --enable-targets=x86_64-linux-gnu,x86_64-linux-gnux32,x86_64-pep
endif
ifeq ($(DEB_TARGET_ARCH),x32)
	CONFARGS += --enable-targets=x86_64-linux-gnu,x86_64-pep
endif
ifneq (,$(filter $(DEB_TARGET_ARCH),amd64 i386 x32))
	CONFLICTS = -VextraConflicts="binutils-mingw-w64-i686 (<< 2.23.52.20130612-1+3), binutils-mingw-w64-x86-64 (<< 2.23.52.20130612-1+3)"
endif
ifeq ($(DEB_TARGET_ARCH),kfreebsd-i386)
	CONFARGS += --enable-targets=x86_64-kfreebsd-gnu
endif
ifeq ($(DEB_TARGET_ARCH),mips)
       CONFARGS += --enable-targets=mips64-linux-gnuabi64,mips64-linux-gnuabin32
endif
ifeq ($(DEB_TARGET_ARCH),mipsel)
       CONFARGS += --enable-targets=mips64el-linux-gnuabi64,mips64el-linux-gnuabin32
endif
ifeq ($(DEB_TARGET_ARCH),mipsn32)
       CONFARGS += --enable-targets=mips64-linux-gnuabi64,mips-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),mipsn32el)
       CONFARGS += --enable-targets=mips64el-linux-gnuabi64,mipsel-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),mips64)
       CONFARGS += --enable-targets=mips64-linux-gnuabin32,mips-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),mips64el)
       CONFARGS += --enable-targets=mips64el-linux-gnuabin32,mipsel-linux-gnu
endif
ifeq ($(DEB_TARGET_ARCH),aarch64)
       CONFARGS += --enable-targets=aarch64_be-linux-gnu
endif

with_check := yes
ifneq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	with_check := disabled through DEB_BUILD_OPTIONS
endif
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)
#ifneq (,$(filter $(DEB_HOST_ARCH),mips mipsel))
#      with_check := disabled for architecture $(DEB_HOST_ARCH)
#endif

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 %-stamp .pc CVS debian builddir-% test-summary, $(wildcard *)))

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

#################
# patch targets #
#################

patch: patch-stamp
patch-stamp:
ifneq ($(PATCHED_SOURCES),yes)
	QUILT_PATCHES=$(CURDIR)/debian/patches \
	  quilt --quiltrc /dev/null push -a || test $$? = 2
endif
	touch $@

unpatch:
	QUILT_PATCHES=$(CURDIR)/debian/patches \
	  quilt --quiltrc /dev/null pop -a -R || test $$? = 2
	rm -rf .pc

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: unpatch
	$(checkdir)
	-rm -fr builddir-multi builddir-single builddir-hppa64
	-find . -name \*.gmo -o -name \*~ -o -name \*.info ! -name sysroff.info | xargs rm -f
	-rm -f $(pwd)/test-summary*
	-rm -fr $(d_bin) $(d_dev) $(d_mul) $(d_mdev) $(d_doc) $(d_hppa64) $(d_src)
	-rm -fr builddir-static
	-rm -fr $(d_static) $(d_udeb)
	-rm -rf debian/patched debian/tmp debian/files* debian/substvars
	-rm -f debian/*.orig debian/*.rej
	-rm -rf $(d_cross) debian/files debian/substvars 
	-rm -rf builddir-$(TARGET) {configure,build,install}-cross-stamp
	for i in debian/*.in; do \
	    case "$$i" in debian/control*.in) continue; esac; \
	    rm -f $${i%*.in}; \
	done

	-rm -f *-stamp

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

control-stamp: debian/control.in $(if $(TARGET),debian/control.cross.in)
ifneq (,$(TARGET))
	sed "/^$$/ q" < debian/control.in > debian/control
	sed -e "s/__TARGET__/$$(echo -n $(TARGET) | sed s/_/-/g)/" \
                 < debian/control.cross.in >> debian/control
else
	cp debian/control.in debian/control
endif
ifneq (,$(CROSS))
	sed -e "s/__TARGET__/$$(echo -n $(CROSS) | sed s/_/-/g)/" \
		< debian/strip.cross.in >> debian/strip.cross
	chmod 755 debian/strip.cross
endif
	touch $@

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

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

configure-single-stamp: patch-stamp control-stamp
	$(checkdir)

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

	rm -rf configure-single-stamp \
		builddir-single
	mkdir builddir-single
	cd builddir-single && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" \
		../configure --with-sysroot=/ $(SINGLE_CONFARGS)
	$(MAKE) -C builddir-single configure-host
	touch configure-single-stamp

build-single-stamp: configure-single-stamp
	$(checkdir)
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	    $(MAKE) -C builddir-single/bfd headers
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	    $(MAKE) $(NJOBS) -C builddir-single
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
ifeq ($(with_check),yes)
	-env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	    $(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; \
	if [ ! -f /usr/share/doc/binutils/test-summary.gz ]; then \
	  echo "No test results available for the installed binutils version"; \
	elif [ -x /usr/bin/python ]; then \
	  echo "Test results, compared with installed binutils:"; \
	  zcat /usr/share/doc/binutils/test-summary.gz > test-summary-installed; \
	  if python debian/test-suite-compare.py test-summary-installed test-summary; then \
	    : ; \
	  elif [ -n "$(ignore_regressions)" ]; then \
	    echo "$(ignore_regressions)"; \
	  else \
	    case "$(DEB_HOST_ARCH)" in \
	      powerpc) \
		echo "WARNING: ignoring test results";; \
	      *) \
		false;; \
	    esac; \
	  fi; \
	else \
	  echo "python not installed, not comparing test results."; \
	fi
endif
endif
	touch build-single-stamp


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

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

# strictly speaking this is incorrect as the first column of this file should
# be ignored, but it's not obvious how to compute a proper list of triplets
# which Debian cares about since this table only lists official ports and the
# other tables combined give too many ports and generate triplets which break
# the binutils build; also, it's not possible to use --enable-targets=all
# either; see:
# http://lists.debian.org/debian-dpkg/2011/02/msg00085.html
multiarch_targets := $(shell sed -n 's/^\([^[:space:]\#]\+\).*/\1/p' /usr/share/dpkg/archtable)

# some extra targets which were present in earlier versions of the
# multiarch_targets list; would be good to find out who needs them for what
multiarch_targets += \
	aarch64-linux-gnu \
	aarch64_be-linux-gnu \
	alpha-linux-gnu \
	arm-linux-gnueabi \
	i686-linux-gnu \
	m32r-linux-gnu \
	m68k-linux-gnu \
	m68k-rtems \
	powerpc-linux-gnu \
	powerpc64-linux-gnu \
	powerpc64le-linux-gnu \
	s390x-linux-gnu \
	sh-linux-gnu \
	sh64-linux-gnu \
	sparc-linux-gnu \
	sparc64-linux-gnu \
	x86_64-linux-gnu \
	x86_64-linux-gnux32 \
	spu \
	x86_64-pep

configure-multi-stamp: patch-stamp
	$(checkdir)
	rm -rf configure-multi-stamp \
		builddir-multi
	mkdir builddir-multi
	cd builddir-multi \
	    && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" ../configure $(CONFARGS) \
		--with-sysroot=/ \
		--enable-targets=$(subst $(SPACE),$(COMMA),$(multiarch_targets))
	$(MAKE) -C builddir-multi configure-host
	touch configure-multi-stamp

build-multi-stamp: configure-multi-stamp
	$(checkdir)
	$(MAKE) -C builddir-multi/bfd headers
	env MAKE="$(MAKE) VERSION=$(MULTI_VERSION)" \
	  $(MAKE) $(NJOBS) -C builddir-multi
	touch build-multi-stamp

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

#################
# static target #
#################

configure-static-stamp: patch-stamp
	$(checkdir)
	rm -rf configure-static-stamp \
		builddir-static
	mkdir builddir-static
	cd builddir-static \
	    && env CC="$(CC)" CXX="$(CXX)" CFLAGS="-g0 -Os" ../configure \
		$(filter-out --enable-shared --enable-plugins --enable-targets=%, $(CONFARGS))
	$(MAKE) -C builddir-static configure-bfd
	$(MAKE) -C builddir-static configure-ld
	touch configure-static-stamp

build-static-stamp: configure-static-stamp
	$(checkdir)
	$(MAKE) $(NJOBS) -C builddir-static/libiberty CCLD='$(CC) -all-static'
	$(MAKE) $(NJOBS) -C builddir-static/bfd CCLD='$(CC) -all-static'
	$(MAKE) $(NJOBS) -C builddir-static/ld CCLD='$(CC) -all-static'
	touch build-static-stamp

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

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

configure-hppa64-stamp: patch-stamp
	$(checkdir)
	rm -rf configure-hppa64-stamp \
		builddir-hppa64
	mkdir builddir-hppa64
	cd builddir-hppa64 \
	    && env CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" ../configure \
		$(CONFARGS) \
		--target=hppa64-linux-gnu
	$(MAKE) -C builddir-hppa64 configure-host
	touch configure-hppa64-stamp

build-hppa64-stamp: configure-hppa64-stamp
	$(checkdir)
	$(MAKE) -C builddir-hppa64/bfd headers
	env MAKE="$(MAKE) VERSION=$(HPPA64_VERSION)" \
	  $(MAKE) $(NJOBS) -C builddir-hppa64
	touch build-hppa64-stamp

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

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

build_stamps = build-single-stamp
ifeq ($(with_multiarch),yes)
       build_stamps += build-multi-stamp
endif
ifeq ($(DEB_HOST_ARCH),hppa)
       build_stamps += build-hppa64-stamp
endif
ifneq (,$(TARGET))
  ifneq (,$(findstring static-cross,$(DEB_BUILD_OPTIONS)))
       build_stamps = build-static-cross-stamp
  else
       build_stamps = build-cross-stamp
  endif
endif

ifeq ($(BACKPORT),true)
    build_stamps :=
    with_check := no
endif

build: pre-build build-stamp
build-arch: pre-build build-stamp
build-indep: pre-build build-stamp
build-stamp: $(build_stamps)
	touch build-stamp

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

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

install_stamps = install-stamp
ifeq ($(DEB_HOST_ARCH),hppa)
       install_stamps += install-hppa64-stamp
endif
ifeq ($(with_static),yes)
       install_stamps += install-static-stamp
endif
ifneq (,$(TARGET))
  ifneq (,$(findstring static-cross,$(DEB_BUILD_OPTIONS)))
        install_stamps = install-static-cross-stamp
  else
        install_stamps = install-cross-stamp
  endif
endif
ifeq ($(BACKPORT),true)
    install_stamps :=
endif
install: $(install_stamps)
install-stamp: checkroot build-stamp
	$(checkdir)

	rm -fr $(d_bin) $(d_dev) $(d_mul) $(d_mdev) $(d_doc) $(d_src)
	$(install_dir) $(d_bin) $(d_dev) $(d_mul) $(d_mdev) $(d_doc) $(d_src)

	: # install binutils and -dev stuff
	env MAKE="$(MAKE) VERSION=$(SINGLE_VERSION)" \
	  $(MAKE) -C builddir-single \
		CFLAGS="$(CFLAGS)" prefix=$(pwd)/$(d_bin)/$(PF) \
		mandir=$(pwd)/$(d_bin)/$(PF)/share/man \
		infodir=$(pwd)/$(d_doc)/$(PF)/share/info install

ifeq ($(with_multiarch),yes)
	: # now install binutils-multiarch stuff
	env MAKE="$(MAKE) VERSION=$(MULTI_VERSION)" \
          $(MAKE) -C builddir-multi \
		CFLAGS="$(CFLAGS)" \
		prefix=$(pwd)/$(d_mul)/$(PF) \
		mandir=$(pwd)/$(d_mul)/$(PF)/share/man \
		infodir=$(pwd)/$(d_doc)/$(PF)/share/info 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_bin)/$(PF)/man/man1/configure.1
	rm -f $(d_doc)/$(PF)/share/info/configure.* $(d_doc)/$(PF)/share/info/standards.*
	: # *sigh*, bugs.debian.org/213524
	rm -f $(d_doc)/$(PF)/share/info/dir*

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
	rm -fr $(d_mul)/$(PF)/lib/ldscripts

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

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

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

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

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

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

	: # Remove windres manpages
	rm -f $(d_bin)/$(PF)/share/man/man1/windres.1

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

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

	: # Provide $(DEB_HOST_GNU_TYPE)- prefixed binaries
	for i in \
	  addr2line ar as c++filt elfedit gprof ld ld.bfd \
	  $(if $(with_gold),ld.gold dwp) \
	  nm objcopy objdump ranlib readelf size strings strip; \
	do \
	  ln -sf $$i $(d_bin)/usr/bin/$(DEB_HOST_GNU_TYPE)-$$i; \
	  ln -sf $$i.1.gz $(d_bin)/usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-$$i.1.gz; \
	done

	touch install-stamp

install-hppa64-stamp: checkroot build-hppa64-stamp
	$(checkdir)

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

	: # install binutils-hppa64 stuff
	env MAKE="$(MAKE) VERSION=$(HPPA64_VERSION)" \
          $(MAKE) -C builddir-hppa64 \
		CFLAGS="$(CFLAGS)" \
		prefix=$(pwd)/$(d_hppa64)/$(PF)/ \
		mandir=$(pwd)/$(d_hppa64)/$(PF)/share/man \
		infodir=$(pwd)/$(d_hppa64)/$(PF)/share/info 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/.

	: # 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

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

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

	touch install-hppa64-stamp

install-static-stamp: checkroot build-static-stamp
	$(checkdir)

	rm -fr $(d_static) $(d_udeb)
	$(install_dir) $(d_static) $(d_udeb)

	: # Copy static ld-new into /bin for both -static and -static-udeb
	$(install_dir) $(d_static)/bin
	$(install_binary) builddir-static/ld/ld-new $(d_static)/bin/ld_static
	$(install_dir) $(d_udeb)/bin
	$(install_binary) builddir-static/ld/ld-new $(d_udeb)/bin/ld_static
ifeq ($(with_strip),yes)
	pkg_create_dbgsym $(p_static) $(d_static) || true
	$(STRIP) --strip-unneeded $(d_static)/bin/ld_static $(d_udeb)/bin/ld_static
endif

	touch install-static-stamp

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

#######################
# 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)//usr/share/info/bfd.info*
	rm -f $(d_doc)//usr/share/info/bfdint.info*
	rm -f $(d_doc)//usr/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 -9
	gzip -9 $(d_doc)/$(PF)/share/info/*

	dpkg-gencontrol -isp -P$(d_doc) -p$(p_doc)
	chown -R root:root $(d_doc)
	chmod -R go=rX  $(d_doc)
	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 -9
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/
	tar -c --xz -C .. --exclude=CVS \
		-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/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 -isp -P$(d_src) -p$(p_src)
	chown -R root:root $(d_src)
	chmod -R go=rX  $(d_src)
	dpkg --build $(d_src) ..

endif

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

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

binary-arch: checkroot build install
	$(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 -9f $(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 -isp -P$(d_cross) -p$(p_cross) \
		-VBuilt-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W binutils-source)"
	dpkg --build $(d_cross) ..

else
	: # generate some control & helper files
	nver=$$(echo $(DEB_UPSTREAM) | awk -F. '{ OFS="."; $$NF=$$NF+1; print }'); \
	for i in debian/*.in; do \
	    case "$$i" in debian/control.cross.in) continue; 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' \
		$$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 ($(DEB_HOST_ARCH),hppa)
	$(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_bin).overrides \
		$(d_bin)/$(PF)/share/lintian/overrides/$(p_bin)
ifeq ($(with_multiarch),yes)
	$(install_file) -D debian/$(p_mul).overrides \
		$(d_mul)/$(PF)/share/lintian/overrides/$(p_mul)
endif
ifeq ($(with_static),yes)
	$(install_file) -D debian/$(p_static).overrides \
		$(d_static)/$(PF)/share/lintian/overrides/$(p_static)
	$(install_file) -D debian/$(p_udeb).overrides \
		$(d_udeb)/$(PF)/share/lintian/overrides/$(p_udeb)
endif
ifeq ($(DEB_HOST_ARCH),hppa)
	$(install_file) -D debian/$(p_hppa64).overrides \
		$(d_hppa64)/$(PF)/share/lintian/overrides/$(p_hppa64)
endif

	: # install maintainer scrtips
	$(install_dir) $(d_bin)/DEBIAN
	$(install_script) debian/binutils.postinst $(d_bin)/DEBIAN/postinst
	$(install_script) debian/binutils.postrm $(d_bin)/DEBIAN/postrm
	$(install_file) debian/binutils.shlibs $(d_bin)/DEBIAN/shlibs

	$(install_dir) $(d_dev)/DEBIAN

ifeq ($(with_multiarch),yes)
	$(install_dir) $(d_mul)/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
endif

ifeq ($(with_static),yes)
	$(install_dir) $(d_static)/DEBIAN
	$(install_script) debian/binutils-static.preinst $(d_static)/DEBIAN/preinst
	$(install_dir) $(d_udeb)/DEBIAN
endif

ifeq ($(DEB_HOST_ARCH),hppa)
	$(install_dir) $(d_hppa64)/DEBIAN
	$(install_script) debian/binutils-hppa64.postinst $(d_hppa64)/DEBIAN/postinst
	$(install_script) debian/binutils-hppa64.postrm $(d_hppa64)/DEBIAN/postrm
	$(install_file) debian/binutils-hppa64.shlibs $(d_hppa64)/DEBIAN/shlibs
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)/

ifeq ($(with_static),yes)
	$(install_dir) $(d_static)/$(PF)/share/doc/$(p_static)/
	$(install_file)	debian/changelog $(d_static)/$(PF)/share/doc/$(p_static)/changelog.Debian
	$(install_file)	debian/copyright $(d_static)/$(PF)/share/doc/$(p_static)/
endif

	$(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 ($(DEB_HOST_ARCH),hppa)
	$(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)
	$(install_file) $(pwd)/test-summary $(d_bin)/$(PF)/share/doc/$(p_bin)/
endif
endif
	$(install_file) binutils/NEWS debian/README.cross \
                        $(d_bin)/$(PF)/share/doc/$(p_bin)/

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

	for pkg in bfd gas gprof ld; do \
	  $(install_dir) $(d_bin)/$(PF)/share/doc/$(p_bin)/$$pkg; \
	done
	$(install_file) bfd/ChangeLog bfd/PORTING bfd/TODO \
			$(d_bin)/$(PF)/share/doc/$(p_bin)/bfd/
	$(install_file) gas/ChangeLog gas/NEWS $(d_bin)/$(PF)/share/doc/$(p_bin)/gas/
	$(install_file) gprof/ChangeLog gprof/TODO gprof/TEST \
			$(d_bin)/$(PF)/share/doc/$(p_bin)/gprof/
	$(install_file) ld/ChangeLog ld/TODO ld/NEWS \
			$(d_bin)/$(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_bin)/$(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_bin)/$(PF)/share/doc/$(p_bin)/gprof/.

	: # Compress stuff that needs it
	gzip -9 $(d_bin)/$(PF)/share/man/man1/*.1
	find $(d_bin)/$(PF)/share/doc/$(p_bin)/ -type f ! -name copyright -a ! -name bbconv.pl | xargs gzip -9
ifeq ($(with_static),yes)
	find $(d_static)/$(PF)/share/doc/$(p_static)/ -type f ! -name copyright | xargs gzip -9
endif

	: # Finish it all up
	find $(d_bin) -type f | xargs file | grep ELF | cut -d: -f 1 | xargs dpkg-shlibdeps
	dpkg-gencontrol -isp -P$(d_bin) -p$(p_bin) $(CONFLICTS) $(gold_provides)
	cd $(d_bin) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | xargs md5sum > DEBIAN/md5sums

	rm -f debian/substvars
	dpkg-gencontrol -isp -P$(d_dev) -p$(p_dev)
	cd $(d_dev) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | 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 -isp -P$(d_mul) -p$(p_mul)
	cd $(d_mul) && find -type f  ! -regex './DEBIAN/.*' -printf '%P\n' | xargs md5sum > DEBIAN/md5sums

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

ifeq ($(with_static),yes)
	dpkg-gencontrol -isp -P$(d_static) -p$(p_static)
	dpkg-gencontrol -isp -P$(d_udeb) -p$(p_udeb) -fdebian/files~
	dpkg-distaddfile $(STATIC_UDEB) debian-installer optional
endif

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

	chown -R root:root $(d_bin) $(d_dev)
	chmod -R go=rX  $(d_bin) $(d_dev)
	dpkg --build $(d_bin) ..
	dpkg --build $(d_dev) ..
ifeq ($(with_multiarch),yes)
	chown -R root:root $(d_mul)
	chmod -R go=rX  $(d_mul)
	dpkg --build $(d_mul) ..

	chown -R root:root $(d_mdev)
	chmod -R go=rX  $(d_mdev)
	dpkg --build $(d_mdev) ..
endif
ifeq ($(with_static),yes)
	chown -R root:root $(d_static) $(d_udeb)
	chmod -R go=rX  $(d_static) $(d_udeb)
	dpkg --build $(d_static) ..
	dpkg --build $(d_udeb) ../$(STATIC_UDEB)
endif
ifeq ($(DEB_HOST_ARCH),hppa)
	chown -R root:root $(d_hppa64)
	chmod -R go=rX  $(d_hppa64)
	dpkg --build $(d_hppa64) ..
endif

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

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

# Process the following only if $(TARGET) is set
ifneq (,$(TARGET))

p_cross = $(subst _,-,binutils-$(TARGET))
d_cross = debian/$(p_cross)

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

ifneq ($(with_sysroot),)
  CONFARGS += --with-sysroot=$(with_sysroot)
endif
ifneq ($(with_build_sysroot),)
  CONFARGS += --with-build-sysroot=$(with_build_sysroot)
endif
ifeq ($(with_gold),yes)
  CONFARGS += --enable-ld=default --enable-gold
endif

configure-cross-stamp: patch-stamp control-stamp
	$(checkdir)
	test "" != "$(TARGET)"
	rm -rf configure-cross-stamp builddir-$(TARGET)
	mkdir builddir-$(TARGET)
	cd builddir-$(TARGET) \
	    && env CC="$(CC)" CXX="$(CXX)" ../configure \
		$(CONFARGS) \
		--target=$(TARGET)
	touch $@

build-cross-stamp: configure-cross-stamp
	$(checkdir)
	test "" != "$(TARGET)"
	$(MAKE) -C builddir-$(TARGET) $(NJOBS) CFLAGS="$(CFLAGS)"
	touch $@

install-cross-stamp: build-cross-stamp
	$(checkdir)
	test "" != "$(TARGET)"
	rm -rf $(d_cross)
	$(MAKE) -C builddir-$(TARGET) prefix=$(pwd)/$(d_cross)/$(PF) \
		mandir=$(pwd)/$(d_cross)/$(PF)/share/man install
	rm -rf $(d_cross)/$(PF)/lib* $(d_cross)/$(PF)/info $(d_cross)/$(PF)/share/locale

	$(call strip_package, $(p_cross), $(d_cross),$(DEB_HOST_GNU_TYPE)/$(TARGET))
	chmod ugo-x $(d_cross)/$(PF)/$(DEB_HOST_GNU_TYPE)/$(TARGET)/lib/*.so

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

	gzip -9 $(d_cross)/$(PF)/share/man/man1/*
	touch $@

configure-host-cross-stamp: configure-cross-stamp
	$(checkdir)
	test "" != "$(TARGET)"
	$(MAKE) configure-host -C builddir-$(TARGET) $(NJOBS) CFLAGS="$(CFLAGS)"
	touch $@

build-static-cross-stamp: configure-host-cross-stamp
	$(checkdir)
	test "" != "$(TARGET)"
	$(MAKE) -C builddir-$(TARGET) $(NJOBS) CFLAGS="$(CFLAGS)" LDFLAGS="-all-static"
	touch $@

install-static-cross-stamp: build-static-cross-stamp install-cross-stamp

binary-cross: 
	@echo "Please use dpkg-buildpackage instead of calling binary-cross directly; see README.cross"
	@false

endif # ifneq ($(TARGET),)

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

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

ifeq ($(with_strip),yes)
define strip_package
	: # Strip shared libraries
	if which pkg_create_dbgsym >/dev/null 2>&1; then \
	  pkg_create_dbgsym $1 $2; \
	fi
	$(STRIP) --strip-unneeded $2/$(PF)/$3/lib/libbfd-*so
	$(STRIP) --strip-unneeded $2/$(PF)/$3/lib/libopcodes-*so
	$(STRIP) $$(file $2/$(PF)/bin/* |awk -F: '$$0 !~ /script/ {print $$1}')
endef
else
define strip_package
endef
endif

remove-gfdl-files:
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)
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