File: rules

package info (click to toggle)
egcs 1.1.2-0slink2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 80,844 kB
  • ctags: 90,426
  • sloc: ansic: 675,911; cpp: 103,606; sh: 26,374; pascal: 22,878; yacc: 13,856; asm: 10,896; makefile: 8,137; lisp: 7,252; exp: 3,490; fortran: 1,519; sed: 587; objc: 482; awk: 223; csh: 106; ml: 94; perl: 18
file content (1262 lines) | stat: -rwxr-xr-x 38,994 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
#! /usr/bin/make -f
# -*- mode: makefile -*-
# Build rules for egcs (1.1) and egcs-snapshot (incompatible with egcs 1.0.3)
# Based heavily on Ian Jackson's sample rules file for GNU hello
# Copyright 1994,1995 by Ian Jackson.
# 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.)
#
# Rewritten to use debhelper by Matthias Klose.
# Thouroughly pounded on in post-1.1 by Daniel Jacobowitz.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
DH_VERSION=1.1.24

# the recipient for the test summaries. Send with: debian/rules mail-summary
S_EMAIL = egcs@packages.debian.org egcs-testresults@egcs.cygnus.com

# Just in case...
SHELL = bash -e

# The name of the source package
PKGSOURCE := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2; exit 0}')

#CPPFLAGS	= -DDEBIAN
CFLAGS		= $(CPPFLAGS)
CC		= cc $(CPPFLAGS)
LDFLAGS		= -s
BOOT_CFLAGS	= -g -O2 $(CPPFLAGS)

ARCH := $(strip $(shell dpkg --print-gnu-build-architecture))
GNUARCH = $(ARCH)-linux
SECONDARY-ARCH = $(findstring $(ARCH),m68k sparc)
SECONDARY-ARCH = $(findstring $(ARCH),m68k i486 sparc)
GLIBC20_ARCH = $(findstring $(ARCH),alpha i486 m68k)
# for slink versions of this package, set RELEASE to slink
RELEASE=slink

ifneq ($(RELEASE),slink)
  ifeq ($(ARCH),i486)
    FIRST_PRIMARY:=2.91.63-1.1
  endif
endif

ifeq ($(ARCH),$(SECONDARY-ARCH))
  gcc_name = egcc
else
  gcc_name = gcc
endif

# ARM port fails if built with optimization.
ifeq ($(ARCH),arm)
  BOOT_CFLAGS = -g $(CPPFLAGS)
endif

# There are three classes of packages this can build: gcc, gcc-ss, and
# gcc-snap-main are the types.  These are SNAPSHOT=no, yes, and fake
# respectively.  gcc-snap-main produces a package named gcc, but of a
# snapshot version.
# This is all controlled by the environment variable BUILDFAKE=yes

ifeq ($(PKGSOURCE),egcs)
 SNAPSHOT = no
else
 ifneq ($(BUILDFAKE),yes)
  SNAPSHOT=yes
 else
  SNAPSHOT=fake
 endif
endif

# The version number can be found in gcc/version.c e.g.
# char *version_string = "egcs-2.90.28 980423 (egcs-1.0.3 prerelease)";
VER := $(strip $(shell grep version_string gcc/version.c \
			| sed -e 's/^.*"egcs-/egcs-/' -e 's/ .*$$//'))
# The numeric part of the egcs version number
VERNO := $(strip $(shell echo $(VER) | sed -e 's/egcs-//'))
NEXTVERNO := $(shell echo $(VERNO) | awk -F. '{OFS="."; $$NF = $$NF + 1; print}')
# The major egcs version number (1.x); this must work for snapshots too!
EGCSVERNO := $(shell echo $(VERNO) | awk -F. ' \
		BEGIN { ev[291]="1.1"; ev[292]="1.2"; ev[293]="1.2"} \
		{print ev[$$1$$2]}')
PWD := $(shell pwd)
# The base version number for the egcs packages.
DPKGVER := $(VERNO)-$(shell dpkg-parsechangelog \
				| awk -F- '/^Version:/ {print $$NF}')
# The binutils version needed.
# The oldest suitable versions for the various platforms can be found in
# INSTALL/specific.html ; we take a tighter dependency if possible to be on
# the safe side (something like newest( version in stable, versions for the
# various platforms in INSTALL/specific.html) ).
BINUTILSV = 2.9.1

# Look for libg++ and librx
with_libgpp := $(strip $(shell if [ -d libg++ ]; \
			then echo yes; else echo no; fi))

# Is this system using glibc 2.1?
libc_version := $(shell ls -1 /lib/libc-*.so | sed -e 's|/.*-||' -e 's|\.so||')

glibc21 = $(shell if dpkg --compare-versions $(libc_version) ge 2.0.90; \
	      then echo yes; else echo no; fi)

# Library versions and names
lib_version := $(strip \
		$(shell awk -F= '/^VERSION/ {print $$NF}' libstdc++/Makefile.in))
SONAME	    := $(shell echo $(lib_version) | sed -e 's/\.[0-9]$$//')

ifeq ($(with_libgpp),yes)
lgp_version := $(strip \
		$(shell awk -F= '/^VERSION/ {print $$NF}' libg++/Makefile.in))
# package name has to be different than libg++2.8
#LGPSONAME   := $(shell echo $(lgp_version) | sed -e 's/\.[0-9]$$//')
LGPSONAME   = $(lgp_version)
endif

# Is the libapi patch installed?
libapi_patch := $(shell if [ -f config.if ]; then echo yes; else echo no; fi)
ifeq ($(libapi_patch),yes)
  if_config := $(shell topsrcdir=$(PWD); target_os=linux-gnu; \
        target=$(ARCH)-debian-linux-gnu; . config.if; \
	echo $$libstdcxx_interface $$cxx_interface $$libc_interface)
  LIBSTDCXX_IF	:= $(word 1, $(if_config))
  CXX_IF	:= $(word 2, $(if_config))
  LIBC_IF	:= $(word 3, $(if_config))
  cxx_inc_dir   = g++-$(LIBSTDCXX_IF)
  lib_arlib	= libstdc++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lib_version).a
  lib_marlink	= libstdc++$(LIBC_IF)$(CXX_IF).a.$(LIBSTDCXX_IF)
  lib_shlib	= libstdc++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lib_version).so
  lib_mshlink	= libstdc++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF)
ifeq ($(glibc21),yes)
  ifneq ($(ARCH),$(GLIBC20_ARCH))
    lib_compatlink= libstdc++.so.$(SONAME)
    lgp_compatlink= libg++.so.$(LGPSONAME)
  endif
else
  lib_compatlink= libstdc++.so.$(SONAME)
  lgp_compatlink= libg++.so.$(LGPSONAME)
endif
  lgp_arlib	= libg++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lgp_version).a
  lgp_marlink	= libg++$(LIBC_IF)$(CXX_IF).a.$(LIBSTDCXX_IF)
  lgp_shlib	= libg++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lgp_version).so
  lgp_mshlink	= libg++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF)
  # lib_linkdir is the directory for the lib{stdc,g}++.{a,so} links
  lib_linkdir	= lib/gcc-lib/$(GNUARCH)/$(VER)
else
  cxx_inc_dir   = g++
  lib_shlib	= libstdc++.so.$(lib_version)
  lib_mshlink	= libstdc++.so.$(SONAME)
  lgp_shlib	= libg++.so.$(lgp_version)
  lgp_mshlink	= libg++.so.$(LGPSONAME)
  lib_linkdir	= lib
endif
# PF is the installation prefix for the package without the leading slash.
# It's "usr" for egcs releases; egcs snapshots go elsewhere.
ifneq ($(SNAPSHOT),yes)
  PF = usr
else
  PF = usr/lib/egcs-ss
endif
# the locations of libf2c.a and f2c.h; /usr/lib and /usr/include, not gcc-lib
F2CINUSR = 0
# the f2c name changed to g2c
F2CNAME = g2c
builddir = builddir
LIBBUILDDIR = $(GNUARCH)

with_check := $(strip $(shell if [ -f contrib/test_summary ]; \
		then echo yes; else echo test_summary script not found; fi))
# If you don't want to run the egcs testsuite, set `with_check' to `no'
#with_check := disabled by hand
ifeq ($(with_check),yes)
  ifneq ($(shell runtest --version 2>/dev/null \
		| awk '/^Framework/ {print $$NF}'),1.3.0)
    with_check := no appropriate DejaGnu version installed
  endif
endif

# See, if the GNU pascal compiler is found
with_pascal := $(strip $(shell if [ -d gcc/p ]; then echo yes; else echo no; fi))
# if pascal doesn't build on some target, disable it ...
ifeq ($(ARCH), $(findstring $(ARCH),arm powerpc))
  with_pascal := disabled for architecture $(ARCH)
endif
# disable the GNU pascal compiler by hand
#with_pascal := disabled by hand

# disable GNU pascal for 2.93.x
#ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) ge 2.93; echo $$?),0)
#   with_pascal := still disabled for version 2.93.x
#endif

with_java := $(strip \
	$(shell if [ -d gcc/java ]; then echo yes; else echo no; fi))
with_chill := $(strip \
	$(shell if [ -d gcc/ch ]; then echo yes; else echo no; fi))
# needs libgc4
with_objc_gc := $(strip \
	$(shell if [ -d libobjc ]; then echo yes; else echo no; fi))
# disable ObjC garbage collection library (needs libgc4)
#with_objc_gc := disabled by hand

CONFARGS = -v --prefix=/$(PF) --enable-threads --enable-shared
ifeq ($(ARCH),i486)
    CONFARGS+= --enable-haifa
endif
ifeq ($(ARCH),powerpc)
    CONFARGS+= --enable-haifa
endif
ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) ge 2.92; echo $$?),0)
    ifneq ($(CPPLIB),no)
        CONFARGS += --enable-cpplib --enable-c-cpplib
        # --enable-c-mbchar this seems to break some code, but the snapshot is
        # in project/experimental anyway.
        CONFARGS += --enable-c-mbchar
    endif
    CONFARGS += --with-fast-fixincludes
endif
ifeq ($(with_objc_gc),yes)
    CONFARGS += --enable-objc-gc
endif
ifeq ($(with_java),yes)
    CONFARGS += --enable-java-gc=boehm
endif
CONFARGS += $(GNUARCH)

# Abbreviations
I = install -p
# Install regular file
IR = $(I) -m 644
# Install script
IS = $(I) -m 755

default: build

ctrl_flags = -DCV=$(VERNO) -DNV=$(NEXTVERNO) \
	-DEPCV=1:$(VERNO) -DEPNV=1:$(NEXTVERNO) \
	-DBINUTILSV=$(BINUTILSV) -DSRCNAME=$(PKGSOURCE) \
	-D__$(ARCH)__ -DARCH=$(ARCH)
ifeq ($(ARCH),$(SECONDARY-ARCH))
  ctrl_flags += -DSECONDARY
else
  ctrl_flags +=	-DPRIMARY
  ifneq ($(FIRST_PRIMARY),)
    ctrl_flags += -DFIRST_PRIMARY="$(FIRST_PRIMARY)"
  endif
endif
ifeq ($(with_pascal),yes)
  ctrl_flags +=	-DPASCAL
endif
ifeq ($(with_objc_gc),yes)
  ctrl_flags +=	-DOBJC_GC
endif
ifeq ($(with_libgpp),yes)
  ctrl_flags += -DLIBGPP
endif
ifeq ($(with_chill),yes)
  ctrl_flags += -DCHILL
endif
ifeq ($(with_java),yes)
  ctrl_flags += -DJAVA
endif

ifeq ($(SNAPSHOT),no)
  snap_awk = {next}
else
  ctrl_flags += -DSNAPSHOT
  snap_awk = {print " [ This is a developer snapshot. Don'\''t use it for production."; print " Please read /usr/doc/<package-name>/README.snapshot! ]"; print " ."; next}
  ifeq ($(SNAPSHOT),fake)
    ctrl_flags += -DFAKE
  endif
endif

ifeq ($(glibc21),yes)
  ifeq ($(ARCH),$(GLIBC20_ARCH))
    ifeq ($(libapi_patch),yes)
      PKG_SONAME     = $(SONAME)-glibc2.1
      LGP_PKG_SONAME = $(LGPSONAME)-glibc2.1
    else
      PKG_SONAME     = $(SONAME)
      LGP_PKG_SONAME = $(LGPSONAME)
    endif
  else
      PKG_SONAME     = $(SONAME)
      LGP_PKG_SONAME = $(LGPSONAME)
  endif
else
  PKG_SONAME     = $(SONAME)
  LGP_PKG_SONAME = $(LGPSONAME)
endif
# debian/control depends on:
#    debian/control.in debian/changelog debian/rules
#    gcc/version.c libstdc++/Makefile.in
debian/control: debian/control.in debian/changelog debian/rules \
    gcc/version.c libstdc++/Makefile.in
	rm -f debian/control
	cpp -A- -P $(ctrl_flags) debian/control.in \
	  | awk '/^ *$$/ && x !~ /^ / {next} /SNAPSHOT_WARNING/ $(snap_awk) /NEWLINE/ {print ""; next} {print; x=$$0}' | sed -e '/^[^ ]/s/  */ /g' -e 's/  *\([,)]\)/\1/g' -e 's/ *$$//' \
	  | sed -e 's/_LIB_SO_/$(PKG_SONAME)/g' -e 's/_LGP_SO_/$(LGP_PKG_SONAME)/g' \
	  > debian/control

build: debian/control patched-stamp build-stamp
build-stamp:
	dh_testdir gcc/cccp.c
	dh_testversion $(DH_VERSION)
# give information about the build process
	@echo "-------------------------- Build process variables --------------------------"
	@echo "Package source: $(PKGSOURCE)"
	@echo "Version: $(VER) (numerical version: $(VERNO), next: $(NEXTVERNO))"
	@echo "Base Debian version: $(DPKGVER)"
	@echo -e "Configured with: $(foreach i,$(CONFARGS),$(i)\n\t)"
	@echo "Using shell $(SHELL)"
	@echo "Architecture: $(ARCH) (GNU: $(GNUARCH))"
	@echo "Binutils dependency: $(BINUTILSV)"
	@echo "SONAME: $(SONAME)"
	@echo "CPPFLAGS: $(CPPFLAGS)"
	@echo "CFLAGS: $(CFLAGS)"
	@echo "LDFLAGS: $(LDFLAGS)"
	@echo "BOOT_CFLAGS: $(BOOT_CFLAGS)"
	@echo "Install prefix: $(PF)"
ifneq ($(ARCH),$(SECONDARY-ARCH))
	@echo "Will build a primary C compiler."
else
	@echo "Will build a secondary C compiler."
endif
ifeq ($(with_check),yes)
	@echo "Will run the testsuite."
else
	@echo "Will not run the testsuite: $(with_check)"
	@echo "Please install dejagnu from project/experimental and restart."
	false
endif
ifeq ($(with_objc_gc),yes)
	@echo "Will build the extra ObjC runtime for garbage collection."
else
	@echo "Will not build the extra ObjC runtime for garbage collection."
endif
ifeq ($(with_pascal),yes)
	@echo "Will build the Pascal compiler."
else
	@echo "Will not build the Pascal compiler: $(with_pascal)"
endif
ifeq ($(with_libgpp),yes)
	@echo "Will build the deprecated g++ libraries."
else
	@echo "Will not build the deprecated g++ libraries: $(with_libgpp)"
endif
ifeq ($(libapi_patch),yes)
	@echo "Use new naming schema for libraries."
endif
ifeq ($(F2CINUSR),1)
	@echo "lib$(F2CNAME).a, $(F2CNAME).h under /$(PF) ."
else
	@echo "lib$(F2CNAME).a, $(F2CNAME).h under gcclib ."
endif
	@echo "-----------------------------------------------------------------------------"
	@echo ""
# configure
	rm -f build-stamp

	: # generate debian/README.Debian
	cat debian/README patched-stamp > debian/README.Debian

ifeq ($(with_pascal),yes)
	if [ ! -f gcc/p/config-lang.in ]; then \
	  cp -p gcc/p/config-lang.in.debian gcc/p/config-lang.in; \
	else \
	  true; \
	fi
else
	if [ -f gcc/p/config-lang.in ]; then \
	  mv -f gcc/p/config-lang.in gcc/p/config-lang.in.debian; \
	else \
	  true; \
	fi
endif
	-rm -f gcc/configure
	cd gcc && autoconf
	if [ ! -d $(builddir) ]; then mkdir $(builddir); else true; fi
	if [ ! -f $(builddir)/Makefile ]; then \
	  cd $(builddir); CC="$(CC)" ../configure $(CONFARGS) ; \
	fi
# build
ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) lt 2.92; echo $$?),0)
	echo "/* empty */" > gcc/mbchar.c
endif
	rm -f bootstrap-protocol
	( \
	  set +e; \
	  $(MAKE) -C $(builddir) bootstrap-lean CC="$(CC)" CFLAGS="$(CFLAGS)" \
		BOOT_CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(LDFLAGS)"; \
	  echo $$? > status; \
	) 2>&1 | tee bootstrap-protocol
	s=`cat status`; rm -f status; test $$s -eq 0
	$(MAKE) -C $(builddir)/gcc/cp g++FAQ.info
	$(MAKE) -C $(builddir)/$(LIBBUILDDIR)/libio info
ifeq ($(with_libgpp),yes)
	$(MAKE) -C $(builddir)/$(LIBBUILDDIR)/libg++ info
endif
	-chmod 755 contrib/warn_summary
	if [ -x contrib/warn_summary ]; then \
	    rm -f bootstrap-summary; \
	    contrib/warn_summary bootstrap-protocol > bootstrap-summary; \
	fi
# make check ...
ifeq ($(with_check),yes)
	rm -f test-protocol
	-$(MAKE) -C $(builddir) -k check 2>&1 | tee test-protocol
	-chmod 755 contrib/test_summary
	if [ -x contrib/test_summary ]; then \
	  rm -f test-summary; \
	  ( \
	    cd $(builddir); \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	      ../contrib/test_summary -i $(PWD)/patched-stamp -m "$(S_EMAIL)" \
	  ) > raw-test-summary; \
	  awk '/^cat/, /^EOF/' raw-test-summary | grep -v EOF > test-summary; \
	fi
  ifeq ($(with_pascal),yes)
	if [ -f gcc/p/test_summary ]; then \
	  chmod +x gcc/p/test_summary; \
	  gcc/p/test_summary < test-protocol > gpc-test-summary; \
	fi
  endif
endif
	touch build-stamp

tst: patched-stamp
	mkdir $(builddir) || true
	if [ ! -f $(builddir)/Makefile ]; then \
	  cd $(builddir); ../configure $(CONFARGS) ; \
	fi
	$(MAKE) -C $(builddir) all-bootstrap CC="$(CC)" CFLAGS="$(CFLAGS)" \
		BOOT_CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(LDFLAGS)"
	$(MAKE) -C $(builddir)/gcc CC="$(CC)" CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)" LANGUAGES="c pascal"

mail-summary:
	@if [ ! -f /usr/bin/Mail ]; then \
	  echo "Please install the mailx package to send the summary"; \
	  exit 1; \
	fi
	-chmod 755 contrib/test_summary
	if [ -x contrib/test_summary ]; then \
	  rm -f test-summary; \
	  ( \
	    cd $(builddir); \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	      ../contrib/test_summary -i $(PWD)/patched-stamp -m "$(S_EMAIL)" \
	  ) > raw-test-summary; \
	fi
	echo -n "Send summary to $(S_EMAIL) (y/n) "; read x; \
	case "$$x" in \
	  y*|Y*) cat raw-test-summary | sh; echo "Sent mail to $(S_EMAIL)";; \
	  *) echo "Mail not sent.";; \
	esac

# the unpacked-* and patched-* stamps aren't removed, because the changes
# cannot be undone (well perhaps patch --reverse ...).
clean: debian/control
	dh_testdir gcc/cccp.c
	rm -f {build,install}-stamp
	rm -f {bootstrap,gpc-test,test,raw-test}-{protocol,summary}
	rm -f first-move-stamp status
	rm -rf $(builddir)
	rm -f debian/*.shlibs debian/README.Debian
	rm -f if*.c pxxx gcc/configure
ifeq ($(with_pascal),yes)
	rm -f gcc/p/doc/*info
	rm -f gcc/p/test/{fjf51,fjf141aa,fjf199aa,magic,?,knownbugs/a.out}
endif
	if [ -f gcc/p/config-lang.in.debian ]; then \
	  mv -f gcc/p/config-lang.in.debian gcc/p/config-lang.in; \
	else true; fi
	rm -f debian/$(p_lib).*
	rm -f debian/$(p_dev).*
	rm -f debian/$(p_lgp).*
	rm -f debian/$(p_lgd).*
	$(MAKE) -f debian/rules reverse-patches
	$(MAKE) -C debian/bugs clean
ifeq ($(with_libgpp),yes)
	: # this must be patched _before_ the $(MAKE) build is called.
	$(MAKE) -f debian/rules patched-libg++-name
endif
	dh_clean
	rm -f debian/control
	$(MAKE) -f debian/rules debian/control

# ------------------------------------------------------------------------------
# some abbrevations for the package names and directories;
# p_XXX is the package name, d_XXX is the package directory
# these macros are only used in the binary-* targets.

# p_gcc used only for primary compiler, p_gpc used only for pascal.
ifeq ($(SNAPSHOT),yes)
  ss_suffix = -ss
endif

p_gcc	= $(gcc_name)$(ss_suffix)
p_cpp	= cpp$(ss_suffix)
p_objc	= gobjc$(ss_suffix)
p_gpp	= g++$(ss_suffix)
p_g77	= g77$(ss_suffix)
p_g77d	= g77-doc$(ss_suffix)
p_gch	= chill$(ss_suffix)
p_java	= gcj$(ss_suffix)
p_gpc	= gpc$(ss_suffix)
p_gpcd	= gpc-doc$(ss_suffix)
p_lib	= libstdc++$(PKG_SONAME)$(ss_suffix)
p_dev	= libstdc++$(PKG_SONAME)-dev$(ss_suffix)
p_lgp	= libg++$(LGP_PKG_SONAME)$(ss_suffix)
p_lgd	= libg++$(LGP_PKG_SONAME)-dev$(ss_suffix)
#p_lib	= libstdc++$(SONAME)$(ss_suffix)
#p_dev	= libstdc++$(SONAME)-dev$(ss_suffix)
#p_lgp	= libg++$(LGPSONAME)$(ss_suffix)
#p_lgd	= libg++$(LGPSONAME)-dev$(ss_suffix)
p_doc	= egcs-docs$(ss_suffix)

d=debian/tmp

d_gcc	= $(d)
d_cpp	= debian/$(p_cpp)
d_objc	= debian/$(p_objc)
d_gpp	= debian/$(p_gpp)
d_g77	= debian/$(p_g77)
d_g77d	= debian/$(p_g77d)
d_gch	= debian/$(p_gch)
d_java	= debian/$(p_java)
d_gpc	= debian/$(p_gpc)
d_gpcd	= debian/$(p_gpcd)
d_lib	= debian/$(p_lib)
d_dev	= debian/$(p_dev)
d_lgp	= debian/$(p_lgp)
d_lgd	= debian/$(p_lgd)
d_doc	= debian/$(p_doc)

ifeq ($(ARCH),powerpc)
  p_nof  = egcs-nof$(ss_suffix)
  d_nof  = debian/$(p_nof)
endif

# base files are part of gcc (primary) or g++ (secondary)
# the g++ package has to be moved last!
base_files = \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{SYSCALLS.c.X,collect2,specs} \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{libgcc.*,*.o} \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include/{README,*.h}

dirs_gcc = \
	usr/doc/$(p_gcc) \
	$(PF)/bin \
	$(PF)/info \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include \
	$(PF)/man/man1 \
	$(PF)/include/$(cxx_inc_dir)/std \
	$(PF)/include/$(cxx_inc_dir)/gen \
	$(PF)/$(GNUARCH)/lib
files_gcc = \
	$(PF)/bin/{egcc,gcov} \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cc1 \
	$(PF)/man/man1/{egcc.1,gcov.1}
ifneq ($(ARCH),$(SECONDARY-ARCH))
  files_gcc += \
	$(PF)/bin/{protoize,unprotoize} \
	$(PF)/man/man1/{protoize,unprotoize}.1
endif

ifeq ($(ARCH),powerpc)
  dirs_gcc += \
	$(PF)/lib/nof \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/nof \
	$(PF)/$(GNUARCH)/lib/nof
  dirs_nof = \
	$(PF)/lib/nof \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/nof
  files_nof = \
	$(PF)/lib/nof \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/nof
 ifeq ($(CXX_IF),1.1)
  files_nof += $(PF)/lib/nof/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
 endif
endif

dirs_cpp = \
	usr/doc/$(p_cpp) \
	$(PF)/man/man1 \
	$(PF)/info \
	$(PF)/bin
files_cpp = \
	$(PF)/bin/cpp \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cpp \
	$(PF)/man/man1/cpp.1 \
	$(PF)/info/cpp.info*
ifneq ($(ARCH),$(SECONDARY-ARCH))
  ifneq ($(SNAPSHOT),yes)
    dirs_gcc += lib
    dirs_cpp += lib
    files_cpp += lib/cpp
  endif
endif

dirs_objc = \
	usr/doc/$(p_gcc) \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include
files_objc = \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include/objc \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{cc1obj,libobjc*.a}

dirs_gpp = \
	usr/doc/$(p_gpp) \
	$(PF)/bin \
	$(PF)/info \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include \
	$(PF)/man/man1
files_gpp = \
	$(PF)/bin/{c++,g++} \
	$(PF)/info/g++FAQ.info \
	$(PF)/man/man1/{c++,g++}.1 \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cc1plus \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include/{new,typeinfo,exception}
ifeq ($(ARCH),$(SECONDARY-ARCH))
  files_gpp += $(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cpp
else
  files_gpp += $(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include/new.h
endif

dirs_g77 = \
	usr/doc/$(p_g77) \
	$(PF)/bin \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include \
	$(PF)/include \
	$(PF)/man/man1
files_g77 = \
	$(PF)/bin/g77 \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{f771,lib$(F2CNAME).a} \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/include/$(F2CNAME).h \
	$(PF)/man/man1/g77.1

dirs_g77d = \
	usr/doc/$(p_g77d) \
	$(PF)/info
files_g77d = \
	$(PF)/info/g77*

dirs_chill = \
	usr/doc/$(p_gch) \
	$(PF)/bin \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER) \
	$(PF)/man/man1 \
	$(PF)/info

files_chill = \
	$(PF)/bin/chill \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/*chill* \
	$(PF)/info/chill*

dirs_java = \
	usr/doc/$(p_java) \
	$(PF)/bin \
	$(PF)/man/man1 \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)
files_java = \
	$(PF)/bin/{gcj,gcjh,jv-scan,jcf-dump} \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/jc1 \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/jvgenmain

dirs_gpc = \
	usr/doc/$(p_gpc)/examples \
	$(PF)/bin \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{include,units} \
	$(PF)/man/man1
files_gpc = \
	usr/doc/$(p_gpc)/examples/*.pas \
	$(PF)/bin/{bpc,epc,gpc,pc} \
	$(PF)/man/man1/{bpc,epc,gpc,pc}.1 \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/{gpc-cpp,gpc1,libgpc.a,units}

dirs_gpcd = \
	usr/doc/$(p_gpcd) \
	$(PF)/info
files_gpcd = \
	$(PF)/info/gpc*

dirs_lgp = \
	usr/doc/$(p_lgp) \
	$(PF)/lib
files_lgp = \
	$(addprefix $(PF)/lib/, $(lgp_shlib) $(lgp_mshlink))

dirs_lgd = \
	usr/doc/$(p_lgp) \
	$(PF)/bin \
	$(PF)/info \
	$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER) \
	$(PF)/man/man1 \
	$(PF)/include/$(cxx_inc_dir)/gen
files_lgd = \
	$(PF)/bin/genclass \
	$(PF)/man/man1/genclass.1 \
	$(PF)/info/libg++.info* \
	$(addprefix $(PF)/lib/, $(lgp_arlib) $(lgp_marlink)) \
	$(PF)/$(lib_linkdir)/libg++.{a,so} \
	$(PF)/include/$(cxx_inc_dir)/gen/ \
	$(PF)/include/$(cxx_inc_dir)/{$(shell cd $(PWD)/libg++/src; \
						echo *.h | tr ' ' ,)}

dirs_lib = \
	usr/doc/$(p_lib) \
	$(PF)/lib
files_lib = \
	$(addprefix $(PF)/lib/, $(lib_shlib) $(lib_mshlink) $(lib_compatlink))

ifeq ($(ARCH),powerpc)
 ifeq ($(CXX_IF),1.1)
   files_lib += $(PF)/lib/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
 endif
endif


dirs_dev = \
	usr/doc/$(p_lib) \
	$(PF)/info \
	$(PF)/lib \
	$(PF)/include/$(cxx_inc_dir)/std
# libg++-dev must be moved first !!!
# not all files in $(PF)/include/$(cxx_inc_dir)/,
# but it becomes difficulty to name all these files ...
files_dev = \
	$(addprefix $(PF)/lib/, $(lib_arlib) $(lib_marlink)) \
	$(PF)/include/$(cxx_inc_dir)/ \
	$(PF)/info/iostream* \
	$(PF)/$(lib_linkdir)/libstdc++.{a,so}

dirs_doc = \
	usr/doc/$(p_doc) \
	$(PF)/info
files_doc = \
	$(PF)/info/egcs*

ifeq ($(ARCH),$(SECONDARY-ARCH))
  files_gpp += $(base_files)
else
  files_gcc += $(base_files)
endif

PKGS_ARCH := $(shell awk '/^Package:/ {p=$$2} /^Architecture: any/ {print p}' \
			debian/control)


# ----------------------------------------------------------------------
install: install-stamp first-move-stamp
install-stamp: build-stamp
	dh_testversion $(DH_VERSION)
	dh_testdir gcc/cccp.c
	dh_testroot
	rm -f debian/control
	$(MAKE) -f debian/rules debian/control
	dh_clean -k
	: # Install directories
	dh_installdirs -p$(p_gcc) $(dirs_gcc)
ifneq ($(ARCH),$(SECONDARY-ARCH))
	dh_installdirs -p$(p_cpp) $(dirs_cpp)
endif
	dh_installdirs -p$(p_objc) $(dirs_objc)
	dh_installdirs -p$(p_gpp) $(dirs_gpp)
	dh_installdirs -p$(p_g77) $(dirs_g77)
	dh_installdirs -p$(p_g77d) $(dirs_g77d)
ifeq ($(with_chill),yes)
	dh_installdirs -p$(p_gch) $(dirs_chill)
endif
ifeq ($(with_java),yes)
	dh_installdirs -p$(p_java) $(dirs_java)
endif
ifeq ($(with_pascal),yes)
	dh_installdirs -p$(p_gpc) $(dirs_gpc)
	dh_installdirs -p$(p_gpcd) $(dirs_gpcd)
endif
	dh_installdirs -p$(p_lib) $(dirs_lib)
	dh_installdirs -p$(p_dev) $(dirs_dev)
ifeq ($(with_libgpp),yes)
	dh_installdirs -p$(p_lgp) $(dirs_lgp)
	dh_installdirs -p$(p_lgd) $(dirs_lgd)
endif
	dh_installdirs -p$(p_doc) $(dirs_doc)
ifeq ($(ARCH),powerpc)
	dh_installdirs -p$(p_nof) $(dirs_nof)
endif
	: # Install everything
	$(MAKE) -C $(builddir) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	  BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	  INSTALL="$(I)" \
	  INSTALL_PROGRAM="$(I) -s" prefix=$(PWD)/$(d)/$(PF) install
	: # Adjust the installation such that we can begin moving things around:
	: # - Remove files, which are not part of any package
	rm -f $(d)/$(PF)/bin/$(GNUARCH)-gcc
	rm -f $(d)/$(PF)/bin/c++filt
	rm -f $(d)/$(PF)/lib/libiberty.a
	rm -rf $(d)/$(PF)/$(GNUARCH)

	: # adjustments needed for the snapshot ...
	rm -f $(d)/$(PF)/bin/makeinfo

	touch install-stamp


first-move-stamp: install-stamp
	rm -f install-stamp
	: # - cpp installation
ifneq ($(ARCH),$(SECONDARY-ARCH))
	mv $(d)/$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cpp $(d)/$(PF)/bin/cpp
	ln -sf ../../../../bin/cpp \
		$(d)/$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/cpp
	mv $(d)/$(PF)/man/man1/cccp.1 $(d)/$(PF)/man/man1/cpp.1
  # we don't want the link in /usr/lib for the snapshot
  ifneq ($(SNAPSHOT),yes)
	#ln -sf ../$(PF)/bin/cpp $(d)/lib/cpp
	ln -sf /$(PF)/bin/cpp $(d)/lib/cpp
  endif
else
	rm -f $(d)/$(PF)/man/man1/cccp.1
	rm -f $(d)/$(PF)/info/cpp.info*
endif
	$(IR) debian/gcov.1 $(d)/$(PF)/man/man1/
ifneq ($(ARCH),$(SECONDARY-ARCH))
	: # - Adjust files for primary compiler
	$(I) debian/protoize.1 $(d)/$(PF)/man/man1/
	ln -s protoize.1 $(d)/$(PF)/man/man1/unprotoize.1
	#ln -s /usr/bin/gcc $(d)/$(PF)/bin/egcc
	ln -s gcc $(d)/$(PF)/bin/egcc
else
	: # - Adjust files for secondary compiler
	mv $(d)/$(PF)/bin/gcc $(d)/$(PF)/bin/egcc
	mv $(d)/$(PF)/man/man1/gcc.1 $(d)/$(PF)/man/man1/egcc.1
	rm -f $(d)/$(PF)/bin/{protoize,unprotoize}
	rm -f $(d)/$(PF)/man/man1/{protoize,unprotoize}.1
endif
	: # - Missing c++.1 link, g++ FAQ and c++filt manpage
	ln -s g++.1 $(d)/$(PF)/man/man1/c++.1
	$(IR) $(builddir)/gcc/cp/g++FAQ.info* $(d)/$(PF)/info
#	$(IR) debian/c++filt.1 $(d)/$(PF)/man/man1/
ifeq ($(with_pascal),yes)
	: # adjust gpc
	mv $(d)/$(PF)/doc/$(p_gpc)/demos $(d)/$(PF)/doc/$(p_gpc)/examples
endif
ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) lt 2.92; echo $$?),0)
  ifeq ($(libapi_patch),yes)
#  Don't make the libg++ compatibility link! It conflicts with the
#  libg++2.8 package.
ifeq ($(glibc21),yes)
  ifneq ($(ARCH),$(GLIBC20_ARCH))
	: # - libstdc++ compatibility library
	cd $(builddir)/$(LIBBUILDDIR)/libstdc++ && \
	  $(MAKE) SHLIB=$(lib_compatlink) MSHLINK=$(lib_compatlink) \
	        $(lib_compatlink)
	$(IR) $(builddir)/$(LIBBUILDDIR)/libstdc++/$(lib_compatlink) \
	        $(d)/$(PF)/lib/
  endif
else
	: # - libstdc++ compatibility library
	cd $(builddir)/$(LIBBUILDDIR)/libstdc++ && \
	  $(MAKE) SHLIB=$(lib_compatlink) MSHLINK=$(lib_compatlink) \
	        $(lib_compatlink)
	$(IR) $(builddir)/$(LIBBUILDDIR)/libstdc++/$(lib_compatlink) \
	        $(d)/$(PF)/lib/
endif
    ifeq ($(ARCH),powerpc)
#	LD_LIBRARY_PATH=$(d)/$(PF)/lib/nof \
#	  $(d)/$(PF)/bin/g++ -B$(d)/$(PF)/lib/gcc-lib/$(GNUARCH)/$(VER)/ \
#	  -shared -o $(d)/$(PF)/lib/nof/libstdc++.so.$(SONAME) \
#	  -Wl,-soname,libstdc++.so.$(SONAME) -lm
      ifeq ($(CXX_IF),1.1)
	ln -s $(lib_mshlink) $(d)/$(PF)/lib/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
	ln -s $(lib_mshlink) $(d)/$(PF)/lib/nof/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
      endif
    endif
  endif
endif
	: # - libstdc++ iostream info files
	$(IR) $(builddir)/$(LIBBUILDDIR)/libio/iostream*info* $(d)/$(PF)/info/
ifeq ($(with_libgpp),yes)
	: # - libg++ info files and genclass man page
	$(IR) $(builddir)/$(LIBBUILDDIR)/libg++/libg++.info* $(d)/$(PF)/info/
	$(IR) debian/genclass.1 $(d)/$(PF)/man/man1/
endif

	: # Move files to subpackages.
	dh_movefiles -p$(p_doc) $(files_doc)
ifeq ($(ARCH),powerpc)
	dh_movefiles -p$(p_nof) $(files_nof)
endif
ifneq ($(ARCH),$(SECONDARY-ARCH))
	dh_movefiles -p$(p_cpp) $(files_cpp)
endif
	dh_movefiles -p$(p_objc) $(files_objc)
	dh_movefiles -p$(p_g77) $(files_g77)
	dh_movefiles -p$(p_g77d) $(files_g77d)
ifeq ($(with_chill),yes)
	dh_movefiles -p$(p_gch) $(files_chill)
endif
ifeq ($(with_java),yes)
	dh_movefiles -p$(p_java) $(files_java)
endif
ifeq ($(with_libgpp),yes)
# libg++-dev must be moved before libstdc++-dev !!!
	dh_movefiles -p$(p_lgd) $(files_lgd)
	dh_movefiles -p$(p_lgp) $(files_lgp)
endif
	dh_movefiles -p$(p_dev) $(files_dev)
	dh_movefiles -p$(p_lib) $(files_lib)
ifeq ($(with_pascal),yes)
	dh_movefiles -p$(p_gpc) $(files_gpc)
	dh_movefiles -p$(p_gpcd) $(files_gpcd)
endif
# the gpp package must be moved last! better: the package which contains
# the base files, must be moved last (but $(p_gcc) isn't moved ;-).
	dh_movefiles -p$(p_gpp) $(files_gpp)
#	dh_movefiles -p$(p_gpp) $(shell echo $(files_gpp) | sort -t ' ' -u)

	touch first-move-stamp

usr_doc_files = debian/{README.Debian,BUGS.Debian} \
	$(shell test -f INSTALL/FAQ && echo INSTALL/FAQ)
ifneq ($(SNAPSHOT),no)
  usr_doc_files += debian/README.snapshot
endif
ifeq ($(with_check),yes)
  usr_doc_files += test-summary
endif
ifeq ($(ARCH),sparc)
  usr_doc_files += debian/README.sparc
endif
ifeq ($(ARCH),$(SECONDARY-ARCH))
  doc_pkg = $(p_gpp)
else
  doc_pkg = $(p_cpp)
endif

ifeq ($(ARCH),powerpc)
  ifeq ($(CXX_IF),1.1)
    libstdc_eh_ver = $(empty_random_variable) (>= 2.91.63)
  endif
endif

# ----------------------------------------------------------------------
# Build architecture-dependent files here.
binary-arch: build install
	dh_testversion $(DH_VERSION)
	dh_testdir gcc/cccp.c
	dh_testroot
	: # Install documentation and changelogs
	dh_installchangelogs -a -N$(p_objc) -N$(p_dev) -N$(p_lgd)
	dh_installdocs -a -A -N$(p_objc) -N$(p_dev) -N$(p_lgd) \
		$(usr_doc_files)
	dh_installdocs -p$(p_gcc) gcc/NEWS gcc/BUGS faq.html debian/ANNOUNCE
	ln -sf $(p_gcc) $(d_objc)/usr/doc/$(p_objc)
	dh_installdocs -p$(p_gpp) gcc/cp/NEWS gcc/BUGS faq.html debian/ANNOUNCE
	dh_installdocs -p$(p_g77) gcc/f/NEWS gcc/f/BUGS gcc/README.g77 \
		faq.html debian/ANNOUNCE
	$(IR) libf2c/README $(d_g77)/usr/doc/$(p_g77)/README.libf2c
	$(IR) libio/NEWS $(d_dev)/usr/doc/$(p_lib)/NEWS.libio
	$(IR) libstdc++/NEWS debian/README.libstdc++ \
	    $(d_dev)/usr/doc/$(p_lib)/
	ln -sf $(p_lib) $(d_dev)/usr/doc/$(p_dev)
	$(IR) libg++/NEWS $(d_lgd)/usr/doc/$(p_lgp)/
	ln -sf $(p_lgp) $(d_lgd)/usr/doc/$(p_lgd)

ifeq ($(libapi_patch),yes)
  ifeq ($(LIBC_IF),-libc6.0-)
	mkdir -p $(d_dev)/usr/sbin
	$(IS) debian/libstdc++-dev-config $(d_dev)/usr/sbin
  endif
endif

ifeq ($(with_pascal),yes)
	dh_installdocs -p$(p_gpc) gcc/p/{AUTHORS,README,TODO}
	$(IR) gcc/p/FAQ $(d_gpc)/usr/doc/$(p_gpc)/FAQ.gpc
  ifeq ($(with_check),yes)
	$(IR) gpc-test-summary $(d_gpc)/usr/doc/$(p_gpc)/
  endif
endif
ifeq ($(with_java),yes)
	dh_installdocs -p$(p_java)
endif
ifeq ($(with_chill),yes)
	dh_installdocs -p$(p_gch) gcc/ch/README
endif
#	dh_installexamples -a
#	dh_installmenu -a
#       dh_installinit -a
#	dh_installcron -a
	: # Install man pages and undocumented links
#	dh_installmanpages -a
ifneq ($(SNAPSHOT),yes)
  ifeq ($(with_java),yes)
	dh_undocumented -p$(p_java) gcj.1
	dh_undocumented -p$(p_java) gcjh.1
  endif
  ifeq ($(with_chill),yes)
	dh_undocumented -p$(p_gch) chill.1
  endif
else
  ifeq ($(with_java),yes)
	-ln -s ../../../../man7/undocumented.7 $(d_java)/$(PF)/man/man1/gcj.1
	-ln -s ../../../../man7/undocumented.7 $(d_java)/$(PF)/man/man1/gcjh.1
  endif
  ifeq ($(with_chill),yes)
	-ln -s ../../../../man7/undocumented.7 $(d_gch)/$(PF)/man/man1/chill.1
  endif
endif
	: # remove empty directories, when all components are in place
	for d in `find debian -depth -type d -empty 2> /dev/null`; do \
	  while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \
	done

	: # strip executables and libraries
#	dh_strip -a -Xlibgcc.a -Xlibobjc.a -Xlibg2c.a -Xlibgpc.a
	dh_strip -a
# XXX: in the snapshot package the man pages aren't compressed by default.
# Ok, I can live with it.
	dh_compress -a
	for i in $(usr_doc_files); do \
	  b=`basename $$i`; \
	  if [ -e $(d_lib)/usr/doc/$(p_lib)/$$b ]; then \
	    ln -sf ../$(p_lib)/$$b $(d_lgp)/usr/doc/$(p_lgp)/$$b; \
	  else \
	    ln -sf ../$(p_lib)/$$b.gz $(d_lgp)/usr/doc/$(p_lgp)/$$b.gz; \
	  fi; \
	done
	dh_fixperms -a
ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) lt 2.92; echo $$?),0)
	$(IS) debian/debian-libstdc++.sh  $(d_lib)/usr/doc/$(p_lib)/
	ln -s ../$(p_lib)/debian-libstdc++.sh $(d_gpp)/usr/doc/$(p_gpp)/
endif
#	dh_suidregister -a
# when dh_installdeb is called from the snapshot package, the postinst/prerm
# packages are intentionally not called:
# - we don't want to call update-info for the snapshot ...
# - gcc-ss doesn't provide an alternative for cc
# - libstdc++ and libg++ don't call ldconfig, user should set LD_LIBRARY_PATH
#	dh_makeshlibs -a
ifneq ($(SNAPSHOT),yes)
  ifeq ($(libapi_patch),yes)
   ifeq ($(ARCH),powerpc)
    ifeq ($(CXX_IF),1.1)
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libstdc++$(PKG_SONAME) (>= 2.91.63)" \
		> debian/$(p_lib).shlibs
    else
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libstdc++$(PKG_SONAME)" \
		> debian/$(p_lib).shlibs
    endif
   else
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libstdc++$(PKG_SONAME)" \
		> debian/$(p_lib).shlibs
   endif
	echo "libstdc++ $(SONAME) libstdc++$(PKG_SONAME)" >> debian/$(p_lib).shlibs
   ifeq ($(with_libgpp),yes)
	echo "libg++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libg++$(LGP_PKG_SONAME)" \
		> debian/$(p_lgp).shlibs
#	echo "libg++ $(LGPSONAME) libg++$(LGPSONAME)" >> debian/$(p_lgp).shlibs
   endif
  else
	echo "libstdc++ $(SONAME) libstdc++$(PKG_SONAME)" > debian/$(p_lib).shlibs
   ifeq ($(with_libgpp),yes)
	echo "libg++ $(LGPSONAME) libg++$(LGP_PKG_SONAME)" > debian/$(p_lgp).shlibs
   endif
  endif
endif

	cp -p debian/libstdc++.postinst debian/$(p_lib).postinst
ifeq ($(libapi_patch),yes)
 ifeq ($(libc_interface),-libc6.0-)
	cp -p debian/libstdc++-dev-glibc2.0.postinst debian/$(p_dev).postinst
 else
	cp -p debian/libstdc++-dev.postinst debian/$(p_dev).postinst
 endif
else
	cp -p debian/libstdc++-dev.postinst debian/$(p_dev).postinst
endif
	cp -p debian/libstdc++-dev.prerm debian/$(p_dev).prerm
	cp -p debian/libg++.postinst debian/$(p_lgp).postinst
	cp -p debian/libg++-dev.postinst debian/$(p_lgd).postinst
	cp -p debian/libg++-dev.prerm debian/$(p_lgd).prerm

	: # dh_shlibdeps ... I hope I got it correct now ...
	: # we don't want the dep. on libstdc++, it's hardwired in control
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF)" \
		> debian/shlibs.local
	dh_shlibdeps -a
	dh_installdeb -a
	dh_gencontrol -a -N$(p_objc) -N$(p_g77) -u-v$(DPKGVER)
	dh_gencontrol -p$(p_objc) -p$(p_g77) -u-v1:$(DPKGVER)
	dh_md5sums -a
	dh_builddeb -a

# ----------------------------------------------------------------------
# Build architecture-independent files here.
binary-indep: build install
	dh_testversion $(DH_VERSION)
	dh_testdir gcc/cccp.c
	dh_testroot
	dh_installdocs -i
	dh_installchangelogs -i
#	dh_installexamples -i
#	dh_installmenu -i
#       dh_installinit -i
#	dh_installcron -i
#       dh_installmanpages -i
#       dh_undocumented

	: # remove empty directories, when all components are in place
	for d in `find $(d_doc) $(d_g77d) $(d_gpcd) \
		-depth -type d -empty 2> /dev/null`; do \
	  while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \
	done

	dh_compress -i
	dh_fixperms -i
#	dh_suidregister -i
ifneq ($(SNAPSHOT),yes)
	dh_installdeb -i
endif
	dh_gencontrol -i -u-v$(DPKGVER)
	dh_md5sums -i
	dh_builddeb -i

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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

# ---------------------------------------------------------------------------
# various rules to unpack addons and (un)apply patches.

patch_dir	= debian/patches

# which patches should be applied?
debian_patches = reporting info-name vendor

ifeq ($(with_libgpp),yes)
  debian_patches += libg++-name
endif

ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) ge 2.92; echo $$?),1)
  # patches for egcs-1.1.x only
  debian_patches += builtin-apply cpp-predefines alpha-spec various \
	aspell cp-decl egcs-1.1-reload2 \
	speedup libstdc++-wall # emit-rtl-nan
  ifeq ($(with_pascal),yes)
    debian_patches += gpc gpc-updates
  endif
  ifeq ($(ARCH),m68k)
    debian_patches += 68060-build
  endif

  debian_patches += hjl-19990315-linux # <=> arm libapi autoptr

  ifeq ($(ARCH),powerpc)
    # Still relevant?
    # debian_patches += rs6000-movsf
    debian_patches += egcs-1.1-reload
    debian_patches += ppc-andrew-dwarf-eh ppc-eh-versioning ppc-haifafix
    debian_patches += ppc-loopfix ppc-mi-thunk
  endif

else
  debian_patches += libobjc builtin-apply-1.2
  ifeq ($(with_pascal),yes)
    debian_patches += gpc92
  endif
endif

apply-patches: patched-stamp
reverse-patches:
	for stamp in none `ls -1t patched-*`; do \
	  case "$$stamp" in none|patched-stamp|patched-\*) continue; esac; \
	  patch=`echo $$stamp | sed -e 's/patched-//'`; \
	  echo "trying to revert patch $$patch ..."; \
	  if [ -x $(patch_dir)/$$patch.dpatch ]; then true; else \
	    chmod +x $(patch_dir)/$$patch.dpatch; fi; \
	  if $(patch_dir)/$$patch.dpatch -unpatch; then \
	    echo "reverted $$patch patch."; \
	    rm -f $$stamp; \
	  else \
	    echo "error in reverting $$patch patch."; \
	    exit 1; \
	  fi; \
	done
	rm -f patched-stamp

patched-%: $(patch_dir)/%.dpatch
	if [ -x $< ]; then true; else chmod +x $<; fi
	if [ -f $@ ]; then \
	  echo "$* patches already applied."; exit 1; \
	fi
	$< -patch
	echo "$* patches applied." > $@

orig_dir	= $(shell echo "../`basename $(PWD)`.orig")
libgpp_name	= libg++-2.8.1.3
libgpp_tgz	= ../$(libgpp_name).tar.gz
pascal_tgz	= ../gpc-19990118.tar.gz

# libg++ is part of 2.92.x; gpc doesn't work yet.
#ifeq ($(shell set +e; dpkg --compare-versions $(VERNO) ge 2.92; echo $$?),1)
  debian_addons = unpacked-gpc unpacked-libg++
#else
#  debian_addons = unpacked-libg++
#endif

patched-stamp: unpack-addons $(foreach p,$(debian_patches),patched-$(p))
	echo -e "Integrated packages in the Debian version of egcs:\n" > pxxx
	for i in unpacked-*; do echo -n "  " >> pxxx; cat $$i >> pxxx; done
	echo -e "\nPatches applied in the Debian version of egcs:" >> pxxx
	for i in $(debian_patches); do \
	  echo -e "\n$$i:" >> pxxx; \
	  sed -n 's/^# *DP: */  /p' debian/patches/$$i.dpatch >> pxxx; \
	done
	mv -f pxxx patched-stamp

unpack-addons: $(debian_addons)
remove-addons: reverse-patches
	rm -rf unpacked-gpc gcc/p
	rm -rf unpacked-libg++ README.libg++ libg++ librx
	if [ -d $(orig_dir) ]; then \
	  cd $(orig_dir); \
	  rm -rf unpacked-gpc gcc/p; \
	  rm -rf unpacked-libg++ README.libg++ libg++ librx; \
	fi

unpacked-libg++:
	set -e; \
	if [ -f $(libgpp_tgz) -a ! -d libg++ ]; then \
	  rm -rf libg++ librx README.libg++; \
	  tar zxfp $(libgpp_tgz); \
	  mv $(libgpp_name)/{README.libg++,libg++,librx} ./; \
	  rmdir $(libgpp_name); \
	  if [ -d $(orig_dir) ]; then \
	    tar cf - README.libg++ libg++ librx \
		| (cd $(orig_dir); tar xfp - ); \
	    echo "$(libgpp_tgz) unpacked." > $(orig_dir)/$@; \
	  else true; fi; \
	  echo "$(libgpp_tgz) unpacked." > $@; \
	  echo "Sucessfully unpacked $(libgpp_tgz). However debian/rules"; \
	  echo "need some information from libg++, so you have to restart."; \
	  false; \
	else true; fi

unpacked-gpc:
	set -e; \
	if [ ! -d gpc/p ]; then \
	  rm -rf gcc/p; \
	  tar zxfp $(pascal_tgz); \
	  mv gpc/p gcc; rmdir gpc; rm -f gcc/p/doc/gpc*info*; \
	  if [ -d $(orig_dir) ]; then \
	    tar cf - gcc/p | (cd $(orig_dir); tar xfp - ); \
	    echo "$(pascal_tgz) unpacked." > $(orig_dir)/$@; \
	  else true; fi; \
	else true; fi
	echo "$(pascal_tgz) unpacked." > $@