< prev index next >

make/devkit/Tools.gmk

Print this page


   1 #
   2 # Copyright (c) 2013, 2016, 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


  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 ##########################################################################################
  49 # Define external dependencies
  50 
  51 # Latest that could be made to work.
  52 gcc_ver := gcc-4.9.2
  53 binutils_ver := binutils-2.25
  54 ccache_ver := ccache-3.2.1
  55 mpfr_ver := mpfr-3.0.1
  56 gmp_ver := gmp-4.3.2
  57 mpc_ver := mpc-1.0.1
  58 
  59 GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2
  60 BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2
  61 CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz














  62 MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2
  63 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2
  64 MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz



  65 
  66 # RPMs in OEL6.4
  67 LINUX_VERSION := OEL6.4
  68 RPM_LIST := \
  69     kernel-headers \
  70     glibc glibc-headers glibc-devel \
  71     cups-libs cups-devel \
  72     libX11 libX11-devel \
  73     xorg-x11-proto-devel \
  74     alsa-lib alsa-lib-devel \
  75     libXext libXext-devel \
  76     libXtst libXtst-devel \
  77     libXrender libXrender-devel \
  78     freetype freetype-devel \
  79     libXt libXt-devel \
  80     libSM libSM-devel \
  81     libICE libICE-devel \
  82     libXi libXi-devel \
  83     libXdmcp libXdmcp-devel \
  84     libXau libXau-devel \
  85     libgcc \
  86     zlib zlib-devel \
  87     libffi libffi-devel \
  88     fontconfig fontconfig-devel
  89 
  90 ifeq ($(ARCH),x86_64)
  91   RPM_DIR ?= $(RPM_DIR_x86_64)
  92   RPM_ARCHS := x86_64 noarch
  93   ifeq ($(BUILD),$(HOST))
  94     ifeq ($(TARGET),$(HOST))
  95       # When building the native compiler for x86_64, enable mixed mode.
  96       RPM_ARCHS += i386 i686
  97     endif
  98   endif
  99 else
 100   RPM_DIR ?= $(RPM_DIR_i686)
 101   RPM_ARCHS := i386 i686
 102 endif
 103 
 104 # Sort to remove duplicates
 105 RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST)))))
 106 
 107 #$(info RPM_FILE_LIST $(RPM_FILE_LIST))
 108 
 109 ifeq ($(RPM_FILE_LIST),)
 110   $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs)
 111 endif
 112 
 113 ##########################################################################################
 114 # Define common directories and files
 115 
 116 # Ensure we have 32-bit libs also for x64. We enable mixed-mode.
 117 ifeq (x86_64,$(ARCH))
 118   LIBDIRS := lib64 lib
 119   CFLAGS_lib := -m32
 120 else
 121   LIBDIRS := lib
 122 endif
 123 
 124 # Define directories
 125 RESULT := $(OUTPUTDIR)/result
 126 BUILDDIR := $(OUTPUTDIR)/$(HOST)/$(TARGET)
 127 PREFIX := $(RESULT)/$(HOST)
 128 TARGETDIR := $(PREFIX)/$(TARGET)
 129 SYSROOT := $(TARGETDIR)/sysroot
 130 DOWNLOAD := $(OUTPUTDIR)/download
 131 SRCDIR := $(OUTPUTDIR)/src

 132 
 133 # Marker file for unpacking rpms
 134 rpms := $(SYSROOT)/rpms_unpacked
 135 
 136 # Need to patch libs that are linker scripts to use non-absolute paths
 137 libs := $(SYSROOT)/libs_patched
 138 










 139 ##########################################################################################
 140 # Unpack source packages
 141 
 142 # Generate downloading + unpacking of sources.
 143 define Download
 144   $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1))))))
 145   $(1)_CFG = $$($(1)_DIR)/configure
 146   $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1)))
 147 
 148   $$($(1)_CFG) : $$($(1)_FILE)
 149         mkdir -p $$(SRCDIR)
 150         tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$<
 151         $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \
 152           echo PATCHING $$(p) ; \
 153           patch -d $$($(1)_DIR) -p1 -i $$(p) ; \
 154         )
 155         touch $$@
 156 
 157   $$($(1)_FILE) :
 158         wget -P $(DOWNLOAD) $$($(1))
 159 endef
 160 
 161 # Download and unpack all source packages
 162 $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p))))
 163 
 164 ##########################################################################################
 165 # Unpack RPMS
 166 


















 167 # Note. For building linux you should install rpm2cpio.
 168 define unrpm
 169   $(SYSROOT)/$(notdir $(1)).unpacked \
 170     : $(1)
 171   $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked
 172 endef
 173 
 174 %.unpacked :
 175         $(info Unpacking target rpms and libraries from $<)
 176         @(mkdir -p $(@D); \
 177         cd $(@D); \
 178         rpm2cpio $< | \
 179             cpio --extract --make-directories \
 180                 -f \
 181                 "./usr/share/doc/*" \
 182                 "./usr/share/man/*" \
 183                 "./usr/X11R6/man/*" \
 184                 "*/X11/locale/*" \
 185             || die ; )
 186         touch $@
 187 
 188 $(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p))))
 189 
 190 ##########################################################################################


 193 # gcc will use a path relative to it to resolve lib64. (x86_64).
 194 # we're creating multi-lib compiler with 32bit libc as well, so we should
 195 # have it anyway, but just to make sure...
 196 # Patch libc.so and libpthread.so to force linking against libraries in sysroot
 197 # and not the ones installed on the build machine.
 198 $(libs) : $(rpms)
 199         @echo Patching libc and pthreads
 200         @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \
 201           (cat $$f | sed -e 's|/usr/lib64/||g' \
 202               -e 's|/usr/lib/||g' \
 203               -e 's|/lib64/||g' \
 204               -e 's|/lib/||g' ) > $$f.tmp ; \
 205           mv $$f.tmp $$f ; \
 206         done)
 207         @mkdir -p $(SYSROOT)/usr/lib
 208         @touch $@
 209 
 210 ##########################################################################################
 211 # Create links for ffi header files so that they become visible by default when using the
 212 # devkit.



 213 
 214 $(SYSROOT)/usr/include/ffi.h: $(rpms)
 215         cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 216 
 217 $(SYSROOT)/usr/include/ffitarget.h: $(rpms)
 218         cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 219 
 220 SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h

 221 
 222 ##########################################################################################
 223 
 224 # Define marker files for each source package to be compiled
 225 $(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
 226 
 227 ##########################################################################################
 228 
 229 # Default base config
 230 CONFIG = --target=$(TARGET) \
 231     --host=$(HOST) --build=$(BUILD) \
 232     --prefix=$(PREFIX)
 233 
 234 PATHEXT = $(RESULT)/$(BUILD)/bin:
 235 
 236 PATHPRE = PATH=$(PATHEXT)$(PATH)
 237 BUILDPAR = -j16

 238 
 239 # Default commands to when making
 240 MAKECMD =
 241 INSTALLCMD = install
 242 
 243 
 244 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
 245 
 246 ifeq ($(HOST),$(BUILD))
 247   ifeq ($(HOST),$(TARGET))
 248     TOOLS = $(call declare_tools,_FOR_TARGET,)
 249   endif
 250 endif
 251 
 252 TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-)
 253 
 254 ##########################################################################################
 255 
 256 # Create a TARGET bfd + libiberty only.
 257 # Configure one or two times depending on mulitlib arch.


 300 # compiler on i686 will know 64 bit symbols, BUT later
 301 # we build just the libs again for TARGET, then with whatever the arch
 302 # wants.
 303 $(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS))
 304 
 305 # Makefile creation. Simply run configure in build dir.
 306 $(bfdmakes) \
 307 $(BUILDDIR)/$(binutils_ver)/Makefile \
 308     : $(BINUTILS_CFG)
 309         $(info Configuring $@. Log in $(@D)/log.config)
 310         @mkdir -p $(@D)
 311         ( \
 312           cd $(@D) ; \
 313           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 314               $(BINUTILS_CFG) \
 315               $(CONFIG) \
 316               --with-sysroot=$(SYSROOT) \
 317               --disable-nls \
 318               --program-prefix=$(TARGET)- \
 319               --enable-multilib \


 320         ) > $(@D)/log.config 2>&1
 321         @echo 'done'
 322 
 323 $(BUILDDIR)/$(mpfr_ver)/Makefile \
 324     : $(MPFR_CFG)
 325         $(info Configuring $@. Log in $(@D)/log.config)
 326         @mkdir -p $(@D)
 327         ( \
 328           cd $(@D) ; \
 329           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 330               $(MPFR_CFG) \
 331               $(CONFIG) \
 332               --program-prefix=$(TARGET)- \
 333               --enable-shared=no \
 334               --with-gmp=$(PREFIX) \
 335         ) > $(@D)/log.config 2>&1
 336         @echo 'done'
 337 
 338 $(BUILDDIR)/$(gmp_ver)/Makefile \
 339     : $(GMP_CFG)


 375 endif
 376 
 377 # Want:
 378 # c,c++
 379 # shared libs
 380 # multilib (-m32/-m64 on x64)
 381 # skip native language.
 382 # and link and assemble with the binutils we created
 383 # earlier, so --with-gnu*
 384 $(BUILDDIR)/$(gcc_ver)/Makefile \
 385     : $(GCC_CFG)
 386         $(info Configuring $@. Log in $(@D)/log.config)
 387         mkdir -p $(@D)
 388         ( \
 389           cd $(@D) ; \
 390           $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \
 391               $(CONFIG) \
 392               --with-sysroot=$(SYSROOT) \
 393               --enable-languages=c,c++ \
 394               --enable-shared \
 395               --enable-multilib \
 396               --disable-nls \
 397               --with-gnu-as \
 398               --with-gnu-ld \
 399               --with-mpfr=$(PREFIX) \
 400               --with-gmp=$(PREFIX) \
 401               --with-mpc=$(PREFIX) \
 402         ) > $(@D)/log.config 2>&1
 403         @echo 'done'
 404 
 405 # need binutils for gcc
 406 $(gcc) : $(binutils)
 407 
 408 # as of 4.3 or so need these for doing config
 409 $(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc)
 410 $(mpfr) : $(gmp)
 411 $(mpc) : $(gmp) $(mpfr)
 412 

















 413 ##########################################################################################
 414 # very straightforward. just build a ccache. it is only for host.
 415 $(BUILDDIR)/$(ccache_ver)/Makefile \
 416     : $(CCACHE_CFG)
 417         $(info Configuring $@. Log in $(@D)/log.config)
 418         @mkdir -p $(@D)
 419         @( \
 420           cd $(@D) ; \
 421           $(PATHPRE) $(ENVS) $(CCACHE_CFG) \
 422               $(CONFIG) \
 423         ) > $(@D)/log.config 2>&1
 424         @echo 'done'
 425 
 426 gccpatch = $(TARGETDIR)/gcc-patched
 427 
 428 ##########################################################################################
 429 # For some reason cpp is not created as a target-compiler
 430 ifeq ($(HOST),$(TARGET))
 431   $(gccpatch) : $(gcc) link_libs
 432         @echo -n 'Creating compiler symlinks...'
 433         @for f in cpp; do \
 434           if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \
 435           then \
 436             cd $(PREFIX)/bin && \
 437             ln -s $$f $(TARGET)-$$f ; \
 438           fi \
 439         done
 440         @touch $@
 441         @echo 'done'
 442 
 443   ##########################################################################################
 444   # Ugly at best. Seems that when we compile host->host compiler, that are NOT
 445   # the BUILD compiler, the result will not try searching for libs in package root.
 446   # "Solve" this by create links from the target libdirs to where they are.
 447   link_libs:
 448         @echo -n 'Creating library symlinks...'
 449         @$(foreach l,$(LIBDIRS), \
 450         for f in `cd $(PREFIX)/$(l) && ls`; do \
 451           if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \
 452             mkdir -p $(TARGETDIR)/$(l) && \
 453             cd $(TARGETDIR)/$(l)/ && \
 454             ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
 455           fi \
 456         done;)
 457         @echo 'done'
 458 else
 459   $(gccpatch) :
 460         @echo 'done'
 461 endif
 462 
 463 ##########################################################################################
 464 # Build in two steps.
 465 # make <default>
 466 # make install.
 467 # Use path to our build hosts cross tools
 468 # Always need to build cross tools for build host self.
 469 $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile
 470         $(info Building $(basename $@). Log in $(<D)/log.build)
 471         $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1
 472         @echo -n 'installing...'
 473         $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1

 474         @touch $@
 475         @echo 'done'
 476 
 477 ##########################################################################################
 478 
 479 $(PREFIX)/devkit.info: FRC
 480         @echo 'Creating devkit.info in the root of the kit'
 481         rm -f $@
 482         touch $@
 483         echo '# This file describes to configure how to interpret the contents of this' >> $@
 484         echo '# devkit' >> $@
 485         echo '' >> $@
 486         echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@
 487         echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@
 488         echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@
 489 
 490 ##########################################################################################












 491 
 492 ifeq ($(TARGET), $(HOST))
 493   $(PREFIX)/bin/%:
 494         @echo 'Creating missing $* soft link'
 495         ln -s $(TARGET)-$* $@
 496 
 497   missing-links := $(addprefix $(PREFIX)/bin/, \
 498       addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \
 499       size strings strip)
 500 endif
 501 
 502 ##########################################################################################
 503 
 504 bfdlib : $(bfdlib)
 505 binutils : $(binutils)
 506 rpms : $(rpms)
 507 libs : $(libs)
 508 sysroot : rpms libs
 509 gcc : sysroot $(gcc) $(gccpatch)
 510 all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS)


 511 
 512 # this is only built for host. so separate.
 513 ccache : $(ccache)
 514 
 515 # Force target
 516 FRC:
 517 
 518 .PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot
   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


  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 $(info ARCH=$(ARCH))
  48 
  49 ##########################################################################################
  50 # Define external dependencies
  51 
  52 # Latest that could be made to work.
  53 GCC_VER := 7.3.0
  54 ifeq ($(GCC_VER), 7.3.0)
  55   gcc_ver := gcc-7.3.0
  56   binutils_ver := binutils-2.30
  57   ccache_ver := ccache-3.3.6
  58   mpfr_ver := mpfr-3.1.5
  59   gmp_ver := gmp-6.1.2
  60   mpc_ver := mpc-1.0.3
  61   gdb_ver := gdb-8.1
  62 else ifeq ($(GCC_VER), 4.9.2)
  63   gcc_ver := gcc-4.9.2
  64   binutils_ver := binutils-2.25
  65   ccache_ver := ccache-3.2.1
  66   mpfr_ver := mpfr-3.0.1
  67   gmp_ver := gmp-4.3.2
  68   mpc_ver := mpc-1.0.1
  69   gdb_ver := gdb-7.12.1
  70 else
  71   $(error Unsupported GCC version)
  72 endif
  73 
  74 GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz
  75 BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.xz
  76 CCACHE := https://samba.org/ftp/ccache/$(ccache_ver).tar.xz
  77 MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2
  78 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2
  79 MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz
  80 GDB := http://ftp.gnu.org/gnu/gdb/${gdb_ver}.tar.xz
  81 
  82 OEL_URL := http://yum.oracle.com/repo/OracleLinux/OL6/4/base/$(ARCH)/
  83 
  84 # RPMs in OEL6.4
  85 LINUX_VERSION := OEL6.4
  86 RPM_LIST := \
  87     kernel-headers \
  88     glibc glibc-headers glibc-devel \
  89     cups-libs cups-devel \
  90     libX11 libX11-devel \
  91     xorg-x11-proto-devel \
  92     alsa-lib alsa-lib-devel \
  93     libXext libXext-devel \
  94     libXtst libXtst-devel \
  95     libXrender libXrender-devel \
  96     freetype freetype-devel \
  97     libXt libXt-devel \
  98     libSM libSM-devel \
  99     libICE libICE-devel \
 100     libXi libXi-devel \
 101     libXdmcp libXdmcp-devel \
 102     libXau libXau-devel \
 103     libgcc \
 104     zlib zlib-devel \
 105     libffi libffi-devel \
 106     fontconfig fontconfig-devel
 107 























 108 ##########################################################################################
 109 # Define common directories and files
 110 
 111 # Ensure we have 32-bit libs also for x64. We enable mixed-mode.
 112 ifeq (x86_64,$(ARCH))
 113   LIBDIRS := lib64 lib
 114   CFLAGS_lib := -m32
 115 else
 116   LIBDIRS := lib
 117 endif
 118 
 119 # Define directories
 120 RESULT := $(OUTPUT_ROOT)/result
 121 BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET)
 122 PREFIX := $(RESULT)/$(HOST)
 123 TARGETDIR := $(PREFIX)/$(TARGET)
 124 SYSROOT := $(TARGETDIR)/sysroot
 125 DOWNLOAD := $(OUTPUT_ROOT)/download
 126 DOWNLOAD_RPMS := $(DOWNLOAD)/rpms
 127 SRCDIR := $(OUTPUT_ROOT)/src
 128 
 129 # Marker file for unpacking rpms
 130 rpms := $(SYSROOT)/rpms_unpacked
 131 
 132 # Need to patch libs that are linker scripts to use non-absolute paths
 133 libs := $(SYSROOT)/libs_patched
 134 
 135 ################################################################################
 136 # Download RPMs
 137 download-rpms:
 138         mkdir -p $(DOWNLOAD_RPMS)
 139         # Only run this if rpm dir is empty.
 140         ifeq ($(wildcard $(DOWNLOAD_RPMS)/*.rpm), )
 141           cd $(DOWNLOAD_RPMS) && \
 142               wget -r -np -nd $(patsubst %, -A "*%*.rpm", $(RPM_LIST)) $(OEL_URL)
 143         endif
 144 
 145 ##########################################################################################
 146 # Unpack source packages
 147 
 148 # Generate downloading + unpacking of sources.
 149 define Download
 150   $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1))))))
 151   $(1)_CFG = $$($(1)_DIR)/configure
 152   $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1)))
 153 
 154   $$($(1)_CFG) : $$($(1)_FILE)
 155         mkdir -p $$(SRCDIR)
 156         tar -C $$(SRCDIR) -xf $$<
 157         $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \
 158           echo PATCHING $$(p) ; \
 159           patch -d $$($(1)_DIR) -p1 -i $$(p) ; \
 160         )
 161         touch $$@
 162 
 163   $$($(1)_FILE) :
 164         wget -P $(DOWNLOAD) $$($(1))
 165 endef
 166 
 167 # Download and unpack all source packages
 168 $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC GDB,$(eval $(call Download,$(p))))
 169 
 170 ##########################################################################################
 171 # Unpack RPMS
 172 
 173 ifeq ($(ARCH),x86_64)
 174   RPM_ARCHS := x86_64 noarch
 175   ifeq ($(BUILD),$(HOST))
 176     ifeq ($(TARGET),$(HOST))
 177       # When building the native compiler for x86_64, enable mixed mode.
 178       RPM_ARCHS += i386 i686
 179     endif
 180   endif
 181 else ifeq ($(ARCH),i686))
 182   RPM_ARCHS := i386 i686
 183 else
 184   RPM_ARCHS := $(ARCH)
 185 endif
 186 
 187 RPM_FILE_LIST := $(sort $(foreach a, $(RPM_ARCHS), \
 188   $(wildcard $(patsubst %,$(DOWNLOAD_RPMS)/%*$a.rpm,$(RPM_LIST))) \
 189 ))
 190 
 191 # Note. For building linux you should install rpm2cpio.
 192 define unrpm
 193   $(SYSROOT)/$(notdir $(1)).unpacked : $(1)

 194   $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked
 195 endef
 196 
 197 %.unpacked :
 198         $(info Unpacking target rpms and libraries from $<)
 199         @(mkdir -p $(@D); \
 200         cd $(@D); \
 201         rpm2cpio $< | \
 202             cpio --extract --make-directories \
 203                 -f \
 204                 "./usr/share/doc/*" \
 205                 "./usr/share/man/*" \
 206                 "./usr/X11R6/man/*" \
 207                 "*/X11/locale/*" \
 208             || die ; )
 209         touch $@
 210 
 211 $(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p))))
 212 
 213 ##########################################################################################


 216 # gcc will use a path relative to it to resolve lib64. (x86_64).
 217 # we're creating multi-lib compiler with 32bit libc as well, so we should
 218 # have it anyway, but just to make sure...
 219 # Patch libc.so and libpthread.so to force linking against libraries in sysroot
 220 # and not the ones installed on the build machine.
 221 $(libs) : $(rpms)
 222         @echo Patching libc and pthreads
 223         @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \
 224           (cat $$f | sed -e 's|/usr/lib64/||g' \
 225               -e 's|/usr/lib/||g' \
 226               -e 's|/lib64/||g' \
 227               -e 's|/lib/||g' ) > $$f.tmp ; \
 228           mv $$f.tmp $$f ; \
 229         done)
 230         @mkdir -p $(SYSROOT)/usr/lib
 231         @touch $@
 232 
 233 ##########################################################################################
 234 # Create links for ffi header files so that they become visible by default when using the
 235 # devkit.
 236 ifeq ($(ARCH), x86_64)
 237   $(SYSROOT)/usr/include/ffi.h: $(rpms)
 238         cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 239 
 240   $(SYSROOT)/usr/include/ffitarget.h: $(rpms)
 241         cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .



 242 
 243   SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h
 244 endif
 245 
 246 ##########################################################################################
 247 
 248 # Define marker files for each source package to be compiled
 249 $(foreach t,binutils mpfr gmp mpc gcc ccache gdb,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
 250 
 251 ##########################################################################################
 252 
 253 # Default base config
 254 CONFIG = --target=$(TARGET) \
 255     --host=$(HOST) --build=$(BUILD) \
 256     --prefix=$(PREFIX)
 257 
 258 PATHEXT = $(RESULT)/$(BUILD)/bin:
 259 
 260 PATHPRE = PATH=$(PATHEXT)$(PATH)
 261 NUM_CORES := $(shell cat /proc/cpuinfo | grep -c processor)
 262 BUILDPAR = -j$(NUM_CORES)
 263 
 264 # Default commands to when making
 265 MAKECMD =
 266 INSTALLCMD = install
 267 
 268 
 269 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
 270 
 271 ifeq ($(HOST),$(BUILD))
 272   ifeq ($(HOST),$(TARGET))
 273     TOOLS = $(call declare_tools,_FOR_TARGET,)
 274   endif
 275 endif
 276 
 277 TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-)
 278 
 279 ##########################################################################################
 280 
 281 # Create a TARGET bfd + libiberty only.
 282 # Configure one or two times depending on mulitlib arch.


 325 # compiler on i686 will know 64 bit symbols, BUT later
 326 # we build just the libs again for TARGET, then with whatever the arch
 327 # wants.
 328 $(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS))
 329 
 330 # Makefile creation. Simply run configure in build dir.
 331 $(bfdmakes) \
 332 $(BUILDDIR)/$(binutils_ver)/Makefile \
 333     : $(BINUTILS_CFG)
 334         $(info Configuring $@. Log in $(@D)/log.config)
 335         @mkdir -p $(@D)
 336         ( \
 337           cd $(@D) ; \
 338           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 339               $(BINUTILS_CFG) \
 340               $(CONFIG) \
 341               --with-sysroot=$(SYSROOT) \
 342               --disable-nls \
 343               --program-prefix=$(TARGET)- \
 344               --enable-multilib \
 345               --enable-gold \
 346               --enable-plugins \
 347         ) > $(@D)/log.config 2>&1
 348         @echo 'done'
 349 
 350 $(BUILDDIR)/$(mpfr_ver)/Makefile \
 351     : $(MPFR_CFG)
 352         $(info Configuring $@. Log in $(@D)/log.config)
 353         @mkdir -p $(@D)
 354         ( \
 355           cd $(@D) ; \
 356           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \
 357               $(MPFR_CFG) \
 358               $(CONFIG) \
 359               --program-prefix=$(TARGET)- \
 360               --enable-shared=no \
 361               --with-gmp=$(PREFIX) \
 362         ) > $(@D)/log.config 2>&1
 363         @echo 'done'
 364 
 365 $(BUILDDIR)/$(gmp_ver)/Makefile \
 366     : $(GMP_CFG)


 402 endif
 403 
 404 # Want:
 405 # c,c++
 406 # shared libs
 407 # multilib (-m32/-m64 on x64)
 408 # skip native language.
 409 # and link and assemble with the binutils we created
 410 # earlier, so --with-gnu*
 411 $(BUILDDIR)/$(gcc_ver)/Makefile \
 412     : $(GCC_CFG)
 413         $(info Configuring $@. Log in $(@D)/log.config)
 414         mkdir -p $(@D)
 415         ( \
 416           cd $(@D) ; \
 417           $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \
 418               $(CONFIG) \
 419               --with-sysroot=$(SYSROOT) \
 420               --enable-languages=c,c++ \
 421               --enable-shared \

 422               --disable-nls \
 423               --with-gnu-as \
 424               --with-gnu-ld \
 425               --with-mpfr=$(PREFIX) \
 426               --with-gmp=$(PREFIX) \
 427               --with-mpc=$(PREFIX) \
 428         ) > $(@D)/log.config 2>&1
 429         @echo 'done'
 430 
 431 # need binutils for gcc
 432 $(gcc) : $(binutils)
 433 
 434 # as of 4.3 or so need these for doing config
 435 $(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc)
 436 $(mpfr) : $(gmp)
 437 $(mpc) : $(gmp) $(mpfr)
 438 
 439 ################################################################################
 440 # Build gdb but only where host and target match
 441 ifeq ($(HOST), $(TARGET))
 442   $(BUILDDIR)/$(gdb_ver)/Makefile: $(GDB_CFG)
 443         $(info Configuring $@. Log in $(@D)/log.config)
 444         mkdir -p $(@D)
 445         ( \
 446           cd $(@D) ; \
 447           $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" $(GDB_CFG) \
 448               $(CONFIG) \
 449               --with-sysroot=$(SYSROOT) \
 450         ) > $(@D)/log.config 2>&1
 451         @echo 'done'
 452 
 453   $(gdb): $(gcc)
 454 endif
 455 
 456 ##########################################################################################
 457 # very straightforward. just build a ccache. it is only for host.
 458 $(BUILDDIR)/$(ccache_ver)/Makefile \
 459     : $(CCACHE_CFG)
 460         $(info Configuring $@. Log in $(@D)/log.config)
 461         @mkdir -p $(@D)
 462         @( \
 463           cd $(@D) ; \
 464           $(PATHPRE) $(ENVS) $(CCACHE_CFG) \
 465               $(CONFIG) \
 466         ) > $(@D)/log.config 2>&1
 467         @echo 'done'
 468 
 469 gccpatch = $(TARGETDIR)/gcc-patched
 470 
 471 ##########################################################################################
 472 # For some reason cpp is not created as a target-compiler
 473 ifeq ($(HOST),$(TARGET))
 474   $(gccpatch) : $(gcc) link_libs
 475         @echo -n 'Creating compiler symlinks...'
 476         @for f in cpp; do \
 477           if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \
 478           then \
 479             cd $(PREFIX)/bin && \
 480             ln -fs $$f $(TARGET)-$$f ; \
 481           fi \
 482         done
 483         @touch $@
 484         @echo 'done'
 485 
 486   ##########################################################################################
 487   # Ugly at best. Seems that when we compile host->host compiler, that are NOT
 488   # the BUILD compiler, the result will not try searching for libs in package root.
 489   # "Solve" this by create links from the target libdirs to where they are.
 490   link_libs:
 491         @echo -n 'Creating library symlinks...'
 492         @$(foreach l,$(LIBDIRS), \
 493         for f in `cd $(PREFIX)/$(l) && ls`; do \
 494           if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \
 495             mkdir -p $(TARGETDIR)/$(l) && \
 496             cd $(TARGETDIR)/$(l)/ && \
 497             ln -fs $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
 498           fi \
 499         done;)
 500         @echo 'done'
 501 else
 502   $(gccpatch) :
 503         @echo 'done'
 504 endif
 505 
 506 ##########################################################################################
 507 # Build in two steps.
 508 # make <default>
 509 # make install.
 510 # Use path to our build hosts cross tools
 511 # Always need to build cross tools for build host self.
 512 $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile
 513         $(info Building $(basename $@). Log in $(<D)/log.build)
 514         $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1
 515         @echo -n 'installing...'
 516         $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1
 517         @mkdir -p $(@D)
 518         @touch $@
 519         @echo 'done'
 520 
 521 ##########################################################################################
 522 
 523 $(PREFIX)/devkit.info: FRC
 524         @echo 'Creating devkit.info in the root of the kit'
 525         rm -f $@
 526         touch $@
 527         echo '# This file describes to configure how to interpret the contents of this' >> $@
 528         echo '# devkit' >> $@
 529         echo '' >> $@
 530         echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@
 531         echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@
 532         echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@
 533 
 534 ##########################################################################################
 535 # Copy these makefiles into the root of the kit
 536 $(PREFIX)/Makefile: ./Makefile
 537         rm -rf $@
 538         cp $< $@
 539 
 540 $(PREFIX)/Tools.gmk: ./Tools.gmk
 541         rm -rf $@
 542         cp $< $@
 543 
 544 THESE_MAKEFILES := $(PREFIX)/Makefile $(PREFIX)/Tools.gmk
 545 
 546 ##########################################################################################
 547 
 548 ifeq ($(TARGET), $(HOST))
 549   $(PREFIX)/bin/%:
 550         @echo 'Creating missing $* soft link'
 551         ln -s $(TARGET)-$* $@
 552 
 553   missing-links := $(addprefix $(PREFIX)/bin/, \
 554       addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \
 555       size strings strip ld.bfd ld.gold)
 556 endif
 557 
 558 ##########################################################################################
 559 
 560 bfdlib : $(bfdlib)
 561 binutils : $(binutils)
 562 rpms : $(rpms)
 563 libs : $(libs)
 564 sysroot : rpms libs
 565 gcc : sysroot $(gcc) $(gccpatch)
 566 gdb : $(gdb)
 567 all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) \
 568     $(THESE_MAKEFILES) gdb
 569 
 570 # this is only built for host. so separate.
 571 ccache : $(ccache)
 572 
 573 # Force target
 574 FRC:
 575 
 576 .PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot
< prev index next >