erikj@740: # erikj@740: # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. erikj@740: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. erikj@740: # erikj@740: # This code is free software; you can redistribute it and/or modify it erikj@740: # under the terms of the GNU General Public License version 2 only, as erikj@740: # published by the Free Software Foundation. Oracle designates this erikj@740: # particular file as subject to the "Classpath" exception as provided erikj@740: # by Oracle in the LICENSE file that accompanied this code. erikj@740: # erikj@740: # This code is distributed in the hope that it will be useful, but WITHOUT erikj@740: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or erikj@740: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License erikj@740: # version 2 for more details (a copy is included in the LICENSE file that erikj@740: # accompanied this code). erikj@740: # erikj@740: # You should have received a copy of the GNU General Public License version erikj@740: # 2 along with this work; if not, write to the Free Software Foundation, erikj@740: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. erikj@740: # erikj@740: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA erikj@740: # or visit www.oracle.com if you need additional information or have any erikj@740: # questions. erikj@740: # erikj@740: erikj@740: ########################################################################################## erikj@740: # erikj@740: # Workhorse makefile for creating ONE cross compiler erikj@740: # Needs either to be from BUILD -> BUILD OR have erikj@740: # BUILD -> HOST prebuilt erikj@740: # erikj@740: # NOTE: There is a bug here. We don't limit the erikj@740: # PATH when building BUILD -> BUILD, which means that erikj@740: # if you configure after you've once build the BUILD->BUILD erikj@740: # compiler THAT one will be picked up as the compiler for itself. erikj@740: # This is not so great, especially if you did a partial delete erikj@740: # of the target tree. erikj@740: # erikj@740: # Fix this... erikj@740: # erikj@740: erikj@740: $(info TARGET=$(TARGET)) erikj@740: $(info HOST=$(HOST)) erikj@740: $(info BUILD=$(BUILD)) erikj@740: erikj@740: ARCH := $(word 1,$(subst -, ,$(TARGET))) erikj@740: erikj@740: ########################################################################################## erikj@740: # Define external dependencies erikj@740: erikj@740: # Latest that could be made to work. erikj@740: gcc_ver := gcc-4.7.3 erikj@740: binutils_ver := binutils-2.22 erikj@740: ccache_ver := ccache-3.1.9 erikj@740: mpfr_ver := mpfr-3.0.1 erikj@740: gmp_ver := gmp-4.3.2 erikj@740: mpc_ver := mpc-1.0.1 erikj@740: erikj@740: GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 erikj@740: BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 erikj@740: CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz erikj@740: MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 erikj@740: GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 erikj@740: MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz erikj@740: erikj@740: # RPMs in OEL5.5 erikj@740: RPM_LIST := \ erikj@740: kernel-headers \ erikj@740: glibc-2 glibc-headers glibc-devel \ erikj@740: cups-libs cups-devel \ erikj@740: libX11 libX11-devel \ erikj@740: xorg-x11-proto-devel \ erikj@740: alsa-lib alsa-lib-devel \ erikj@740: libXext libXext-devel \ erikj@740: libXtst libXtst-devel \ erikj@740: libXrender libXrender-devel \ erikj@740: freetype freetype-devel \ erikj@740: libXt libXt-devel \ erikj@740: libSM libSM-devel \ erikj@740: libICE libICE-devel \ erikj@740: libXi libXi-devel \ erikj@740: libXdmcp libXdmcp-devel \ erikj@740: libXau libXau-devel \ erikj@740: libgcc erikj@740: erikj@740: erikj@740: ifeq ($(ARCH),x86_64) erikj@740: RPM_DIR ?= $(RPM_DIR_x86_64) erikj@740: RPM_ARCHS := x86_64 erikj@740: ifeq ($(BUILD),$(HOST)) erikj@740: ifeq ($(TARGET),$(HOST)) erikj@740: # When building the native compiler for x86_64, enable mixed mode. erikj@740: RPM_ARCHS += i386 i686 erikj@740: endif erikj@740: endif erikj@740: else erikj@740: RPM_DIR ?= $(RPM_DIR_i686) erikj@740: RPM_ARCHS := i386 i686 erikj@740: endif erikj@740: erikj@740: # Sort to remove duplicates erikj@740: RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST))))) erikj@740: erikj@740: ifeq ($(RPM_FILE_LIST),) erikj@740: $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs) erikj@740: endif erikj@740: erikj@740: ########################################################################################## erikj@740: # Define common directories and files erikj@740: erikj@740: # Ensure we have 32-bit libs also for x64. We enable mixed-mode. erikj@740: ifeq (x86_64,$(ARCH)) erikj@740: LIBDIRS := lib64 lib erikj@740: CFLAGS_lib := -m32 erikj@740: else erikj@740: LIBDIRS := lib erikj@740: endif erikj@740: erikj@740: # Define directories erikj@740: RESULT := $(OUTPUT_ROOT)/result erikj@740: BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) erikj@740: PREFIX := $(RESULT)/$(HOST) erikj@740: TARGETDIR := $(PREFIX)/$(TARGET) erikj@740: SYSROOT := $(TARGETDIR)/sys-root erikj@740: DOWNLOAD := $(OUTPUT_ROOT)/download erikj@740: SRCDIR := $(OUTPUT_ROOT)/src erikj@740: erikj@740: # Marker file for unpacking rpms erikj@740: rpms := $(SYSROOT)/rpms_unpacked erikj@740: erikj@740: # Need to patch libs that are linker scripts to use non-absolute paths erikj@740: libs := $(SYSROOT)/libs_patched erikj@740: erikj@740: ########################################################################################## erikj@740: # Unpack source packages erikj@740: erikj@740: # Generate downloading + unpacking of sources. erikj@740: define Download erikj@740: $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) erikj@740: $(1)_CFG = $$($(1)_DIR)/configure erikj@740: $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) erikj@740: erikj@740: $$($(1)_CFG) : $$($(1)_FILE) erikj@740: mkdir -p $$(SRCDIR) erikj@740: tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< erikj@740: $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ erikj@740: echo PATCHING $$(p) ; \ erikj@740: patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ erikj@740: ) erikj@740: touch $$@ erikj@740: erikj@740: $$($(1)_FILE) : erikj@740: wget -P $(DOWNLOAD) $$($(1)) erikj@740: endef erikj@740: erikj@740: # Download and unpack all source packages erikj@740: $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p)))) erikj@740: erikj@740: ########################################################################################## erikj@740: # Unpack RPMS erikj@740: erikj@740: # Note. For building linux you should install rpm2cpio. erikj@740: define unrpm erikj@740: $(SYSROOT)/$(notdir $(1)).unpacked \ erikj@740: : $(1) erikj@740: $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked erikj@740: endef erikj@740: erikj@740: %.unpacked : erikj@740: $(info Unpacking target rpms and libraries from $<) erikj@740: @(mkdir -p $(@D); \ erikj@740: cd $(@D); \ erikj@740: rpm2cpio $< | \ erikj@740: cpio --extract --make-directories \ erikj@740: -f \ erikj@740: "./usr/share/doc/*" \ erikj@740: "./usr/share/man/*" \ erikj@740: "./usr/X11R6/man/*" \ erikj@740: "*/X11/locale/*" \ erikj@740: || die ; ) erikj@740: touch $@ erikj@740: erikj@740: $(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p)))) erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: # Note: MUST create a /usr/lib even if not really needed. erikj@740: # gcc will use a path relative to it to resolve lib64. (x86_64). erikj@740: # we're creating multi-lib compiler with 32bit libc as well, so we should erikj@740: # have it anyway, but just to make sure... erikj@740: # Patch libc.so and libpthread.so to force linking against libraries in sysroot erikj@740: # and not the ones installed on the build machine. erikj@740: $(libs) : $(rpms) erikj@740: @echo Patching libc and pthreads erikj@740: @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \ erikj@740: (cat $$f | sed -e 's|/usr/lib64/||g' \ erikj@740: -e 's|/usr/lib/||g' \ erikj@740: -e 's|/lib64/||g' \ erikj@740: -e 's|/lib/||g' ) > $$f.tmp ; \ erikj@740: mv $$f.tmp $$f ; \ erikj@740: done) erikj@740: @mkdir -p $(SYSROOT)/usr/lib erikj@740: @touch $@ erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: # Define marker files for each source package to be compiled erikj@740: $(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: # Default base config erikj@740: CONFIG = --target=$(TARGET) \ erikj@740: --host=$(HOST) --build=$(BUILD) \ erikj@740: --prefix=$(PREFIX) erikj@740: erikj@740: PATHEXT = $(RESULT)/$(BUILD)/bin: erikj@740: erikj@740: PATHPRE = PATH=$(PATHEXT)$(PATH) erikj@740: BUILDPAR = -j16 erikj@740: erikj@740: # Default commands to when making erikj@740: MAKECMD = erikj@740: INSTALLCMD = install erikj@740: erikj@740: erikj@740: 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 erikj@740: erikj@740: ifeq ($(HOST),$(BUILD)) erikj@740: ifeq ($(HOST),$(TARGET)) erikj@740: TOOLS = $(call declare_tools,_FOR_TARGET,) erikj@740: endif erikj@740: endif erikj@740: erikj@740: TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-) erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: # Create a TARGET bfd + libiberty only. erikj@740: # Configure one or two times depending on mulitlib arch. erikj@740: # If multilib, the second should be 32-bit, and we resolve erikj@740: # CFLAG_ to most likely -m32. erikj@740: define mk_bfd erikj@740: $$(info Libs for $(1)) erikj@740: $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ erikj@740: : CFLAGS += $$(CFLAGS_$(1)) erikj@740: $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ erikj@740: : LIBDIRS = --libdir=$(TARGETDIR)/$(1) erikj@740: erikj@740: bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done erikj@740: bfdmakes += $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile erikj@740: endef erikj@740: erikj@740: # Create one set of bfds etc for each multilib arch erikj@740: $(foreach l,$(LIBDIRS),$(eval $(call mk_bfd,$(l)))) erikj@740: erikj@740: # Only build these two libs. erikj@740: $(bfdlib) : MAKECMD = all-libiberty all-bfd erikj@740: $(bfdlib) : INSTALLCMD = install-libiberty install-bfd erikj@740: erikj@740: # Building targets libbfd + libiberty. HOST==TARGET, i.e not erikj@740: # for a cross env. erikj@740: $(bfdmakes) : CONFIG = --target=$(TARGET) \ erikj@740: --host=$(TARGET) --build=$(BUILD) \ erikj@740: --prefix=$(TARGETDIR) \ erikj@740: --with-sysroot=$(SYSROOT) \ erikj@740: $(LIBDIRS) erikj@740: erikj@740: $(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-) erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: $(gcc) \ erikj@740: $(binutils) \ erikj@740: $(gmp) \ erikj@740: $(mpfr) \ erikj@740: $(mpc) \ erikj@740: $(bfdmakes) \ erikj@740: $(ccache) : ENVS += $(TOOLS) erikj@740: erikj@740: # libdir to work around hateful bfd stuff installing into wrong dirs... erikj@740: # ensure we have 64 bit bfd support in the HOST library. I.e our erikj@740: # compiler on i686 will know 64 bit symbols, BUT later erikj@740: # we build just the libs again for TARGET, then with whatever the arch erikj@740: # wants. erikj@740: $(BUILDDIR)/$(binutils_ver)/Makefile : CONFIG += --enable-64-bit-bfd --libdir=$(PREFIX)/$(word 1,$(LIBDIRS)) erikj@740: erikj@740: # Makefile creation. Simply run configure in build dir. erikj@740: $(bfdmakes) \ erikj@740: $(BUILDDIR)/$(binutils_ver)/Makefile \ erikj@740: : $(BINUTILS_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: @mkdir -p $(@D) erikj@740: ( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ erikj@740: $(BINUTILS_CFG) \ erikj@740: $(CONFIG) \ erikj@740: --with-sysroot=$(SYSROOT) \ erikj@740: --disable-nls \ erikj@740: --program-prefix=$(TARGET)- \ erikj@740: --enable-multilib \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: $(BUILDDIR)/$(mpfr_ver)/Makefile \ erikj@740: : $(MPFR_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: @mkdir -p $(@D) erikj@740: ( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ erikj@740: $(MPFR_CFG) \ erikj@740: $(CONFIG) \ erikj@740: --program-prefix=$(TARGET)- \ erikj@740: --enable-shared=no \ erikj@740: --with-gmp=$(PREFIX) \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: $(BUILDDIR)/$(gmp_ver)/Makefile \ erikj@740: : $(GMP_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: @mkdir -p $(@D) erikj@740: ( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ erikj@740: $(GMP_CFG) \ erikj@740: --host=$(HOST) --build=$(BUILD) \ erikj@740: --prefix=$(PREFIX) \ erikj@740: --disable-nls \ erikj@740: --program-prefix=$(TARGET)- \ erikj@740: --enable-shared=no \ erikj@740: --with-mpfr=$(PREFIX) \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: $(BUILDDIR)/$(mpc_ver)/Makefile \ erikj@740: : $(MPC_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: @mkdir -p $(@D) erikj@740: ( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ erikj@740: $(MPC_CFG) \ erikj@740: $(CONFIG) \ erikj@740: --program-prefix=$(TARGET)- \ erikj@740: --enable-shared=no \ erikj@740: --with-mpfr=$(PREFIX) \ erikj@740: --with-gmp=$(PREFIX) \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: # Only valid if glibc target -> linux erikj@740: # proper destructor handling for c++ erikj@740: ifneq (,$(findstring linux,$(TARGET))) erikj@740: $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit erikj@740: endif erikj@740: erikj@740: # Want: erikj@740: # c,c++ erikj@740: # shared libs erikj@740: # multilib (-m32/-m64 on x64) erikj@740: # skip native language. erikj@740: # and link and assemble with the binutils we created erikj@740: # earlier, so --with-gnu* erikj@740: $(BUILDDIR)/$(gcc_ver)/Makefile \ erikj@740: : $(GCC_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: mkdir -p $(@D) erikj@740: ( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \ erikj@740: $(CONFIG) \ erikj@740: --with-sysroot=$(SYSROOT) \ erikj@740: --enable-languages=c,c++ \ erikj@740: --enable-shared \ erikj@740: --enable-multilib \ erikj@740: --disable-nls \ erikj@740: --with-gnu-as \ erikj@740: --with-gnu-ld \ erikj@740: --with-mpfr=$(PREFIX) \ erikj@740: --with-gmp=$(PREFIX) \ erikj@740: --with-mpc=$(PREFIX) \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: # need binutils for gcc erikj@740: $(gcc) : $(binutils) erikj@740: erikj@740: # as of 4.3 or so need these for doing config erikj@740: $(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc) erikj@740: $(mpfr) : $(gmp) erikj@740: $(mpc) : $(gmp) $(mpfr) erikj@740: erikj@740: ########################################################################################## erikj@740: # very straightforward. just build a ccache. it is only for host. erikj@740: $(BUILDDIR)/$(ccache_ver)/Makefile \ erikj@740: : $(CCACHE_CFG) erikj@740: $(info Configuring $@. Log in $(@D)/log.config) erikj@740: @mkdir -p $(@D) erikj@740: @( \ erikj@740: cd $(@D) ; \ erikj@740: $(PATHPRE) $(ENVS) $(CCACHE_CFG) \ erikj@740: $(CONFIG) \ erikj@740: ) > $(@D)/log.config 2>&1 erikj@740: @echo 'done' erikj@740: erikj@740: gccpatch = $(TARGETDIR)/gcc-patched erikj@740: erikj@740: ########################################################################################## erikj@740: # For some reason cpp is not created as a target-compiler erikj@740: ifeq ($(HOST),$(TARGET)) erikj@740: $(gccpatch) : $(gcc) link_libs erikj@740: @echo -n 'Creating compiler symlinks...' erikj@740: @for f in cpp; do \ erikj@740: if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ];\ erikj@740: then \ erikj@740: cd $(PREFIX)/bin && \ erikj@740: ln -s $$f $(TARGET)-$$f ; \ erikj@740: fi \ erikj@740: done erikj@740: @touch $@ erikj@740: @echo 'done' erikj@740: erikj@740: ########################################################################################## erikj@740: # Ugly at best. Seems that when we compile host->host compiler, that are NOT erikj@740: # the BUILD compiler, the result will not try searching for libs in package root. erikj@740: # "Solve" this by create links from the target libdirs to where they are. erikj@740: link_libs: erikj@740: @echo -n 'Creating library symlinks...' erikj@740: @$(foreach l,$(LIBDIRS), \ erikj@740: for f in `cd $(PREFIX)/$(l) && ls`; do \ erikj@740: if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \ erikj@740: mkdir -p $(TARGETDIR)/$(l) && \ erikj@740: cd $(TARGETDIR)/$(l)/ && \ erikj@740: ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \ erikj@740: fi \ erikj@740: done;) erikj@740: @echo 'done' erikj@740: else erikj@740: $(gccpatch) : erikj@740: @echo 'done' erikj@740: endif erikj@740: erikj@740: ########################################################################################## erikj@740: # Build in two steps. erikj@740: # make erikj@740: # make install. erikj@740: # Use path to our build hosts cross tools erikj@740: # Always need to build cross tools for build host self. erikj@740: $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile erikj@740: $(info Building $(basename $@). Log in $( $(&1 erikj@740: @echo -n 'installing...' erikj@740: $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $( $(&1 erikj@740: @touch $@ erikj@740: @echo 'done' erikj@740: erikj@740: ########################################################################################## erikj@740: erikj@740: bfdlib : $(bfdlib) erikj@740: binutils : $(binutils) erikj@740: rpms : $(rpms) erikj@740: libs : $(libs) erikj@740: sysroot : rpms libs erikj@740: gcc : sysroot $(gcc) $(gccpatch) erikj@740: all : binutils gcc bfdlib erikj@740: erikj@740: # this is only built for host. so separate. erikj@740: ccache : $(ccache) erikj@740: erikj@740: .PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot