Tue, 18 Jun 2013 11:30:36 +0200
8015377: Support using compiler devkits on Linux
Reviewed-by: tbell, dholmes
1.1 --- a/common/autoconf/basics.m4 Tue Jun 18 11:29:34 2013 +0200 1.2 +++ b/common/autoconf/basics.m4 Tue Jun 18 11:30:36 2013 +0200 1.3 @@ -363,7 +363,11 @@ 1.4 AC_MSG_ERROR([Cannot specify both --with-devkit and --with-tools-dir at the same time]) 1.5 fi 1.6 TOOLS_DIR=$with_devkit/bin 1.7 - SYS_ROOT=$with_devkit/$host_alias/libc 1.8 + if test -d "$with_devkit/$host_alias/libc"; then 1.9 + SYS_ROOT=$with_devkit/$host_alias/libc 1.10 + elif test -d "$with_devkit/$host/sys-root"; then 1.11 + SYS_ROOT=$with_devkit/$host/sys-root 1.12 + fi 1.13 ]) 1.14 1.15 ])
2.1 --- a/common/autoconf/build-performance.m4 Tue Jun 18 11:29:34 2013 +0200 2.2 +++ b/common/autoconf/build-performance.m4 Tue Jun 18 11:30:36 2013 +0200 2.3 @@ -162,7 +162,12 @@ 2.4 [disable using ccache to speed up recompilations @<:@enabled@:>@])], 2.5 [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes]) 2.6 if test "x$ENABLE_CCACHE" = xyes; then 2.7 + OLD_PATH="$PATH" 2.8 + if test "x$TOOLS_DIR" != x; then 2.9 + PATH=$TOOLS_DIR:$PATH 2.10 + fi 2.11 AC_PATH_PROG(CCACHE, ccache) 2.12 + PATH="$OLD_PATH" 2.13 else 2.14 AC_MSG_CHECKING([for ccache]) 2.15 AC_MSG_RESULT([explicitly disabled])
3.1 --- a/common/autoconf/generated-configure.sh Tue Jun 18 11:29:34 2013 +0200 3.2 +++ b/common/autoconf/generated-configure.sh Tue Jun 18 11:30:36 2013 +0200 3.3 @@ -3782,7 +3782,7 @@ 3.4 #CUSTOM_AUTOCONF_INCLUDE 3.5 3.6 # Do not change or remove the following line, it is needed for consistency checks: 3.7 -DATE_WHEN_GENERATED=1371547755 3.8 +DATE_WHEN_GENERATED=1371547824 3.9 3.10 ############################################################################### 3.11 # 3.12 @@ -7471,7 +7471,11 @@ 3.13 as_fn_error $? "Cannot specify both --with-devkit and --with-tools-dir at the same time" "$LINENO" 5 3.14 fi 3.15 TOOLS_DIR=$with_devkit/bin 3.16 - SYS_ROOT=$with_devkit/$host_alias/libc 3.17 + if test -d "$with_devkit/$host_alias/libc"; then 3.18 + SYS_ROOT=$with_devkit/$host_alias/libc 3.19 + elif test -d "$with_devkit/$host/sys-root"; then 3.20 + SYS_ROOT=$with_devkit/$host/sys-root 3.21 + fi 3.22 3.23 fi 3.24 3.25 @@ -29910,11 +29914,17 @@ 3.26 if test "x$x_includes" = xNONE; then 3.27 if test -f "$SYS_ROOT/usr/X11R6/include/X11/Xlib.h"; then 3.28 x_includes="$SYS_ROOT/usr/X11R6/include" 3.29 + elif test -f "$SYS_ROOT/usr/include/X11/Xlib.h"; then 3.30 + x_includes="$SYS_ROOT/usr/include" 3.31 fi 3.32 fi 3.33 if test "x$x_libraries" = xNONE; then 3.34 if test -f "$SYS_ROOT/usr/X11R6/lib/libX11.so"; then 3.35 x_libraries="$SYS_ROOT/usr/X11R6/lib" 3.36 + elif test "$SYS_ROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 3.37 + x_libraries="$SYS_ROOT/usr/lib64" 3.38 + elif test -f "$SYS_ROOT/usr/lib/libX11.so"; then 3.39 + x_libraries="$SYS_ROOT/usr/lib" 3.40 fi 3.41 fi 3.42 fi 3.43 @@ -30645,8 +30655,7 @@ 3.44 if test "x$OPENJDK_TARGET_OS" = xlinux; then 3.45 if test -d "$SYS_ROOT/usr/X11R6"; then 3.46 OPENWIN_HOME="$SYS_ROOT/usr/X11R6" 3.47 - fi 3.48 - if test -d "$SYS_ROOT/usr/include/X11"; then 3.49 + elif test -d "$SYS_ROOT/usr/include/X11"; then 3.50 OPENWIN_HOME="$SYS_ROOT/usr" 3.51 fi 3.52 fi 3.53 @@ -31539,12 +31548,12 @@ 3.54 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for freetype in some standard locations" >&5 3.55 $as_echo_n "checking for freetype in some standard locations... " >&6; } 3.56 3.57 - if test -s /usr/X11/include/ft2build.h && test -d /usr/X11/include/freetype2/freetype; then 3.58 - DEFAULT_FREETYPE_CFLAGS="-I/usr/X11/include/freetype2 -I/usr/X11/include" 3.59 - DEFAULT_FREETYPE_LIBS="-L/usr/X11/lib -lfreetype" 3.60 + if test -s $SYS_ROOT/usr/X11/include/ft2build.h && test -d $SYS_ROOT/usr/X11/include/freetype2/freetype; then 3.61 + DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/X11/include/freetype2 -I$SYS_ROOT/usr/X11/include" 3.62 + DEFAULT_FREETYPE_LIBS="-L$SYS_ROOT/usr/X11/lib -lfreetype" 3.63 fi 3.64 - if test -s /usr/include/ft2build.h && test -d /usr/include/freetype2/freetype; then 3.65 - DEFAULT_FREETYPE_CFLAGS="-I/usr/include/freetype2" 3.66 + if test -s $SYS_ROOT/usr/include/ft2build.h && test -d $SYS_ROOT/usr/include/freetype2/freetype; then 3.67 + DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/include/freetype2" 3.68 DEFAULT_FREETYPE_LIBS="-lfreetype" 3.69 fi 3.70 3.71 @@ -33220,6 +33229,10 @@ 3.72 fi 3.73 3.74 if test "x$ENABLE_CCACHE" = xyes; then 3.75 + OLD_PATH="$PATH" 3.76 + if test "x$TOOLS_DIR" != x; then 3.77 + PATH=$TOOLS_DIR:$PATH 3.78 + fi 3.79 # Extract the first word of "ccache", so it can be a program name with args. 3.80 set dummy ccache; ac_word=$2 3.81 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 3.82 @@ -33260,6 +33273,7 @@ 3.83 fi 3.84 3.85 3.86 + PATH="$OLD_PATH" 3.87 else 3.88 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ccache" >&5 3.89 $as_echo_n "checking for ccache... " >&6; }
4.1 --- a/common/autoconf/libraries.m4 Tue Jun 18 11:29:34 2013 +0200 4.2 +++ b/common/autoconf/libraries.m4 Tue Jun 18 11:30:36 2013 +0200 4.3 @@ -123,11 +123,17 @@ 4.4 if test "x$x_includes" = xNONE; then 4.5 if test -f "$SYS_ROOT/usr/X11R6/include/X11/Xlib.h"; then 4.6 x_includes="$SYS_ROOT/usr/X11R6/include" 4.7 + elif test -f "$SYS_ROOT/usr/include/X11/Xlib.h"; then 4.8 + x_includes="$SYS_ROOT/usr/include" 4.9 fi 4.10 fi 4.11 if test "x$x_libraries" = xNONE; then 4.12 if test -f "$SYS_ROOT/usr/X11R6/lib/libX11.so"; then 4.13 x_libraries="$SYS_ROOT/usr/X11R6/lib" 4.14 + elif test "$SYS_ROOT/usr/lib64/libX11.so" && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then 4.15 + x_libraries="$SYS_ROOT/usr/lib64" 4.16 + elif test -f "$SYS_ROOT/usr/lib/libX11.so"; then 4.17 + x_libraries="$SYS_ROOT/usr/lib" 4.18 fi 4.19 fi 4.20 fi 4.21 @@ -153,8 +159,7 @@ 4.22 if test "x$OPENJDK_TARGET_OS" = xlinux; then 4.23 if test -d "$SYS_ROOT/usr/X11R6"; then 4.24 OPENWIN_HOME="$SYS_ROOT/usr/X11R6" 4.25 - fi 4.26 - if test -d "$SYS_ROOT/usr/include/X11"; then 4.27 + elif test -d "$SYS_ROOT/usr/include/X11"; then 4.28 OPENWIN_HOME="$SYS_ROOT/usr" 4.29 fi 4.30 fi 4.31 @@ -359,12 +364,12 @@ 4.32 if test "x$FREETYPE2_FOUND" = xno; then 4.33 AC_MSG_CHECKING([for freetype in some standard locations]) 4.34 4.35 - if test -s /usr/X11/include/ft2build.h && test -d /usr/X11/include/freetype2/freetype; then 4.36 - DEFAULT_FREETYPE_CFLAGS="-I/usr/X11/include/freetype2 -I/usr/X11/include" 4.37 - DEFAULT_FREETYPE_LIBS="-L/usr/X11/lib -lfreetype" 4.38 + if test -s $SYS_ROOT/usr/X11/include/ft2build.h && test -d $SYS_ROOT/usr/X11/include/freetype2/freetype; then 4.39 + DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/X11/include/freetype2 -I$SYS_ROOT/usr/X11/include" 4.40 + DEFAULT_FREETYPE_LIBS="-L$SYS_ROOT/usr/X11/lib -lfreetype" 4.41 fi 4.42 - if test -s /usr/include/ft2build.h && test -d /usr/include/freetype2/freetype; then 4.43 - DEFAULT_FREETYPE_CFLAGS="-I/usr/include/freetype2" 4.44 + if test -s $SYS_ROOT/usr/include/ft2build.h && test -d $SYS_ROOT/usr/include/freetype2/freetype; then 4.45 + DEFAULT_FREETYPE_CFLAGS="-I$SYS_ROOT/usr/include/freetype2" 4.46 DEFAULT_FREETYPE_LIBS="-lfreetype" 4.47 fi 4.48
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/common/makefiles/devkit/Makefile Tue Jun 18 11:30:36 2013 +0200 5.3 @@ -0,0 +1,123 @@ 5.4 +# 5.5 +# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 5.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 +# 5.8 +# This code is free software; you can redistribute it and/or modify it 5.9 +# under the terms of the GNU General Public License version 2 only, as 5.10 +# published by the Free Software Foundation. Oracle designates this 5.11 +# particular file as subject to the "Classpath" exception as provided 5.12 +# by Oracle in the LICENSE file that accompanied this code. 5.13 +# 5.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 5.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.17 +# version 2 for more details (a copy is included in the LICENSE file that 5.18 +# accompanied this code). 5.19 +# 5.20 +# You should have received a copy of the GNU General Public License version 5.21 +# 2 along with this work; if not, write to the Free Software Foundation, 5.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.23 +# 5.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.25 +# or visit www.oracle.com if you need additional information or have any 5.26 +# questions. 5.27 +# 5.28 + 5.29 +########################################################################################## 5.30 +# 5.31 +# This Makefile, together with Tools.gmk, can be used to compile a set of 5.32 +# gcc based cross compilation, portable, self contained packages, capable 5.33 +# of building OpenJDK. 5.34 +# 5.35 +# In addition to the makefiles, access to Oracle Linux installation 5.36 +# media is required. This has been tested against Oracle Enterprise Linux 5.37 +# 5.5. Set variables RPM_DIR_x86_64 and RPM_DIR_i686 respectively to point 5.38 +# to directory containing the RPMs. 5.39 +# 5.40 +# By default this Makefile will build crosstools for: 5.41 +# * i686-unknown-linux-gnu 5.42 +# * x86_64-unknown-linux-gnu 5.43 +# The x86_64 version of the compilers will work in multi arch mode and will 5.44 +# be able to compile 32bit binaries with the -m32 flag. This makes the 5.45 +# explicit cross compiler for i686 somewhat redundant and is a known issue. 5.46 +# 5.47 +# To build the full set of crosstools, use a command line looking like this: 5.48 +# 5.49 +# make tars RPM_DIR_x86_64=/tmp/oel55-x86_64/Server/ RPM_DIR_i686=/tmp/oel55-i686/Server/ 5.50 +# 5.51 +# To create a x86_64 package without the redundant i686 cross compiler, do 5.52 +# like this: 5.53 +# 5.54 +# make tars platforms=x86_64-unknown-linux-gnu RPM_DIR_x86_64=/tmp/oel55-x86_64/Server/ RPM_DIR_i686=/tmp/oel55-i686/Server/ 5.55 + 5.56 +# 5.57 +# Main makefile which iterates over all host and target platforms. 5.58 +# 5.59 + 5.60 +os := $(shell uname -o) 5.61 +cpu := x86_64 5.62 +#$(shell uname -p) 5.63 + 5.64 +# 5.65 +# This wrapper script can handle exactly these platforms 5.66 +# 5.67 +platforms := $(foreach p,x86_64 i686,$(p)-unknown-linux-gnu) 5.68 +#platforms := $(foreach p,x86_64,$(p)-unknown-linux-gnu) 5.69 + 5.70 +# Figure out what platform this is building on. 5.71 +me := $(cpu)-$(if $(findstring Linux,$(os)),unknown-linux-gnu) 5.72 + 5.73 +$(info Building on platform $(me)) 5.74 + 5.75 +all compile : $(platforms) 5.76 + 5.77 +ifeq (,$(SKIP_ME)) 5.78 +$(foreach p,$(filter-out $(me),$(platforms)),$(eval $(p) : $$(me))) 5.79 +endif 5.80 + 5.81 +OUTPUT_ROOT = $(abspath ../../../build/devkit) 5.82 +RESULT = $(OUTPUT_ROOT)/result 5.83 + 5.84 +submakevars = HOST=$@ BUILD=$(me) \ 5.85 + RESULT=$(RESULT) PREFIX=$(RESULT)/$@ \ 5.86 + OUTPUT_ROOT=$(OUTPUT_ROOT) 5.87 +$(platforms) : 5.88 + @echo 'Building compilers for $@' 5.89 + @echo 'Targets: $(platforms)' 5.90 + for p in $@ $(filter-out $@,$(platforms)); do \ 5.91 + $(MAKE) -f Tools.gmk all $(submakevars) \ 5.92 + TARGET=$$p || exit 1 ; \ 5.93 + done 5.94 + @echo 'Building ccache program for $@' 5.95 + $(MAKE) -f Tools.gmk ccache $(submakevars) TARGET=$@ 5.96 + @echo 'All done"' 5.97 + 5.98 +$(foreach a,i686 x86_64,$(eval $(a) : $(filter $(a)%,$(platforms)))) 5.99 + 5.100 +ia32 : i686 5.101 +today := $(shell date +%Y%m%d) 5.102 + 5.103 + 5.104 +define Mktar 5.105 +$(1)_tar = $$(RESULT)/sdk-$(1)-$$(today).tar.gz 5.106 +$$($(1)_tar) : PLATFORM = $(1) 5.107 +TARFILES += $$($(1)_tar) 5.108 +$$($(1)_tar) : $(1) $$(shell find $$(RESULT)/$(1)) 5.109 +endef 5.110 + 5.111 +$(foreach p,$(platforms),$(eval $(call Mktar,$(p)))) 5.112 + 5.113 +tars : all $(TARFILES) 5.114 +onlytars : $(TARFILES) 5.115 +%.tar.gz : 5.116 + @echo 'Creating compiler package $@' 5.117 + cd $(RESULT)/$(PLATFORM) && tar -czf $@ * 5.118 + touch $@ 5.119 + 5.120 +clean : 5.121 + rm -rf build result 5.122 + 5.123 +FORCE : 5.124 +.PHONY : $(configs) $(platforms) 5.125 + 5.126 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/common/makefiles/devkit/Tools.gmk Tue Jun 18 11:30:36 2013 +0200 6.3 @@ -0,0 +1,473 @@ 6.4 +# 6.5 +# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 6.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 +# 6.8 +# This code is free software; you can redistribute it and/or modify it 6.9 +# under the terms of the GNU General Public License version 2 only, as 6.10 +# published by the Free Software Foundation. Oracle designates this 6.11 +# particular file as subject to the "Classpath" exception as provided 6.12 +# by Oracle in the LICENSE file that accompanied this code. 6.13 +# 6.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 6.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 +# version 2 for more details (a copy is included in the LICENSE file that 6.18 +# accompanied this code). 6.19 +# 6.20 +# You should have received a copy of the GNU General Public License version 6.21 +# 2 along with this work; if not, write to the Free Software Foundation, 6.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 +# 6.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.25 +# or visit www.oracle.com if you need additional information or have any 6.26 +# questions. 6.27 +# 6.28 + 6.29 +########################################################################################## 6.30 +# 6.31 +# Workhorse makefile for creating ONE cross compiler 6.32 +# Needs either to be from BUILD -> BUILD OR have 6.33 +# BUILD -> HOST prebuilt 6.34 +# 6.35 +# NOTE: There is a bug here. We don't limit the 6.36 +# PATH when building BUILD -> BUILD, which means that 6.37 +# if you configure after you've once build the BUILD->BUILD 6.38 +# compiler THAT one will be picked up as the compiler for itself. 6.39 +# This is not so great, especially if you did a partial delete 6.40 +# of the target tree. 6.41 +# 6.42 +# Fix this... 6.43 +# 6.44 + 6.45 +$(info TARGET=$(TARGET)) 6.46 +$(info HOST=$(HOST)) 6.47 +$(info BUILD=$(BUILD)) 6.48 + 6.49 +ARCH := $(word 1,$(subst -, ,$(TARGET))) 6.50 + 6.51 +########################################################################################## 6.52 +# Define external dependencies 6.53 + 6.54 +# Latest that could be made to work. 6.55 +gcc_ver := gcc-4.7.3 6.56 +binutils_ver := binutils-2.22 6.57 +ccache_ver := ccache-3.1.9 6.58 +mpfr_ver := mpfr-3.0.1 6.59 +gmp_ver := gmp-4.3.2 6.60 +mpc_ver := mpc-1.0.1 6.61 + 6.62 +GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 6.63 +BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 6.64 +CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz 6.65 +MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 6.66 +GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 6.67 +MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz 6.68 + 6.69 +# RPMs in OEL5.5 6.70 +RPM_LIST := \ 6.71 + kernel-headers \ 6.72 + glibc-2 glibc-headers glibc-devel \ 6.73 + cups-libs cups-devel \ 6.74 + libX11 libX11-devel \ 6.75 + xorg-x11-proto-devel \ 6.76 + alsa-lib alsa-lib-devel \ 6.77 + libXext libXext-devel \ 6.78 + libXtst libXtst-devel \ 6.79 + libXrender libXrender-devel \ 6.80 + freetype freetype-devel \ 6.81 + libXt libXt-devel \ 6.82 + libSM libSM-devel \ 6.83 + libICE libICE-devel \ 6.84 + libXi libXi-devel \ 6.85 + libXdmcp libXdmcp-devel \ 6.86 + libXau libXau-devel \ 6.87 + libgcc 6.88 + 6.89 + 6.90 +ifeq ($(ARCH),x86_64) 6.91 + RPM_DIR ?= $(RPM_DIR_x86_64) 6.92 + RPM_ARCHS := x86_64 6.93 + ifeq ($(BUILD),$(HOST)) 6.94 + ifeq ($(TARGET),$(HOST)) 6.95 + # When building the native compiler for x86_64, enable mixed mode. 6.96 + RPM_ARCHS += i386 i686 6.97 + endif 6.98 + endif 6.99 +else 6.100 + RPM_DIR ?= $(RPM_DIR_i686) 6.101 + RPM_ARCHS := i386 i686 6.102 +endif 6.103 + 6.104 +# Sort to remove duplicates 6.105 +RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST))))) 6.106 + 6.107 +ifeq ($(RPM_FILE_LIST),) 6.108 + $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs) 6.109 +endif 6.110 + 6.111 +########################################################################################## 6.112 +# Define common directories and files 6.113 + 6.114 +# Ensure we have 32-bit libs also for x64. We enable mixed-mode. 6.115 +ifeq (x86_64,$(ARCH)) 6.116 + LIBDIRS := lib64 lib 6.117 + CFLAGS_lib := -m32 6.118 +else 6.119 + LIBDIRS := lib 6.120 +endif 6.121 + 6.122 +# Define directories 6.123 +RESULT := $(OUTPUT_ROOT)/result 6.124 +BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) 6.125 +PREFIX := $(RESULT)/$(HOST) 6.126 +TARGETDIR := $(PREFIX)/$(TARGET) 6.127 +SYSROOT := $(TARGETDIR)/sys-root 6.128 +DOWNLOAD := $(OUTPUT_ROOT)/download 6.129 +SRCDIR := $(OUTPUT_ROOT)/src 6.130 + 6.131 +# Marker file for unpacking rpms 6.132 +rpms := $(SYSROOT)/rpms_unpacked 6.133 + 6.134 +# Need to patch libs that are linker scripts to use non-absolute paths 6.135 +libs := $(SYSROOT)/libs_patched 6.136 + 6.137 +########################################################################################## 6.138 +# Unpack source packages 6.139 + 6.140 +# Generate downloading + unpacking of sources. 6.141 +define Download 6.142 +$(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) 6.143 +$(1)_CFG = $$($(1)_DIR)/configure 6.144 +$(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) 6.145 + 6.146 +$$($(1)_CFG) : $$($(1)_FILE) 6.147 + mkdir -p $$(SRCDIR) 6.148 + tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< 6.149 + $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ 6.150 + echo PATCHING $$(p) ; \ 6.151 + patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ 6.152 + ) 6.153 + touch $$@ 6.154 + 6.155 +$$($(1)_FILE) : 6.156 + wget -P $(DOWNLOAD) $$($(1)) 6.157 +endef 6.158 + 6.159 +# Download and unpack all source packages 6.160 +$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p)))) 6.161 + 6.162 +########################################################################################## 6.163 +# Unpack RPMS 6.164 + 6.165 +# Note. For building linux you should install rpm2cpio. 6.166 +define unrpm 6.167 +$(SYSROOT)/$(notdir $(1)).unpacked \ 6.168 + : $(1) 6.169 +$$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked 6.170 +endef 6.171 + 6.172 +%.unpacked : 6.173 + $(info Unpacking target rpms and libraries from $<) 6.174 + @(mkdir -p $(@D); \ 6.175 + cd $(@D); \ 6.176 + rpm2cpio $< | \ 6.177 + cpio --extract --make-directories \ 6.178 + -f \ 6.179 + "./usr/share/doc/*" \ 6.180 + "./usr/share/man/*" \ 6.181 + "./usr/X11R6/man/*" \ 6.182 + "*/X11/locale/*" \ 6.183 + || die ; ) 6.184 + touch $@ 6.185 + 6.186 +$(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p)))) 6.187 + 6.188 +########################################################################################## 6.189 + 6.190 +# Note: MUST create a <sys-root>/usr/lib even if not really needed. 6.191 +# gcc will use a path relative to it to resolve lib64. (x86_64). 6.192 +# we're creating multi-lib compiler with 32bit libc as well, so we should 6.193 +# have it anyway, but just to make sure... 6.194 +# Patch libc.so and libpthread.so to force linking against libraries in sysroot 6.195 +# and not the ones installed on the build machine. 6.196 +$(libs) : $(rpms) 6.197 + @echo Patching libc and pthreads 6.198 + @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \ 6.199 + (cat $$f | sed -e 's|/usr/lib64/||g' \ 6.200 + -e 's|/usr/lib/||g' \ 6.201 + -e 's|/lib64/||g' \ 6.202 + -e 's|/lib/||g' ) > $$f.tmp ; \ 6.203 + mv $$f.tmp $$f ; \ 6.204 + done) 6.205 + @mkdir -p $(SYSROOT)/usr/lib 6.206 + @touch $@ 6.207 + 6.208 +########################################################################################## 6.209 + 6.210 +# Define marker files for each source package to be compiled 6.211 +$(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) 6.212 + 6.213 +########################################################################################## 6.214 + 6.215 +# Default base config 6.216 +CONFIG = --target=$(TARGET) \ 6.217 + --host=$(HOST) --build=$(BUILD) \ 6.218 + --prefix=$(PREFIX) 6.219 + 6.220 +PATHEXT = $(RESULT)/$(BUILD)/bin: 6.221 + 6.222 +PATHPRE = PATH=$(PATHEXT)$(PATH) 6.223 +BUILDPAR = -j16 6.224 + 6.225 +# Default commands to when making 6.226 +MAKECMD = 6.227 +INSTALLCMD = install 6.228 + 6.229 + 6.230 +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 6.231 + 6.232 +ifeq ($(HOST),$(BUILD)) 6.233 +ifeq ($(HOST),$(TARGET)) 6.234 +TOOLS = $(call declare_tools,_FOR_TARGET,) 6.235 +endif 6.236 +endif 6.237 + 6.238 +TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-) 6.239 + 6.240 +########################################################################################## 6.241 + 6.242 +# Create a TARGET bfd + libiberty only. 6.243 +# Configure one or two times depending on mulitlib arch. 6.244 +# If multilib, the second should be 32-bit, and we resolve 6.245 +# CFLAG_<name> to most likely -m32. 6.246 +define mk_bfd 6.247 +$$(info Libs for $(1)) 6.248 +$$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 6.249 + : CFLAGS += $$(CFLAGS_$(1)) 6.250 +$$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 6.251 + : LIBDIRS = --libdir=$(TARGETDIR)/$(1) 6.252 + 6.253 +bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done 6.254 +bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile 6.255 +endef 6.256 + 6.257 +# Create one set of bfds etc for each multilib arch 6.258 +$(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l)))) 6.259 + 6.260 +# Only build these two libs. 6.261 +$(bfdlib) : MAKECMD = all-libiberty all-bfd 6.262 +$(bfdlib) : INSTALLCMD = install-libiberty install-bfd 6.263 + 6.264 +# Building targets libbfd + libiberty. HOST==TARGET, i.e not 6.265 +# for a cross env. 6.266 +$(bfdmakes) : CONFIG = --target=$(TARGET) \ 6.267 + --host=$(TARGET) --build=$(BUILD) \ 6.268 + --prefix=$(TARGETDIR) \ 6.269 + --with-sysroot=$(SYSROOT) \ 6.270 + $(LIBDIRS) 6.271 + 6.272 +$(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-) 6.273 + 6.274 +########################################################################################## 6.275 + 6.276 +$(gcc) \ 6.277 +$(binutils) \ 6.278 +$(gmp) \ 6.279 +$(mpfr) \ 6.280 +$(mpc) \ 6.281 +$(bfdmakes) \ 6.282 +$(ccache) : ENVS += $(TOOLS) 6.283 + 6.284 +# libdir to work around hateful bfd stuff installing into wrong dirs... 6.285 +# ensure we have 64 bit bfd support in the HOST library. I.e our 6.286 +# compiler on i686 will know 64 bit symbols, BUT later 6.287 +# we build just the libs again for TARGET, then with whatever the arch 6.288 +# wants. 6.289 +$(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS)) 6.290 + 6.291 +# Makefile creation. Simply run configure in build dir. 6.292 +$(bfdmakes) \ 6.293 +$(BUILDDIR)/$(binutils_ver)/Makefile \ 6.294 + : $(BINUTILS_CFG) 6.295 + $(info Configuring $@. Log in $(@D)/log.config) 6.296 + @mkdir -p $(@D) 6.297 + ( \ 6.298 + cd $(@D) ; \ 6.299 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 6.300 + $(BINUTILS_CFG) \ 6.301 + $(CONFIG) \ 6.302 + --with-sysroot=$(SYSROOT) \ 6.303 + --disable-nls \ 6.304 + --program-prefix=$(TARGET)- \ 6.305 + --enable-multilib \ 6.306 + ) > $(@D)/log.config 2>&1 6.307 + @echo 'done' 6.308 + 6.309 +$(BUILDDIR)/$(mpfr_ver)/Makefile \ 6.310 + : $(MPFR_CFG) 6.311 + $(info Configuring $@. Log in $(@D)/log.config) 6.312 + @mkdir -p $(@D) 6.313 + ( \ 6.314 + cd $(@D) ; \ 6.315 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 6.316 + $(MPFR_CFG) \ 6.317 + $(CONFIG) \ 6.318 + --program-prefix=$(TARGET)- \ 6.319 + --enable-shared=no \ 6.320 + --with-gmp=$(PREFIX) \ 6.321 + ) > $(@D)/log.config 2>&1 6.322 + @echo 'done' 6.323 + 6.324 +$(BUILDDIR)/$(gmp_ver)/Makefile \ 6.325 + : $(GMP_CFG) 6.326 + $(info Configuring $@. Log in $(@D)/log.config) 6.327 + @mkdir -p $(@D) 6.328 + ( \ 6.329 + cd $(@D) ; \ 6.330 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 6.331 + $(GMP_CFG) \ 6.332 + --host=$(HOST) --build=$(BUILD) \ 6.333 + --prefix=$(PREFIX) \ 6.334 + --disable-nls \ 6.335 + --program-prefix=$(TARGET)- \ 6.336 + --enable-shared=no \ 6.337 + --with-mpfr=$(PREFIX) \ 6.338 + ) > $(@D)/log.config 2>&1 6.339 + @echo 'done' 6.340 + 6.341 +$(BUILDDIR)/$(mpc_ver)/Makefile \ 6.342 + : $(MPC_CFG) 6.343 + $(info Configuring $@. Log in $(@D)/log.config) 6.344 + @mkdir -p $(@D) 6.345 + ( \ 6.346 + cd $(@D) ; \ 6.347 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 6.348 + $(MPC_CFG) \ 6.349 + $(CONFIG) \ 6.350 + --program-prefix=$(TARGET)- \ 6.351 + --enable-shared=no \ 6.352 + --with-mpfr=$(PREFIX) \ 6.353 + --with-gmp=$(PREFIX) \ 6.354 + ) > $(@D)/log.config 2>&1 6.355 + @echo 'done' 6.356 + 6.357 +# Only valid if glibc target -> linux 6.358 +# proper destructor handling for c++ 6.359 +ifneq (,$(findstring linux,$(TARGET))) 6.360 +$(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit 6.361 +endif 6.362 + 6.363 +# Want: 6.364 +# c,c++ 6.365 +# shared libs 6.366 +# multilib (-m32/-m64 on x64) 6.367 +# skip native language. 6.368 +# and link and assemble with the binutils we created 6.369 +# earlier, so --with-gnu* 6.370 +$(BUILDDIR)/$(gcc_ver)/Makefile \ 6.371 + : $(GCC_CFG) 6.372 + $(info Configuring $@. Log in $(@D)/log.config) 6.373 + mkdir -p $(@D) 6.374 + ( \ 6.375 + cd $(@D) ; \ 6.376 + $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \ 6.377 + $(CONFIG) \ 6.378 + --with-sysroot=$(SYSROOT) \ 6.379 + --enable-languages=c,c++ \ 6.380 + --enable-shared \ 6.381 + --enable-multilib \ 6.382 + --disable-nls \ 6.383 + --with-gnu-as \ 6.384 + --with-gnu-ld \ 6.385 + --with-mpfr=$(PREFIX) \ 6.386 + --with-gmp=$(PREFIX) \ 6.387 + --with-mpc=$(PREFIX) \ 6.388 + ) > $(@D)/log.config 2>&1 6.389 + @echo 'done' 6.390 + 6.391 +# need binutils for gcc 6.392 +$(gcc) : $(binutils) 6.393 + 6.394 +# as of 4.3 or so need these for doing config 6.395 +$(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc) 6.396 +$(mpfr) : $(gmp) 6.397 +$(mpc) : $(gmp) $(mpfr) 6.398 + 6.399 +########################################################################################## 6.400 +# very straightforward. just build a ccache. it is only for host. 6.401 +$(BUILDDIR)/$(ccache_ver)/Makefile \ 6.402 + : $(CCACHE_CFG) 6.403 + $(info Configuring $@. Log in $(@D)/log.config) 6.404 + @mkdir -p $(@D) 6.405 + @( \ 6.406 + cd $(@D) ; \ 6.407 + $(PATHPRE) $(ENVS) $(CCACHE_CFG) \ 6.408 + $(CONFIG) \ 6.409 + ) > $(@D)/log.config 2>&1 6.410 + @echo 'done' 6.411 + 6.412 +gccpatch = $(TARGETDIR)/gcc-patched 6.413 + 6.414 +########################################################################################## 6.415 +# For some reason cpp is not created as a target-compiler 6.416 +ifeq ($(HOST),$(TARGET)) 6.417 +$(gccpatch) : $(gcc) link_libs 6.418 + @echo -n 'Creating compiler symlinks...' 6.419 + @for f in cpp; do \ 6.420 + if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ];\ 6.421 + then \ 6.422 + cd $(PREFIX)/bin && \ 6.423 + ln -s $$f $(TARGET)-$$f ; \ 6.424 + fi \ 6.425 + done 6.426 + @touch $@ 6.427 + @echo 'done' 6.428 + 6.429 +########################################################################################## 6.430 +# Ugly at best. Seems that when we compile host->host compiler, that are NOT 6.431 +# the BUILD compiler, the result will not try searching for libs in package root. 6.432 +# "Solve" this by create links from the target libdirs to where they are. 6.433 +link_libs: 6.434 + @echo -n 'Creating library symlinks...' 6.435 + @$(foreach l,$(LIBDIRS), \ 6.436 + for f in `cd $(PREFIX)/$(l) && ls`; do \ 6.437 + if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \ 6.438 + mkdir -p $(TARGETDIR)/$(l) && \ 6.439 + cd $(TARGETDIR)/$(l)/ && \ 6.440 + ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \ 6.441 + fi \ 6.442 + done;) 6.443 + @echo 'done' 6.444 +else 6.445 +$(gccpatch) : 6.446 + @echo 'done' 6.447 +endif 6.448 + 6.449 +########################################################################################## 6.450 +# Build in two steps. 6.451 +# make <default> 6.452 +# make install. 6.453 +# Use path to our build hosts cross tools 6.454 +# Always need to build cross tools for build host self. 6.455 +$(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile 6.456 + $(info Building $(basename $@). Log in $(<D)/log.build) 6.457 + $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1 6.458 + @echo -n 'installing...' 6.459 + $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1 6.460 + @touch $@ 6.461 + @echo 'done' 6.462 + 6.463 +########################################################################################## 6.464 + 6.465 +bfdlib : $(bfdlib) 6.466 +binutils : $(binutils) 6.467 +rpms : $(rpms) 6.468 +libs : $(libs) 6.469 +sysroot : rpms libs 6.470 +gcc : sysroot $(gcc) $(gccpatch) 6.471 +all : binutils gcc bfdlib 6.472 + 6.473 +# this is only built for host. so separate. 6.474 +ccache : $(ccache) 6.475 + 6.476 +.PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot