| 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 | PATCH_SCRIPT = ./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 | # Map the HelenOS target to binutils target.
|
|---|
| 72 | ifeq ($(PLATFORM),amd64)
|
|---|
| 73 | TARGET=amd64-linux-gnu
|
|---|
| 74 | else ($(PLATFORM),arm32)
|
|---|
| 75 | TARGET=arm-linux-gnu
|
|---|
| 76 | else ($(PLATFORM),ia32)
|
|---|
| 77 | TARGET=i686-pc-linux-gnu
|
|---|
| 78 | else ($(PLATFORM),ia64)
|
|---|
| 79 | TARGET=ia64-pc-linux-gnu
|
|---|
| 80 | else ($(PLATFORM),mips32)
|
|---|
| 81 | TARGET=mipsel-linux-gnu
|
|---|
| 82 | else ($(PLATFORM),mips32eb)
|
|---|
| 83 | TARGET=mips-linux-gnu
|
|---|
| 84 | else ($(PLATFORM),mips64)
|
|---|
| 85 | TARGET=mips64el-linux-gnu
|
|---|
| 86 | else ($(PLATFORM),ppc32)
|
|---|
| 87 | TARGET=ppc-linux-gnu
|
|---|
| 88 | else ($(PLATFORM),ppc64)
|
|---|
| 89 | TARGET=ppc64-linux-gnu
|
|---|
| 90 | else ($(PLATFORM),sparc64)
|
|---|
| 91 | TARGET=sparc64-linux-gnu
|
|---|
| 92 | endif
|
|---|
| 93 |
|
|---|
| 94 | # Binutils configure flags.
|
|---|
| 95 | CONF_FLAGS = --disable-nls --disable-shared --enable-static \
|
|---|
| 96 | --with-zlib=no
|
|---|
| 97 |
|
|---|
| 98 | # Binutils make targets.
|
|---|
| 99 | MAKE_TARGETS = all-gas all-ld
|
|---|
| 100 |
|
|---|
| 101 | # Patch native Makefile.common.
|
|---|
| 102 | # Download and extract binutils.
|
|---|
| 103 | # Check presence of gcc compiler.
|
|---|
| 104 | # Patch $PATH to intercept toolchain calls.
|
|---|
| 105 | # Generate false toolchain.
|
|---|
| 106 | # Patch binutils.
|
|---|
| 107 | # Configure binutils for target architecture.
|
|---|
| 108 | # Make binutils.
|
|---|
| 109 | # Copy binaries.
|
|---|
| 110 | all: $(COMMON_MAKEFILE_PATCHED) all_ $(REDIST_FILENAME) $(REDIST_DETECT)
|
|---|
| 111 | ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
|
|---|
| 112 | OLDPATH = $(PATH)
|
|---|
| 113 | PATH = $(PWD):$(PATH)
|
|---|
| 114 | export PATH
|
|---|
| 115 | ./toolchain.sh gcc $(CC) '$(CFLAGS)'
|
|---|
| 116 | ./toolchain.sh as $(AS)
|
|---|
| 117 | ./toolchain.sh ar $(AR)
|
|---|
| 118 | ./toolchain.sh ranlib
|
|---|
| 119 | ./toolchain.sh ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
|
|---|
| 120 | ./toolchain.sh objdump $(OBJDUMP)
|
|---|
| 121 | ./toolchain.sh objcopy $(OBJCOPY)
|
|---|
| 122 | ./toolchain.sh strip $(STRIP)
|
|---|
| 123 | ./intrusive.sh do $(REDIST_DIR)
|
|---|
| 124 | ORIG_DIR = $(subst $(space),\ ,$(PWD))
|
|---|
| 125 | cd $(REDIST_DIR)
|
|---|
| 126 | ./configure --target=$(TARGET) $(CONF_FLAGS)
|
|---|
| 127 | make $(MAKE_TARGETS)
|
|---|
| 128 | cd $(ORIG_DIR)
|
|---|
| 129 | cp $(REDIST_DIR)/gas/as-new ./as
|
|---|
| 130 | cp $(REDIST_DIR)/ld/ld-new ./ld
|
|---|
| 131 | PATH = $(OLDPATH)
|
|---|
| 132 | export PATH
|
|---|
| 133 | else
|
|---|
| 134 | echo 'Skipped: Cannot build binutils with unsupported compiler.'
|
|---|
| 135 | endif
|
|---|
| 136 |
|
|---|
| 137 | # Create patched Makefile.common from native Makefile.common.
|
|---|
| 138 | $(COMMON_MAKEFILE_PATCHED): $(PATCH_SCRIPT) $(COMMON_MAKEFILE_NATIVE)
|
|---|
| 139 | awk -f $^ > $@
|
|---|
| 140 |
|
|---|
| 141 | # Download binutils redistributable package.
|
|---|
| 142 | $(REDIST_FILENAME):
|
|---|
| 143 | wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
|
|---|
| 144 |
|
|---|
| 145 | # Extract binutils source tree.
|
|---|
| 146 | $(REDIST_DETECT): $(REDIST_FILENAME)
|
|---|
| 147 | tar -x -j -f $<
|
|---|
| 148 | mv -f $(REDIST_NAME) $(REDIST_DIR)
|
|---|
| 149 |
|
|---|
| 150 | # Delete binaries.
|
|---|
| 151 | # Clean binutils.
|
|---|
| 152 | # Unpatch binutils.
|
|---|
| 153 | # Delete generated scripts.
|
|---|
| 154 | clean:
|
|---|
| 155 | rm -f as ld
|
|---|
| 156 | ORIG_DIR = $(subst $(space),\ ,$(PWD))
|
|---|
| 157 | cd $(REDIST_DIR)
|
|---|
| 158 | make distclean
|
|---|
| 159 | cd $(ORIG_DIR)
|
|---|
| 160 | ./intrusive.sh undo $(REDIST_DIR)
|
|---|
| 161 | rm -f gcc as ar ranlib ld objdump objcopy strip
|
|---|
| 162 | rm -f $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 163 |
|
|---|