< prev index next >

make/devkit/Tools.gmk

Print this page

        

@@ -1,7 +1,7 @@
 #
-# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.  Oracle designates this

@@ -42,28 +42,46 @@
 $(info TARGET=$(TARGET))
 $(info HOST=$(HOST))
 $(info BUILD=$(BUILD))
 
 ARCH := $(word 1,$(subst -, ,$(TARGET)))
+$(info ARCH=$(ARCH))
 
 ##########################################################################################
 # Define external dependencies
 
 # Latest that could be made to work.
-gcc_ver := gcc-4.9.2
-binutils_ver := binutils-2.25
-ccache_ver := ccache-3.2.1
-mpfr_ver := mpfr-3.0.1
-gmp_ver := gmp-4.3.2
-mpc_ver := mpc-1.0.1
-
-GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2
-BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2
-CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz
+GCC_VER := 7.3.0
+ifeq ($(GCC_VER), 7.3.0)
+  gcc_ver := gcc-7.3.0
+  binutils_ver := binutils-2.30
+  ccache_ver := ccache-3.3.6
+  mpfr_ver := mpfr-3.1.5
+  gmp_ver := gmp-6.1.2
+  mpc_ver := mpc-1.0.3
+  gdb_ver := gdb-8.1
+else ifeq ($(GCC_VER), 4.9.2)
+  gcc_ver := gcc-4.9.2
+  binutils_ver := binutils-2.25
+  ccache_ver := ccache-3.2.1
+  mpfr_ver := mpfr-3.0.1
+  gmp_ver := gmp-4.3.2
+  mpc_ver := mpc-1.0.1
+  gdb_ver := gdb-7.12.1
+else
+  $(error Unsupported GCC version)
+endif
+
+GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz
+BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.xz
+CCACHE := https://samba.org/ftp/ccache/$(ccache_ver).tar.xz
 MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2
 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2
-MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz
+MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz
+GDB := http://ftp.gnu.org/gnu/gdb/${gdb_ver}.tar.xz
+
+OEL_URL := http://yum.oracle.com/repo/OracleLinux/OL6/4/base/$(ARCH)/
 
 # RPMs in OEL6.4
 LINUX_VERSION := OEL6.4
 RPM_LIST := \
     kernel-headers \

@@ -85,33 +103,10 @@
     libgcc \
     zlib zlib-devel \
     libffi libffi-devel \
     fontconfig fontconfig-devel
 
-ifeq ($(ARCH),x86_64)
-  RPM_DIR ?= $(RPM_DIR_x86_64)
-  RPM_ARCHS := x86_64 noarch
-  ifeq ($(BUILD),$(HOST))
-    ifeq ($(TARGET),$(HOST))
-      # When building the native compiler for x86_64, enable mixed mode.
-      RPM_ARCHS += i386 i686
-    endif
-  endif
-else
-  RPM_DIR ?= $(RPM_DIR_i686)
-  RPM_ARCHS := i386 i686
-endif
-
-# Sort to remove duplicates
-RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST)))))
-
-#$(info RPM_FILE_LIST $(RPM_FILE_LIST))
-
-ifeq ($(RPM_FILE_LIST),)
-  $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs)
-endif
-
 ##########################################################################################
 # Define common directories and files
 
 # Ensure we have 32-bit libs also for x64. We enable mixed-mode.
 ifeq (x86_64,$(ARCH))

@@ -120,24 +115,35 @@
 else
   LIBDIRS := lib
 endif
 
 # Define directories
-RESULT := $(OUTPUTDIR)/result
-BUILDDIR := $(OUTPUTDIR)/$(HOST)/$(TARGET)
+RESULT := $(OUTPUT_ROOT)/result
+BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET)
 PREFIX := $(RESULT)/$(HOST)
 TARGETDIR := $(PREFIX)/$(TARGET)
 SYSROOT := $(TARGETDIR)/sysroot
-DOWNLOAD := $(OUTPUTDIR)/download
-SRCDIR := $(OUTPUTDIR)/src
+DOWNLOAD := $(OUTPUT_ROOT)/download
+DOWNLOAD_RPMS := $(DOWNLOAD)/rpms
+SRCDIR := $(OUTPUT_ROOT)/src
 
 # Marker file for unpacking rpms
 rpms := $(SYSROOT)/rpms_unpacked
 
 # Need to patch libs that are linker scripts to use non-absolute paths
 libs := $(SYSROOT)/libs_patched
 
+################################################################################
+# Download RPMs
+download-rpms:
+        mkdir -p $(DOWNLOAD_RPMS)
+        # Only run this if rpm dir is empty.
+        ifeq ($(wildcard $(DOWNLOAD_RPMS)/*.rpm), )
+          cd $(DOWNLOAD_RPMS) && \
+              wget -r -np -nd $(patsubst %, -A "*%*.rpm", $(RPM_LIST)) $(OEL_URL)
+        endif
+
 ##########################################################################################
 # Unpack source packages
 
 # Generate downloading + unpacking of sources.
 define Download

@@ -145,11 +151,11 @@
   $(1)_CFG = $$($(1)_DIR)/configure
   $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1)))
 
   $$($(1)_CFG) : $$($(1)_FILE)
         mkdir -p $$(SRCDIR)
-        tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$<
+        tar -C $$(SRCDIR) -xf $$<
         $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \
           echo PATCHING $$(p) ; \
           patch -d $$($(1)_DIR) -p1 -i $$(p) ; \
         )
         touch $$@

@@ -157,19 +163,36 @@
   $$($(1)_FILE) :
         wget -P $(DOWNLOAD) $$($(1))
 endef
 
 # Download and unpack all source packages
-$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p))))
+$(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC GDB,$(eval $(call Download,$(p))))
 
 ##########################################################################################
 # Unpack RPMS
 
+ifeq ($(ARCH),x86_64)
+  RPM_ARCHS := x86_64 noarch
+  ifeq ($(BUILD),$(HOST))
+    ifeq ($(TARGET),$(HOST))
+      # When building the native compiler for x86_64, enable mixed mode.
+      RPM_ARCHS += i386 i686
+    endif
+  endif
+else ifeq ($(ARCH),i686))
+  RPM_ARCHS := i386 i686
+else
+  RPM_ARCHS := $(ARCH)
+endif
+
+RPM_FILE_LIST := $(sort $(foreach a, $(RPM_ARCHS), \
+  $(wildcard $(patsubst %,$(DOWNLOAD_RPMS)/%*$a.rpm,$(RPM_LIST))) \
+))
+
 # Note. For building linux you should install rpm2cpio.
 define unrpm
-  $(SYSROOT)/$(notdir $(1)).unpacked \
-    : $(1)
+  $(SYSROOT)/$(notdir $(1)).unpacked : $(1)
   $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked
 endef
 
 %.unpacked :
         $(info Unpacking target rpms and libraries from $<)

@@ -208,23 +231,24 @@
         @touch $@
 
 ##########################################################################################
 # Create links for ffi header files so that they become visible by default when using the
 # devkit.
+ifeq ($(ARCH), x86_64)
+  $(SYSROOT)/usr/include/ffi.h: $(rpms)
+        cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 
-$(SYSROOT)/usr/include/ffi.h: $(rpms)
-        cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
-
-$(SYSROOT)/usr/include/ffitarget.h: $(rpms)
-        cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
+  $(SYSROOT)/usr/include/ffitarget.h: $(rpms)
+        cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) .
 
-SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h
+  SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h
+endif
 
 ##########################################################################################
 
 # Define marker files for each source package to be compiled
-$(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
+$(foreach t,binutils mpfr gmp mpc gcc ccache gdb,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done))
 
 ##########################################################################################
 
 # Default base config
 CONFIG = --target=$(TARGET) \

@@ -232,11 +256,12 @@
     --prefix=$(PREFIX)
 
 PATHEXT = $(RESULT)/$(BUILD)/bin:
 
 PATHPRE = PATH=$(PATHEXT)$(PATH)
-BUILDPAR = -j16
+NUM_CORES := $(shell cat /proc/cpuinfo | grep -c processor)
+BUILDPAR = -j$(NUM_CORES)
 
 # Default commands to when making
 MAKECMD =
 INSTALLCMD = install
 

@@ -315,10 +340,12 @@
               $(CONFIG) \
               --with-sysroot=$(SYSROOT) \
               --disable-nls \
               --program-prefix=$(TARGET)- \
               --enable-multilib \
+              --enable-gold \
+              --enable-plugins \
         ) > $(@D)/log.config 2>&1
         @echo 'done'
 
 $(BUILDDIR)/$(mpfr_ver)/Makefile \
     : $(MPFR_CFG)

@@ -390,11 +417,10 @@
           $(PATHPRE) $(ENVS) $(GCC_CFG) $(EXTRA_CFLAGS) \
               $(CONFIG) \
               --with-sysroot=$(SYSROOT) \
               --enable-languages=c,c++ \
               --enable-shared \
-              --enable-multilib \
               --disable-nls \
               --with-gnu-as \
               --with-gnu-ld \
               --with-mpfr=$(PREFIX) \
               --with-gmp=$(PREFIX) \

@@ -408,10 +434,27 @@
 # as of 4.3 or so need these for doing config
 $(BUILDDIR)/$(gcc_ver)/Makefile : $(gmp) $(mpfr) $(mpc)
 $(mpfr) : $(gmp)
 $(mpc) : $(gmp) $(mpfr)
 
+################################################################################
+# Build gdb but only where host and target match
+ifeq ($(HOST), $(TARGET))
+  $(BUILDDIR)/$(gdb_ver)/Makefile: $(GDB_CFG)
+        $(info Configuring $@. Log in $(@D)/log.config)
+        mkdir -p $(@D)
+        ( \
+          cd $(@D) ; \
+          $(PATHPRE) $(ENVS) CFLAGS="$(CFLAGS)" $(GDB_CFG) \
+              $(CONFIG) \
+              --with-sysroot=$(SYSROOT) \
+        ) > $(@D)/log.config 2>&1
+        @echo 'done'
+
+  $(gdb): $(gcc)
+endif
+
 ##########################################################################################
 # very straightforward. just build a ccache. it is only for host.
 $(BUILDDIR)/$(ccache_ver)/Makefile \
     : $(CCACHE_CFG)
         $(info Configuring $@. Log in $(@D)/log.config)

@@ -432,11 +475,11 @@
         @echo -n 'Creating compiler symlinks...'
         @for f in cpp; do \
           if [ ! -e $(PREFIX)/bin/$(TARGET)-$$f ]; \
           then \
             cd $(PREFIX)/bin && \
-            ln -s $$f $(TARGET)-$$f ; \
+            ln -fs $$f $(TARGET)-$$f ; \
           fi \
         done
         @touch $@
         @echo 'done'
 

@@ -449,11 +492,11 @@
         @$(foreach l,$(LIBDIRS), \
         for f in `cd $(PREFIX)/$(l) && ls`; do \
           if [ ! -e $(TARGETDIR)/$(l)/$$f ]; then \
             mkdir -p $(TARGETDIR)/$(l) && \
             cd $(TARGETDIR)/$(l)/ && \
-            ln -s $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
+            ln -fs $(if $(findstring /,$(l)),../,)../../$(l)/$$f $$f; \
           fi \
         done;)
         @echo 'done'
 else
   $(gccpatch) :

@@ -469,10 +512,11 @@
 $(TARGETDIR)/%.done : $(BUILDDIR)/%/Makefile
         $(info Building $(basename $@). Log in $(<D)/log.build)
         $(PATHPRE) $(ENVS) $(MAKE) $(BUILDPAR) -f $< -C $(<D) $(MAKECMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.build 2>&1
         @echo -n 'installing...'
         $(PATHPRE) $(MAKE) $(INSTALLPAR) -f $< -C $(<D) $(INSTALLCMD) $(MAKECMD.$(notdir $@)) > $(<D)/log.install 2>&1
+        @mkdir -p $(@D)
         @touch $@
         @echo 'done'
 
 ##########################################################################################
 

@@ -486,30 +530,44 @@
         echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@
         echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@
         echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@
 
 ##########################################################################################
+# Copy these makefiles into the root of the kit
+$(PREFIX)/Makefile: ./Makefile
+        rm -rf $@
+        cp $< $@
+
+$(PREFIX)/Tools.gmk: ./Tools.gmk
+        rm -rf $@
+        cp $< $@
+
+THESE_MAKEFILES := $(PREFIX)/Makefile $(PREFIX)/Tools.gmk
+
+##########################################################################################
 
 ifeq ($(TARGET), $(HOST))
   $(PREFIX)/bin/%:
         @echo 'Creating missing $* soft link'
         ln -s $(TARGET)-$* $@
 
   missing-links := $(addprefix $(PREFIX)/bin/, \
       addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \
-      size strings strip)
+      size strings strip ld.bfd ld.gold)
 endif
 
 ##########################################################################################
 
 bfdlib : $(bfdlib)
 binutils : $(binutils)
 rpms : $(rpms)
 libs : $(libs)
 sysroot : rpms libs
 gcc : sysroot $(gcc) $(gccpatch)
-all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS)
+gdb : $(gdb)
+all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) \
+    $(THESE_MAKEFILES) gdb
 
 # this is only built for host. so separate.
 ccache : $(ccache)
 
 # Force target
< prev index next >