tags:

views:

147

answers:

2

I have to compile multiple versions of an app written in C++ and I think to use ccache for speeding up the process.

ccache howtos have examples which suggest to create symlinks named gcc, g++ etc and make sure they appear in PATH before the original gcc binaries, so ccache is used instead.

So far so good, but I'd like to use ccache only when compiling this particular app, not always.

Of course, I can write a shell script that will try to create these symlinks every time I want to compile the app and will delete them when the app is compiled. But this looks like filesystem abuse to me.

Are there better ways to use ccache selectively, not always?

For compilation of a single source code file, I could just manually call ccache instead of gcc and be done, but I have to deal with a complex app that uses an automated build system for multiple source code files.

A: 

What OS? Linux? Most packaged versions of ccache already put those symlinks into a directory, for example on my Fedora machine they live in /usr/lib64/ccache.

So you could just do

PATH=/usr/lib64/ccache:${PATH} make

when you want to build with ccache.

Most packages also install a file in /etc/profile.d/ which automatically enables ccache, by adding it to the PATH as above.

If that's the case on your system, just set CCACHE_DISABLE=1 (see man ccache for more info) in your environment to disable ccache - ccache will still be run, but will simply call the real compiler.

James
Setting CCACHE_DISABLE seems to be ok, thank you.
A: 

The alternative to creating symlinks is to explicitly use ccache gcc as the C compiler and ccache g++ as the C++ compiler. For instance, if your Makefile uses the variables CC and CXX to specify the compilers, you can build with make CC="ccache gcc" CXX="ccache g++" or do set it up at configure time (./configure CC="ccache gcc" CXX="ccache g++").

Joel Rosdahl