source: mainline/uspace/app/binutils/intrusive.sh@ da287d1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since da287d1 was ac7c7e36, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Corrected documentation typo.

  • Property mode set to 100755
File size: 8.7 KB
Line 
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 be 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# Patch 4
69# Whereas most systems maps pid_t to signed int, HelenOS maps it
70# to 64-bit unsigned integer (which is further masked by libposix to
71# 64-bit signed integer). Because libiberty blindly expects pid_t to be
72# signed int, there is some type incompatibility in libiberty
73# files related to executing a subprocess. Since both as and ld are
74# not runtime dependent on this functionality, the simplest solution is
75# to patch libiberty to avoid compiler warnings.
76#
77# Patch 5
78# When host and target system is equal, libbfd wants to compile a support
79# for core files, which is dependent on non-standard headers sys/param.h
80# and sys/user.h. Since we are cross compiling even when host and target
81# are equal, variables related to core file support must be cleared.
82#
83# Patch 6
84# There is a few occurences in binutils where POSIX function is declared
85# and called without first including the corresponding header. Such
86# declarations cause a problem to the linker, because all functions
87# from libposix are prefixed with the posix_ prefix.
88#
89# Patch 7
90# Implementation of fnmatch inside libiberty is not very friendly to the
91# non-GNU libc which implements its own native fnmatch. To resolve this
92# incompatibility, libiberty fnmatch has to be manually hidden.
93#
94# Patch 8
95# When building binutils for arm32 target, there is a conflict with
96# libposix function name redefinitons in one of the arm-specific files.
97#
98
99case "$1" in
100 "do")
101 # Backup original files.
102 cp -f "$2/configure" "$2/configure.backup"
103 cp -f "$2/bfd/configure" "$2/bfd/configure.backup"
104 cp -f "$2/gas/configure" "$2/gas/configure.backup"
105 cp -f "$2/gas/config/tc-arm.c" "$2/gas/config/tc-arm.c.backup"
106 cp -f "$2/intl/configure" "$2/intl/configure.backup"
107 cp -f "$2/ld/configure" "$2/ld/configure.backup"
108 cp -f "$2/libiberty/configure" "$2/libiberty/configure.backup"
109 cp -f "$2/libiberty/Makefile.in" "$2/libiberty/Makefile.in.backup"
110 cp -f "$2/include/fnmatch.h" "$2/include/fnmatch.h.backup"
111 cp -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch.c.backup"
112 cp -f "$2/libiberty/pex-common.h" "$2/libiberty/pex-common.h.backup"
113 cp -f "$2/libiberty/xstrerror.c" "$2/libiberty/xstrerror.c.backup"
114 cp -f "$2/opcodes/configure" "$2/opcodes/configure.backup"
115
116 # Patch main binutils configure script.
117 cat "$2/configure.backup" | \
118 # See Patch 1.
119 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
120 > "$2/configure"
121
122 # Patch bfd configure script.
123 cat "$2/bfd/configure.backup" | \
124 # See Patch 1.
125 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
126 # See Patch 5.
127 sed 's/COREFILE=".*"/COREFILE='\'\''/g' | \
128 sed 's/COREFILE=[^ ]*/COREFILE='\'\''/g' \
129 > "$2/bfd/configure"
130
131 # Patch gas configure script.
132 cat "$2/gas/configure.backup" | \
133 # See Patch 1.
134 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
135 > "$2/gas/configure"
136
137 # Patch gas tc-arm.c.
138 cat "$2/gas/config/tc-arm.c.backup" | \
139 # See Patch 8.
140 sed 's/\(#include "dwarf2dbg.h"\)/\1\n#undef div/g' \
141 > "$2/gas/config/tc-arm.c"
142
143 # Patch intl configure script.
144 cat "$2/intl/configure.backup" | \
145 # See Patch 1.
146 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
147 > "$2/intl/configure"
148
149 # Patch ld configure script.
150 cat "$2/ld/configure.backup" | \
151 # See Patch 1.
152 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
153 # See Patch 3.
154 sed 's/^enable_plugins=yes/enable_plugins=no/g' \
155 > "$2/ld/configure"
156
157 # Patch libiberty configure script.
158 cat "$2/libiberty/configure.backup" | \
159 # See Patch 1.
160 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
161 > "$2/libiberty/configure"
162
163 # Hide libiberty fnmatch implementation.
164 # See Patch 7.
165 mv -f "$2/include/fnmatch.h" "$2/include/fnmatch_hide.h"
166 (
167 # Avoid compiler warning for empty compilation unit.
168 echo 'char __fnmatch_hide(void);'
169 echo 'char __fnmatch_hide(void) { return 0; }'
170 echo '#define __GNU_LIBRARY__'
171 cat "$2/libiberty/fnmatch.c.backup"
172 ) > "$2/libiberty/fnmatch.c"
173 mv -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch_hide.c"
174 cat "$2/libiberty/Makefile.in.backup" | \
175 sed 's/fnmatch/fnmatch_hide/g' \
176 > "$2/libiberty/Makefile.in"
177
178 # Patch libiberty pex-common.h.
179 cat "$2/libiberty/pex-common.h.backup" | \
180 # See Patch 4.
181 sed 's/pid_t (\*wait)/int (*wait)/g' \
182 > "$2/libiberty/pex-common.h"
183
184 # Patch libiberty xstrerror.c.
185 # See Patch 6.
186 (
187 echo '#include <string.h>'
188 echo '#define DONT_DECLARE_STRERROR'
189 cat "$2/libiberty/xstrerror.c.backup"
190 ) > "$2/libiberty/xstrerror.c"
191
192 # Patch opcodes configure script.
193 cat "$2/opcodes/configure.backup" | \
194 # See Patch 1.
195 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
196 # See Patch 2.
197 sed 's/BUILD_LIBS=-liberty/BUILD_LIBS=..\/libiberty\/libiberty.a/g' \
198 > "$2/opcodes/configure"
199
200 ;;
201 "undo")
202 # Restore original files.
203 mv -f "$2/configure.backup" "$2/configure"
204 mv -f "$2/bfd/configure.backup" "$2/bfd/configure"
205 mv -f "$2/gas/configure.backup" "$2/gas/configure"
206 mv -f "$2/gas/config/tc-arm.c.backup" "$2/gas/config/tc-arm.c"
207 mv -f "$2/intl/configure.backup" "$2/intl/configure"
208 mv -f "$2/ld/configure.backup" "$2/ld/configure"
209 mv -f "$2/libiberty/configure.backup" "$2/libiberty/configure"
210 mv -f "$2/libiberty/Makefile.in.backup" "$2/libiberty/Makefile.in"
211 rm -f "$2/include/fnmatch_hide.h" "$2/libiberty/fnmatch_hide.c"
212 mv -f "$2/include/fnmatch.h.backup" "$2/include/fnmatch.h"
213 mv -f "$2/libiberty/fnmatch.c.backup" "$2/libiberty/fnmatch.c"
214 mv -f "$2/libiberty/pex-common.h.backup" "$2/libiberty/pex-common.h"
215 mv -f "$2/libiberty/xstrerror.c.backup" "$2/libiberty/xstrerror.c"
216 mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
217 ;;
218 *)
219 ;;
220esac
221
Note: See TracBrowser for help on using the repository browser.