Lab 4: GCC Build from Source
We're learning to use programs like Make and Automake/Autotools to create huge software projects in this lab. x86-001 and aarch64-002 are the two servers I'll be working on.
Task:
On both servers, I'll download, build, and install the latest development version of the GCC compiler.
Below are the steps to complete the lab!
1. Clone the GCC repository using the below command
git clone git://gcc.gnu.org/git/gcc.git
Create a separate build directory to avoid building GCC in the source directory
mkdir ~/gcc-build-001
cd gcc-build-001
3. To set up GCC to be installed in a specific location (e.g., gcc-test-001), Run the configure script with the preferred prefix for the installation path
~/gcc/gcc/configure --prefix=$HOME/gcc-test-001
4. Build the source code using the below command
time make -j 24 |& tee build.log
The -j option in make specifies the maximum number of jobs that can run simultaneously.
The |& operator is shorthand for 2>&1 |, which redirects both standard output and standard error and pipes them into the tee command. The tee command then saves this output to a specified file.
- real: The actual elapsed time from start to finish
- user: The total CPU time spent executing in user mode
- sys: The CPU time spent executing in system mode
5. Install the build
command: make install
6. Test the build
commands:
export PATH=$HOME/gcc-test-001/bin:$PATH
gcc --version
make check
7. Verify the installation by checking the GCC version.
command: gcc --version
~/gcc-test-001/bin/gcc --version
8. Build a C program
To verify that the newly built GCC can compile a simple C program:
Create a test C program:
nano test.cAdd the following simple C code:
Compile the program using the built GCC:
~/gcc-test-001/bin/gcc test.c -o test
Run the compiled program: ./test
If it printsHello, GCC!, then your compiler works correctly.
9. Update the time stamp on the file "passes.cc"
Method 1: Usingthe touch command
commands:
cd ~/gcc/gcc
touch passes.cc
Method 2: Editing and saving the file manually
commands:
nano passes.cc
10. Rebuild the software after updating passes.cc
11. Perform a "Null Rebuild"Run
makeagain without modifying any files:time make -j 24 |& tee null_rebuild.log
Reflections:
Building software from source, especially something as complicated as GCC, was a terrific hands-on experience in this lab. Although the first build took a while, it was rewarding to see it finished successfully. The significance of version control in development environments became clearer to me after testing the new compiler and contrasting it with the system's GCC. The incremental and null rebuilds demonstrated how to optimize compilation by recompiling only the files that are required. To measure performance for troubleshooting and benchmarking, I also learned to utilize time and logging. Overall, it was a difficult but worthwhile exercise that helped me better understand software compilation.

.png)
Comments
Post a Comment