1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/common/makefiles/devkit/Tools.gmk Tue Jun 18 11:30:36 2013 +0200 1.3 @@ -0,0 +1,473 @@ 1.4 +# 1.5 +# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 +# 1.8 +# This code is free software; you can redistribute it and/or modify it 1.9 +# under the terms of the GNU General Public License version 2 only, as 1.10 +# published by the Free Software Foundation. Oracle designates this 1.11 +# particular file as subject to the "Classpath" exception as provided 1.12 +# by Oracle in the LICENSE file that accompanied this code. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 +# or visit www.oracle.com if you need additional information or have any 1.26 +# questions. 1.27 +# 1.28 + 1.29 +########################################################################################## 1.30 +# 1.31 +# Workhorse makefile for creating ONE cross compiler 1.32 +# Needs either to be from BUILD -> BUILD OR have 1.33 +# BUILD -> HOST prebuilt 1.34 +# 1.35 +# NOTE: There is a bug here. We don't limit the 1.36 +# PATH when building BUILD -> BUILD, which means that 1.37 +# if you configure after you've once build the BUILD->BUILD 1.38 +# compiler THAT one will be picked up as the compiler for itself. 1.39 +# This is not so great, especially if you did a partial delete 1.40 +# of the target tree. 1.41 +# 1.42 +# Fix this... 1.43 +# 1.44 + 1.45 +$(info TARGET=$(TARGET)) 1.46 +$(info HOST=$(HOST)) 1.47 +$(info BUILD=$(BUILD)) 1.48 + 1.49 +ARCH := $(word 1,$(subst -, ,$(TARGET))) 1.50 + 1.51 +########################################################################################## 1.52 +# Define external dependencies 1.53 + 1.54 +# Latest that could be made to work. 1.55 +gcc_ver := gcc-4.7.3 1.56 +binutils_ver := binutils-2.22 1.57 +ccache_ver := ccache-3.1.9 1.58 +mpfr_ver := mpfr-3.0.1 1.59 +gmp_ver := gmp-4.3.2 1.60 +mpc_ver := mpc-1.0.1 1.61 + 1.62 +GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 1.63 +BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 1.64 +CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz 1.65 +MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 1.66 +GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 1.67 +MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz 1.68 + 1.69 +# RPMs in OEL5.5 1.70 +RPM_LIST := \ 1.71 + kernel-headers \ 1.72 + glibc-2 glibc-headers glibc-devel \ 1.73 + cups-libs cups-devel \ 1.74 + libX11 libX11-devel \ 1.75 + xorg-x11-proto-devel \ 1.76 + alsa-lib alsa-lib-devel \ 1.77 + libXext libXext-devel \ 1.78 + libXtst libXtst-devel \ 1.79 + libXrender libXrender-devel \ 1.80 + freetype freetype-devel \ 1.81 + libXt libXt-devel \ 1.82 + libSM libSM-devel \ 1.83 + libICE libICE-devel \ 1.84 + libXi libXi-devel \ 1.85 + libXdmcp libXdmcp-devel \ 1.86 + libXau libXau-devel \ 1.87 + libgcc 1.88 + 1.89 + 1.90 +ifeq ($(ARCH),x86_64) 1.91 + RPM_DIR ?= $(RPM_DIR_x86_64) 1.92 + RPM_ARCHS := x86_64 1.93 + ifeq ($(BUILD),$(HOST)) 1.94 + ifeq ($(TARGET),$(HOST)) 1.95 + # When building the native compiler for x86_64, enable mixed mode. 1.96 + RPM_ARCHS += i386 i686 1.97 + endif 1.98 + endif 1.99 +else 1.100 + RPM_DIR ?= $(RPM_DIR_i686) 1.101 + RPM_ARCHS := i386 i686 1.102 +endif 1.103 + 1.104 +# Sort to remove duplicates 1.105 +RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST))))) 1.106 + 1.107 +ifeq ($(RPM_FILE_LIST),) 1.108 + $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs) 1.109 +endif 1.110 + 1.111 +########################################################################################## 1.112 +# Define common directories and files 1.113 + 1.114 +# Ensure we have 32-bit libs also for x64. We enable mixed-mode. 1.115 +ifeq (x86_64,$(ARCH)) 1.116 + LIBDIRS := lib64 lib 1.117 + CFLAGS_lib := -m32 1.118 +else 1.119 + LIBDIRS := lib 1.120 +endif 1.121 + 1.122 +# Define directories 1.123 +RESULT := $(OUTPUT_ROOT)/result 1.124 +BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) 1.125 +PREFIX := $(RESULT)/$(HOST) 1.126 +TARGETDIR := $(PREFIX)/$(TARGET) 1.127 +SYSROOT := $(TARGETDIR)/sys-root 1.128 +DOWNLOAD := $(OUTPUT_ROOT)/download 1.129 +SRCDIR := $(OUTPUT_ROOT)/src 1.130 + 1.131 +# Marker file for unpacking rpms 1.132 +rpms := $(SYSROOT)/rpms_unpacked 1.133 + 1.134 +# Need to patch libs that are linker scripts to use non-absolute paths 1.135 +libs := $(SYSROOT)/libs_patched 1.136 + 1.137 +########################################################################################## 1.138 +# Unpack source packages 1.139 + 1.140 +# Generate downloading + unpacking of sources. 1.141 +define Download 1.142 +$(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) 1.143 +$(1)_CFG = $$($(1)_DIR)/configure 1.144 +$(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) 1.145 + 1.146 +$$($(1)_CFG) : $$($(1)_FILE) 1.147 + mkdir -p $$(SRCDIR) 1.148 + tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< 1.149 + $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ 1.150 + echo PATCHING $$(p) ; \ 1.151 + patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ 1.152 + ) 1.153 + touch $$@ 1.154 + 1.155 +$$($(1)_FILE) : 1.156 + wget -P $(DOWNLOAD) $$($(1)) 1.157 +endef 1.158 + 1.159 +# Download and unpack all source packages 1.160 +$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p)))) 1.161 + 1.162 +########################################################################################## 1.163 +# Unpack RPMS 1.164 + 1.165 +# Note. For building linux you should install rpm2cpio. 1.166 +define unrpm 1.167 +$(SYSROOT)/$(notdir $(1)).unpacked \ 1.168 + : $(1) 1.169 +$$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked 1.170 +endef 1.171 + 1.172 +%.unpacked : 1.173 + $(info Unpacking target rpms and libraries from $<) 1.174 + @(mkdir -p $(@D); \ 1.175 + cd $(@D); \ 1.176 + rpm2cpio $< | \ 1.177 + cpio --extract --make-directories \ 1.178 + -f \ 1.179 + "./usr/share/doc/*" \ 1.180 + "./usr/share/man/*" \ 1.181 + "./usr/X11R6/man/*" \ 1.182 + "*/X11/locale/*" \ 1.183 + || die ; ) 1.184 + touch $@ 1.185 + 1.186 +$(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p)))) 1.187 + 1.188 +########################################################################################## 1.189 + 1.190 +# Note: MUST create a <sys-root>/usr/lib even if not really needed. 1.191 +# gcc will use a path relative to it to resolve lib64. (x86_64). 1.192 +# we're creating multi-lib compiler with 32bit libc as well, so we should 1.193 +# have it anyway, but just to make sure... 1.194 +# Patch libc.so and libpthread.so to force linking against libraries in sysroot 1.195 +# and not the ones installed on the build machine. 1.196 +$(libs) : $(rpms) 1.197 + @echo Patching libc and pthreads 1.198 + @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \ 1.199 + (cat $$f | sed -e 's|/usr/lib64/||g' \ 1.200 + -e 's|/usr/lib/||g' \ 1.201 + -e 's|/lib64/||g' \ 1.202 + -e 's|/lib/||g' ) > $$f.tmp ; \ 1.203 + mv $$f.tmp $$f ; \ 1.204 + done) 1.205 + @mkdir -p $(SYSROOT)/usr/lib 1.206 + @touch $@ 1.207 + 1.208 +########################################################################################## 1.209 + 1.210 +# Define marker files for each source package to be compiled 1.211 +$(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) 1.212 + 1.213 +########################################################################################## 1.214 + 1.215 +# Default base config 1.216 +CONFIG = --target=$(TARGET) \ 1.217 + --host=$(HOST) --build=$(BUILD) \ 1.218 + --prefix=$(PREFIX) 1.219 + 1.220 +PATHEXT = $(RESULT)/$(BUILD)/bin: 1.221 + 1.222 +PATHPRE = PATH=$(PATHEXT)$(PATH) 1.223 +BUILDPAR = -j16 1.224 + 1.225 +# Default commands to when making 1.226 +MAKECMD = 1.227 +INSTALLCMD = install 1.228 + 1.229 + 1.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 1.231 + 1.232 +ifeq ($(HOST),$(BUILD)) 1.233 +ifeq ($(HOST),$(TARGET)) 1.234 +TOOLS = $(call declare_tools,_FOR_TARGET,) 1.235 +endif 1.236 +endif 1.237 + 1.238 +TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-) 1.239 + 1.240 +########################################################################################## 1.241 + 1.242 +# Create a TARGET bfd + libiberty only. 1.243 +# Configure one or two times depending on mulitlib arch. 1.244 +# If multilib, the second should be 32-bit, and we resolve 1.245 +# CFLAG_<name> to most likely -m32. 1.246 +define mk_bfd 1.247 +$$(info Libs for $(1)) 1.248 +$$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 1.249 + : CFLAGS += $$(CFLAGS_$(1)) 1.250 +$$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ 1.251 + : LIBDIRS = --libdir=$(TARGETDIR)/$(1) 1.252 + 1.253 +bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done 1.254 +bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile 1.255 +endef 1.256 + 1.257 +# Create one set of bfds etc for each multilib arch 1.258 +$(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l)))) 1.259 + 1.260 +# Only build these two libs. 1.261 +$(bfdlib) : MAKECMD = all-libiberty all-bfd 1.262 +$(bfdlib) : INSTALLCMD = install-libiberty install-bfd 1.263 + 1.264 +# Building targets libbfd + libiberty. HOST==TARGET, i.e not 1.265 +# for a cross env. 1.266 +$(bfdmakes) : CONFIG = --target=$(TARGET) \ 1.267 + --host=$(TARGET) --build=$(BUILD) \ 1.268 + --prefix=$(TARGETDIR) \ 1.269 + --with-sysroot=$(SYSROOT) \ 1.270 + $(LIBDIRS) 1.271 + 1.272 +$(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-) 1.273 + 1.274 +########################################################################################## 1.275 + 1.276 +$(gcc) \ 1.277 +$(binutils) \ 1.278 +$(gmp) \ 1.279 +$(mpfr) \ 1.280 +$(mpc) \ 1.281 +$(bfdmakes) \ 1.282 +$(ccache) : ENVS += $(TOOLS) 1.283 + 1.284 +# libdir to work around hateful bfd stuff installing into wrong dirs... 1.285 +# ensure we have 64 bit bfd support in the HOST library. I.e our 1.286 +# compiler on i686 will know 64 bit symbols, BUT later 1.287 +# we build just the libs again for TARGET, then with whatever the arch 1.288 +# wants. 1.289 +$(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS)) 1.290 + 1.291 +# Makefile creation. Simply run configure in build dir. 1.292 +$(bfdmakes) \ 1.293 +$(BUILDDIR)/$(binutils_ver)/Makefile \ 1.294 + : $(BINUTILS_CFG) 1.295 + $(info Configuring $@. Log in $(@D)/log.config) 1.296 + @mkdir -p $(@D) 1.297 + ( \ 1.298 + cd $(@D) ; \ 1.299 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 1.300 + $(BINUTILS_CFG) \ 1.301 + $(CONFIG) \ 1.302 + --with-sysroot=$(SYSROOT) \ 1.303 + --disable-nls \ 1.304 + --program-prefix=$(TARGET)- \ 1.305 + --enable-multilib \ 1.306 + ) > $(@D)/log.config 2>&1 1.307 + @echo 'done' 1.308 + 1.309 +$(BUILDDIR)/$(mpfr_ver)/Makefile \ 1.310 + : $(MPFR_CFG) 1.311 + $(info Configuring $@. Log in $(@D)/log.config) 1.312 + @mkdir -p $(@D) 1.313 + ( \ 1.314 + cd $(@D) ; \ 1.315 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 1.316 + $(MPFR_CFG) \ 1.317 + $(CONFIG) \ 1.318 + --program-prefix=$(TARGET)- \ 1.319 + --enable-shared=no \ 1.320 + --with-gmp=$(PREFIX) \ 1.321 + ) > $(@D)/log.config 2>&1 1.322 + @echo 'done' 1.323 + 1.324 +$(BUILDDIR)/$(gmp_ver)/Makefile \ 1.325 + : $(GMP_CFG) 1.326 + $(info Configuring $@. Log in $(@D)/log.config) 1.327 + @mkdir -p $(@D) 1.328 + ( \ 1.329 + cd $(@D) ; \ 1.330 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 1.331 + $(GMP_CFG) \ 1.332 + --host=$(HOST) --build=$(BUILD) \ 1.333 + --prefix=$(PREFIX) \ 1.334 + --disable-nls \ 1.335 + --program-prefix=$(TARGET)- \ 1.336 + --enable-shared=no \ 1.337 + --with-mpfr=$(PREFIX) \ 1.338 + ) > $(@D)/log.config 2>&1 1.339 + @echo 'done' 1.340 + 1.341 +$(BUILDDIR)/$(mpc_ver)/Makefile \ 1.342 + : $(MPC_CFG) 1.343 + $(info Configuring $@. Log in $(@D)/log.config) 1.344 + @mkdir -p $(@D) 1.345 + ( \ 1.346 + cd $(@D) ; \ 1.347 + $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ 1.348 + $(MPC_CFG) \ 1.349 + $(CONFIG) \ 1.350 + --program-prefix=$(TARGET)- \ 1.351 + --enable-shared=no \ 1.352 + --with-mpfr=$(PREFIX) \ 1.353 + --with-gmp=$(PREFIX) \ 1.354 + ) > $(@D)/log.config 2>&1 1.355 + @echo 'done' 1.356 + 1.357 +# Only valid if glibc target -> linux 1.358 +# proper destructor handling for c++ 1.359 +ifneq (,$(findstring linux,$(TARGET))) 1.360 +$(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit 1.361 +endif 1.362 + 1.363 +# Want: 1.364 +# c,c++ 1.365 +# shared libs 1.366 +# multilib (-m32/-m64 on x64) 1.367 +# skip native language. 1.368 +# and link and assemble with the binutils we created 1.369 +# earlier, so --with-gnu* 1.370 +$(BUILDDIR)/$(gcc_ver)/Makefile \ 1.371 + : $(GCC_CFG) 1.372 + $(info Configuring $@. Log in $(@D)/log.config) 1.373 + mkdir -p $(@D) 1.374 + ( \ 1.375 + cd $(@D) ; \ 1.376 + $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \ 1.377 + $(CONFIG) \ 1.378 + --with-sysroot=$(SYSROOT) \ 1.379 + --enable-languages=c,c++ \ 1.380 + --enable-shared \ 1.381 + --enable-multilib \ 1.382 + --disable-nls \ 1.383 + --with-gnu-as \ 1.384 + --with-gnu-ld \ 1.385 + --with-mpfr=$(PREFIX) \ 1.386 + --with-gmp=$(PREFIX) \ 1.387 + --with-mpc=$(PREFIX) \ 1.388 + ) > $(@D)/log.config 2>&1 1.389 + @echo 'done' 1.390 + 1.391 +# need binutils for gcc 1.392 +$(gcc) : $(binutils) 1.393 + 1.394 +# as of 4.3 or so need these for doing config 1.395 +$(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc) 1.396 +$(mpfr) : $(gmp) 1.397 +$(mpc) : $(gmp) $(mpfr) 1.398 + 1.399 +########################################################################################## 1.400 +# very straightforward. just build a ccache. it is only for host. 1.401 +$(BUILDDIR)/$(ccache_ver)/Makefile \ 1.402 + : $(CCACHE_CFG) 1.403 + $(info Configuring $@. Log in $(@D)/log.config) 1.404 + @mkdir -p $(@D) 1.405 + @( \ 1.406 + cd $(@D) ; \ 1.407 + $(PATHPRE) $(ENVS) $(CCACHE_CFG) \ 1.408 + $(CONFIG) \ 1.409 + ) > $(@D)/log.config 2>&1 1.410 + @echo 'done' 1.411 + 1.412 +gccpatch = $(TARGETDIR)/gcc-patched 1.413 + 1.414 +########################################################################################## 1.415 +# For some reason cpp is not created as a target-compiler 1.416 +ifeq ($(HOST),$(TARGET)) 1.417 +$(gccpatch) : $(gcc) link_libs 1.418 + @echo -n 'Creating compiler symlinks...' 1.419 + @for f in cpp; do \ 1.420 + if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ];\ 1.421 + then \ 1.422 + cd $(PREFIX)/bin && \ 1.423 + ln -s $$f $(TARGET)-$$f ; \ 1.424 + fi \ 1.425 + done 1.426 + @touch $@ 1.427 + @echo 'done' 1.428 + 1.429 +########################################################################################## 1.430 +# Ugly at best. Seems that when we compile host->host compiler, that are NOT 1.431 +# the BUILD compiler, the result will not try searching for libs in package root. 1.432 +# "Solve" this by create links from the target libdirs to where they are. 1.433 +link_libs: 1.434 + @echo -n 'Creating library symlinks...' 1.435 + @$(foreach l,$(LIBDIRS), \ 1.436 + for f in `cd $(PREFIX)/$(l) && ls`; do \ 1.437 + if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \ 1.438 + mkdir -p $(TARGETDIR)/$(l) && \ 1.439 + cd $(TARGETDIR)/$(l)/ && \ 1.440 + ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \ 1.441 + fi \ 1.442 + done;) 1.443 + @echo 'done' 1.444 +else 1.445 +$(gccpatch) : 1.446 + @echo 'done' 1.447 +endif 1.448 + 1.449 +########################################################################################## 1.450 +# Build in two steps. 1.451 +# make <default> 1.452 +# make install. 1.453 +# Use path to our build hosts cross tools 1.454 +# Always need to build cross tools for build host self. 1.455 +$(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile 1.456 + $(info Building $(basename $@). Log in $(<D)/log.build) 1.457 + $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1 1.458 + @echo -n 'installing...' 1.459 + $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1 1.460 + @touch $@ 1.461 + @echo 'done' 1.462 + 1.463 +########################################################################################## 1.464 + 1.465 +bfdlib : $(bfdlib) 1.466 +binutils : $(binutils) 1.467 +rpms : $(rpms) 1.468 +libs : $(libs) 1.469 +sysroot : rpms libs 1.470 +gcc : sysroot $(gcc) $(gccpatch) 1.471 +all : binutils gcc bfdlib 1.472 + 1.473 +# this is only built for host. so separate. 1.474 +ccache : $(ccache) 1.475 + 1.476 +.PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot