-
Notifications
You must be signed in to change notification settings - Fork 19
/
cross_build_binutils.sh
executable file
·226 lines (198 loc) · 5.53 KB
/
cross_build_binutils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
#
# script for building cross binutils packages
# skip to CONFIGURE line below for the interesting part
#
PKGNAM=binutils
VERSION=${VERSION:-"2.25.1"}
BUILD=${BUILD:-"1"}
CC=${CC:-"gcc"}
TARGET=${TARGET:-"aarch64"}
SYSROOT=/usr/gnemul/$TARGET
if [ -z "$NUMJOBS" ]
then
NUMJOBS=`getconf _NPROCESSORS_ONLN 2> /dev/null`
if [ $? -ne 0 ]
then
NUMJOBS=`grep -c ^processor /proc/cpuinfo 2> /dev/null`
[ $? -ne 0 ] && NUMJOBS=2
fi
NUMJOBS=$((NUMJOBS*2))
fi
[ -f /etc/debian_version ] && system="debian"
[ -f /etc/slackware-version ] && system="slackware"
usage() {
echo "usage: $0 help|build|package|repackage|deb|slackpkg [source path]"
}
case "$1" in
-h|help) usage
echo " [source path]"
exit 0
;;
build) package="" ;;
deb) package="debian" ;;
slackpkg) package="slackware" ;;
package) package="$system" ;;
repackage) skipbuild="1"; package="$system" ;;
*) echo "unknown command: \"$1\""; usage; exit 2 ;;
esac
shift
if [ -d "$1" ]
then
SRC_PATH="$1"
else
testdir=../${PKGNAM}.git
[ -f "$testdir/configure" ] && SRC_PATH="$testdir"
testdir=../${PKGNAM}-gdb.git
[ -f "$testdir/configure" ] && SRC_PATH="$testdir"
testdir=../${PKGNAM}
[ -f "$testdir/configure" ] && SRC_PATH="$testdir"
testdir=../${PKGNAM}-gdb
[ -f "$testdir/configure" ] && SRC_PATH="$testdir"
testdir=../${PKGNAM}-${VERSION}
[ -f "$testdir/configure" ] && SRC_PATH="$testdir"
fi
if [ ! -d "$SRC_PATH" -a -z "$skipbuild" ]
then
echo "Error: could not find source directory."
echo "Give the source path as an argument."
exit 1
fi
HARCH=`uname -m`
case "$HARCH" in
i?86) HARCH=i486 ;;
aarch64) HBITS="64" ;;
x86_64) HBITS="64"; [ "$system" = "debian" ] && HARCH="amd64" ;;
armv7l) HARCH=armhf;;
arm*) HARCH=arm ;;
esac
HTRIPLET=`$CC -dumpmachine`
case "$system" in
slackware) vendor="slackware"; os="linux"; slackware="slackware-" ;;
*) vendor="linux"; os="gnu"; HBITS="" ;;
esac
if [ -z "$TRIPLET" ]
then
TRIPLET=${TARGET}-${vendor}-${os}
case "$TARGET" in
armhf) TRIPLET=arm-${slackware}linux-gnueabihf;;
arm) TRIPLET=arm-${slackware}linux-gnueabi;;
openwrt) TRIPLET=mips-openwrt-linux-uclibc;;
x32) TRIPLET=x86_64-${slackware}linux-gnux32;;
esac
fi
case "$TARGET" in
x32) TBITS="x32" ;;
*64) TBITS="64" ;;
*) TBITS="" ;;
esac
HOST_OPTS="--prefix=/usr --with-gnu-ld --with-gnu-as"
case "$system" in
slackware)
LIBDIR="lib$TBITS"
HOST_OPTS="$HOST_OPTS --disable-multiarch"
HOST_OPTS="$HOST_OPTS --libdir=/usr/lib$HBITS"
;;
debian)
LIBDIR="lib/$TRIPLET"
HOST_OPTS="$HOST_OPTS --enable-multiarch"
HOST_OPTS="$HOST_OPTS --libdir=/usr/lib/$HTRIPLET"
;;
esac
LIBPATH=/usr/$TRIPLET/lib$HBITS
LIBPATH="$LIBPATH:$SYSROOT/usr/local/$LIBDIR"
LIBPATH="$LIBPATH:$SYSROOT/$LIBDIR"
LIBPATH="$LIBPATH:$SYSROOT/usr/$LIBDIR"
#
# CONFIGURE
#
if [ -z "$skipbuild" ]
then
if ! $SRC_PATH/configure $HOST_OPTS --target=$TRIPLET \
--build=$HTRIPLET --host=$HTRIPLET \
--enable-plugins --enable-threads --disable-nls \
--enable-gold=yes --enable-ld=default \
--enable-64-bit-bfd \
--disable-bootstrap --disable-shared --enable-multilib \
--with-sysroot=$SYSROOT \
--with-lib-path=$LIBPATH
then
echo -e "\nconfigure failed, aborting."
exit 2
fi
if ! make -j"$NUMJOBS"
then
echo -e "\nbuild failed, aborting."
exit 3
fi
rm -Rf ./root
mkdir root
if ! make DESTDIR=`pwd`/root install
then
echo -e "\ninstallation failed, aborting."
exit 4
fi
CROSSLD=./root/usr/bin/${TRIPLET}-ld
if [ ! -x $CROSSLD ] || $CROSSLD -v | grep -qv "$VERSION\$"
then
echo -e "\ncross ld binary version mismatch"
fi
fi
[ -z "$package" ] && exit 0
( cd root
rm -Rf usr/include usr/man usr/info usr/share
find ./ | xargs file | grep -e "executable" -e "shared object" \
| grep ELF | cut -f 1 -d : \
| xargs strip --strip-unneeded 2> /dev/null
)
if [ "$package" = "slackware" ]
then
SLACKVER=`. /etc/os-release; echo $VERSION`
PKGNAME="$PKGNAM-$TARGET"
mkdir root/install
cat > root/install/slack-desc << _EOF
$PKGNAME: binutils for the $TARGET architecture
$PKGNAME:
$PKGNAME: Binutils is a collection of binary utilities. It includes "as"
$PKGNAME: (the portable GNU assembler), "ld" (the GNU linker), and other
$PKGNAME: utilities for creating and working with binary programs.
$PKGNAME: This version deals and creates with binaries and object files
$PKGNAME: for the $TARGET architecture.
$PKGNAME: Target is: $TRIPLET
$PKGNAME: sysroot: $SYSROOT
$PKGNAME: Version $VERSION for Slackware$HBITS $SLACKVER
$PKGNAME:
_EOF
(cd root; makepkg -c y -l y ../$PKGNAME-$VERSION-$HARCH-$BUILD.txz)
exit 0
fi
[ "$package" = "debian" ] || exit 1
mkdir -p debian/control
( cd root
find * -type f | sort | xargs md5sum > ../debian/control/md5sums
tar c -z --owner=root --group=root -f ../debian/data.tar.gz ./
)
SIZE=`du -s root | cut -f1`
[ -f debian/control/control ] || cat > debian/control/control << _EOF
Package: $PKGNAM-$TRIPLET
Source: $PKGNAM
Version: $VERSION
Installed-Size: $SIZE
Maintainer: Andre Przywara <[email protected]>
Architecture: $HARCH
Depends: libc6, zlib1g (>= 1:1.1.4)
Built-Using: binutils
Section: devel
Priority: extra
Description: GNU binary utilities, for $TRIPLET target
This package provides GNU assembler, linker and binary utilities
for the $TRIPLET target, for use in a cross-compilation environment.
.
You don't need this package unless you plan to cross-compile programs
for $TRIPLET.
_EOF
(cd debian/control; tar c -z --owner=root --group=root -f ../control.tar.gz *)
echo "2.0" > debian/debian-binary
PKGNAME=${PKGNAM}-${TRIPLET}_${VERSION}-${BUILD}_${HARCH}.deb
rm -f $PKGNAME
(cd debian; ar q ../$PKGNAME debian-binary control.tar.gz data.tar.gz)