1. make use of multi-core CPU:
if you have multi-core CPU, you can speed-up compiling of your code by doing the following:
make -j4 (if you have 2-core CPU) or
make -j5 (if you have 3-core CPU) or
make -j6 (if you have 4-core CPU)
This is parallel compiling on one computer. To determine the number of cores in your CPU, use the following command
cat /proc/cpuinfo | grep processor | wc -l
I define it in my shell as
alias numcpu='cat /proc/cpuinfo | grep processor | wc -l'
2. use ccache
ccache can be installed on Ubuntu with
sudo apt-get install ccache
After this is done, make changes in the Makefile like
CC = ccache gcc
CXX = ccache g++
When the code is recompiled, you will see clear speed-up.