| 1 | #! /bin/bash
|
|---|
| 2 |
|
|---|
| 3 | #
|
|---|
| 4 | # Copyright (c) 2011 Petr Koupy
|
|---|
| 5 | # All rights reserved.
|
|---|
| 6 | #
|
|---|
| 7 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 8 | # modification, are permitted provided that the following conditions
|
|---|
| 9 | # are met:
|
|---|
| 10 | #
|
|---|
| 11 | # - Redistributions of source code must retain the above copyright
|
|---|
| 12 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 13 | # - Redistributions in binary form must reproduce the above copyright
|
|---|
| 14 | # notice, this list of conditions and the following disclaimer in the
|
|---|
| 15 | # documentation and/or other materials provided with the distribution.
|
|---|
| 16 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 17 | # derived from this software without specific prior written permission.
|
|---|
| 18 | #
|
|---|
| 19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 29 | #
|
|---|
| 30 |
|
|---|
| 31 | #
|
|---|
| 32 | # This shell script is reserved for intrusive patches (hacks) to binutils
|
|---|
| 33 | # that cannot be done in a clean and isolated way or for which doing so
|
|---|
| 34 | # would require too much complexity.
|
|---|
| 35 | #
|
|---|
| 36 | # List of patch descriptions:
|
|---|
| 37 | #
|
|---|
| 38 | # Patch 1
|
|---|
| 39 | # Even though binutils build process supports cross compilation where
|
|---|
| 40 | # build and host platforms are different, it is not easily applicable
|
|---|
| 41 | # to HelenOS. It would be difficult to satisfy binutils expectations
|
|---|
| 42 | # of host headers, libraries and tools on a build system (at least
|
|---|
| 43 | # until these are developed/ported). Another issue would be the
|
|---|
| 44 | # necessity to carry out time consuming full canadian cross compilation
|
|---|
| 45 | # (even in case when build, host and target hardware platforms are the
|
|---|
| 46 | # same). Instead of going into such trouble, it is easier to leverage
|
|---|
| 47 | # already built HelenOS toolchain as a first stage of canadian cross
|
|---|
| 48 | # and trick binutils scripts to do a simple cross compilation while
|
|---|
| 49 | # actually doing second stage of canadian cross. Because binutils
|
|---|
| 50 | # configure scripts try to compile and execute various testing code, it
|
|---|
| 51 | # have to be ensured that these tests are skipped. Such behaviour can
|
|---|
| 52 | # be acomplished by patching cross compilation flag while leaving host
|
|---|
| 53 | # and build parameters empty (i.e. configure script believes it is
|
|---|
| 54 | # not doing cross compilation while skipping some testing as in the case
|
|---|
| 55 | # of cross compilation).
|
|---|
| 56 | #
|
|---|
| 57 | # Patch 2
|
|---|
| 58 | # Enabled cross compilation flag brings along some anomalies which
|
|---|
| 59 | # have to reverted.
|
|---|
| 60 | #
|
|---|
| 61 | # Patch 3
|
|---|
| 62 | # Binutils plugin support is dependent on libdl.so library.
|
|---|
| 63 | # By default, the plugin support is switched off for all
|
|---|
| 64 | # configure scripts of binutils. The only exception is configure
|
|---|
| 65 | # script of ld 2.21 (and possibly above), where plugin support
|
|---|
| 66 | # became mandatory (although not really needed).
|
|---|
| 67 | #
|
|---|
| 68 |
|
|---|
| 69 | case "$1" in
|
|---|
| 70 | "do")
|
|---|
| 71 | # Backup original files.
|
|---|
| 72 | cp -f "$2/configure" "$2/configure.backup"
|
|---|
| 73 | cp -f "$2/bfd/configure" "$2/bfd/configure.backup"
|
|---|
| 74 | cp -f "$2/gas/configure" "$2/gas/configure.backup"
|
|---|
| 75 | cp -f "$2/intl/configure" "$2/intl/configure.backup"
|
|---|
| 76 | cp -f "$2/ld/configure" "$2/ld/configure.backup"
|
|---|
| 77 | cp -f "$2/libiberty/configure" "$2/libiberty/configure.backup"
|
|---|
| 78 | cp -f "$2/opcodes/configure" "$2/opcodes/configure.backup"
|
|---|
| 79 |
|
|---|
| 80 | # Patch main binutils configure script.
|
|---|
| 81 | cat "$2/configure.backup" | \
|
|---|
| 82 | # See Patch 1.
|
|---|
| 83 | sed 's/^cross_compiling=no/cross_compiling=yes/g' \
|
|---|
| 84 | > "$2/configure"
|
|---|
| 85 |
|
|---|
| 86 | # Patch bfd configure script.
|
|---|
| 87 | cat "$2/bfd/configure.backup" | \
|
|---|
| 88 | # See Patch 1.
|
|---|
| 89 | sed 's/^cross_compiling=no/cross_compiling=yes/g' \
|
|---|
| 90 | > "$2/bfd/configure"
|
|---|
| 91 |
|
|---|
| 92 | # Patch gas configure script.
|
|---|
| 93 | cat "$2/gas/configure.backup" | \
|
|---|
| 94 | # See Patch 1.
|
|---|
| 95 | sed 's/^cross_compiling=no/cross_compiling=yes/g' \
|
|---|
| 96 | > "$2/gas/configure"
|
|---|
| 97 |
|
|---|
| 98 | # Patch intl configure script.
|
|---|
| 99 | cat "$2/intl/configure.backup" | \
|
|---|
| 100 | # See Patch 1.
|
|---|
| 101 | sed 's/^cross_compiling=no/cross_compiling=yes/g' \
|
|---|
| 102 | > "$2/intl/configure"
|
|---|
| 103 |
|
|---|
| 104 | # Patch ld configure script.
|
|---|
| 105 | cat "$2/ld/configure.backup" | \
|
|---|
| 106 | # See Patch 1.
|
|---|
| 107 | sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
|
|---|
| 108 | # See Patch 3.
|
|---|
| 109 | sed 's/^enable_plugins=yes/enable_plugins=no/g' \
|
|---|
| 110 | > "$2/ld/configure"
|
|---|
| 111 |
|
|---|
| 112 | # Patch libiberty configure script.
|
|---|
| 113 | cat "$2/libiberty/configure.backup" | \
|
|---|
| 114 | # See Patch 1.
|
|---|
| 115 | sed 's/^cross_compiling=no/cross_compiling=yes/g' \
|
|---|
| 116 | > "$2/libiberty/configure"
|
|---|
| 117 |
|
|---|
| 118 | # Patch opcodes configure script.
|
|---|
| 119 | cat "$2/opcodes/configure.backup" | \
|
|---|
| 120 | # See Patch 1.
|
|---|
| 121 | sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
|
|---|
| 122 | # See Patch 2.
|
|---|
| 123 | sed 's/BUILD_LIBS=-liberty/BUILD_LIBS=..\/libiberty\/libiberty.a/g' \
|
|---|
| 124 | > "$2/opcodes/configure"
|
|---|
| 125 |
|
|---|
| 126 | ;;
|
|---|
| 127 | "undo")
|
|---|
| 128 | # Restore original files.
|
|---|
| 129 | mv -f "$2/configure.backup" "$2/configure"
|
|---|
| 130 | mv -f "$2/bfd/configure.backup" "$2/bfd/configure"
|
|---|
| 131 | mv -f "$2/gas/configure.backup" "$2/gas/configure"
|
|---|
| 132 | mv -f "$2/intl/configure.backup" "$2/intl/configure"
|
|---|
| 133 | mv -f "$2/ld/configure.backup" "$2/ld/configure"
|
|---|
| 134 | mv -f "$2/libiberty/configure.backup" "$2/libiberty/configure"
|
|---|
| 135 | mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
|
|---|
| 136 | ;;
|
|---|
| 137 | *)
|
|---|
| 138 | ;;
|
|---|
| 139 | esac
|
|---|
| 140 |
|
|---|