| 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 | # Symlink to the sources of the ported application.
|
|---|
| 33 | APP_DIR = ./src
|
|---|
| 34 |
|
|---|
| 35 | # Default directory for the binutils source tree.
|
|---|
| 36 | REDIST_DIR = ./redist
|
|---|
| 37 |
|
|---|
| 38 | # Absolute path to the binutils source tree.
|
|---|
| 39 | # Can be set externally, defaults to $REDIST_DIR.
|
|---|
| 40 | BINUTILS_ABS_PATH ?= $(subst $(space),\ ,$(PWD))/$(REDIST_DIR)
|
|---|
| 41 |
|
|---|
| 42 | # $USPACE_PREFIX have to be based on the absolute path,
|
|---|
| 43 | # because targets derived from it will be referenced from
|
|---|
| 44 | # other than the current directory.
|
|---|
| 45 | USPACE_PREFIX = $(subst $(space),\ ,$(PWD))/../..
|
|---|
| 46 |
|
|---|
| 47 | # Ensure static configuration of Makefile.common.
|
|---|
| 48 | STATIC_ONLY = y
|
|---|
| 49 |
|
|---|
| 50 | # Makefile.common for native applications.
|
|---|
| 51 | COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
|
|---|
| 52 |
|
|---|
| 53 | # Generated from native Makefile.common.
|
|---|
| 54 | COMMON_MAKEFILE_PATCHED = ./Makefile.common
|
|---|
| 55 |
|
|---|
| 56 | # AWK script which generates patched Makefile.common.
|
|---|
| 57 | PATCH_SCRIPT = ./patch.awk
|
|---|
| 58 |
|
|---|
| 59 | # Compilers that can be used to build binutils.
|
|---|
| 60 | SUPPORTED_COMPILERS = gcc_cross gcc_native
|
|---|
| 61 |
|
|---|
| 62 | # Patched Makefile.common for ported user space applications.
|
|---|
| 63 | include $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 64 |
|
|---|
| 65 | # Map the HelenOS target to binutils target.
|
|---|
| 66 | ifeq ($(PLATFORM),amd64)
|
|---|
| 67 | TARGET=amd64-linux-gnu
|
|---|
| 68 | else ($(PLATFORM),arm32)
|
|---|
| 69 | TARGET=arm-linux-gnu
|
|---|
| 70 | else ($(PLATFORM),ia32)
|
|---|
| 71 | TARGET=i686-pc-linux-gnu
|
|---|
| 72 | else ($(PLATFORM),ia64)
|
|---|
| 73 | TARGET=ia64-pc-linux-gnu
|
|---|
| 74 | else ($(PLATFORM),mips32)
|
|---|
| 75 | TARGET=mipsel-linux-gnu
|
|---|
| 76 | else ($(PLATFORM),mips32eb)
|
|---|
| 77 | TARGET=mips-linux-gnu
|
|---|
| 78 | else ($(PLATFORM),mips64)
|
|---|
| 79 | TARGET=mips64el-linux-gnu
|
|---|
| 80 | else ($(PLATFORM),ppc32)
|
|---|
| 81 | TARGET=ppc-linux-gnu
|
|---|
| 82 | else ($(PLATFORM),ppc64)
|
|---|
| 83 | TARGET=ppc64-linux-gnu
|
|---|
| 84 | else ($(PLATFORM),sparc64)
|
|---|
| 85 | TARGET=sparc64-linux-gnu
|
|---|
| 86 | endif
|
|---|
| 87 |
|
|---|
| 88 | # Binutils configure flags.
|
|---|
| 89 | CONF_FLAGS = --disable-nls --disable-shared --enable-static \
|
|---|
| 90 | --with-zlib=no
|
|---|
| 91 |
|
|---|
| 92 | # Binutils make targets.
|
|---|
| 93 | MAKE_TARGETS = all-gas all-ld
|
|---|
| 94 |
|
|---|
| 95 | # Patch native Makefile.common.
|
|---|
| 96 | # Check presence of gcc compiler.
|
|---|
| 97 | # Patch $PATH to intercept toolchain calls.
|
|---|
| 98 | # Generate false toolchain.
|
|---|
| 99 | # Create symlink to the binutils directory.
|
|---|
| 100 | # Patch binutils.
|
|---|
| 101 | # Configure binutils for target architecture.
|
|---|
| 102 | # Make binutils.
|
|---|
| 103 | # Copy binaries.
|
|---|
| 104 | all: $(COMMON_MAKEFILE_PATCHED) all_
|
|---|
| 105 | ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
|
|---|
| 106 | OLDPATH = $(PATH)
|
|---|
| 107 | PATH = $(PWD):$(PATH)
|
|---|
| 108 | export PATH
|
|---|
| 109 | ./toolchain.sh gcc $(CC) '$(CFLAGS)'
|
|---|
| 110 | ./toolchain.sh as $(AS)
|
|---|
| 111 | ./toolchain.sh ar $(AR)
|
|---|
| 112 | ./toolchain.sh ranlib
|
|---|
| 113 | ./toolchain.sh ld $(LD) '$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
|
|---|
| 114 | ./toolchain.sh objdump $(OBJDUMP)
|
|---|
| 115 | ./toolchain.sh objcopy $(OBJCOPY)
|
|---|
| 116 | ./toolchain.sh strip $(STRIP)
|
|---|
| 117 | ln -s -T $(BINUTILS_ABS_PATH) $(APP_DIR)
|
|---|
| 118 | ./intrusive.sh do $(APP_DIR)
|
|---|
| 119 | ORIG_DIR = $(subst $(space),\ ,$(PWD))
|
|---|
| 120 | cd $(APP_DIR)
|
|---|
| 121 | ./configure --target=$(TARGET) $(CONF_FLAGS)
|
|---|
| 122 | make $(MAKE_TARGETS)
|
|---|
| 123 | cd $(ORIG_DIR)
|
|---|
| 124 | cp $(APP_DIR)/gas/as-new ./as
|
|---|
| 125 | cp $(APP_DIR)/ld/ld-new ./ld
|
|---|
| 126 | PATH = $(OLDPATH)
|
|---|
| 127 | export PATH
|
|---|
| 128 | else
|
|---|
| 129 | echo 'Skipped: Cannot build binutils with unsupported compiler.'
|
|---|
| 130 | endif
|
|---|
| 131 |
|
|---|
| 132 | # Create patched Makefile.common from native Makefile.common.
|
|---|
| 133 | $(COMMON_MAKEFILE_PATCHED): $(PATCH_SCRIPT) $(COMMON_MAKEFILE_NATIVE)
|
|---|
| 134 | awk -f $^ > $@
|
|---|
| 135 |
|
|---|
| 136 | # Delete binaries.
|
|---|
| 137 | # Clean binutils.
|
|---|
| 138 | # Unpatch binutils.
|
|---|
| 139 | # Delete symlink
|
|---|
| 140 | # Delete generated scripts.
|
|---|
| 141 | clean:
|
|---|
| 142 | rm -f as ld
|
|---|
| 143 | ORIG_DIR = $(subst $(space),\ ,$(PWD))
|
|---|
| 144 | cd $(APP_DIR)
|
|---|
| 145 | make distclean
|
|---|
| 146 | cd $(ORIG_DIR)
|
|---|
| 147 | ./intrusive.sh undo $(APP_DIR)
|
|---|
| 148 | rm -f $(APP_DIR)
|
|---|
| 149 | rm -f gcc as ar ranlib ld objdump objcopy strip
|
|---|
| 150 | rm -f $(COMMON_MAKEFILE_PATCHED)
|
|---|
| 151 |
|
|---|