jdk

Форк
0
/
Tools.gmk 
724 строки · 22.1 Кб
1
#
2
# Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
#
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation.  Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
10
#
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
16
#
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
#
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
23
# questions.
24
#
25

26
##########################################################################################
27
#
28
# Workhorse makefile for creating ONE cross compiler
29
# Needs either to be from BUILD -> BUILD OR have
30
# BUILD -> HOST prebuilt
31
#
32
# NOTE: There is a bug here. We don't limit the
33
# PATH when building BUILD -> BUILD, which means that
34
# if you configure after you've once build the BUILD->BUILD
35
# compiler THAT one will be picked up as the compiler for itself.
36
# This is not so great, especially if you did a partial delete
37
# of the target tree.
38
#
39
# Fix this...
40
#
41

42
$(info TARGET=$(TARGET))
43
$(info HOST=$(HOST))
44
$(info BUILD=$(BUILD))
45

46
ARCH := $(word 1,$(subst -, ,$(TARGET)))
47

48
ifeq ($(TARGET), arm-linux-gnueabihf)
49
  ARCH=armhfp
50
endif
51

52
$(info ARCH=$(ARCH))
53

54
KERNEL_HEADERS_RPM := kernel-headers
55

56
ifeq ($(BASE_OS), OL)
57
  ifeq ($(ARCH), aarch64)
58
    BASE_URL := https://yum.oracle.com/repo/OracleLinux/OL7/6/base/$(ARCH)/
59
    LINUX_VERSION := OL7.6
60
    KERNEL_HEADERS_RPM := kernel-uek-headers
61
  else
62
    BASE_URL := https://yum.oracle.com/repo/OracleLinux/OL6/4/base/$(ARCH)/
63
    LINUX_VERSION := OL6.4
64
  endif
65
else ifeq ($(BASE_OS), Fedora)
66
  ifeq ($(ARCH), riscv64)
67
    DEFAULT_OS_VERSION := rawhide/68692
68
    ifeq ($(BASE_OS_VERSION), )
69
      BASE_OS_VERSION := $(DEFAULT_OS_VERSION)
70
    endif
71
    BASE_URL := http://fedora.riscv.rocks/repos-dist/$(BASE_OS_VERSION)/$(ARCH)/Packages/
72
  else
73
    DEFAULT_OS_VERSION := 27
74
    LATEST_ARCHIVED_OS_VERSION := 35
75
    ifeq ($(BASE_OS_VERSION), )
76
      BASE_OS_VERSION := $(DEFAULT_OS_VERSION)
77
    endif
78
    ifeq ($(filter x86_64 armhfp, $(ARCH)), )
79
      FEDORA_TYPE := fedora-secondary
80
    else
81
      FEDORA_TYPE := fedora/linux
82
    endif
83
    NOT_ARCHIVED := $(shell [ $(BASE_OS_VERSION) -gt $(LATEST_ARCHIVED_OS_VERSION) ] && echo true)
84
    ifeq ($(NOT_ARCHIVED),true)
85
      BASE_URL := https://dl.fedoraproject.org/pub/$(FEDORA_TYPE)/releases/$(BASE_OS_VERSION)/Everything/$(ARCH)/os/Packages/
86
    else
87
      BASE_URL := https://archives.fedoraproject.org/pub/archive/$(FEDORA_TYPE)/releases/$(BASE_OS_VERSION)/Everything/$(ARCH)/os/Packages/
88
    endif
89
  endif
90
  LINUX_VERSION := Fedora_$(BASE_OS_VERSION)
91
else
92
  $(error Unknown base OS $(BASE_OS))
93
endif
94

95
##########################################################################################
96
# Define external dependencies
97

98
# Latest that could be made to work.
99
GCC_VER := 13.2.0
100
ifeq ($(GCC_VER), 13.2.0)
101
  gcc_ver := gcc-13.2.0
102
  binutils_ver := binutils-2.41
103
  ccache_ver := ccache-3.7.12
104
  mpfr_ver := mpfr-4.2.0
105
  gmp_ver := gmp-6.3.0
106
  mpc_ver := mpc-1.3.1
107
  gdb_ver := gdb-13.2
108
  REQUIRED_MIN_MAKE_MAJOR_VERSION := 4
109
else ifeq ($(GCC_VER), 11.3.0)
110
  gcc_ver := gcc-11.3.0
111
  binutils_ver := binutils-2.39
112
  ccache_ver := ccache-3.7.12
113
  mpfr_ver := mpfr-4.1.1
114
  gmp_ver := gmp-6.2.1
115
  mpc_ver := mpc-1.2.1
116
  gdb_ver := gdb-11.2
117
  REQUIRED_MIN_MAKE_MAJOR_VERSION := 4
118
else ifeq ($(GCC_VER), 11.2.0)
119
  gcc_ver := gcc-11.2.0
120
  binutils_ver := binutils-2.37
121
  ccache_ver := ccache-3.7.12
122
  mpfr_ver := mpfr-4.1.0
123
  gmp_ver := gmp-6.2.1
124
  mpc_ver := mpc-1.2.1
125
  gdb_ver := gdb-11.1
126
  REQUIRED_MIN_MAKE_MAJOR_VERSION := 4
127
else ifeq ($(GCC_VER), 10.3.0)
128
  gcc_ver := gcc-10.3.0
129
  binutils_ver := binutils-2.36.1
130
  ccache_ver := ccache-3.7.11
131
  mpfr_ver := mpfr-4.1.0
132
  gmp_ver := gmp-6.2.0
133
  mpc_ver := mpc-1.1.0
134
  gdb_ver := gdb-10.1
135
  REQUIRED_MIN_MAKE_MAJOR_VERSION := 4
136
else ifeq ($(GCC_VER), 10.2.0)
137
  gcc_ver := gcc-10.2.0
138
  binutils_ver := binutils-2.35
139
  ccache_ver := ccache-3.7.11
140
  mpfr_ver := mpfr-4.1.0
141
  gmp_ver := gmp-6.2.0
142
  mpc_ver := mpc-1.1.0
143
  gdb_ver := gdb-9.2
144
  REQUIRED_MIN_MAKE_MAJOR_VERSION := 4
145
else ifeq ($(GCC_VER), 9.2.0)
146
  gcc_ver := gcc-9.2.0
147
  binutils_ver := binutils-2.34
148
  ccache_ver := ccache-3.7.3
149
  mpfr_ver := mpfr-3.1.5
150
  gmp_ver := gmp-6.1.2
151
  mpc_ver := mpc-1.0.3
152
  gdb_ver := gdb-8.3
153
else ifeq ($(GCC_VER), 8.3.0)
154
  gcc_ver := gcc-8.3.0
155
  binutils_ver := binutils-2.32
156
  ccache_ver := ccache-3.7.3
157
  mpfr_ver := mpfr-3.1.5
158
  gmp_ver := gmp-6.1.2
159
  mpc_ver := mpc-1.0.3
160
  gdb_ver := gdb-8.3
161
else ifeq ($(GCC_VER), 7.3.0)
162
  gcc_ver := gcc-7.3.0
163
  binutils_ver := binutils-2.30
164
  ccache_ver := ccache-3.3.6
165
  mpfr_ver := mpfr-3.1.5
166
  gmp_ver := gmp-6.1.2
167
  mpc_ver := mpc-1.0.3
168
  gdb_ver := gdb-8.1
169
else ifeq ($(GCC_VER), 4.9.2)
170
  gcc_ver := gcc-4.9.2
171
  binutils_ver := binutils-2.25
172
  ccache_ver := ccache-3.2.1
173
  mpfr_ver := mpfr-3.0.1
174
  gmp_ver := gmp-4.3.2
175
  mpc_ver := mpc-1.0.1
176
  gdb_ver := gdb-7.12.1
177
else
178
  $(error Unsupported GCC version)
179
endif
180

181
ifneq ($(REQUIRED_MIN_MAKE_MAJOR_VERSION),)
182
  MAKE_MAJOR_VERSION := $(word 1,$(subst ., ,$(MAKE_VERSION)))
183
  SUPPORTED_MAKE_VERSION := $(shell [ $(MAKE_MAJOR_VERSION) -ge $(REQUIRED_MIN_MAKE_MAJOR_VERSION) ] && echo true)
184
  ifneq ($(SUPPORTED_MAKE_VERSION),true)
185
    $(error "Make v$(MAKE_VERSION) is too old, must use v$(REQUIRED_MIN_MAKE_MAJOR_VERSION) or above")
186
  endif
187
endif
188

189
ccache_ver_only := $(patsubst ccache-%,%,$(ccache_ver))
190

191

192
GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz
193
BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.gz
194
CCACHE := https://github.com/ccache/ccache/releases/download/v$(ccache_ver_only)/$(ccache_ver).tar.xz
195
MPFR := https://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2
196
GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2
197
MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz
198
GDB := http://ftp.gnu.org/gnu/gdb/${gdb_ver}.tar.xz
199

200
# RPMs used by all BASE_OS
201
RPM_LIST := \
202
    $(KERNEL_HEADERS_RPM) \
203
    glibc glibc-headers glibc-devel \
204
    cups-libs cups-devel \
205
    libX11 libX11-devel \
206
    xorg-x11-proto-devel \
207
    alsa-lib alsa-lib-devel \
208
    libXext libXext-devel \
209
    libXtst libXtst-devel \
210
    libXrender libXrender-devel \
211
    libXrandr libXrandr-devel \
212
    freetype freetype-devel \
213
    libXt libXt-devel \
214
    libSM libSM-devel \
215
    libICE libICE-devel \
216
    libXi libXi-devel \
217
    libXdmcp libXdmcp-devel \
218
    libXau libXau-devel \
219
    libgcc libxcrypt \
220
    zlib zlib-devel \
221
    libffi libffi-devel \
222
    fontconfig fontconfig-devel \
223
    systemtap-sdt-devel \
224
    #
225

226
##########################################################################################
227
# Define common directories and files
228

229
# Ensure we have 32-bit libs also for x64. We enable mixed-mode.
230
ifeq (x86_64,$(ARCH))
231
  LIBDIRS := lib64 lib
232
  CFLAGS_lib := -m32
233
else
234
  LIBDIRS := lib
235
endif
236

237
# Define directories
238
BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET)
239
TARGETDIR := $(PREFIX)/$(TARGET)
240
SYSROOT := $(TARGETDIR)/sysroot
241
DOWNLOAD := $(OUTPUT_ROOT)/download
242
DOWNLOAD_RPMS := $(DOWNLOAD)/rpms/$(TARGET)-$(LINUX_VERSION)
243
SRCDIR := $(OUTPUT_ROOT)/src
244

245
# Marker file for unpacking rpms
246
rpms := $(SYSROOT)/rpms_unpacked
247

248
# Need to patch libs that are linker scripts to use non-absolute paths
249
libs := $(SYSROOT)/libs_patched
250

251
################################################################################
252
# Download RPMs
253
download-rpms:
254
	mkdir -p $(DOWNLOAD_RPMS)
255
        # Only run this if rpm dir is empty.
