File: rules

package info (click to toggle)
gcc-8-cross-ports 19
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,856 kB
  • sloc: makefile: 584; sh: 68; python: 55
file content (670 lines) | stat: -rwxr-xr-x 25,754 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
#!/usr/bin/make -f

, := ,
space :=
space +=
$(space) := 
$(space) +=

NJOBS =
# Support parallel=<n> in DEB_BUILD_OPTIONS (see #209008)
ifneq (,$(filter parallel=%,$(subst $(,), ,$(DEB_BUILD_OPTIONS))))
  NJOBS := -j $(subst parallel=,,$(filter parallel=%,$(subst $(,),$(space),$(DEB_BUILD_OPTIONS))))
endif

vendor := $(shell if dpkg-vendor --derives-from Ubuntu; then echo Ubuntu; else echo Debian; fi)

GCC_VER := $(shell dpkg-parsechangelog |egrep ^Source:|cut -f2 -d' '|cut -f2 -d'-')

ifeq ($(GCC_VER),4.8)
  MIN_VER_GCC      := 4.8.1-16
  PPA_VER_GCC      := 4.8.1
endif

ifeq ($(GCC_VER),4.9)
  MIN_VER_GCC      := 4.9.2-10ubuntu5~
  PPA_VER_GCC      := 4.9.2
endif

ifeq ($(GCC_VER),5)
  MIN_VER_GCC      := 5.3.1-2~
  PPA_VER_GCC      := 5.3.1
endif

ifeq ($(GCC_VER),6)
  MIN_VER_GCC      := 6.1.1-9~
  PPA_VER_GCC      := 6.1.1
endif

ifeq ($(GCC_VER),7)
  MIN_VER_GCC      := 7.2.0-6~
  PPA_VER_GCC      := 7.2.0
endif

ifeq ($(GCC_VER),8)
  MIN_VER_GCC      := 8.3.0-2~
  PPA_VER_GCC      := 8.3.0-2~
endif

ifndef MIN_VER_GCC
  MIN_VER_GCC      := ${GCC_VER}.0.1-0~
  #MIN_VER_GCC      := ${GCC_VER}-20160225-0~
endif

DEB_NAME_ACT     := $(shell dpkg-parsechangelog| sed -n 's/-*//; s/^Source: \(.*\)/\1/p')
DEB_SVER_ACT     := $(shell dpkg-parsechangelog| sed -n 's/-*//; s/^Version: \(.*\)/\1/p')
DEB_VER_ACT      := $(shell /bin/sh debian/new_cross_version.sh $(if $(filter $(DEB_NAME_ACT), gcc-8-cross),arm64,ppc64))
CROSS_EXT       := cross$(DEB_VER_ACT)
CROSS_EXT       := cross2

VER_GCC        := $(shell dpkg-parsechangelog -l/usr/src/gcc-${GCC_VER}/debian/changelog | awk '/^Version:/ {print $$2}' | sed 's/-[^-]*$$//')
GCC_DIR        := /usr/src/gcc-${GCC_VER}
GCC_TARBALL := $(wildcard $(GCC_DIR)/gcc-*.xz)
VER_BINUTILS   := 2.30-11
MIN_VER_BINUTILS   := 2.30-11
VER_ISL      := 0.14-1~
MIN_VER_GLIBC   := 2.27

DEB_VER_GCC    := $(shell dpkg-parsechangelog -l${GCC_DIR}/debian/changelog | egrep '^Version:' | cut -f 2 -d ' ')

CROSS_BIARCH_armhf:=armel
CROSS_BIARCH_armel:=armhf
CROSS_BIARCH_powerpc:=ppc64
CROSS_BIARCH_s390x:=s390

HOST_ARCHS_alpha = amd64 i386 x32
# FIXME: adding amd64 in HOST_ARCHS_amd64 hard codes the indep build
# to amd64 buildds ...
HOST_ARCHS_amd64 = amd64 arm64 i386 ppc64el x32
HOST_ARCHS_armhf = amd64 i386 x32 arm64 ppc64el
HOST_ARCHS_armel = amd64 i386 x32 arm64 ppc64el
HOST_ARCHS_arm64 = amd64 i386 x32 ppc64el
HOST_ARCHS_hppa = amd64 i386 x32
HOST_ARCHS_i386 = amd64 arm64 ppc64el x32
HOST_ARCHS_m68k = amd64 i386 x32
HOST_ARCHS_mips = amd64 i386 x32
HOST_ARCHS_mipsel = amd64 i386 x32
HOST_ARCHS_mipsn32 = amd64 i386 x32
HOST_ARCHS_mipsn32el = amd64 i386 x32
HOST_ARCHS_mips64 = amd64 i386 x32
HOST_ARCHS_mips64el = amd64 i386 x32
HOST_ARCHS_mipsr6 = amd64 i386 x32
HOST_ARCHS_mipsr6el = amd64 i386 x32
HOST_ARCHS_mipsn32r6 = amd64 i386 x32
HOST_ARCHS_mipsn32r6el = amd64 i386 x32
HOST_ARCHS_mips64r6 = amd64 i386 x32
HOST_ARCHS_mips64r6el = amd64 i386 x32
HOST_ARCHS_powerpc = amd64 i386 x32 ppc64el
HOST_ARCHS_powerpcspe = amd64 i386 x32
HOST_ARCHS_ppc64 = amd64 i386 x32
HOST_ARCHS_ppc64el = amd64 i386 x32 ppc64
HOST_ARCHS_riscv64 = amd64 i386 x32
HOST_ARCHS_s390x = amd64 i386 x32
HOST_ARCHS_sh4 = amd64 i386 x32
HOST_ARCHS_sparc64 = amd64 i386 x32
HOST_ARCHS_x32 = amd64 arm64 i386 ppc64el

HOST_GNU_TYPE    := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
HOST_ARCH        := $(shell dpkg-architecture -qDEB_HOST_ARCH)
stamp            := stamp-dir/

ifeq (,$(CROSS_ARCHS))
  ifeq ($(DEB_NAME_ACT),gcc-8-cross)
    ifneq (,$(filter $(HOST_ARCH),amd64 i386 x32))
      CROSS_ARCHS  = amd64
      CROSS_ARCHS  += s390x ppc64el arm64 armhf armel \
	$(if $(filter $(vendor), Ubuntu), powerpc, mips mipsel mips64el) \
        $(if $(filter $(HOST_ARCH), amd64 x32), i386)
        # $(if $(filter $(HOST_ARCH), i386 x32), amd64)
    else ifeq ($(HOST_ARCH),arm64)
      CROSS_ARCHS = amd64 armel armhf i386
    else ifeq ($(HOST_ARCH),ppc64)
      CROSS_ARCHS = ppc64el
    else ifeq ($(HOST_ARCH),ppc64el)
      CROSS_ARCHS = amd64 i386 $(if $(filter $(vendor), Ubuntu), powerpc) armel armhf arm64
    else
      CROSS_ARCHS =
    endif
    GCC_PORTS_BUILD=
  else ifeq ($(DEB_NAME_ACT),gcc-8-cross-mipsen)
    ifneq (,$(filter $(HOST_ARCH),amd64 i386 x32))
      CROSS_ARCHS  ?= mips64 \
        mipsr6 mipsr6el mips64r6 mips64r6el
      # n32: mipsn32 mipsn32el mipsn32r6 mipsn32r6el
      # have problem on ada
    endif
    GCC_PORTS_BUILD=-mipsen
  else # -ports package
    ifneq (,$(filter $(HOST_ARCH),amd64 i386 x32))
      CROSS_ARCHS  ?= alpha hppa m68k powerpcspe ppc64 riscv64 sh4 sparc64 \
		$(if $(filter $(vendor), Ubuntu), mips mipsel mips64el, powerpc) \
		$(if $(filter $(HOST_ARCH), amd64 i386), x32)
    else ifeq ($(HOST_ARCH),arm64)
      CROSS_ARCHS = x32
    else ifeq ($(HOST_ARCH),ppc64el)
      CROSS_ARCHS = x32 $(if $(filter $(vendor), Ubuntu),, powerpc)
    else
      CROSS_ARCHS =
    endif
    GCC_PORTS_BUILD=-ports
  endif
endif

CROSS_ARCH       = $(subst .,,$(suffix $@))
KERNEL_ARCH      = $(KERNEL_ARCH_$(CROSS_ARCH))
CROSS_BIARCH     = $(CROSS_BIARCH_$(CROSS_ARCH))
_gnu_type        = $(shell dpkg-architecture -a$(1) -qDEB_HOST_GNU_TYPE -f)
_pkg_gnu_type    = $(shell dpkg-architecture -a$(1) -qDEB_HOST_GNU_TYPE -f | tr _ -)
CROSS_GNU_TYPE   = $(call _gnu_type,${CROSS_ARCH})
HOST_ARCHS       = $(HOST_ARCH_$(CROSS_ARCH))
ADA_HOST_ARCHS   = $(HOST_ARCH_$(CROSS_ARCH))
ADA64_HOST_ARCHS = $(filter-out i386,$(HOST_ARCH_$(CROSS_ARCH)))

ARM32_MULTILIBS :=
ifeq ($(vendor),Ubuntu)
  ARM32_MULTILIBS := yes
endif

ifeq ($(vendor),Debian)
  skip_dbg_packages = yes
  skip_arm32ml_packages = yes
endif

libgcc_source := $(shell apt-cache show --no-all-versions libgcc1-arm64-cross | awk '/^Source:/ { print $$2 }')
#ifneq ($(DEB_NAME_ACT),$(libgcc_source))
#  skip_common_packages = yes
#endif

BINUTILS_BUILD_DEPS = $(foreach a,$(CROSS_ARCHS),binutils-$(call _pkg_gnu_type,$(a)) (>= $(MIN_VER_BINUTILS)) [$(HOST_ARCHS_$(a))]$(,))
GLIBC_BUILD_DEPS = $(foreach a,$(CROSS_ARCHS),libc6$(if $(filter $(a),alpha ia64),.1)-dev-$(a)-cross (>= $(MIN_VER_GLIBC)) [$(HOST_ARCHS_$(a))]$(,))
LINUX_BUILD_DEPS = $(foreach a,$(CROSS_ARCHS),linux-libc-dev-$(a)-cross [$(HOST_ARCHS_$(a))]$(,))

# build multilib cross compilers
ifeq ($(ARM32_MULTILIBS),yes)
  ifneq (,$(filter armel, $(CROSS_ARCHS)))
    EXTRA_BUILD_DEPS += libc6-dev-armhf-cross [$(HOST_ARCHS_armel)],
    ifeq ($(skip_common_packages),yes)
      GCC_BUILD_DEPS += libhfgcc1-armel-cross [$(HOST_ARCHS_armel)],
    endif
  endif

  ifneq (,$(filter armhf, $(CROSS_ARCHS)))
    EXTRA_BUILD_DEPS += libc6-dev-armel-cross [$(HOST_ARCHS_armhf)],
    ifeq ($(skip_common_packages),yes)
      GCC_BUILD_DEPS += libsfgcc1-armhf-cross [$(HOST_ARCHS_armhf)],
    endif
  endif
endif

