1 #
   2 # Copyright (c) 2013, 2018, 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 ifeq ($(BASE_OS), OL)
  55   BASE_URL := http://yum.oracle.com/repo/OracleLinux/OL6/4/base/$(ARCH)/
  56   LINUX_VERSION := OL6.4
  57 else ifeq ($(BASE_OS), Fedora)
  58   DEFAULT_OS_VERSION := 27
  59   ifeq ($(BASE_OS_VERSION), )
  60     BASE_OS_VERSION := $(DEFAULT_OS_VERSION)
  61   endif
  62   ifeq ($(filter x86_64 armhfp, $(ARCH)), )
  63     FEDORA_TYPE := fedora-secondary
  64   else
  65     FEDORA_TYPE := fedora/linux
  66   endif
  67   ARCHIVED := $(shell [ $(BASE_OS_VERSION) -lt $(DEFAULT_OS_VERSION) ] && echo true)
  68   ifeq ($(ARCHIVED),true)
  69     BASE_URL := https://archives.fedoraproject.org/pub/archive/$(FEDORA_TYPE)/releases/$(BASE_OS_VERSION)/Everything/$(ARCH)/os/Packages/
  70   else
  71     BASE_URL := https://dl.fedoraproject.org/pub/$(FEDORA_TYPE)/releases/$(BASE_OS_VERSION)/Everything/$(ARCH)/os/Packages/
  72   endif
  73   LINUX_VERSION := Fedora_$(BASE_OS_VERSION)
  74 else
  75   $(error Unknown base OS $(BASE_OS))
  76 endif
  77 
  78 ##########################################################################################
  79 # Define external dependencies
  80 
  81 # Latest that could be made to work.
  82 GCC_VER := 8.2.0
  83 ifeq ($(GCC_VER), 8.2.0)
  84   gcc_ver := gcc-8.2.0
  85   binutils_ver := binutils-2.30
  86   ccache_ver := ccache-3.5.1a
  87   CCACHE_DIRNAME := ccache-3.5.1
  88   mpfr_ver := mpfr-3.1.5
  89   gmp_ver := gmp-6.1.2
  90   mpc_ver := mpc-1.0.3
  91   gdb_ver := gdb-8.2.1
  92 else ifeq ($(GCC_VER), 7.3.0)
  93   gcc_ver := gcc-7.3.0
  94   binutils_ver := binutils-2.30
  95   ccache_ver := ccache-3.3.6
  96   mpfr_ver := mpfr-3.1.5
  97   gmp_ver := gmp-6.1.2
  98   mpc_ver := mpc-1.0.3
  99   gdb_ver := gdb-8.1
 100 else ifeq ($(GCC_VER), 4.9.2)
 101   gcc_ver := gcc-4.9.2
 102   binutils_ver := binutils-2.25
 103   ccache_ver := ccache-3.2.1
 104   mpfr_ver := mpfr-3.0.1
 105   gmp_ver := gmp-4.3.2
 106   mpc_ver := mpc-1.0.1
 107   gdb_ver := gdb-7.12.1
 108 else
 109   $(error Unsupported GCC version)
 110 endif
 111 
 112 GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz
 113 BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.xz
 114 CCACHE := https://samba.org/ftp/ccache/$(ccache_ver).tar.xz
 115 MPFR := https://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2
 116 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2
 117 MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz
 118 GDB := http://ftp.gnu.org/gnu/gdb/${gdb_ver}.tar.xz
 119 
 120 # RPMs used by all BASE_OS
 121 RPM_LIST := \
 122     kernel-headers \
 123     glibc glibc-headers glibc-devel \
 124     cups-libs cups-devel \
 125     libX11 libX11-devel \
 126     xorg-x11-proto-devel \
 127     alsa-lib alsa-lib-devel \
 128     libXext libXext-devel \
 129     libXtst libXtst-devel \
 130     libXrender libXrender-devel \
 131     libXrandr libXrandr-devel \
 132     freetype freetype-devel \
 133     libXt libXt-devel \
 134     libSM libSM-devel \
 135     libICE libICE-devel \
 136     libXi libXi-devel \
 137     libXdmcp libXdmcp-devel \
 138     libXau libXau-devel \
 139     libgcc \
 140     zlib zlib-devel \
 141     libffi libffi-devel \
 142     fontconfig fontconfig-devel \
 143     systemtap-sdt-devel \
 144     #
 145 
 146 ##########################################################################################
 147 # Define common directories and files
 148 
 149 # Ensure we have 32-bit libs also for x64. We enable mixed-mode.
 150 ifeq (x86_64,$(ARCH))
 151   LIBDIRS := lib64 lib
 152   CFLAGS_lib := -m32
 153 else
 154   LIBDIRS := lib
 155 endif
 156 
 157 # Define directories
 158 BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET)
 159 TARGETDIR := $(PREFIX)/$(TARGET)
 160 SYSROOT := $(TARGETDIR)/sysroot
 161 DOWNLOAD := $(OUTPUT_ROOT)/download
 162 DOWNLOAD_RPMS := $(DOWNLOAD)/rpms/$(TARGET)-$(LINUX_VERSION)
 163 SRCDIR := $(OUTPUT_ROOT)/src
 164 
 165 # Marker file for unpacking rpms
 166 rpms := $(SYSROOT)/rpms_unpacked
 167 
 168 # Need to patch libs that are linker scripts to use non-absolute paths
 169 libs := $(SYSROOT)/libs_patched
 170 
 171 ################################################################################
 172 # Download RPMs
 173 download-rpms:
 174         mkdir -p $(DOWNLOAD_RPMS)
 175         # Only run this if rpm dir is empty.
 176         ifeq ($(wildcard $(DOWNLOAD_RPMS)/*.rpm), )
 177           cd $(DOWNLOAD_RPMS) && \
 178               wget -r -np -nd $(patsubst %, -A "*%*.rpm", $(RPM_LIST)) $(BASE_URL)
 179         endif
 180 
 181 ##########################################################################################
 182 # Unpack source packages
 183 
 184 # Generate downloading + unpacking of sources.
 185 define Download
 186   # Allow override
 187   $(1)_DIRNAME ?= $(basename $(basename $(notdir $($(1)))))
 188   $(1)_DIR = $(abspath $(SRCDIR)/$$($(1)_DIRNAME))
 189   $(1)_CFG = $$($(1)_DIR)/configure
 190   $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1)))
 191 
 192   $$($(1)_CFG) : $$($(1)_FILE)
 193         mkdir -p $$(SRCDIR)
 194         tar -C $$(SRCDIR) -xf $$<
 195         $$(foreach p,$$(abspath $$(wildcard patches/$$(notdir $$($(1)_DIR)).patch)), \
 196           echo PATCHING $$(p) ; \
 197           patch -d $$($(1)_DIR) -p1 -i $$(p) ; \
 198         )
 199         touch $$@
 200 
 201   $$($(1)_FILE) :
 202         wget -P $(DOWNLOAD) $$($(1))
 203 endef
 204 
 205 # Download and unpack all source packages
 206 $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC GDB,$(eval $(call Download,$(p))))
 207 
 208 ##########################################################################################
 209 # Unpack RPMS
 210 
 211 RPM_ARCHS := $(ARCH) noarch
 212 ifeq ($(ARCH),x86_64)
 213   ifeq ($(BUILD),$(HOST))
 214     ifeq ($(TARGET),$(HOST))
 215       # When building the native compiler for x86_64, enable mixed mode.
 216       RPM_ARCHS += i386 i686
 217     endif
 218   endif
 219 else ifeq ($(ARCH),i686)
 220   RPM_ARCHS += i386
 221 else ifeq ($(ARCH), armhfp)
 222   RPM_ARCHS += armv7hl
 223 endif
 224 
 225 RPM_FILE_LIST := $(sort $(foreach a, $(RPM_ARCHS), \
 226   $(wildcard $(patsubst %,$(DOWNLOAD_RPMS)/%*$a.rpm,$(RPM_LIST))) \
 227 ))
 228 
 229 # Note. For building linux you should install rpm2cpio.
 230 define unrpm
 231   $(SYSROOT)/$(notdir $(1)).unpacked : $(1)
 232   $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked
 233 endef
 234 
 235 %.unpacked :
 236         $(info Unpacking target rpms and libraries from $<)
 237         @(mkdir -p $(@D); \
 238         cd $(@D); \
 239         rpm2cpio $< | \
 240             cpio --extract --make-directories \
 241                 -f \
 242                 "./usr/share/doc/*" \
 243                 "./usr/share/man/*" \
 244                 "./usr/X11R6/man/*" \
 245                 "*/X11/locale/*" \
 246             || die ; )
 247         touch $@
 248 
 249 $(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p))))
 250 
 251 ##########################################################################################
 252 
 253 # Note: MUST create a <sysroot>/usr/lib even if not really needed.
 254 # gcc will use a path relative to it to resolve lib64. (x86_64).
 255 # we're creating multi-lib compiler with 32bit libc as well, so we should
 256 # have it anyway, but just to make sure...
 257 # Patch libc.so and libpthread.so to force linking against libraries in sysroot
 258 # and not the ones installed on the build machine.
 259 $(libs) : $(rpms)
 260         @echo Patching libc and pthreads
 261         @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \
 262           (cat $$f | sed -e 's|/usr/lib64/||g' \
 263               -e 's|/usr/lib/||g' \
 264               -e 's|/lib64/||g' \
 265               -e 's|/lib/||g' ) > $$f.tmp ; \
 266           mv $$f.tmp $$f ; \
 267         done)
 268         @mkdir -p $(SYSROOT)/usr/lib
 269         @touch $@
 270 
 271 ##########################################################################################
 272 # Create links for ffi header files so that they become visible by default when using the
 273 # devkit.
 274 ifeq ($(ARCH), x86_64)
 275   $(SYSROOT)/usr/include/ffi.h: $(rpms)
 276         cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 277 
 278   $(SYSROOT)/usr/include/ffitarget.h: $(rpms)
 279         cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 280 
 281   SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h
 282 endif
 283 
 284 ##########################################################################################
 285 
 286 # Define marker files for each source package to be compiled
 287 $(foreach t,binutils mpfr gmp mpc gcc ccache gdb,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
 288 
 289 ##########################################################################################
 290 
 291 # Default base config
 292 CONFIG = --target=$(TARGET) \
 293     --host=$(HOST) --build=$(BUILD) \
 294     --prefix=$(PREFIX)
 295 
 296 PATHEXT = $(PREFIX)/bin:
 297 
 298 PATHPRE = PATH=$(PATHEXT)$(PATH)
 299 NUM_CORES := $(shell cat /proc/cpuinfo | grep -c processor)
 300 BUILDPAR = -j$(NUM_CORES)
 301 
 302 # Default commands to when making
 303 MAKECMD =
 304 INSTALLCMD = install
 305 
 306 
 307 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
 308 
 309 ifeq ($(HOST),$(BUILD))
 310   ifeq ($(HOST),$(TARGET))
 311     TOOLS = $(call declare_tools,_FOR_TARGET,)
 312   endif
 313 endif
 314 
 315 TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-)
 316 
 317 ##########################################################################################
 318 
 319 # Create a TARGET bfd + libiberty only.
 320 # Configure one or two times depending on mulitlib arch.
 321 # If multilib, the second should be 32-bit, and we resolve
 322 # CFLAG_<name> to most likely -m32.
 323 define mk_bfd
 324   $$(info Libs for $(1))
 325   $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \
 326       : CFLAGS += $$(CFLAGS_$(1))
 327   $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \
 328       : LIBDIRS = --libdir=$(TARGETDIR)/$(1)
 329 
 330   bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done
 331   bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile
 332 endef
 333 
 334 # Create one set of bfds etc for each multilib arch
 335 $(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l))))
 336 
 337 # Only build these two libs.
 338 $(bfdlib) : MAKECMD = all-libiberty all-bfd
 339 $(bfdlib) : INSTALLCMD = install-libiberty install-bfd
 340 
 341 # Building targets libbfd + libiberty. HOST==TARGET, i.e not
 342 # for a cross env.
 343 $(bfdmakes) : CONFIG = --target=$(TARGET) \
 344     --host=$(TARGET) --build=$(BUILD) \
 345     --prefix=$(TARGETDIR) \
 346     --with-sysroot=$(SYSROOT) \
 347     $(LIBDIRS)
 348 
 349 $(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-)
 350 
 351 ##########################################################################################
 352 
 353 $(gcc) \
 354     $(binutils) \
 355     $(gmp) \
 356     $(mpfr) \
 357     $(mpc) \
 358     $(bfdmakes) \
 359     $(ccache) : ENVS += $(TOOLS)
 360 
 361 # libdir to work around hateful bfd stuff installing into wrong dirs...
 362 # ensure we have 64 bit bfd support in the HOST library. I.e our
 363 # compiler on i686 will know 64 bit symbols, BUT later
 364 # we build just the libs again for TARGET, then with whatever the arch
 365 # wants.
 366 $(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS))
 367 
 368 # Makefile creation. Simply run configure in build dir.
 369 # Setting CFLAGS to -O2 generates a much faster ld.
 370 $(bfdmakes) \
 371 $(BUILDDIR)/$(binutils_ver)/Makefile \
 372     : $(BINUTILS_CFG)
 373         $(info Configuring $@. Log in $(@D)/log.config)
 374         @mkdir -p $(@D)
 375         ( \
 376           cd $(@D) ; \
 377           $(PATHPRE) $(ENVS) CFLAGS="-O2 $(CFLAGS)" \
 378               $(BINUTILS_CFG) \
 379               $(CONFIG) \
 380               --with-sysroot=$(SYSROOT) \
 381               --disable-nls \
 382               --program-prefix=$(TARGET)- \
 383               --enable-multilib \
 384               --enable-gold=default \
 385               --enable-threads \
 386               --enable-plugins \
 387         ) > $(@D)/log.config 2>&1
 388         @echo 'done'
 389 
 390 $(BUILDDIR)/$(mpfr_ver)/Makefile \
 391     : $(MPFR_CFG)
 392         $(info Configuring $@. Log in $(@D)/log.config)
 393         @mkdir -p $(@D)
 394         ( \
 395           cd $(@D) ; \
 396           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 397               $(MPFR_CFG) \
 398               $(CONFIG) \
 399               --program-prefix=$(TARGET)- \
 400               --enable-shared=no \
 401               --with-gmp=$(PREFIX) \
 402         ) > $(@D)/log.config 2>&1
 403         @echo 'done'
 404 
 405 $(BUILDDIR)/$(gmp_ver)/Makefile \
 406     : $(GMP_CFG)
 407         $(info Configuring $@. Log in $(@D)/log.config)
 408         @mkdir -p $(@D)
 409         ( \
 410           cd $(@D) ; \
 411           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 412               $(GMP_CFG) \
 413               --host=$(HOST) --build=$(BUILD) \
 414               --prefix=$(PREFIX) \
 415               --disable-nls \
 416               --program-prefix=$(TARGET)- \
 417               --enable-shared=no \
 418               --with-mpfr=$(PREFIX) \
 419         ) > $(@D)/log.config 2>&1
 420         @echo 'done'
 421 
 422 $(BUILDDIR)/$(mpc_ver)/Makefile \
 423     : $(MPC_CFG)
 424         $(info Configuring $@. Log in $(@D)/log.config)
 425         @mkdir -p $(@D)
 426         ( \
 427           cd $(@D) ; \
 428           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 429               $(MPC_CFG) \
 430               $(CONFIG) \
 431               --program-prefix=$(TARGET)- \
 432               --enable-shared=no \
 433               --with-mpfr=$(PREFIX) \
 434               --with-gmp=$(PREFIX) \
 435         ) > $(@D)/log.config 2>&1
 436         @echo 'done'
 437 
 438 # Only valid if glibc target -> linux
 439 # proper destructor handling for c++
 440 ifneq (,$(findstring linux,$(TARGET)))
 441   $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit
 442 endif
 443 
 444 ifeq ($(ARCH), armhfp)
 445   $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG +=  --with-float=hard
 446 endif
 447 
 448 ifneq ($(filter ppc64 ppc64le s390x, $(ARCH)), )
 449   # We only support 64-bit on these platforms anyway
 450   CONFIG += --disable-multilib
 451 endif
 452 
 453 # Want:
 454 # c,c++
 455 # shared libs
 456 # multilib (-m32/-m64 on x64)
 457 # skip native language.
 458 # and link and assemble with the binutils we created
 459 # earlier, so --with-gnu*
 460 $(BUILDDIR)/$(gcc_ver)/Makefile \
 461     : $(GCC_CFG)
 462         $(info Configuring $@. Log in $(@D)/log.config)
 463         mkdir -p $(@D)
 464         ( \
 465           cd $(@D) ; \
 466           $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \
 467               $(CONFIG) \
 468               --with-sysroot=$(SYSROOT) \
 469               --enable-languages=c,c++ \
 470               --enable-shared \
 471               --disable-nls \
 472               --with-gnu-as \
 473               --with-gnu-ld \
 474               --with-mpfr=$(PREFIX) \
 475               --with-gmp=$(PREFIX) \
 476               --with-mpc=$(PREFIX) \
 477         ) > $(@D)/log.config 2>&1
 478         @echo 'done'
 479 
 480 # need binutils for gcc
 481 $(gcc) : $(binutils)
 482 
 483 # as of 4.3 or so need these for doing config
 484 $(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc)
 485 $(mpfr) : $(gmp)
 486 $(mpc) : $(gmp) $(mpfr)
 487 
 488 ################################################################################
 489 # Build gdb but only where host and target match
 490 ifeq ($(HOST), $(TARGET))
 491   $(BUILDDIR)/$(gdb_ver)/Makefile: $(GDB_CFG)
 492         $(info Configuring $@. Log in $(@D)/log.config)
 493         mkdir -p $(@D)
 494         ( \
 495           cd $(@D) ; \
 496           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" $(GDB_CFG) \
 497               $(CONFIG) \
 498               --with-sysroot=$(SYSROOT) \
 499         ) > $(@D)/log.config 2>&1
 500         @echo 'done'
 501 
 502   $(gdb): $(gcc)
 503 else
 504   $(BUILDDIR)/$(gdb_ver)/Makefile:
 505         $(info Faking $@, not used when cross-compiling)
 506         mkdir -p $(@D)
 507         echo "install:" > $@
 508         @echo 'done'
 509 endif
 510 
 511 ##########################################################################################
 512 # very straightforward. just build a ccache. it is only for host.
 513 $(BUILDDIR)/$(ccache_ver)/Makefile \
 514     : $(CCACHE_CFG)
 515         $(info Configuring $@. Log in $(@D)/log.config)
 516         @mkdir -p $(@D)
 517         @( \
 518           cd $(@D) ; \
 519           $(PATHPRE) $(ENVS) $(CCACHE_CFG) \
 520               $(CONFIG) \
 521         ) > $(@D)/log.config 2>&1
 522         @echo 'done'
 523 
 524 gccpatch = $(TARGETDIR)/gcc-patched
 525 
 526 ##########################################################################################
 527 # For some reason cpp is not created as a target-compiler
 528 ifeq ($(HOST),$(TARGET))
 529   $(gccpatch) : $(gcc) link_libs
 530         @echo -n 'Creating compiler symlinks...'
 531         @for f in cpp; do \
 532           if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \
 533           then \
 534             cd $(PREFIX)/bin && \
 535             ln -fs $$f $(TARGET)-$$f ; \
 536           fi \
 537         done
 538         @touch $@
 539         @echo 'done'
 540 
 541   ##########################################################################################
 542   # Ugly at best. Seems that when we compile host->host compiler, that are NOT
 543   # the BUILD compiler, the result will not try searching for libs in package root.
 544   # "Solve" this by create links from the target libdirs to where they are.
 545   link_libs:
 546         @echo -n 'Creating library symlinks...'
 547         @$(foreach l,$(LIBDIRS), \
 548         for f in `cd $(PREFIX)/$(l) && ls`; do \
 549           if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \
 550             mkdir -p $(TARGETDIR)/$(l) && \
 551             cd $(TARGETDIR)/$(l)/ && \
 552             ln -fs $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
 553           fi \
 554         done;)
 555         @echo 'done'
 556 else
 557   $(gccpatch) :
 558         @echo 'done'
 559 endif
 560 
 561 ##########################################################################################
 562 # Build in two steps.
 563 # make <default>
 564 # make install.
 565 # Use path to our build hosts cross tools
 566 # Always need to build cross tools for build host self.
 567 $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile
 568         $(info Building $(basename $@). Log in $(<D)/log.build)
 569         $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1
 570         @echo -n 'installing...'
 571         $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1
 572         @mkdir -p $(@D)
 573         @touch $@
 574         @echo 'done'
 575 
 576 ##########################################################################################
 577 
 578 $(PREFIX)/devkit.info:
 579         @echo 'Creating devkit.info in the root of the kit'
 580         rm -f $@
 581         touch $@
 582         echo '# This file describes to configure how to interpret the contents of this' >> $@
 583         echo '# devkit' >> $@
 584         echo '' >> $@
 585         echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@
 586         echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@
 587         echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$(TARGET)/sysroot"' >> $@
 588         echo 'DEVKIT_EXTRA_PATH="$$DEVKIT_ROOT/bin"' >> $@
 589 
 590 ##########################################################################################
 591 # Copy these makefiles into the root of the kit
 592 $(PREFIX)/Makefile: ./Makefile
 593         rm -rf $@
 594         cp $< $@
 595 
 596 $(PREFIX)/Tools.gmk: ./Tools.gmk
 597         rm -rf $@
 598         cp $< $@
 599 
 600 THESE_MAKEFILES := $(PREFIX)/Makefile $(PREFIX)/Tools.gmk
 601 
 602 ##########################################################################################
 603 
 604 ifeq ($(TARGET), $(HOST))
 605   # To build with dtrace support, the build needs access to the dtrace executable from the
 606   # sysroot. Generally we don't want to add binaries in the sysroot to the path, but
 607   # luckily this seems to execute well enough on a different host Linux distro, so symlink
 608   # it into the main bin dir.
 609   $(PREFIX)/bin/dtrace:
 610         @echo 'Creating dtrace soft link'
 611         ln -s ../$(HOST)/sysroot/usr/bin/dtrace $@
 612 
 613   $(PREFIX)/bin/%:
 614         @echo 'Creating missing $* soft link'
 615         ln -s $(TARGET)-$* $@
 616 
 617   missing-links := $(addprefix $(PREFIX)/bin/, \
 618       addr2line ar as c++ c++filt dwp elfedit g++ gcc gcc-$(GCC_VER) gprof ld ld.bfd \
 619       ld.gold nm objcopy objdump ranlib readelf size strings strip)
 620 endif
 621 
 622 ##########################################################################################
 623 
 624 bfdlib : $(bfdlib)
 625 binutils : $(binutils)
 626 rpms : $(rpms)
 627 libs : $(libs)
 628 sysroot : rpms libs
 629 gcc : sysroot $(gcc) $(gccpatch)
 630 gdb : $(gdb)
 631 all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) \
 632     $(THESE_MAKEFILES) gdb
 633 
 634 # this is only built for host. so separate.
 635 ccache : $(ccache)
 636 
 637 .PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot