Tools.gmk revision 1788:015cff85d10d
13229Spst# 23229Spst# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 33229Spst# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43229Spst# 53229Spst# This code is free software; you can redistribute it and/or modify it 63229Spst# under the terms of the GNU General Public License version 2 only, as 73229Spst# published by the Free Software Foundation. Oracle designates this 83229Spst# particular file as subject to the "Classpath" exception as provided 93229Spst# by Oracle in the LICENSE file that accompanied this code. 103229Spst# 113229Spst# This code is distributed in the hope that it will be useful, but WITHOUT 123229Spst# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 133229Spst# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 143229Spst# version 2 for more details (a copy is included in the LICENSE file that 153229Spst# accompanied this code). 163229Spst# 173229Spst# You should have received a copy of the GNU General Public License version 183229Spst# 2 along with this work; if not, write to the Free Software Foundation, 193229Spst# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 203229Spst# 2118471Swosch# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2250476Speter# or visit www.oracle.com if you need additional information or have any 2318471Swosch# questions. 243229Spst# 253229Spst 263229Spst########################################################################################## 273229Spst# 283229Spst# Workhorse makefile for creating ONE cross compiler 293229Spst# Needs either to be from BUILD -> BUILD OR have 303229Spst# BUILD -> HOST prebuilt 313229Spst# 323229Spst# NOTE: There is a bug here. We don't limit the 333229Spst# PATH when building BUILD -> BUILD, which means that 343229Spst# if you configure after you've once build the BUILD->BUILD 353229Spst# compiler THAT one will be picked up as the compiler for itself. 363229Spst# This is not so great, especially if you did a partial delete 373229Spst# of the target tree. 383229Spst# 393229Spst# Fix this... 403229Spst# 413229Spst 423229Spst$(info TARGET=$(TARGET)) 433229Spst$(info HOST=$(HOST)) 443229Spst$(info BUILD=$(BUILD)) 453229Spst 463229SpstARCH := $(word 1,$(subst -, ,$(TARGET))) 473229Spst 483229Spst########################################################################################## 493229Spst# Define external dependencies 503229Spst 513229Spst# Latest that could be made to work. 523229Spstgcc_ver := gcc-4.9.2 533229Spstbinutils_ver := binutils-2.25 543229Spstccache_ver := ccache-3.2.1 553229Spstmpfr_ver := mpfr-3.0.1 563229Spstgmp_ver := gmp-4.3.2 573229Spstmpc_ver := mpc-1.0.1 583229Spst 593229SpstGCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 603229SpstBINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 613229SpstCCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz 623229SpstMPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 633229SpstGMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 643229SpstMPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz 653229Spst 663229Spst# RPMs in OEL6.4 673229SpstLINUX_VERSION := OEL6.4 683229SpstRPM_LIST := \ 693229Spst kernel-headers \ 703229Spst glibc glibc-headers glibc-devel \ 713229Spst cups-libs cups-devel \ 723229Spst libX11 libX11-devel \ 733229Spst xorg-x11-proto-devel \ 743229Spst alsa-lib alsa-lib-devel \ 753229Spst libXext libXext-devel \ 763229Spst libXtst libXtst-devel \ 773229Spst libXrender libXrender-devel \ 783229Spst freetype freetype-devel \ 793229Spst libXt libXt-devel \ 803229Spst libSM libSM-devel \ 813229Spst libICE libICE-devel \ 823229Spst libXi libXi-devel \ 833229Spst libXdmcp libXdmcp-devel \ 843229Spst libXau libXau-devel \ 853229Spst libgcc 863229Spst 873229Spst 8897419Salfredifeq ($(ARCH),x86_64) 8997419Salfred RPM_DIR ?= $(RPM_DIR_x86_64) 903229Spst RPM_ARCHS := x86_64 noarch 913229Spst ifeq ($(BUILD),$(HOST)) 923229Spst ifeq ($(TARGET),$(HOST)) 933229Spst # When building the native compiler for x86_64, enable mixed mode. 943229Spst RPM_ARCHS += i386 i686 953229Spst endif 963229Spst endif 973229Spstelse 983229Spst RPM_DIR ?= $(RPM_DIR_i686) 993229Spst RPM_ARCHS := i386 i686 1003229Spstendif 1013229Spst 1023229Spst# Sort to remove duplicates 1033229SpstRPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST))))) 1043229Spst 1053229Spst#$(info RPM_FILE_LIST $(RPM_FILE_LIST)) 1063229Spst 1073229Spstifeq ($(RPM_FILE_LIST),) 1083229Spst $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs) 1093229Spstendif 1103229Spst 1113229Spst########################################################################################## 1123229Spst# Define common directories and files 1133229Spst 1143229Spst# Ensure we have 32-bit libs also for x64. We enable mixed-mode. 1153229Spstifeq (x86_64,$(ARCH)) 1163229Spst LIBDIRS := lib64 lib 1173229Spst CFLAGS_lib := -m32 1183229Spstelse 1193229Spst LIBDIRS := lib 1203229Spstendif 1213229Spst 1223229Spst# Define directories 1233229SpstRESULT := $(OUTPUT_ROOT)/result 1243229SpstBUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) 1253229SpstPREFIX := $(RESULT)/$(HOST) 12646078SimpTARGETDIR := $(PREFIX)/$(TARGET) 1273229SpstSYSROOT := $(TARGETDIR)/sysroot 1283229SpstDOWNLOAD := $(OUTPUT_ROOT)/download 1293229SpstSRCDIR := $(OUTPUT_ROOT)/src 1303229Spst 1313229Spst# Marker file for unpacking rpms 1323229Spstrpms := $(SYSROOT)/rpms_unpacked 1333229Spst 1343229Spst# Need to patch libs that are linker scripts to use non-absolute paths 1353229Spstlibs := $(SYSROOT)/libs_patched 1363229Spst 1373229Spst########################################################################################## 1383229Spst# Unpack source packages 1393229Spst 1403229Spst# Generate downloading + unpacking of sources. 1413229Spstdefine Download 1423229Spst $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) 1433229Spst $(1)_CFG = $$($(1)_DIR)/configure 1443229Spst $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) 1453229Spst 1463229Spst $$($(1)_CFG) : $$($(1)_FILE) 1473229Spst mkdir -p $$(SRCDIR) 1483229Spst tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< 1493229Spst $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ 1503229Spst echo PATCHING $$(p) ; \ 1513229Spst patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ 1523229Spst ) 1533229Spst touch $$@ 1543229Spst 1553229Spst $$($(1)_FILE) : 1563229Spst wget -P $(DOWNLOAD) $$($(1)) 1573229Spstendef 1583229Spst 1593229Spst# Download and unpack all source packages 1603229Spst$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p)))) 1613229Spst 1623229Spst########################################################################################## 1633229Spst# Unpack RPMS 1643229Spst 1653229Spst# Note. For building linux you should install rpm2cpio. 1663229Spstdefine unrpm 1673229Spst $(SYSROOT)/$(notdir $(1)).unpacked \ 1683229Spst : $(1) 1693229Spst $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked 1703229Spstendef 1713229Spst 1723229Spst%.unpacked : 1733229Spst $(info Unpacking target rpms and libraries from $<) 1743229Spst @(mkdir -p $(@D); \ 1753229Spst cd $(@D); \ 1763229Spst rpm2cpio $< | \ 1773229Spst cpio --extract --make-directories \ 1783229Spst -f \ 1793229Spst "./usr/share/doc/*" \ 1803229Spst "./usr/share/man/*" \ 1813229Spst "./usr/X11R6/man/*" \ 1823229Spst "*/X11/locale/*" \ 1833229Spst || die ; ) 1843229Spst touch $@ 1853229Spst 1863229Spst$(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p)))) 1873229Spst 1883229Spst########################################################################################## 1893229Spst 1903229Spst# Note: MUST create a <sysroot>/usr/lib even if not really needed. 1913229Spst# gcc will use a path relative to it to resolve lib64. (x86_64). 1923229Spst# we're creating multi-lib compiler with 32bit libc as well, so we should 1933229Spst# have it anyway, but just to make sure... 1943229Spst# Patch libc.so and libpthread.so to force linking against libraries in sysroot 1953229Spst# and not the ones installed on the build machine. 1963229Spst$(libs) : $(rpms) 1973229Spst @echo Patching libc and pthreads 1983229Spst @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \ 1993229Spst (cat $$f | sed -e 's|/usr/lib64/||g' \ 2003229Spst -e 's|/usr/lib/||g' \ 2013229Spst -e 's|/lib64/||g' \ 2023229Spst -e 's|/lib/||g' ) > $$f.tmp ; \ 2033229Spst mv $$f.tmp $$f ; \ 2043229Spst done) 2053229Spst @mkdir -p $(SYSROOT)/usr/lib 2063229Spst @touch $@ 2073229Spst 2083229Spst########################################################################################## 2093229Spst 2103229Spst# Define marker files for each source package to be compiled 2113229Spst$(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) 2123229Spst 2133229Spst########################################################################################## 2143229Spst 2153229Spst# Default base config 2163229SpstCONFIG = --target=$(TARGET) \ 2173229Spst --host=$(HOST) --build=$(BUILD) \ 2183229Spst --prefix=$(PREFIX) 2193229Spst 2203229SpstPATHEXT = $(RESULT)/$(BUILD)/bin: 2213229Spst 2223229SpstPATHPRE = PATH=$(PATHEXT)$(PATH) 2233229SpstBUILDPAR = -j16 2243229Spst 2253229Spst# Default commands to when making 2263229SpstMAKECMD = 2273229SpstINSTALLCMD = install 2283229Spst 2293229Spst 2303229Spstdeclare_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 2313229Spst 2323229Spstifeq ($(HOST),$(BUILD)) 2333229Spst ifeq ($(HOST),$(TARGET)) 2343229Spst TOOLS = $(call declare_tools,_FOR_TARGET,) 2353229Spst endif 2363229Spstendif 2373229Spst 2383229SpstTOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-) 2393229Spst 2403229Spst########################################################################################## 2413229Spst 2423229Spst# Create a TARGET bfd + libiberty only. 2433229Spst# Configure one or two times depending on mulitlib arch. 2443229Spst# If multilib, the second should be 32-bit, and we resolve 2453229Spst# CFLAG_<name> to most likely -m32. 2463229Spstdefine mk_bfd 2473229Spst $$(info Libs for $(1)) 2483229Spst $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 2493229Spst : CFLAGS += $$(CFLAGS_$(1)) 2503229Spst $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 2513229Spst : LIBDIRS = --libdir=$(TARGETDIR)/$(1) 2523229Spst 2533229Spst bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done 2543229Spst bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile 2553229Spstendef 2563229Spst 2573229Spst# Create one set of bfds etc for each multilib arch 2583229Spst$(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l)))) 2593229Spst 2603229Spst# Only build these two libs. 2613229Spst$(bfdlib) : MAKECMD = all-libiberty all-bfd 26246078Simp$(bfdlib) : INSTALLCMD = install-libiberty install-bfd 2633229Spst 2643229Spst# Building targets libbfd + libiberty. HOST==TARGET, i.e not 2653229Spst# for a cross env. 2663229Spst$(bfdmakes) : CONFIG = --target=$(TARGET) \ 2673229Spst --host=$(TARGET) --build=$(BUILD) \ 2683229Spst --prefix=$(TARGETDIR) \ 2693229Spst --with-sysroot=$(SYSROOT) \ 2703229Spst $(LIBDIRS) 2713229Spst 2723229Spst$(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-) 2733229Spst 2743229Spst########################################################################################## 2753229Spst 2763229Spst$(gcc) \ 2773229Spst $(binutils) \ 2783229Spst $(gmp) \ 2793229Spst $(mpfr) \ 2803229Spst $(mpc) \ 2813229Spst $(bfdmakes) \ 2823229Spst $(ccache) : ENVS += $(TOOLS) 2833229Spst 2843229Spst# libdir to work around hateful bfd stuff installing into wrong dirs... 2853229Spst# ensure we have 64 bit bfd support in the HOST library. I.e our 2863229Spst# compiler on i686 will know 64 bit symbols, BUT later 2873229Spst# we build just the libs again for TARGET, then with whatever the arch 2883229Spst# wants. 2893229Spst$(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS)) 2903229Spst 2913229Spst# Makefile creation. Simply run configure in build dir. 2923229Spst$(bfdmakes) \ 2933229Spst$(BUILDDIR)/$(binutils_ver)/Makefile \ 2943229Spst : $(BINUTILS_CFG) 2953229Spst $(info Configuring $@. Log in $(@D)/log.config) 2963229Spst @mkdir -p $(@D) 2973229Spst ( \ 2983229Spst cd $(@D) ; \ 2993229Spst $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 3003229Spst $(BINUTILS_CFG) \ 3013229Spst $(CONFIG) \ 3023229Spst --with-sysroot=$(SYSROOT) \ 3033229Spst --disable-nls \ 3043229Spst --program-prefix=$(TARGET)- \ 3053229Spst --enable-multilib \ 3063229Spst ) > $(@D)/log.config 2>&1 3073229Spst @echo 'done' 3083229Spst 3093229Spst$(BUILDDIR)/$(mpfr_ver)/Makefile \ 3103229Spst : $(MPFR_CFG) 3113229Spst $(info Configuring $@. Log in $(@D)/log.config) 3123229Spst @mkdir -p $(@D) 3133229Spst ( \ 3143229Spst cd $(@D) ; \ 3153229Spst $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 3163229Spst $(MPFR_CFG) \ 3173229Spst $(CONFIG) \ 3183229Spst --program-prefix=$(TARGET)- \ 31913572Spst --enable-shared=no \ 3203229Spst --with-gmp=$(PREFIX) \ 3213229Spst ) > $(@D)/log.config 2>&1 3223229Spst @echo 'done' 3233229Spst 3243229Spst$(BUILDDIR)/$(gmp_ver)/Makefile \ 3253229Spst : $(GMP_CFG) 3263229Spst $(info Configuring $@. Log in $(@D)/log.config) 3273229Spst @mkdir -p $(@D) 3283229Spst ( \ 3293229Spst cd $(@D) ; \ 3303229Spst $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 3313229Spst $(GMP_CFG) \ 332 --host=$(HOST) --build=$(BUILD) \ 333 --prefix=$(PREFIX) \ 334 --disable-nls \ 335 --program-prefix=$(TARGET)- \ 336 --enable-shared=no \ 337 --with-mpfr=$(PREFIX) \ 338 ) > $(@D)/log.config 2>&1 339 @echo 'done' 340 341$(BUILDDIR)/$(mpc_ver)/Makefile \ 342 : $(MPC_CFG) 343 $(info Configuring $@. Log in $(@D)/log.config) 344 @mkdir -p $(@D) 345 ( \ 346 cd $(@D) ; \ 347 $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 348 $(MPC_CFG) \ 349 $(CONFIG) \ 350 --program-prefix=$(TARGET)- \ 351 --enable-shared=no \ 352 --with-mpfr=$(PREFIX) \ 353 --with-gmp=$(PREFIX) \ 354 ) > $(@D)/log.config 2>&1 355 @echo 'done' 356 357# Only valid if glibc target -> linux 358# proper destructor handling for c++ 359ifneq (,$(findstring linux,$(TARGET))) 360 $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit 361endif 362 363# Want: 364# c,c++ 365# shared libs 366# multilib (-m32/-m64 on x64) 367# skip native language. 368# and link and assemble with the binutils we created 369# earlier, so --with-gnu* 370$(BUILDDIR)/$(gcc_ver)/Makefile \ 371 : $(GCC_CFG) 372 $(info Configuring $@. Log in $(@D)/log.config) 373 mkdir -p $(@D) 374 ( \ 375 cd $(@D) ; \ 376 $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \ 377 $(CONFIG) \ 378 --with-sysroot=$(SYSROOT) \ 379 --enable-languages=c,c++ \ 380 --enable-shared \ 381 --enable-multilib \ 382 --disable-nls \ 383 --with-gnu-as \ 384 --with-gnu-ld \ 385 --with-mpfr=$(PREFIX) \ 386 --with-gmp=$(PREFIX) \ 387 --with-mpc=$(PREFIX) \ 388 ) > $(@D)/log.config 2>&1 389 @echo 'done' 390 391# need binutils for gcc 392$(gcc) : $(binutils) 393 394# as of 4.3 or so need these for doing config 395$(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc) 396$(mpfr) : $(gmp) 397$(mpc) : $(gmp) $(mpfr) 398 399########################################################################################## 400# very straightforward. just build a ccache. it is only for host. 401$(BUILDDIR)/$(ccache_ver)/Makefile \ 402 : $(CCACHE_CFG) 403 $(info Configuring $@. Log in $(@D)/log.config) 404 @mkdir -p $(@D) 405 @( \ 406 cd $(@D) ; \ 407 $(PATHPRE) $(ENVS) $(CCACHE_CFG) \ 408 $(CONFIG) \ 409 ) > $(@D)/log.config 2>&1 410 @echo 'done' 411 412gccpatch = $(TARGETDIR)/gcc-patched 413 414########################################################################################## 415# For some reason cpp is not created as a target-compiler 416ifeq ($(HOST),$(TARGET)) 417 $(gccpatch) : $(gcc) link_libs 418 @echo -n 'Creating compiler symlinks...' 419 @for f in cpp; do \ 420 if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \ 421 then \ 422 cd $(PREFIX)/bin && \ 423 ln -s $$f $(TARGET)-$$f ; \ 424 fi \ 425 done 426 @touch $@ 427 @echo 'done' 428 429 ########################################################################################## 430 # Ugly at best. Seems that when we compile host->host compiler, that are NOT 431 # the BUILD compiler, the result will not try searching for libs in package root. 432 # "Solve" this by create links from the target libdirs to where they are. 433 link_libs: 434 @echo -n 'Creating library symlinks...' 435 @$(foreach l,$(LIBDIRS), \ 436 for f in `cd $(PREFIX)/$(l) && ls`; do \ 437 if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \ 438 mkdir -p $(TARGETDIR)/$(l) && \ 439 cd $(TARGETDIR)/$(l)/ && \ 440 ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \ 441 fi \ 442 done;) 443 @echo 'done' 444else 445 $(gccpatch) : 446 @echo 'done' 447endif 448 449########################################################################################## 450# Build in two steps. 451# make <default> 452# make install. 453# Use path to our build hosts cross tools 454# Always need to build cross tools for build host self. 455$(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile 456 $(info Building $(basename $@). Log in $(<D)/log.build) 457 $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1 458 @echo -n 'installing...' 459 $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1 460 @touch $@ 461 @echo 'done' 462 463########################################################################################## 464 465$(PREFIX)/devkit.info: FRC 466 @echo 'Creating devkit.info in the root of the kit' 467 rm -f $@ 468 touch $@ 469 echo '# This file describes to configure how to interpret the contents of this' >> $@ 470 echo '# devkit' >> $@ 471 echo '' >> $@ 472 echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@ 473 echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@ 474 echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@ 475 476########################################################################################## 477 478ifeq ($(TARGET), $(HOST)) 479 $(PREFIX)/bin/%: 480 @echo 'Creating missing $* soft link' 481 ln -s $(TARGET)-$* $@ 482 483 missing-links := $(addprefix $(PREFIX)/bin/, \ 484 addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \ 485 size strings strip) 486endif 487 488########################################################################################## 489 490bfdlib : $(bfdlib) 491binutils : $(binutils) 492rpms : $(rpms) 493libs : $(libs) 494sysroot : rpms libs 495gcc : sysroot $(gcc) $(gccpatch) 496all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) 497 498# this is only built for host. so separate. 499ccache : $(ccache) 500 501# Force target 502FRC: 503 504.PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot 505