ifneq (,$(filter amd64, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-i386-amd64-cross [$(HOST_ARCHS_amd64)],
  EXTRA_BUILD_DEPS += libc6-dev-x32-amd64-cross [$(HOST_ARCHS_amd64)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-amd64-cross [$(HOST_ARCHS_amd64)],
    GCC_BUILD_DEPS += libx32gcc1-amd64-cross [$(HOST_ARCHS_amd64)],
  endif
endif

ifneq (,$(filter i386, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-amd64-i386-cross [$(HOST_ARCHS_i386)],
  EXTRA_BUILD_DEPS += libc6-dev-x32-i386-cross [$(HOST_ARCHS_i386)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-i386-cross [$(HOST_ARCHS_i386)],
    GCC_BUILD_DEPS += libx32gcc1-i386-cross [$(HOST_ARCHS_i386)],
  endif
endif

ifneq (,$(filter x32, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-i386-x32-cross [$(HOST_ARCHS_x32)],
  EXTRA_BUILD_DEPS += libc6-dev-amd64-x32-cross [$(HOST_ARCHS_x32)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-x32-cross [$(HOST_ARCHS_x32)],
    GCC_BUILD_DEPS += lib64gcc1-x32-cross [$(HOST_ARCHS_x32)],
  endif
endif

ifneq (,$(filter ppc64, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-powerpc-ppc64-cross [$(HOST_ARCHS_ppc64)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-ppc64-cross [$(HOST_ARCHS_ppc64)],
  endif
endif

ifneq (,$(filter s390x, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-s390-s390x-cross [$(HOST_ARCHS_s390x)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-s390x-cross [$(HOST_ARCHS_s390x)],
  endif
endif

ifneq (,$(filter sparc64, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-sparc-sparc64-cross [$(HOST_ARCHS_sparc64)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-sparc64-cross [$(HOST_ARCHS_sparc64)],
  endif
endif

ifneq (,$(filter powerpc, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-ppc64-powerpc-cross [$(HOST_ARCHS_powerpc)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-powerpc-cross [$(HOST_ARCHS_powerpc)],
  endif
endif

ifneq (,$(filter mips, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mips-cross [$(HOST_ARCHS_mips)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mips-cross [$(HOST_ARCHS_mips)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-mips-cross [$(HOST_ARCHS_mips)],
    GCC_BUILD_DEPS += libn32gcc1-mips-cross [$(HOST_ARCHS_mips)],
  endif
endif

ifneq (,$(filter mipsel, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsel-cross [$(HOST_ARCHS_mipsel)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mipsel-cross [$(HOST_ARCHS_mipsel)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-mipsel-cross [$(HOST_ARCHS_mipsel)],
    GCC_BUILD_DEPS += libn32gcc1-mipsel-cross [$(HOST_ARCHS_mipsel)],
  endif
endif

ifneq (,$(filter mipsn32, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mipsn32-cross [$(HOST_ARCHS_mipsn32)],
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsn32-cross [$(HOST_ARCHS_mipsn32)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mipsn32-cross [$(HOST_ARCHS_mipsn32)],
    GCC_BUILD_DEPS += lib64gcc1-mipsn32-cross [$(HOST_ARCHS_mipsn32)],
  endif
endif

ifneq (,$(filter mipsn32el, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mipsn32el-cross [$(HOST_ARCHS_mipsn32el)],
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsn32el-cross [$(HOST_ARCHS_mipsn32el)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mipsn32el-cross [$(HOST_ARCHS_mipsn32el)],
    GCC_BUILD_DEPS += lib64gcc1-mipsn32el-cross [$(HOST_ARCHS_mipsn32el)],
  endif
endif

ifneq (,$(filter mips64, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mips64-cross [$(HOST_ARCHS_mips64)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mips64-cross [$(HOST_ARCHS_mips64)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mips64-cross [$(HOST_ARCHS_mips64)],
    GCC_BUILD_DEPS += libn32gcc1-mips64-cross [$(HOST_ARCHS_mips64)],
  endif
endif

ifneq (,$(filter mips64el, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mips64el-cross [$(HOST_ARCHS_mips64el)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mips64el-cross [$(HOST_ARCHS_mips64el)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mips64el-cross [$(HOST_ARCHS_mips64el)],
    GCC_BUILD_DEPS += libn32gcc1-mips64el-cross [$(HOST_ARCHS_mips64el)],
  endif
endif

ifneq (,$(filter mipsr6, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsr6-cross [$(HOST_ARCHS_mipsr6)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mipsr6-cross [$(HOST_ARCHS_mipsr6)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-mipsr6-cross [$(HOST_ARCHS_mipsr6)],
    GCC_BUILD_DEPS += libn32gcc1-mipsr6-cross [$(HOST_ARCHS_mipsr6)],
  endif
endif

ifneq (,$(filter mipsr6el, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsr6el-cross [$(HOST_ARCHS_mipsr6el)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mipsr6el-cross [$(HOST_ARCHS_mipsr6el)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib64gcc1-mipsr6el-cross [$(HOST_ARCHS_mipsr6el)],
    GCC_BUILD_DEPS += libn32gcc1-mipsr6el-cross [$(HOST_ARCHS_mipsr6el)],
  endif
endif

ifneq (,$(filter mipsn32r6, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mipsn32r6-cross [$(HOST_ARCHS_mipsn32r6)],
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsn32r6-cross [$(HOST_ARCHS_mipsn32r6)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mipsn32r6-cross [$(HOST_ARCHS_mipsn32r6)],
    GCC_BUILD_DEPS += lib64gcc1-mipsn32r6-cross [$(HOST_ARCHS_mipsn32r6)],
  endif
endif

ifneq (,$(filter mipsn32r6el, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mipsn32r6el-cross [$(HOST_ARCHS_mipsn32r6el)],
  EXTRA_BUILD_DEPS += libc6-dev-mips64-mipsn32r6el-cross [$(HOST_ARCHS_mipsn32r6el)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mipsn32r6el-cross [$(HOST_ARCHS_mipsn32r6el)],
    GCC_BUILD_DEPS += lib64gcc1-mipsn32r6el-cross [$(HOST_ARCHS_mipsn32r6el)],
  endif
endif

ifneq (,$(filter mips64r6, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mips64r6-cross [$(HOST_ARCHS_mips64r6)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mips64r6-cross [$(HOST_ARCHS_mips64r6)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mips64r6-cross [$(HOST_ARCHS_mips64r6)],
    GCC_BUILD_DEPS += libn32gcc1-mips64r6-cross [$(HOST_ARCHS_mips64r6)],
  endif
endif

ifneq (,$(filter mips64r6el, $(CROSS_ARCHS)))
  EXTRA_BUILD_DEPS += libc6-dev-mips32-mips64r6el-cross [$(HOST_ARCHS_mips64r6el)],
  EXTRA_BUILD_DEPS += libc6-dev-mipsn32-mips64r6el-cross [$(HOST_ARCHS_mips64r6el)],
  ifeq ($(skip_common_packages),yes)
    GCC_BUILD_DEPS += lib32gcc1-mips64r6el-cross [$(HOST_ARCHS_mips64r6el)],
    GCC_BUILD_DEPS += libn32gcc1-mips64r6el-cross [$(HOST_ARCHS_mips64r6el)],
  endif
endif

PHOBOS_ARCHS = amd64 i386 x32 armel armhf
PHOBOS_DEP = libgphobos-GCC_VER-dev-CROSS_ARCH-cross (= $${gcc:Version}),
# FIXME: Set correctly ...
PHOBOS_ML_DEP = libgphobos-GCC_VER-dev-CROSS_ARCH-cross (= $${gcc:Version}),


info:
	@echo "Package name:             ${DEB_NAME_ACT} ${DEB_VER_ACT}"
	@echo
	@echo "GCC ${GCC_VER} version:          ${VER_GCC}     	${DEB_VER_GCC}"
	@echo
	@echo "Target architecture:      ${CROSS_ARCH}"
	@echo "Target GNU type:          ${CROSS_GNU_TYPE}"
	@echo "Host architecture:        ${HOST_ARCH}"
	@echo "Host GNU type:            ${HOST_GNU_TYPE}"
	@echo "skips (debug/common/armml): $(skip_dbg_packages)/$(skip_common_packages)/$(skip_arm32ml_packages)"

$(stamp)init-gcc:
	@echo START $@
	mkdir -p gcc
	set -ex; \
	cd gcc ; \
	ln -sf $(GCC_TARBALL) $(notdir $(GCC_TARBALL)) ;\
	cp -a  $(GCC_DIR)/debian/ . ; \
	if [ -n "$$(grep -v '^\#' $(CURDIR)/debian/patches/gcc-$(GCC_VER)/series)" ]; then \
	  QUILT_PATCHES=$(CURDIR)/debian/patches/gcc-$(GCC_VER) quilt push --quiltrc /dev/null -a ; \
	fi
#	set -ex; \
#	if dpkg --compare-versions $(DEB_VER_GCC) le 8.1.0-3; then \
#	  cd gcc; \
#	  patch -p1 < ../debian/patches/gcc-8/updates.diff; \
#	fi
	touch $@

$(stamp)build-gcc.%: $(stamp)init-gcc
	@echo START $@
	@if [ "$(HOST_ARCH)" = "$(CROSS_ARCH)" ] && [ "X$(dbp_flag)" = X-B ]; then \
	  echo "Skipping binary-arch build for $(CROSS_ARCH)"; \
	else \
	  set -x; \
	  echo ${CROSS_ARCH} >gcc/debian/target; \
	  cd gcc && \
	    WITH_SYSROOT=/ \
	    PKG_IGNORE_CURRENTLY_BUILDING=1 \
	    BACKPORT=false \
	    WITHOUT_LANG="hppa64 jit nvptx" \
	    $(if $(filter $(HOST_ARCH),$(CROSS_ARCH)),FORCE_CROSS_LAYOUT=yes WITH_BOOTSTRAP=off) \
	    GCC_PORTS_BUILD=$(GCC_PORTS_BUILD) \
	    dpkg-buildpackage $(if $(filter $(HOST_ARCH),$(CROSS_ARCH)),$(subst -b,-A,$(dbp_flag)),$(dbp_flag)) -uc -us -d; \
	fi
	touch $@

clean:
	rm -rf gcc tmp-*
	rm -f  *.*deb *.changes *.buildinfo debian/files
	rm -rf $(stamp)
	mkdir $(stamp)
	dh_clean


$(stamp)repack-%:
	@umask 022; \
	if [ -z "$(TARGET_ARCH)" ]; then \
	  echo >&2 "repack: macro TARGET_ARCH not set"; \
	  exit 1; \
	fi; \
	t_arch=$(TARGET_ARCH); \
	t_gnu_type=$(call _gnu_type,$(TARGET_ARCH)); \
	deb=$*; \
	pkgname=`echo $$deb | cut -d'_' -f1`; \
	tmp=tmp-$$pkgname; \
	if [ "$(skip_dbg_packages)" = yes ]; then \
	  case $$deb in *-dbg*) exit 0; esac; \
	fi; \
	echo "repack $$pkgname ($$deb) ..."; \
	rm -rf $$tmp; \
	mkdir -p $$tmp; \
	dpkg-deb -x $$deb $$tmp; \
	dpkg-deb -e $$deb $$tmp/DEBIAN; \
	sed -i -e's/^Source:.*/Source: $(DEB_NAME_ACT) ($(DEB_SVER_ACT))/' \
	  -e "/^Depends:/s/$(DEB_VER_GCC)/$(DEB_VER_GCC)$(CROSS_EXT)/g" \
	  -e "/^Recommends:/s/$(DEB_VER_GCC)/$(DEB_VER_GCC)$(CROSS_EXT)/g" \
	  -e "/^Suggests:/s/$(DEB_VER_GCC)/$(DEB_VER_GCC)$(CROSS_EXT)/g" \
	  -e "/^Version:/s/$(DEB_VER_GCC)/$(DEB_VER_GCC)$(CROSS_EXT)/" \
	  $$tmp/DEBIAN/control ; \
	sed -i -e "/^Depends:/s/\(libgnat-[0-9]*\) (>= $(DEB_VER_GCC)$(CROSS_EXT))/\1 (>= $(VER_GCC))/g" \
	  $$tmp/DEBIAN/control ; \
	sed -i -e "/^Depends:/s/\(libgnatvsn[0-9]*\) (>= $(DEB_VER_GCC)$(CROSS_EXT))/\1 (>= $(VER_GCC))/g" \
	  $$tmp/DEBIAN/control ; \
	case $$pkgname in \
	  gcc-$(GCC_VER)-$${t_gnu_type}) \
	    sed -i -e '/Depends/s/\(libcc1[^,]*\)$(CROSS_EXT)/\1/' \
	      $$tmp/DEBIAN/control;; \
	  *-cross) \
	    sed -i -e '/^Depends:/s/\(-base *( *\)=\([^)]*\)cross[^)]*)/\1>=\2)/' \
	      $$tmp/DEBIAN/control;; \
	esac; \
	install -d -m 755 $$tmp/usr/share/lintian/overrides; \
	if [ -e debian/overrides/$$pkgname ]; then \
	  cp debian/overrides/$$pkgname $$tmp/usr/share/lintian/overrides/; \
	fi; \
	case "$$pkgname" in \
	  gcc-$(GCC_VER)-cross-base*) \
	    ;; \
	  gcc-$(GCC_VER)-multilib) \
	    echo "$$pkgname binary: binary-from-other-architecture" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname \
	    ;; \
	  gccgo-$(GCC_VER)*) \
	    echo "$$pkgname binary: binary-from-other-architecture" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: non-standard-dir-in-usr" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    ;; \
	  *-multilib-*) \
	    ;; \
	  cpp-*|g++-*|gcc-*|gccgo-*|gdc-*|gfortran-*|gobjc*|gnat-$(GCC_VER)-sjlj-*) \
	    echo "$$pkgname binary: binary-from-other-architecture" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname \
	    ;; \
	  gnat-$(GCC_VER)-*) \
	    echo "$$pkgname binary: binary-from-other-architecture" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: non-standard-dir-in-usr" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    ;; \
	  *-dev-$${t_arch}-cross) \
	    echo "$$pkgname binary: arch-independent-package-contains-binary-or-object" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: non-standard-dir-in-usr" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    ;; \
	  *-dbg-$${t_arch}-cross) \
	    echo "$$pkgname binary: arch-independent-package-contains-binary-or-object" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: debug-package-should-be-named-dbg" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: non-standard-dir-in-usr" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    ;; \
	  *-pic-$${t_arch}-cross) \
	    echo "$$pkgname binary: arch-independent-package-contains-binary-or-object" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    ;; \
	  *-$${t_arch}-cross) \
	    echo "$$pkgname binary: arch-independent-package-contains-binary-or-object" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: non-standard-dir-in-usr" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: shlibs-declares-dependency-on-other-package" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: postinst-has-useless-call-to-ldconfig" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    echo "$$pkgname binary: postrm-has-useless-call-to-ldconfig" \
	      >> $$tmp/usr/share/lintian/overrides/$$pkgname; \
	    case "$$pkgname" in \
	      *-hppa-cross) \
	        echo "$$pkgname binary: binary-compiled-with-profiling-enabled" \
	          >> $$tmp/usr/share/lintian/overrides/$$pkgname;; \
	      libgphobos*) \
	        echo "$$pkgname binary: embedded-library" \
	          >> $$tmp/usr/share/lintian/overrides/$$pkgname;; \
	    esac; \
	    ;; \
	esac; \
	if [ -e $$tmp/usr/share/doc/gcc-${GCC_VER}-$${t_gnu_type}-base/changelog.Debian.gz ]; then \
	  mv $$tmp/usr/share/doc/gcc-${GCC_VER}-$${t_gnu_type}-base/changelog.Debian.gz \
	     $$tmp/usr/share/doc/gcc-${GCC_VER}-$${t_gnu_type}-base/changelog.Debian.gcc-${GCC_VER}.gz; \
	  gzip -c9n debian/changelog \
	    > $$tmp/usr/share/doc/gcc-${GCC_VER}-$${t_gnu_type}-base/changelog.Debian.gz;\
	fi ; \
	rm -f $$tmp/DEBIAN/md5sums; \
	(cd $$tmp && find usr -type f | LC_ALL=C sort | xargs -r md5sum >>DEBIAN/md5sums); \
	find $$tmp/DEBIAN -name md5sums -empty | xargs -r rm -f; \
	newdeb=`echo $$deb|sed -e "s/\(.*\)_\(.*\)_\(.*\)/\1_\2$(CROSS_EXT)_\3/g"`; \
	NO_PKG_MANGLE=1 dpkg-deb -b $$tmp ../$$newdeb; \
	rm -rf $$tmp
	touch $@

$(stamp)repack-debs-arch: $(stamp)build
	@echo START $@
	dh_testroot
	$(MAKE) $(NJOBS) -f debian/rules TARGET_ARCH=$(HOST_ARCH) \
		$(addprefix $(stamp)repack-,$(wildcard *_$(HOST_ARCH).deb))
	$(MAKE) $(NJOBS) -f debian/rules TARGET_ARCH=$(HOST_ARCH) \
		$(addprefix $(stamp)repack-,$(wildcard *$(DEB_VER_GCC)_$(HOST_ARCH).ddeb))
	rm -f *$(DEB_VER_GCC)_$(HOST_ARCH).ddeb
	if [ -f ../gcc-$(GCC_VER)-$(call _gnu_type,$(HOST_ARCH))-dbgsym_${DEB_VER_GCC}$(CROSS_EXT)_$(HOST_ARCH).ddeb ]; then mv -f ../*.ddeb . ; fi
	touch $@

$(stamp)repack-debs-indep: $(stamp)build
	@echo START $@
	dh_testroot
	set -e; \
	$(foreach arch,$(CROSS_ARCHS), \
	  $(MAKE) $(NJOBS) -f debian/rules TARGET_ARCH=$(arch) \
		$(addprefix $(stamp)repack-,$(wildcard *-$(arch)-cross_*_all.deb)); \
	)
	$(MAKE) $(NJOBS) -f debian/rules TARGET_ARCH=$(HOST_ARCH) \
		$(addprefix $(stamp)repack-,$(wildcard gcc-$(GCC_VER)-cross-base$(GCC_PORTS_BUILD)_*_all.deb))
	touch $@

build: $(stamp)build
$(stamp)build: $(foreach arch,$(CROSS_ARCHS),$(addsuffix .$(arch),$(stamp)build-gcc))
	@echo START $@
	touch $@

build: dbp_flag = -b
build-arch: dbp_flag = -B
build-indep: dbp_flag = -b

build-arch: $(stamp)build
build-indep: $(stamp)build

binary: binary-arch binary-indep
binary-arch:  build-arch $(stamp)build $(stamp)repack-debs-arch $(stamp)mangle-debian-files-arch
binary-indep: build-indep $(stamp)build $(stamp)repack-debs-indep $(stamp)mangle-debian-files-indep

define generate_debian_files
	touch debian/files
	for deb in $1; do \
	  [ -f "$$deb" ] || continue; \
	  pkg=`basename $$deb`; \
	  if [ "$(skip_dbg_packages)" = yes ]; then \
	    case $$pkg in *-dbg*) continue; esac; \
	  fi; \
	  if [ "$(skip_arm32ml_packages)" = yes ] && grep -q "^$$pkg$$" debian/packages.arm32ml; then \
	    continue; \
	  fi; \
	  if [ "$(skip_common_packages)" = yes ] && grep -q "^$$pkg$$" debian/packages.common; then \
	    continue; \
	  fi; \
	  echo -n "$$pkg " >>debian/files; \
	  dpkg-deb -I $$deb | grep Section  | cut -d ' ' -f 3 | tr "\n" ' ' >>debian/files; \
	  dpkg-deb -I $$deb | grep Priority | cut -d ' ' -f 3 | tr -d "\n" >>debian/files; \
	  echo "" >>debian/files; \
	done
endef

$(stamp)mangle-debian-files-arch: build $(stamp)repack-debs-arch $(stamp)debian-files-base
	@echo START $@
	$(call generate_debian_files, *_$(HOST_ARCH).deb)
	sed -i -e "s/${DEB_VER_GCC}_/${DEB_VER_GCC}$(CROSS_EXT)_/g" debian/files
	touch $@

$(stamp)mangle-debian-files-indep: $(stamp)repack-debs-indep $(stamp)debian-files-base
	@echo START $@
	$(call generate_debian_files, *_all.deb)
	sed -i -e "s/${DEB_VER_GCC}_/${DEB_VER_GCC}$(CROSS_EXT)_/g" debian/files
	touch $@

$(stamp)debian-files-base:
	@echo START $@
	rm -f debian/files
	touch $@


control:
	sed -e "s/MIN_VER_GCC/${MIN_VER_GCC}/g" \
	    -e "s/GCC_BUILD_DEPS/$(GCC_BUILD_DEPS)/g" \
	    -e "s/BINUTILS_BUILD_DEPS/$(BINUTILS_BUILD_DEPS)/g" \
	    -e "s/GLIBC_BUILD_DEPS/$(GLIBC_BUILD_DEPS)/g" \
	    -e "s/EXTRA_BUILD_DEPS/${EXTRA_BUILD_DEPS}/g" \
	    -e "s/LINUX_BUILD_DEPS/$(LINUX_BUILD_DEPS)/g" \
	    -e "s/GCC_VER/${GCC_VER}/g" \
	    -e "s/MIN_VER_BINUTILS/${MIN_VER_BINUTILS}/g" \
	    -e "s/VER_BINUTILS/${VER_BINUTILS}/g" \
	    -e "s/VER_ISL/${VER_ISL}/g" \
	    -e "s/GCC_PORTS_BUILD/$(GCC_PORTS_BUILD)/g" \
	    $(CURDIR)/debian/control.source.in >$(CURDIR)/debian/control

	$(foreach a,$(CROSS_ARCHS), \
	  sed \
	    -e 's/PHOBOS_DEP/$(if $(filter $(a),$(PHOBOS_ARCHS)),${PHOBOS_DEP})/g' \
	    -e 's/PHOBOS_ML_DEP/$(if $(filter $(a),$(PHOBOS_ARCHS)),${PHOBOS_ML_DEP})/g' \
	    -e 's/CROSS_ARCH/$(a)/g' \
	    -e 's/CROSS_GNU_TYPE/$(call _pkg_gnu_type,$(a))/g' \
	    -e 's/MIN_VER_GCC/${MIN_VER_GCC}/g' \
	    -e 's/GCC_VER/${GCC_VER}/g' \
	    -e 's/MIN_VER_BINUTILS/${MIN_VER_BINUTILS}/g' \
	    -e 's/@host_archs@/$(filter-out $(a),$(HOST_ARCHS_$(a)))/g' \
	    -e 's/@ada_host_archs@/$(filter-out $(a),$(HOST_ARCHS_$(a)))/g' \
	    -e 's/@ada64_host_archs@/$(filter-out $(a),$(filter-out XXXi386,$(HOST_ARCHS_$(a))))/g' \
	    $(CURDIR)/debian/control.$(a).in >>$(CURDIR)/debian/control; )

	python3 debian/remove-unbuilt \
	  $(if $(filter yes,$(skip_dbg_packages)), --skip-dbg-packages) \
	  $(if $(filter yes,$(skip_arm32ml_packages)), --skip-arm32ml-packages) \
	  $(if $(filter yes,$(skip_common_packages)), --skip-common-packages) \
	  debian/control debian/packages.invalid debian/packages.arm32ml debian/packages.common \
	  > debian/control.new && mv debian/control.new debian/control

sort-pkgfiles:
	for i in packages.arm32ml packages.common packages.invalid; do \
	  LC_ALL=C sort -u debian/$$i > debian/$$i.tmp; \
	  mv -f debian/$$i.tmp debian/$$i; \
	done

.PRECIOUS: $(stamp)init-dirs \
	$(stamp)init-gcc \
	$(stamp)build \
	$(stamp)build-gcc.% \
	$(stamp)debian-files-base \
	$(stamp)repack-debs-arch \
	$(stamp)repack-debs-indep \
	$(stamp)repack-debs-indep.% \
	$(stamp)mangle-debian-files-arch
	$(stamp)mangle-debian-files-indep \
	build build-arch build-indep binary binary-arch binary-indep