| 1 | #
|
|---|
| 2 | # Copyright (c) 2011 Petr Koupy
|
|---|
| 3 | # All rights reserved.
|
|---|
| 4 | #
|
|---|
| 5 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | # modification, are permitted provided that the following conditions
|
|---|
| 7 | # are met:
|
|---|
| 8 | #
|
|---|
| 9 | # - Redistributions of source code must retain the above copyright
|
|---|
| 10 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | # - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | # notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | # documentation and/or other materials provided with the distribution.
|
|---|
| 14 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | # derived from this software without specific prior written permission.
|
|---|
| 16 | #
|
|---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | #
|
|---|
| 28 |
|
|---|
| 29 | nullstring =
|
|---|
| 30 | space = $(nullstring) # space
|
|---|
| 31 |
|
|---|
| 32 | # Information for obtaining specific binutils redistributable package.
|
|---|
| 33 | # Might be subject to change in the future.
|
|---|
| 34 | REDIST_VERSION = 2.21
|
|---|
| 35 | REDIST_NAME = binutils-$(REDIST_VERSION)
|
|---|
| 36 | REDIST_FILENAME = $(REDIST_NAME).tar.bz2
|
|---|
| 37 | REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
|
|---|
| 38 |
|
|---|
| 39 | # Directory for the binutils source tree.
|
|---|
| 40 | REDIST_DIR = ./redist
|
|---|
| 41 |
|
|---|
| 42 | # File to detect the presence of binutils source tree.
|
|---|
| 43 | REDIST_DETECT = $(REDIST_DIR)/configure
|
|---|
| 44 |
|
|---|
| 45 | # $USPACE_PREFIX have to be based on the absolute path,
|
|---|
| 46 | # because targets derived from it will be referenced from
|
|---|
| 47 | # other than the current directory.
|
|---|
| 48 | USPACE_PREFIX = $(subst $(space),\ ,$(PWD))/../..
|
|---|
| 49 |
|
|---|
| 50 | # Ensure static configuration of Makefile.common.
|
|---|
| 51 | STATIC_ONLY = y
|
|---|
| 52 |
|
|---|
| 53 | # Link with POSIX runtime library.
|
|---|
| 54 | POSIX_COMPAT = y
|
|---|
| 55 |
|
|---|
| 56 | # Makefile.common for native applications.
|
|---|
| 57 | COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
|
|---|
| 58 |
|
|---|
| 59 | # Generated from native Makefile.common.
|
|---|
| 60 | COMMON_MAKEFILE_PATCHED = ./Makefile.common
|
|---|
| 61 |
|
|---|
| 62 | # AWK script which generates patched Makefile.common.
|
|---|
| 63 | MAKEFILE_PATCH = ./patch.awk
|
|---|
| 64 |
|
|---|
| 65 | # Compilers that can be used to build binutils.
|
|---|
| 66 | SUPPORTED_COMPILERS = gcc_cross gcc_native
|
|---|
| 67 |
|
|---|
| 68 | # Patched Makefile.common for ported user space applications.
|
|---|
| 69 | include $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 70 |
|
|---|
| 71 | # Patch $PATH to intercept toolchain calls.
|
|---|
| 72 | PATH := $(PWD):$(PATH)
|
|---|
| 73 |
|
|---|
| 74 | # Shell script for false toolchain generation.
|
|---|
| 75 | TOOLCHAIN_SCRIPT = ./toolchain.sh
|
|---|
| 76 |
|
|---|
| 77 | # False toolchain.
|
|---|
| 78 | TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
|
|---|
| 79 |
|
|---|
| 80 | # Stamp indicating whether the binutils source tree is patched.
|
|---|
| 81 | BINUTILS_PATCHED = ./done
|
|---|
| 82 |
|
|---|
| 83 | # Shell script for instrusive patches of binutils source tree.
|
|---|
| 84 | BINUTILS_PATCH = ./intrusive.sh
|
|---|
| 85 |
|
|---|
| 86 | # Detection whether the binutils are already configured.
|
|---|
| 87 | BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
|
|---|
| 88 |
|
|---|
| 89 | # Map the HelenOS target to binutils target.
|
|---|
| 90 | ifeq ($(PLATFORM),amd64)
|
|---|
| 91 | TARGET=amd64-linux-gnu
|
|---|
| 92 | else ($(PLATFORM),arm32)
|
|---|
| 93 | TARGET=arm-linux-gnu
|
|---|
| 94 | else ($(PLATFORM),ia32)
|
|---|
| 95 | TARGET=i686-pc-linux-gnu
|
|---|
| 96 | else ($(PLATFORM),ia64)
|
|---|
| 97 | TARGET=ia64-pc-linux-gnu
|
|---|
| 98 | else ($(PLATFORM),mips32)
|
|---|
| 99 | TARGET=mipsel-linux-gnu
|
|---|
| 100 | else ($(PLATFORM),mips32eb)
|
|---|
| 101 | TARGET=mips-linux-gnu
|
|---|
| 102 | else ($(PLATFORM),mips64)
|
|---|
| 103 | TARGET=mips64el-linux-gnu
|
|---|
| 104 | else ($(PLATFORM),ppc32)
|
|---|
| 105 | TARGET=ppc-linux-gnu
|
|---|
| 106 | else ($(PLATFORM),ppc64)
|
|---|
| 107 | TARGET=ppc64-linux-gnu
|
|---|
| 108 | else ($(PLATFORM),sparc64)
|
|---|
| 109 | TARGET=sparc64-linux-gnu
|
|---|
| 110 | endif
|
|---|
| 111 |
|
|---|
| 112 | # Binutils configure flags.
|
|---|
| 113 | CONF_FLAGS = --disable-nls --disable-shared --enable-static \
|
|---|
| 114 | --with-zlib=no
|
|---|
| 115 |
|
|---|
| 116 | # Binutils make targets.
|
|---|
| 117 | MAKE_TARGETS = all-gas all-ld
|
|---|
| 118 |
|
|---|
| 119 | # Check presence of gcc compiler.
|
|---|
| 120 | # Make binutils.
|
|---|
| 121 | # Copy binaries.
|
|---|
| 122 | ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
|
|---|
| 123 | all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
|
|---|
| 124 | $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
|
|---|
| 125 | export PATH
|
|---|
| 126 | make -C $(REDIST_DIR) $(MAKE_TARGETS)
|
|---|
| 127 | cp -f $(REDIST_DIR)/gas/as-new ./as
|
|---|
| 128 | cp -f $(REDIST_DIR)/ld/ld-new ./ld
|
|---|
| 129 | else
|
|---|
| 130 | all:
|
|---|
| 131 | # Skipped: Cannot build binutils with unsupported compiler.
|
|---|
| 132 | endif
|
|---|
| 133 |
|
|---|
| 134 | # Create patched Makefile.common from native Makefile.common.
|
|---|
| 135 | $(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
|
|---|
| 136 | awk -f $^ > $@
|
|---|
| 137 |
|
|---|
| 138 | # Download binutils redistributable package.
|
|---|
| 139 | $(REDIST_FILENAME):
|
|---|
| 140 | wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
|
|---|
| 141 |
|
|---|
| 142 | # Extract binutils source tree.
|
|---|
| 143 | $(REDIST_DETECT): $(REDIST_FILENAME)
|
|---|
| 144 | tar -x -j -f $<
|
|---|
| 145 | mv -f $(REDIST_NAME) $(REDIST_DIR)
|
|---|
| 146 |
|
|---|
| 147 | # Generate false toolchain scripts.
|
|---|
| 148 | $(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
|
|---|
| 149 | $^ gcc $(CC) '$(CFLAGS)'
|
|---|
| 150 | $^ as $(AS)
|
|---|
| 151 | $^ ar $(AR)
|
|---|
| 152 | $^ ranlib
|
|---|
| 153 | $^ ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
|
|---|
| 154 | $^ objdump $(OBJDUMP)
|
|---|
| 155 | $^ objcopy $(OBJCOPY)
|
|---|
| 156 | $^ strip $(STRIP)
|
|---|
| 157 |
|
|---|
| 158 | # Patch binutils source tree.
|
|---|
| 159 | $(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
|
|---|
| 160 | $^ do $(REDIST_DIR)
|
|---|
| 161 | touch $@
|
|---|
| 162 |
|
|---|
| 163 | # Configure binutils.
|
|---|
| 164 | $(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
|
|---|
| 165 | $^ --target=$(TARGET) $(CONF_FLAGS)
|
|---|
| 166 |
|
|---|
| 167 | # Delete binaries.
|
|---|
| 168 | # Clean binutils.
|
|---|
| 169 | # Unpatch binutils.
|
|---|
| 170 | # Delete generated scripts.
|
|---|
| 171 | clean:
|
|---|
| 172 | rm -f as ld
|
|---|
| 173 | make -C $(REDIST_DIR) distclean
|
|---|
| 174 | ./intrusive.sh undo $(REDIST_DIR)
|
|---|
| 175 | rm -f $(BINUTILS_PATCHED)
|
|---|
| 176 | rm -f $(TOOLCHAIN)
|
|---|
| 177 | rm -f $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 178 |
|
|---|