Skip to content

Instantly share code, notes, and snippets.

@weldpua2008
Last active January 15, 2017 14:37
Show Gist options
  • Save weldpua2008/9d9db911a0dc179c09e1d95e19208334 to your computer and use it in GitHub Desktop.
Save weldpua2008/9d9db911a0dc179c09e1d95e19208334 to your computer and use it in GitHub Desktop.
How to build toolchain(gcc 4.1.x & 4.9.x)
# http://stackoverflow.com/questions/27028240/gnu-configure-options-for-binutils-gcc-glib
# https://gcc.gnu.org/wiki/InstallingGCC
# https://gcc.gnu.org/ml/gcc-help/2008-02/msg00356.html
# Rebuild GCC 4.9.3
# Get all deb files:
apt-get --download-only --reinstall -o Dir::Cache="/root/4.9" -o Dir::Cache::archives="./" install gcc-4.9-multilib
#
mkdir /root/toolchain_src/ && cd /root/toolchain_src/
wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2
tar xjvf gcc-4.9.3.tar.bz2
./contrib/download_prerequisites
mkdir objdir&& cd objdir
$PWD/../gcc-*/configure --prefix=/opt/tools/dev-tools-4.9 \
-v --with-pkgversion='Ubuntu/Linaro 4.9.3' \
--program-suffix=-4.9 --enable-shared --enable-linker-build-id --with-system-zlib \
--libexecdir=/opt/tools/dev-t\ools-4.9/lib --without-included-gettext \
--enable-threads=posix --with-gxx-include-dir=/opt/tools/dev-tools-4.9/include/c++/4.9 \
--libdir=/opt/tools/dev-tools-4.9/lib --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes \
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror \
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic \
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-sysroot=/ --enable-nls && \
make -j $(nproc || grep -c ^processor /proc/cpuinfo|| echo "1") && \
make install
#
apt-get build-dep -y gcc-4.9-multilib
apt-get source -y gcc-4.9-multilib
dpkg-source -x gcc-4.9_4.9.2-0ubuntu1~12.04.dsc
cd gcc-4.9-4.9.2
dpkg-buildpackage -rfakeroot -b
cd gcc-*
#detect Version
_DETECTED_VERSION=$(cat gcc*.dsc 2> /dev/null|grep -E -i "^Version"|cut -d ":" -f2|tr -d ' '|head -1)
[[ "x$_DETECTED_VERSION" != "x" ]] && GCC_PKG_VERSION="$_DETECTED_VERSION"
unset _DETECTED_VERSION || true
# OR build with the custom path
tar -xf gcc-4.9.2.tar.xz
mv gcc-4.9.2 src
cd src && ./contrib/download_prerequisites
cd ..&&mkdir objdir&& cd objdir
$PWD/../src/configure --prefix=/opt/tools/dev-tools-4.9 \
-v --with-pkgversion='Ubuntu/Linaro 4.9.2-0ubuntu1~12.04' \
--program-suffix=-4.9 --enable-shared --enable-linker-build-id --with-system-zlib \
--libexecdir=/opt/tools/dev-tools-4.9/lib --without-included-gettext \
--enable-threads=posix --with-gxx-include-dir=/opt/tools/dev-tools-4.9/include/c++/4.9 \
--libdir=/opt/tools/dev-tools-4.9/lib --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes \
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror \
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic \
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-sysroot=/ --enable-nls && \
make -j $(nproc || grep -c ^processor /proc/cpuinfo|| echo "1") && \
make install
## Compiling GCC 4.1.2 for Ubuntu 12.04
# http://tomjbward.co.uk/compiling-gcc-4-1-2-for-ubuntu-12-04-foundry-plugin-development/
First get the right GCC and Packages
Open up a Terminal in Ubuntu, create a temp directory for doing everything in and then download the gcc tar:
mkdir /tmp/gcc
cd /tmp/gcc
wget http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
Next we need to untar the source into a sub-directory and create a build folder, which is where the final executable and libs will go from the build.
tar -xvjpf ./gcc-4.1.2.tar.bz2
mkdir ./build
Finally we need to install a few external packages in order to build gcc, which we can install using the following command:
sudo apt-get install linux-headers-$(uname -r) zlib1g zlib1g-dev zlibc gcc-multilib
We should now have our folder structure set, the source downloaded and un-zipped and the external packages we need installed.
Source Changes for Ubuntu
Unbuntu made a few subtle changes that means if we try and build with the vanilla gcc source, we'll run into a few problems. Luckily it's only one change that needs to be made, in ./gcc-4.1.2/libstdc++-v3/configure where on line 8284 you need to change:
sed -e 's/GNU ld version \([0-9.][0-9.]*\).*/\1/'`
to
sed -e 's/GNU ld (GNU Binutils for Ubuntu) \([0-9.][0-9.]*\).*/\1/'`
GCC also requires a few libs that are in a different structure for Ubuntu. To fix this add the following symbolic links
sudo ln -s /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/crt1.o
sudo ln -s /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/crti.o
sudo ln -s /usr/lib/x86_64-linux-gnu/crtn.o /usr/lib/crtn.o
Compiling GCC
Now we need to run configure to build up the make file to build GCC. First go to the build directory we created earlier and run the following configure command:
mkdir /tmp/gcc412/build
../gcc-4.1.2/configure --program-suffix=-4.1 --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --disable-libunwind-exceptions --enable-__cxa_atexit --enable-languages=c,c++ --disable-multilib
That should complete pretty quickly. Once that's complete, just run the following make command:
make -j 2 bootstrap MAKEINFO=makeinfo
sudo make install
To start compiling and install! Hopefully that'll complete without any issue, and you should be able to run "gcc-4.1" to compile with this version of gcc.
### Toolchain helpful links:
# https://wiki.ubuntu.com/ToolChain - ToolChain
# Linaro GCC is performance focused branch of the current GCC stable release and includes backports of the improvements and bug fixes that Linaro and others have done upstream.
# https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition - ToolchainTransition
# https://wiki.ubuntu.com/ToolChain/CompilerFlags - CompilerFlags
# https://wiki.ubuntu.com/NewReleaseCycleProcess - Planning and decisions for updating binutils and GCC are usually made six months before a new release cycle starts. Initial uploads are done as part of the NewReleaseCycleProcess. GCC and binutils are updated during the release cycle.
# PPA packages
# Updated toolchain packages can be found in two PPAs.
# • https://launchpad.net/~ubuntu-toolchain-r/+archive/ppa hosts updates from release branches (e.g. Ubuntu 14.04 LTS released with gcc-4.8.2 and the PPA has gcc-4.8.3).
# • https://launchpad.net/~ubuntu-toolchain-r/+archive/test hosts newer upstream versions (e.g. gcc-4.9 is found here for Ubuntu 14.04 LTS).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment