source: mainline/uspace/app/binutils/intrusive.sh@ 1916d1f

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

Libiberty fnmatch prevented from shadowing libposix fnmatch.

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