Open Rongronggg9 opened 2 years ago
Building GCC
These instructions describe how to use the scripts in mips_tool_chain.git/build_scripts to build GCC from the FSF sources. There are two main ways to use these scripts, One is to use the make_workarea script to create a work area and then use the build.linux and build.elf scripts to do the builds. These scripts call build_toolchain to do the actual work after setting various default options that may be useful for internal developers. The second way to build is to use the build_toolchain script directly. The intention is that internal users would use make_workarea to do their builds and while external users may also use make_workarea it might be easier for them to use build_toolchain directly as they would then only need that one script and a description of what options to call it with.
Building with make_workarea
To start out you need the make_workarea script, this script is in the mips_tool_chain.git repository. By running 'make_workarea /path/to/dir' the script will create /path/to/dir (it should not exist when you run make_workarea) and populate it with the build tools.
Once you have run make_workarea, the directory that was created will contain build.elf and build.linux, these are the two top level build scripts for building the mips cross-compilers and can be run without modifying them in any way, though you might want to edit them to change what you are building. By default, build.linux builds the mips-mti-linux-gnu target and build.elf builds the mips-mti-elf target. You could change these to build the mips-img-linux-gnu and mips-img-elf targets if you wanted or you could change the build.linux script to build one of the non-imagination specific targets like mips-linux-gnu, mipsel-linux-gnu, mips64-linux-gnu, or mipsel64-linux-gnu.
The build scripts build and install the tools into directories that use the target name as part of the directory name so you can build multiple sets of tools, with different targets, in one workarea if you want.
Building GCC on a MIPS machine
If you want to build GCC on a mips machine (a malta box or a Cavium box for example) the easiest way is to use the build.linux script but change the target name. Instead of building mips-mti-linux-gnu, set TARGET to mipsisa32r2-linux-gnu (if you are on a big-endian box) or mipsisa32r2el-linxu-gnu (little-endian). These targets are not multilib targets, they will build one set of libraries for a mips32r2 target. They are native compilers in the sense that you can run them on the box you build them on but they will still build their own glibc to use. Note that if you compile a program with one of these compilers and link with shared libraries, Linux will not automatically find your new libraries in your sysroot. You need to use the --dynamic-linker and -rpath options if you want your program to use the dynamic linker and shared libraries you just built.
You can also build the mipsisa32r2-linux-gnu or mipsisa32r2el-linux-gnu targets on an x86 box to create cross-compilers without multilibs.
Modifying build.elf or build.linux
Below are some of the things you might want to change in the build scripts.
b/build_toolchain update ...
The build scripts will automatically checkout any needed sources from the dmz git repositories but if you want to check out the sources manually so you can edit them before building you can uncomment out the update command or just run that command to checkout various sources (gcc, binutils, glibc, newlib, etc.).
If your machine doesn't have gmp, mpfr, and mpc packages on it you may want to run update to get these packages. If you update them then GCC will use them instead of the system versions. If you do not explicitly run update to get these packages, the build tool will build GCC with the gmp, mpfr, and mpc packages that are installed on the system where you are building.
b/build_toolchain build
There are a lot of options you can specify to the build script. They are not all listed here but some of the most common are:
--src=<component>:<location>
You can specify a different location to pick up the GCC or other component sources (binutils, newlib, etc) and you can specify a tar file, a git repository, or an existing directory as the source for any of the packages used in the build.
--disable-multilib
If you only want to build/test the default target of a multilib compiler (like mips-mti-linux-gnu or mips-img-elf) you can use --disable-multilib to significantly speed up the build by not building all the various multilib libraries (currently 52 for mips-mti- targets). The mips-mti-linux-gnu and mips-mti-elf targets default to the mips32r2, big-endian, hard-float O32 ABI. mips-img- targets default to mips32r6, big-endian, hard-float O32 ABI.
--jobs=3
The parallelism passed in to Make.
--path=/path
/path is added to $PATH so the scripts will find various tools there.
--prefix=/path
The compiler and other tools are installed under /path.
--sysroot=/path
When building the system libraries (newlib or glibc) they are installed under this location, when building binutils and gcc the system libraries are searched for in this location.
b/build_toolchain check
This command runs the GCC testsuite. Examples of its use are in the build.elf and build.linux scripts. Note that the tests use the installed dejagnu tools and baseboards. The tests use some new baseboards I created and have been submitted (and committed) to the dejangu project.
Building GCC with build_toolchain
If you want to give someone external to MIPS instructions on how to build GCC it might be easier to just send them the build_toolchain script with instructions on using it instead of having them set up a workarea with make_workarea and using build.linux or build.elf. Here are some examples of build_toolchain calls with the arguments you might pass to build GCC:
This builds GCC from the top-of-tree sources pulled from the MIPS repositories.
R=/directory/where/build_toolchain/is/installed $R/build_toolchain build --path=$R/install/bin --source=$R/src --build=$R/obj \ --prefix=$R/install --target=mips-unknown-linux-gnu --sysroot=$R/install/sysroot \ --jobs=5 binutils-gdb initial_gcc linux_headers sysroot gcc qemu
This builds GCC from released FSF sources pulled from their download sites.
R=/directory/where/build_toolchain/is/installed ./build_toolchain build \ --path=$R/install/bin \ --source=$R/src \ --build=$R/obj \ --prefix=$R/install \ --target=mipsisa32r2-unknown-linux-gnu \ --sysroot=$R/install/sysroot \ --jobs=5 \ --src=gcc:ftp://ftp.gnu.org/gnu/gcc/gcc-4.9.1/gcc-4.9.1.tar.bz2 \ --src=binutils:ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2 \ --src=gdb:ftp://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz \ --src=glibc:ftp://ftp.gnu.org/gnu/glibc/glibc-2.19.tar.bz2 \ --src=qemu:http://wiki.qemu-project.org/download/qemu-2.1.0.tar.bz2 \ --src=gmp:ftp://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.bz2 \ --src=mpfr:ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.bz2 \ --src=mpc:ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz \ --src=linux:ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.bz2 \ binutils gdb gmp mpfr mpc initial_gcc linux glibc gcc qemu
Hi there,
build_scripts/README
contains a link pointing to https://info.mips.com/display/SWWIKI/Building+GCC, but it has been broken for a long time. Could you please update the link or simply post a backup here?https://github.com/MIPS/mips_tool_chain/blob/43d515b183294719073d605f7ad1bbd21fa66ce0/build_scripts/README#L1-L3