參考資訊:
https://github.com/andrew-d/static-binaries/blob/master/binutils/arm/build.sh
run.sh
#!/bin/bash
set -e
set -o pipefail
set -x
BINUTILS_VERSION=2.39
function build_binutils() {
rm -rf build
mkdir build
cd build
curl -LO http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz
tar xzvf binutils-${BINUTILS_VERSION}.tar.gz
mkdir build
cd build
TMPFILE=`pwd`/configure.output
../binutils-${BINUTILS_VERSION}/configure --help > $TMPFILE
CONFIGURE_OPTS=""
for opt in disable-nls enable-static-link disable-shared-plugins disable-dynamicplugin disable-tls disable-pie; do
grep -qs $opt $TMPFILE && CONFIGURE_OPTS="$CONFIGURE_OPTS --$opt"
done
for opt in enable-static; do
grep -qs $opt $TMPFILE && CONFIGURE_OPTS="$CONFIGURE_OPTS --$opt=yes"
done
for opt in enable-shared; do
grep -qs $opt $TMPFILE && CONFIGURE_OPTS="$CONFIGURE_OPTS --$opt=no"
done
rm -f $TMPFILE
CC='arm-linux-gnueabi-gcc -static -fPIC' \
CXX='arm-linux-gnueabi-g++ -static -static-libstdc++ -fPIC' \
LD='arm-linux-gnueabi-ld' \
../binutils-${BINUTILS_VERSION}/configure --target=arm-linux-gnueabi --prefix=`pwd` ${CONFIGURE_OPTS}
make
make clean
make LDFLAGS=-all-static
OUTPUT_FILES="ar nm-new objcopy objdump ranlib readelf size strings"
for f in ${OUTPUT_FILES};
do
arm-linux-gnueabi-strip binutils/$f
done
arm-linux-gnueabi-strip ld/ld-new
arm-linux-gnueabi-strip gas/as-new
}
function doit() {
build_binutils
rm -rf output
mkdir output
OUT_DIR=output/`uname | tr 'A-Z' 'a-z'`/`uname -m`
mkdir -p $OUT_DIR
for f in ar objcopy objdump ranlib readelf size strings;
do
cp binutils/$f $OUT_DIR/
done
cp binutils/nm-new $OUT_DIR/nm
cp ld/ld-new $OUT_DIR/ld
cp gas/as-new $OUT_DIR/as
echo "finished !"
}
doit
編譯
$ sudo apt-get install gcc-arm-linux-gnueabi* texinfo file -y
$ chmod a+x ./run.sh
$ ./run.sh
$ ls build/build/output/linux/*/
ar as ld nm objcopy objdump ranlib readelf size strings