256
        ifeq ($(wildcard $(DOWNLOAD_RPMS)/*.rpm), )
257
	  cd $(DOWNLOAD_RPMS) && \
258
	      wget -r -np -nd $(patsubst %, -A "*%*.rpm", $(RPM_LIST)) $(BASE_URL)
259
        endif
260

261
##########################################################################################
262
# Unpack source packages
263

264
# Generate downloading + unpacking of sources.
265
define Download
266
  # Allow override
267
  $(1)_DIRNAME ?= $(basename $(basename $(notdir $($(1)))))
268
  $(1)_DIR = $(abspath $(SRCDIR)/$$($(1)_DIRNAME))
269
  $(1)_CFG = $$($(1)_DIR)/configure
270
  $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1)))
271

272
  $$($(1)_CFG) : $$($(1)_FILE)
273
	mkdir -p $$(SRCDIR)
274
	tar -C $$(SRCDIR) -xf $$<
275
	$$(foreach p,$$(abspath $$(wildcard patches/$$(ARCH)-$$(notdir $$($(1)_DIR)).patch)), \
276
	  echo PATCHING $$(p) ; \
277
	  patch -d $$($(1)_DIR) -p1 -i $$(p) ; \
278
	)
279
	touch $$@
280

281
  $$($(1)_FILE) :
282
	wget -P $(DOWNLOAD) $$($(1))
283
endef
284

285
# Download and unpack all source packages
286
$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC GDB,$(eval $(call Download,$(p))))
287

288
##########################################################################################
289
# Unpack RPMS
290

291
RPM_ARCHS := $(ARCH) noarch
292
ifeq ($(ARCH),x86_64)
293
  # Enable mixed mode.
294
  RPM_ARCHS += i386 i686
295
else ifeq ($(ARCH),i686)
296
  RPM_ARCHS += i386
297
else ifeq ($(ARCH), armhfp)
298
  RPM_ARCHS += armv7hl
299
endif
300

301
RPM_FILE_LIST := $(sort $(foreach a, $(RPM_ARCHS), \
302
  $(wildcard $(patsubst %,$(DOWNLOAD_RPMS)/%*$a.rpm,$(RPM_LIST))) \
303
))
304

305
# Note. For building linux you should install rpm2cpio.
306
define unrpm
307
  $(SYSROOT)/$(notdir $(1)).unpacked : $(1)
308
  $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked
309
endef
310

311
%.unpacked :
312
	$(info Unpacking target rpms and libraries from $<)
313
	@(mkdir -p $(@D); \
314
	cd $(@D); \
315
	rpm2cpio $< | \
316
	    cpio --extract --make-directories \
317
	        -f \
318
	        "./usr/share/doc/*" \
319
	        "./usr/share/man/*" \
320
	        "./usr/X11R6/man/*" \
321
	        "*/X11/locale/*" \
322
	    || die ; )
323
	touch $@
324

325
$(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p))))
326

327
##########################################################################################
328

329
# Note: MUST create a <sysroot>/usr/lib even if not really needed.
330
# gcc will use a path relative to it to resolve lib64. (x86_64).
331
# we're creating multi-lib compiler with 32bit libc as well, so we should
332
# have it anyway, but just to make sure...
333
# Patch libc.so and libpthread.so to force linking against libraries in sysroot
334
# and not the ones installed on the build machine.
335
$(libs) : $(rpms)
336
	@echo Patching libc and pthreads
337
	@(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \
338
	  (cat $$f | sed -e 's|/usr/lib64/||g' \
339
	      -e 's|/usr/lib/||g' \
340
	      -e 's|/lib64/||g' \
341
	      -e 's|/lib/||g' ) > $$f.tmp ; \
342
	  mv $$f.tmp $$f ; \
343
	done)
344
	@mkdir -p $(SYSROOT)/usr/lib
345
	@touch $@
346

347
##########################################################################################
348
# Create links for ffi header files so that they become visible by default when using the
349
# devkit.
350
ifeq ($(ARCH), x86_64)
351
  $(SYSROOT)/usr/include/ffi.h: $(rpms)
352
	cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
353

354
  $(SYSROOT)/usr/include/ffitarget.h: $(rpms)
355
	cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
356

357
  SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h
358
endif
359

360
##########################################################################################
361

362
# Define marker files for each source package to be compiled
363
$(foreach t,binutils mpfr gmp mpc gcc ccache gdb,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
364

365
##########################################################################################
366

367
# Default base config
368
CONFIG = --target=$(TARGET) \
369
    --host=$(HOST) --build=$(BUILD) \
370
    --prefix=$(PREFIX)
371

372
PATHEXT = $(PREFIX)/bin:
373

374
PATHPRE = PATH=$(PATHEXT)$(PATH)
375
NUM_CORES := $(shell cat /proc/cpuinfo | grep -c processor)
376
BUILDPAR = -j$(NUM_CORES)
377

378
# Default commands to when making
379
MAKECMD =
380
INSTALLCMD = install
381

382

383
declare_tools = CC$(1)=$(2)gcc LD$(1)=$(2)ld AR$(1)=$(2)ar AS$(1)=$(2)as RANLIB$(1)=$(2)ranlib CXX$(1)=$(2)g++ OBJDUMP$(1)=$(2)objdump
384

385
ifeq ($(HOST),$(BUILD))
386
  ifeq ($(HOST),$(TARGET))
387
    TOOLS = $(call declare_tools,_FOR_TARGET,)
388
  endif
389
endif
390

391
TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-)
392

393
##########################################################################################
394

395
# Create a TARGET bfd + libiberty only.
396
# Configure one or two times depending on mulitlib arch.
397
# If multilib, the second should be 32-bit, and we resolve
398
# CFLAG_<name> to most likely -m32.
399
define mk_bfd
400
  $$(info Libs for $(1))
401
  $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \
402
      : CFLAGS += $$(CFLAGS_$(1))
403
  $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \
404
      : LIBDIRS = --libdir=$(TARGETDIR)/$(1)
405

406
  bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done
407
  bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile
408
endef
409

410
# Create one set of bfds etc for each multilib arch
411
$(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l))))
412

413
# Only build these two libs.
414
$(bfdlib) : MAKECMD = all-libiberty all-bfd
415
$(bfdlib) : INSTALLCMD = install-libiberty install-bfd
416

417
# Building targets libbfd + libiberty. HOST==TARGET, i.e not
418
# for a cross env.
419
$(bfdmakes) : CONFIG = --target=$(TARGET) \
420
    --host=$(TARGET) --build=$(BUILD) \
421
    --prefix=$(TARGETDIR) \
422
    --with-sysroot=$(SYSROOT) \
423
    $(LIBDIRS)
424

425
$(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-)
426

427
##########################################################################################
428

429
$(gcc) \
430
    $(binutils) \
431
    $(gmp) \
432
    $(mpfr) \
433
    $(mpc) \
434
    $(bfdmakes) \
435
    $(ccache) : ENVS += $(TOOLS)
436

437
# libdir to work around hateful bfd stuff installing into wrong dirs...
438
# ensure we have 64 bit bfd support in the HOST library. I.e our
439
# compiler on i686 will know 64 bit symbols, BUT later
440
# we build just the libs again for TARGET, then with whatever the arch
441
# wants.
442
$(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS))
443

444
ifneq ($(ARCH), riscv64)
445
  # gold is not available for riscv64 for some reason,
446
  # and subsequent linking will fail if we try to enable it.
447
  LINKER_CONFIG := --enable-gold=default
448
endif
449

450
# Makefile creation. Simply run configure in build dir.
451
# Setting CFLAGS to -O2 generates a much faster ld.
452
$(bfdmakes) \
453
$(BUILDDIR)/$(binutils_ver)/Makefile \
454
    : $(BINUTILS_CFG)
455
	$(info Configuring $@. Log in $(@D)/log.config)
456
	@mkdir -p $(@D)
457
	( \
458
	  cd $(@D) ; \
459
	  $(PATHPRE) $(ENVS) CFLAGS="-O2 $(CFLAGS)" \
460
	      $(BINUTILS_CFG) \
461
	      $(CONFIG) \
462
	      $(LINKER_CONFIG) \
463
	      --with-sysroot=$(SYSROOT) \
464
	      --disable-nls \
465
	      --program-prefix=$(TARGET)- \
466
	      --enable-multilib \
467
	      --enable-threads \
468
	      --enable-plugins \
469
	) > $(@D)/log.config 2>&1
470
	@echo 'done'
471

472
$(BUILDDIR)/$(mpfr_ver)/Makefile \
473
    : $(MPFR_CFG)
474
	$(info Configuring $@. Log in $(@D)/log.config)
475
	@mkdir -p $(@D)
476
	( \
477
	  cd $(@D) ; \
478
	  $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
479
	      $(MPFR_CFG) \
480
	      $(CONFIG) \
481
	      --program-prefix=$(TARGET)- \
482
	      --enable-shared=no \
483
	      --with-gmp=$(PREFIX) \
484
	) > $(@D)/log.config 2>&1
485
	@echo 'done'
486

487
$(BUILDDIR)/$(gmp_ver)/Makefile \
488
    : $(GMP_CFG)
489
	$(info Configuring $@. Log in $(@D)/log.config)
490
	@mkdir -p $(@D)
491
	( \
492
	  cd $(@D) ; \
493
	  $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
494
	      $(GMP_CFG) \
495
	      --host=$(HOST) --build=$(BUILD) \
496
	      --prefix=$(PREFIX) \
497
	      --disable-nls \
498
	      --program-prefix=$(TARGET)- \
499
	      --enable-shared=no \
500
	      --with-mpfr=$(PREFIX) \
501
	) > $(@D)/log.config 2>&1
502
	@echo 'done'
503

504
$(BUILDDIR)/$(mpc_ver)/Makefile \
505
    : $(MPC_CFG)
506
	$(info Configuring $@. Log in $(@D)/log.config)
507
	@mkdir -p $(@D)
508
	( \
509
	  cd $(@D) ; \
510
	  $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
511
	      $(MPC_CFG) \
512
	      $(CONFIG) \
513
	      --program-prefix=$(TARGET)- \
514
	      --enable-shared=no \
515
	      --with-mpfr=$(PREFIX) \
516
	      --with-gmp=$(PREFIX) \
517
	) > $(@D)/log.config 2>&1
518
	@echo 'done'
519

520
# Only valid if glibc target -> linux
521
# proper destructor handling for c++
522
ifneq (,$(findstring linux,$(TARGET)))
523
  $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit
524
endif
525

526
ifeq ($(ARCH), armhfp)
527
  $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG +=  --with-float=hard
528
endif
529

530
ifneq ($(filter riscv64 ppc64 ppc64le s390x, $(ARCH)), )
531
  # We only support 64-bit on these platforms anyway
532
  CONFIG += --disable-multilib
533
endif
534

535
# Want:
536
# c,c++
537
# shared libs
538
# multilib (-m32/-m64 on x64)
539
# skip native language.
540
# and link and assemble with the binutils we created
541
# earlier, so --with-gnu*
542
$(BUILDDIR)/$(gcc_ver)/Makefile \
543
    : $(GCC_CFG)
544
	$(info Configuring $@. Log in $(@D)/log.config)
545
	mkdir -p $(@D)
546
	( \
547
	  cd $(@D) ; \
548
	  $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \
549
	      $(CONFIG) \
550
	      --with-sysroot=$(SYSROOT) \
551
	      --with-debug-prefix-map=$(OUTPUT_ROOT)=devkit \
552
	      --enable-languages=c,c++ \
553
	      --enable-shared \
554
	      --disable-nls \
555
	      --with-gnu-as \
556
	      --with-gnu-ld \
557
	      --with-mpfr=$(PREFIX) \
558
	      --with-gmp=$(PREFIX) \
559
	      --with-mpc=$(PREFIX) \
560
	) > $(@D)/log.config 2>&1
561
	@echo 'done'
562

563
# need binutils for gcc
564
$(gcc) : $(binutils)
565

566
# as of 4.3 or so need these for doing config
567
$(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc)
568
$(mpfr) : $(gmp)
569
$(mpc) : $(gmp) $(mpfr)
570

571
################################################################################
572
# Build gdb but only where host and target match
573
ifeq ($(HOST), $(TARGET))
574
  $(BUILDDIR)/$(gdb_ver)/Makefile: $(GDB_CFG)
575
	$(info Configuring $@. Log in $(@D)/log.config)
576
	mkdir -p $(@D)
577
	( \
578
	  cd $(@D) ; \
579
	  $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" $(GDB_CFG) \
580
	      $(CONFIG) \
581
	      --with-sysroot=$(SYSROOT) \
582
	) > $(@D)/log.config 2>&1
583
	@echo 'done'
584

585
  $(gdb): $(gcc)
586
else
587
  $(BUILDDIR)/$(gdb_ver)/Makefile:
588
	$(info Faking $@, not used when cross-compiling)
589
	mkdir -p $(@D)
590
	echo "install:" > $@
591
	@echo 'done'
592
endif
593

594
##########################################################################################
595
# very straightforward. just build a ccache. it is only for host.
596
$(BUILDDIR)/$(ccache_ver)/Makefile \
597
    : $(CCACHE_CFG)
598
	$(info Configuring $@. Log in $(@D)/log.config)
599
	@mkdir -p $(@D)
600
	@( \
601
	  cd $(@D) ; \
602
	  $(PATHPRE) $(ENVS) $(CCACHE_CFG) \
603
	      $(CONFIG) \
604
	) > $(@D)/log.config 2>&1
605
	@echo 'done'
606

607
gccpatch = $(TARGETDIR)/gcc-patched
608

609
##########################################################################################
610
# For some reason cpp is not created as a target-compiler
611
ifeq ($(HOST),$(TARGET))
612
  $(gccpatch) : $(gcc) link_libs
613
	@echo -n 'Creating compiler symlinks...'
614
	@for f in cpp; do \
615
	  if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \
616
	  then \
617
	    cd $(PREFIX)/bin && \
618
	    ln -fs $$f $(TARGET)-$$f ; \
619
	  fi \
620
	done
621
	@touch $@
622
	@echo 'done'
623

624
  ##########################################################################################
625
  # Ugly at best. Seems that when we compile host->host compiler, that are NOT
626
  # the BUILD compiler, the result will not try searching for libs in package root.
627
  # "Solve" this by create links from the target libdirs to where they are.
628
  link_libs:
629
	@echo -n 'Creating library symlinks...'
630
	@$(foreach l,$(LIBDIRS), \
631
	for f in `cd $(PREFIX)/$(l) && ls`; do \
632
	  if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \
633
	    mkdir -p $(TARGETDIR)/$(l) && \
634
	    cd $(TARGETDIR)/$(l)/ && \
635
	    ln -fs $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
636
	  fi \
637
	done;)
638
	@echo 'done'
639
else
640
  $(gccpatch) :
641
	@echo 'done'
642
endif
643

644
##########################################################################################
645
# Build in two steps.
646
# make <default>
647
# make install.
648
# Use path to our build hosts cross tools
649
# Always need to build cross tools for build host self.
650
$(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile
651
	$(info Building $(basename $@). Log in $(<D)/log.build)
652
	$(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1
653
	@echo -n 'installing...'
654
	$(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1
655
	@mkdir -p $(@D)
656
	@touch $@
657
	@echo 'done'
658

659
##########################################################################################
660

661
$(PREFIX)/devkit.info:
662
	@echo 'Creating devkit.info in the root of the kit'
663
	rm -f $@
664
	touch $@
665
	echo '# This file describes to configure how to interpret the contents of this' >> $@
666
	echo '# devkit' >> $@
667
	echo '' >> $@
668
	echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@
669
	echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@
670
	echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$(TARGET)/sysroot"' >> $@
671
	echo 'DEVKIT_EXTRA_PATH="$$DEVKIT_ROOT/bin"' >> $@
672

673
##########################################################################################
674
# Copy these makefiles into the root of the kit
675
$(PREFIX)/Makefile: ./Makefile
676
	rm -rf $@
677
	cp $< $@
678

679
$(PREFIX)/Tools.gmk: ./Tools.gmk
680
	rm -rf $@
681
	cp $< $@
682

683
$(PREFIX)/Tars.gmk: ./Tars.gmk
684
	rm -rf $@
685
	cp $< $@
686

687
THESE_MAKEFILES := $(PREFIX)/Makefile $(PREFIX)/Tools.gmk $(PREFIX)/Tars.gmk
688

689
##########################################################################################
690

691
ifeq ($(TARGET), $(HOST))
692
  # To build with dtrace support, the build needs access to the dtrace executable from the
693
  # sysroot. Generally we don't want to add binaries in the sysroot to the path, but
694
  # luckily this seems to execute well enough on a different host Linux distro, so symlink
695
  # it into the main bin dir.
696
  $(PREFIX)/bin/dtrace:
697
	@echo 'Creating dtrace soft link'
698
	ln -s ../$(HOST)/sysroot/usr/bin/dtrace $@
699

700
  $(PREFIX)/bin/%:
701
	@echo 'Creating missing $* soft link'
702
	ln -s $(TARGET)-$* $@
703

704
  missing-links := $(addprefix $(PREFIX)/bin/, \
705
      addr2line ar as c++ c++filt dwp elfedit g++ gcc gcc-$(GCC_VER) gprof ld ld.bfd \
706
      ld.gold nm objcopy objdump ranlib readelf size strings strip)
707
endif
708

709
##########################################################################################
710

711
bfdlib : $(bfdlib)
712
binutils : $(binutils)
713
rpms : $(rpms)
714
libs : $(libs)
715
sysroot : rpms libs
716
gcc : sysroot $(gcc) $(gccpatch)
717
gdb : $(gdb)
718
all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) \
719
    $(THESE_MAKEFILES) gdb
720

721
# this is only built for host. so separate.
722
ccache : $(ccache)
723

724
.PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot
725

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.