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