| 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 | # When redefined to 'y' on the command line, certain areas of this Makefile
|
|---|
| 33 | # behave slightly differently to simplify the maintenance of binutils port.
|
|---|
| 34 | MAINTAIN_BINUTILS=n
|
|---|
| 35 |
|
|---|
| 36 | # Information for obtaining specific binutils redistributable package.
|
|---|
| 37 | # Might be subject to change in the future.
|
|---|
| 38 | REDIST_VERSION = 2.21
|
|---|
| 39 | REDIST_NAME = binutils-$(REDIST_VERSION)
|
|---|
| 40 | REDIST_FILENAME = $(REDIST_NAME).tar.bz2
|
|---|
| 41 | REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
|
|---|
| 42 |
|
|---|
| 43 | # Directory for the binutils source tree.
|
|---|
| 44 | REDIST_DIR = ./redist
|
|---|
| 45 |
|
|---|
| 46 | # File to detect the presence of binutils source tree.
|
|---|
| 47 | REDIST_DETECT = $(REDIST_DIR)/configure
|
|---|
| 48 |
|
|---|
| 49 | # Directory for resulting binutils binaries.
|
|---|
| 50 | BIN_DIR = ./bin
|
|---|
| 51 |
|
|---|
| 52 | # $USPACE_PREFIX have to be based on the absolute path,
|
|---|
| 53 | # because targets derived from it will be referenced from
|
|---|
| 54 | # other than the current directory.
|
|---|
| 55 | USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
|
|---|
| 56 |
|
|---|
| 57 | # Ensure static configuration of Makefile.common.
|
|---|
| 58 | STATIC_ONLY = y
|
|---|
| 59 |
|
|---|
| 60 | # Link with POSIX runtime library.
|
|---|
| 61 | POSIX_COMPAT = y
|
|---|
| 62 |
|
|---|
| 63 | # Makefile.common for native applications.
|
|---|
| 64 | COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
|
|---|
| 65 |
|
|---|
| 66 | # Generated from native Makefile.common.
|
|---|
| 67 | COMMON_MAKEFILE_PATCHED = ./Makefile.common
|
|---|
| 68 |
|
|---|
| 69 | # AWK script which generates patched Makefile.common.
|
|---|
| 70 | MAKEFILE_PATCH = ./patch.awk
|
|---|
| 71 |
|
|---|
| 72 | # Compilers that can be used to build binutils.
|
|---|
| 73 | SUPPORTED_COMPILERS = gcc_cross gcc_native
|
|---|
| 74 |
|
|---|
| 75 | # Patched Makefile.common for ported user space applications.
|
|---|
| 76 | -include $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 77 |
|
|---|
| 78 | # Patch $PATH to intercept toolchain calls.
|
|---|
| 79 | PATH := $(shell pwd):$(PATH)
|
|---|
| 80 | export PATH
|
|---|
| 81 |
|
|---|
| 82 | # Shell script for false toolchain generation.
|
|---|
| 83 | TOOLCHAIN_SCRIPT = ./toolchain.sh
|
|---|
| 84 |
|
|---|
| 85 | # False toolchain.
|
|---|
| 86 | TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
|
|---|
| 87 |
|
|---|
| 88 | # Stamp indicating whether the binutils source tree is patched.
|
|---|
| 89 | BINUTILS_PATCHED = ./done
|
|---|
| 90 |
|
|---|
| 91 | # Shell script for instrusive patches of binutils source tree.
|
|---|
| 92 | BINUTILS_PATCH = ./intrusive.sh
|
|---|
| 93 |
|
|---|
| 94 | # Detection whether the binutils are already configured.
|
|---|
| 95 | BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
|
|---|
| 96 |
|
|---|
| 97 | # Generated source file for libposix function stubs without posix_ prefix.
|
|---|
| 98 | CONFOBJ_SOURCE = ./confobj.c
|
|---|
| 99 |
|
|---|
| 100 | # Dummy object file for libposix function stubs without posix_ prefix..
|
|---|
| 101 | # Required by binutils configure script tests that links against symbols
|
|---|
| 102 | # without including headers (which means that symbols are not prefixed).
|
|---|
| 103 | CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
|
|---|
| 104 |
|
|---|
| 105 | # Required by libposix on RISC platforms.
|
|---|
| 106 | BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
|
|---|
| 107 |
|
|---|
| 108 | # Map the HelenOS target to binutils target.
|
|---|
| 109 | ifeq ($(PLATFORM),amd64)
|
|---|
| 110 | TARGET = amd64-linux-gnu
|
|---|
| 111 | endif
|
|---|
| 112 | ifeq ($(PLATFORM),arm32)
|
|---|
| 113 | TARGET = arm-linux-gnu
|
|---|
| 114 | endif
|
|---|
| 115 | ifeq ($(PLATFORM),ia32)
|
|---|
| 116 | TARGET = i686-pc-linux-gnu
|
|---|
| 117 | endif
|
|---|
| 118 | ifeq ($(PLATFORM),ia64)
|
|---|
| 119 | TARGET = ia64-pc-linux-gnu
|
|---|
| 120 | endif
|
|---|
| 121 | ifeq ($(PLATFORM),mips32)
|
|---|
| 122 | TARGET = mipsel-linux-gnu
|
|---|
| 123 | endif
|
|---|
| 124 | ifeq ($(PLATFORM),mips32eb)
|
|---|
| 125 | TARGET = mips-linux-gnu
|
|---|
| 126 | endif
|
|---|
| 127 | ifeq ($(PLATFORM),mips64)
|
|---|
| 128 | TARGET = mips64el-linux-gnu
|
|---|
| 129 | endif
|
|---|
| 130 | ifeq ($(PLATFORM),ppc32)
|
|---|
| 131 | TARGET = ppc-linux-gnu
|
|---|
| 132 | endif
|
|---|
| 133 | ifeq ($(PLATFORM),ppc64)
|
|---|
| 134 | TARGET = ppc64-linux-gnu
|
|---|
| 135 | endif
|
|---|
| 136 | ifeq ($(PLATFORM),sparc64)
|
|---|
| 137 | TARGET = sparc64-linux-gnu
|
|---|
| 138 | endif
|
|---|
| 139 |
|
|---|
| 140 | # Binutils configure flags.
|
|---|
| 141 | CONF_FLAGS = --disable-nls --disable-shared --enable-static \
|
|---|
| 142 | --with-zlib=no --with-ppl=no --with-cloog=no \
|
|---|
| 143 | --with-gmp=no --with-mpfr=no --with-mpc=no
|
|---|
| 144 |
|
|---|
| 145 | # Binutils make targets.
|
|---|
| 146 | MAKE_TARGETS = all-gas all-ld
|
|---|
| 147 |
|
|---|
| 148 | # Check presence of gcc compiler.
|
|---|
| 149 | # Make binutils.
|
|---|
| 150 | # Copy binaries.
|
|---|
| 151 | ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
|
|---|
| 152 | all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
|
|---|
| 153 | $(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
|
|---|
| 154 | make -C $(REDIST_DIR) $(MAKE_TARGETS)
|
|---|
| 155 | cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
|
|---|
| 156 | cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
|
|---|
| 157 | else
|
|---|
| 158 | all:
|
|---|
| 159 | # Skipped: Cannot build binutils with unsupported compiler.
|
|---|
| 160 | endif
|
|---|
| 161 |
|
|---|
| 162 | # Create patched Makefile.common from native Makefile.common.
|
|---|
| 163 | $(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
|
|---|
| 164 | awk -f $^ > $@
|
|---|
| 165 |
|
|---|
| 166 | # Download binutils redistributable package.
|
|---|
| 167 | $(REDIST_FILENAME):
|
|---|
| 168 | wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
|
|---|
| 169 |
|
|---|
| 170 | # Extract binutils source tree.
|
|---|
| 171 | $(REDIST_DETECT): $(REDIST_FILENAME)
|
|---|
| 172 | tar -x -j -f $<
|
|---|
| 173 | mv -f -T $(REDIST_NAME) $(REDIST_DIR)
|
|---|
| 174 | touch $@
|
|---|
| 175 |
|
|---|
| 176 | # Generate stubs for libposix functions without posix_ prefix.
|
|---|
| 177 | $(CONFOBJ_SOURCE):
|
|---|
| 178 | echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
|
|---|
| 179 | $(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
|
|---|
| 180 | grep F | grep -o -h -I -E 'posix_.*$$' | sort -u | \
|
|---|
| 181 | sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
|
|---|
| 182 |
|
|---|
| 183 | # Compile dummy object for configure script tests.
|
|---|
| 184 | $(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
|
|---|
| 185 | ./gcc -c -o $@ $<
|
|---|
| 186 |
|
|---|
| 187 | # Generate false toolchain scripts.
|
|---|
| 188 | $(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
|
|---|
| 189 | ./$< gcc $(CC) \
|
|---|
| 190 | '$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
|
|---|
| 191 | ./$< as $(AS)
|
|---|
| 192 | ./$< ar $(AR)
|
|---|
| 193 | ./$< ranlib
|
|---|
| 194 | ./$< ld $(LD) \
|
|---|
| 195 | '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
|
|---|
| 196 | ./$< objdump $(OBJDUMP)
|
|---|
| 197 | ./$< objcopy $(OBJCOPY)
|
|---|
| 198 | ./$< strip $(STRIP)
|
|---|
| 199 |
|
|---|
| 200 | # Patch binutils source tree.
|
|---|
| 201 | $(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
|
|---|
| 202 | ./$< do $(REDIST_DIR)
|
|---|
| 203 | touch $@
|
|---|
| 204 |
|
|---|
| 205 | # Configure binutils.
|
|---|
| 206 | # $LD variable have to exported to override configure script caching.
|
|---|
| 207 | $(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
|
|---|
| 208 | export LD=ld; \
|
|---|
| 209 | cd $(REDIST_DIR); \
|
|---|
| 210 | ./configure --target=$(TARGET) $(CONF_FLAGS)
|
|---|
| 211 |
|
|---|
| 212 | # Delete binaries.
|
|---|
| 213 | # Clean binutils.
|
|---|
| 214 | # Unpatch binutils.
|
|---|
| 215 | # Delete everything in redist folder.
|
|---|
| 216 | # Delete generated scripts.
|
|---|
| 217 | clean: $(BINUTILS_PATCH) clean_
|
|---|
| 218 | rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
|
|---|
| 219 | rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
|
|---|
| 220 | ifeq ($(MAINTAIN_BINUTILS),y)
|
|---|
| 221 | if [ -e $(REDIST_DIR)/Makefile ]; then \
|
|---|
| 222 | make -C $(REDIST_DIR) distclean; \
|
|---|
| 223 | fi
|
|---|
| 224 | if [ -e $(BINUTILS_PATCHED) ]; then \
|
|---|
| 225 | ./intrusive.sh undo $(REDIST_DIR); \
|
|---|
| 226 | rm -f $(BINUTILS_PATCHED); \
|
|---|
| 227 | fi
|
|---|
| 228 | else
|
|---|
| 229 | rm -r -f redist/*
|
|---|
| 230 | rm -f $(BINUTILS_PATCHED)
|
|---|
| 231 | endif
|
|---|
| 232 | rm -f $(TOOLCHAIN)
|
|---|
| 233 | rm -f $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 234 |
|
|---|