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 ihse@839: # Needs either to be from BUILD -> BUILD OR have erikj@740: # BUILD -> HOST prebuilt erikj@740: # ihse@839: # NOTE: There is a bug here. We don't limit the ihse@839: # 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 ihse@839: # 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: ihse@839: 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. kevinw@2215: gcc_ver := gcc-4.8.2 kevinw@2215: binutils_ver := binutils-2.24 ihse@839: ccache_ver := ccache-3.1.9 ihse@839: mpfr_ver := mpfr-3.0.1 ihse@839: gmp_ver := gmp-4.3.2 ihse@839: mpc_ver := mpc-1.0.1 erikj@740: ihse@839: GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 ihse@839: BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 ihse@839: CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz ihse@839: MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 ihse@839: GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 ihse@839: MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz erikj@740: erikj@740: # RPMs in OEL5.5 kevinw@2215: LINUX_VERSION := OEL5.5 ihse@839: RPM_LIST := \ ihse@839: kernel-headers \ ihse@839: glibc-2 glibc-headers glibc-devel \ ihse@839: cups-libs cups-devel \ ihse@839: libX11 libX11-devel \ ihse@839: xorg-x11-proto-devel \ ihse@839: alsa-lib alsa-lib-devel \ ihse@839: libXext libXext-devel \ ihse@839: libXtst libXtst-devel \ ihse@839: libXrender libXrender-devel \ ihse@839: freetype freetype-devel \ ihse@839: libXt libXt-devel \ ihse@839: libSM libSM-devel \ ihse@839: libICE libICE-devel \ ihse@839: libXi libXi-devel \ ihse@839: libXdmcp libXdmcp-devel \ ihse@839: libXau libXau-devel \ ihse@839: 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. ihse@839: 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)) ihse@839: LIBDIRS := lib64 lib ihse@839: CFLAGS_lib := -m32 erikj@740: else ihse@839: LIBDIRS := lib erikj@740: endif erikj@740: erikj@740: # Define directories ihse@839: RESULT := $(OUTPUT_ROOT)/result ihse@839: BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) ihse@839: PREFIX := $(RESULT)/$(HOST) ihse@839: TARGETDIR := $(PREFIX)/$(TARGET) kevinw@2215: SYSROOT := $(TARGETDIR)/sysroot ihse@839: DOWNLOAD := $(OUTPUT_ROOT)/download ihse@839: SRCDIR := $(OUTPUT_ROOT)/src erikj@740: erikj@740: # Marker file for unpacking rpms ihse@839: rpms := $(SYSROOT)/rpms_unpacked erikj@740: ihse@839: # Need to patch libs that are linker scripts to use non-absolute paths ihse@839: libs := $(SYSROOT)/libs_patched erikj@740: erikj@740: ########################################################################################## erikj@740: # Unpack source packages erikj@740: ihse@839: # Generate downloading + unpacking of sources. erikj@740: define Download ihse@839: $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) ihse@839: $(1)_CFG = $$($(1)_DIR)/configure ihse@839: $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) erikj@740: ihse@839: $$($(1)_CFG) : $$($(1)_FILE) ihse@839: mkdir -p $$(SRCDIR) ihse@839: tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< ihse@839: $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ ihse@839: echo PATCHING $$(p) ; \ ihse@839: patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ ihse@839: ) ihse@839: touch $$@ erikj@740: ihse@839: $$($(1)_FILE) : ihse@839: 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: ihse@839: # Note. For building linux you should install rpm2cpio. erikj@740: define unrpm ihse@839: $(SYSROOT)/$(notdir $(1)).unpacked \ ihse@839: : $(1) ihse@839: $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked erikj@740: endef erikj@740: ihse@839: %.unpacked : ihse@839: $(info Unpacking target rpms and libraries from $<) ihse@839: @(mkdir -p $(@D); \ ihse@839: cd $(@D); \ ihse@839: rpm2cpio $< | \ ihse@839: cpio --extract --make-directories \ ihse@839: -f \ ihse@839: "./usr/share/doc/*" \ ihse@839: "./usr/share/man/*" \ ihse@839: "./usr/X11R6/man/*" \ ihse@839: "*/X11/locale/*" \ ihse@839: || die ; ) ihse@839: touch $@ erikj@740: erikj@740: $(foreach p,$(RPM_FILE_LIST),$(eval $(call unrpm,$(p)))) erikj@740: erikj@740: ########################################################################################## erikj@740: kevinw@2215: # Note: MUST create a /usr/lib even if not really needed. ihse@839: # gcc will use a path relative to it to resolve lib64. (x86_64). ihse@839: # 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. ihse@839: $(libs) : $(rpms) ihse@839: @echo Patching libc and pthreads ihse@839: @(for f in `find $(SYSROOT) -name libc.so -o -name libpthread.so`; do \ ihse@839: (cat $$f | sed -e 's|/usr/lib64/||g' \ ihse@839: -e 's|/usr/lib/||g' \ ihse@839: -e 's|/lib64/||g' \ ihse@839: -e 's|/lib/||g' ) > $$f.tmp ; \ ihse@839: mv $$f.tmp $$f ; \ ihse@839: done) ihse@839: @mkdir -p $(SYSROOT)/usr/lib ihse@839: @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 ihse@839: CONFIG = --target=$(TARGET) \ ihse@839: --host=$(HOST) --build=$(BUILD) \ ihse@839: --prefix=$(PREFIX) erikj@740: ihse@839: PATHEXT = $(RESULT)/$(BUILD)/bin: erikj@740: ihse@839: PATHPRE = PATH=$(PATHEXT)$(PATH) ihse@839: BUILDPAR = -j16 erikj@740: erikj@740: # Default commands to when making ihse@839: MAKECMD = ihse@839: INSTALLCMD = install erikj@740: erikj@740: ihse@839: 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)) ihse@839: ifeq ($(HOST),$(TARGET)) ihse@839: TOOLS = $(call declare_tools,_FOR_TARGET,) ihse@839: endif erikj@740: endif erikj@740: ihse@839: TOOLS ?= $(call declare_tools,_FOR_TARGET,$(TARGET)-) erikj@740: erikj@740: ########################################################################################## erikj@740: ihse@839: # Create a TARGET bfd + libiberty only. erikj@740: # Configure one or two times depending on mulitlib arch. ihse@839: # If multilib, the second should be 32-bit, and we resolve erikj@740: # CFLAG_ to most likely -m32. erikj@740: define mk_bfd ihse@839: $$(info Libs for $(1)) ihse@839: $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ ihse@839: : CFLAGS += $$(CFLAGS_$(1)) ihse@839: $$(BUILDDIR)/$$(binutils_ver)-$(subst /,-,$(1))/Makefile \ ihse@839: : LIBDIRS = --libdir=$(TARGETDIR)/$(1) erikj@740: ihse@839: bfdlib += $$(TARGETDIR)/$$(binutils_ver)-$(subst /,-,$(1)).done ihse@839: 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. ihse@839: $(bfdlib) : MAKECMD = all-libiberty all-bfd ihse@839: $(bfdlib) : INSTALLCMD = install-libiberty install-bfd erikj@740: ihse@839: # Building targets libbfd + libiberty. HOST==TARGET, i.e not ihse@839: # for a cross env. ihse@839: $(bfdmakes) : CONFIG = --target=$(TARGET) \ ihse@839: --host=$(TARGET) --build=$(BUILD) \ ihse@839: --prefix=$(TARGETDIR) \ ihse@839: --with-sysroot=$(SYSROOT) \ ihse@839: $(LIBDIRS) erikj@740: ihse@839: $(bfdmakes) : TOOLS = $(call declare_tools,_FOR_TARGET,$(TARGET)-) $(call declare_tools,,$(TARGET)-) erikj@740: erikj@740: ########################################################################################## erikj@740: ihse@839: $(gcc) \ ihse@839: $(binutils) \ ihse@839: $(gmp) \ ihse@839: $(mpfr) \ ihse@839: $(mpc) \ ihse@839: $(bfdmakes) \ ihse@839: $(ccache) : ENVS += $(TOOLS) erikj@740: erikj@740: # libdir to work around hateful bfd stuff installing into wrong dirs... ihse@839: # 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 ihse@839: # 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. ihse@839: $(bfdmakes) \ ihse@839: $(BUILDDIR)/$(binutils_ver)/Makefile \ ihse@839: : $(BINUTILS_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: @mkdir -p $(@D) ihse@839: ( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ ihse@839: $(BINUTILS_CFG) \ ihse@839: $(CONFIG) \ ihse@839: --with-sysroot=$(SYSROOT) \ ihse@839: --disable-nls \ ihse@839: --program-prefix=$(TARGET)- \ ihse@839: --enable-multilib \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @echo 'done' erikj@740: ihse@839: $(BUILDDIR)/$(mpfr_ver)/Makefile \ ihse@839: : $(MPFR_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: @mkdir -p $(@D) ihse@839: ( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ ihse@839: $(MPFR_CFG) \ ihse@839: $(CONFIG) \ ihse@839: --program-prefix=$(TARGET)- \ ihse@839: --enable-shared=no \ ihse@839: --with-gmp=$(PREFIX) \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @echo 'done' erikj@740: ihse@839: $(BUILDDIR)/$(gmp_ver)/Makefile \ ihse@839: : $(GMP_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: @mkdir -p $(@D) ihse@839: ( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ ihse@839: $(GMP_CFG) \ ihse@839: --host=$(HOST) --build=$(BUILD) \ ihse@839: --prefix=$(PREFIX) \ ihse@839: --disable-nls \ ihse@839: --program-prefix=$(TARGET)- \ ihse@839: --enable-shared=no \ ihse@839: --with-mpfr=$(PREFIX) \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @echo 'done' erikj@740: ihse@839: $(BUILDDIR)/$(mpc_ver)/Makefile \ ihse@839: : $(MPC_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: @mkdir -p $(@D) ihse@839: ( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" \ ihse@839: $(MPC_CFG) \ ihse@839: $(CONFIG) \ ihse@839: --program-prefix=$(TARGET)- \ ihse@839: --enable-shared=no \ ihse@839: --with-mpfr=$(PREFIX) \ ihse@839: --with-gmp=$(PREFIX) \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @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))) ihse@839: $(BUILDDIR)/$(gcc_ver)/Makefile : CONFIG += --enable-__cxa_atexit erikj@740: endif erikj@740: erikj@740: # Want: ihse@839: # c,c++ ihse@839: # shared libs ihse@839: # multilib (-m32/-m64 on x64) ihse@839: # skip native language. ihse@839: # and link and assemble with the binutils we created ihse@839: # earlier, so --with-gnu* ihse@839: $(BUILDDIR)/$(gcc_ver)/Makefile \ ihse@839: : $(GCC_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: mkdir -p $(@D) ihse@839: ( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \ ihse@839: $(CONFIG) \ ihse@839: --with-sysroot=$(SYSROOT) \ ihse@839: --enable-languages=c,c++ \ ihse@839: --enable-shared \ ihse@839: --enable-multilib \ ihse@839: --disable-nls \ ihse@839: --with-gnu-as \ ihse@839: --with-gnu-ld \ ihse@839: --with-mpfr=$(PREFIX) \ ihse@839: --with-gmp=$(PREFIX) \ ihse@839: --with-mpc=$(PREFIX) \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @echo 'done' erikj@740: erikj@740: # need binutils for gcc ihse@839: $(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) ihse@839: $(mpfr) : $(gmp) ihse@839: $(mpc) : $(gmp) $(mpfr) erikj@740: erikj@740: ########################################################################################## ihse@839: # very straightforward. just build a ccache. it is only for host. ihse@839: $(BUILDDIR)/$(ccache_ver)/Makefile \ ihse@839: : $(CCACHE_CFG) ihse@839: $(info Configuring $@. Log in $(@D)/log.config) ihse@839: @mkdir -p $(@D) ihse@839: @( \ ihse@839: cd $(@D) ; \ ihse@839: $(PATHPRE) $(ENVS) $(CCACHE_CFG) \ ihse@839: $(CONFIG) \ ihse@839: ) > $(@D)/log.config 2>&1 ihse@839: @echo 'done' erikj@740: ihse@839: gccpatch = $(TARGETDIR)/gcc-patched erikj@740: erikj@740: ########################################################################################## ihse@839: # For some reason cpp is not created as a target-compiler erikj@740: ifeq ($(HOST),$(TARGET)) ihse@839: $(gccpatch) : $(gcc) link_libs ihse@839: @echo -n 'Creating compiler symlinks...' ihse@839: @for f in cpp; do \ ihse@839: if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \ ihse@839: then \ ihse@839: cd $(PREFIX)/bin && \ ihse@839: ln -s $$f $(TARGET)-$$f ; \ ihse@839: fi \ ihse@839: done ihse@839: @touch $@ ihse@839: @echo 'done' erikj@740: ihse@839: ########################################################################################## ihse@839: # Ugly at best. Seems that when we compile host->host compiler, that are NOT ihse@839: # the BUILD compiler, the result will not try searching for libs in package root. ihse@839: # "Solve" this by create links from the target libdirs to where they are. ihse@839: link_libs: ihse@839: @echo -n 'Creating library symlinks...' ihse@839: @$(foreach l,$(LIBDIRS), \ ihse@839: for f in `cd $(PREFIX)/$(l) && ls`; do \ ihse@839: if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \ ihse@839: mkdir -p $(TARGETDIR)/$(l) && \ ihse@839: cd $(TARGETDIR)/$(l)/ && \ ihse@839: ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \ ihse@839: fi \ ihse@839: done;) ihse@839: @echo 'done' erikj@740: else ihse@839: $(gccpatch) : ihse@839: @echo 'done' erikj@740: endif erikj@740: erikj@740: ########################################################################################## ihse@839: # Build in two steps. erikj@740: # make ihse@839: # make install. erikj@740: # Use path to our build hosts cross tools ihse@839: # Always need to build cross tools for build host self. ihse@839: $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile ihse@839: $(info Building $(basename $@). Log in $( $(&1 ihse@839: @echo -n 'installing...' ihse@839: $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $( $(&1 ihse@839: @touch $@ ihse@839: @echo 'done' erikj@740: erikj@740: ########################################################################################## erikj@740: kevinw@2215: $(PREFIX)/devkit.info: FRC kevinw@2215: @echo 'Creating devkit.info in the root of the kit' kevinw@2215: rm -f $@ kevinw@2215: touch $@ kevinw@2215: echo '# This file describes to configure how to interpret the contents of this' >> $@ kevinw@2215: echo '# devkit' >> $@ kevinw@2215: echo '' >> $@ kevinw@2215: echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@ kevinw@2215: echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@ kevinw@2215: echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@ kevinw@2215: kevinw@2215: ########################################################################################## kevinw@2215: ihse@839: bfdlib : $(bfdlib) ihse@839: binutils : $(binutils) ihse@839: rpms : $(rpms) ihse@839: libs : $(libs) ihse@839: sysroot : rpms libs ihse@839: gcc : sysroot $(gcc) $(gccpatch) kevinw@2215: all : binutils gcc bfdlib $(PREFIX)/devkit.info erikj@740: ihse@839: # this is only built for host. so separate. ihse@839: ccache : $(ccache) erikj@740: kevinw@2215: # Force target kevinw@2215: FRC: kevinw@2215: ihse@839: .PHONY : gcc all binutils bfdlib link_libs rpms libs sysroot