I have a source directory which uses makefile to compile the code. This makefile/configure file is not written for ccache compatibility. So I thought to use ccache. I created alias in .bashrc as alias gcc='ccache gcc'
, but Makefile is still not considering this definition of gcc. So is there anything I can do without touching Makefile/configure
file such that it takes ccache gcc
instead of gcc
.
Also CC='ccache gcc' ./configure is not an option, since it does not ask for CC.
If I write Makefile then I can provide ${gcc), but this is not an option, since I am not writing Makefile. Is there any way by which we don't need to change anything in source file, but still enable ccache
compiling.
Using ccache globally is not recommended as it will saturate the cache and have few cache hits! Enable it instead for specific packages. Done! From now on, all builds will try to reuse object files from the cache at /var/cache/ccache.
Ccache is a compiler cache. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation is being done again. Ccache has been carefully written to always produce exactly the same compiler output that you would get without the cache.
To enable ccache, simply add '/usr/lib/ccache' to the beginning of your PATH. This directory contains symlinks to ccache, and ccache is smart enough to look at the name of the calling executable to determine which real executable to run.
By default, ccache has a 5 GB limit on the total size of files in the cache and no limit on the number of files. You can set different limits using the command line options -M/--max-size and -F/--max-files.
Aliases are local to the shell they are created in; unlike environment variables they are not passed to any programs that the shell invokes (including make). Make invokes /bin/sh, not /bin/bash, and /bin/sh doesn't read your ~/.bashrc etc. so no aliases defined there will be helpful to you.
I'm not exactly sure why you have placed some of the restrictions you mention on yourself: these things work fine and you haven't given a reason to avoid them that I understand. For example, providing a different CC with configure will work, if the version of autoconf is not really ancient. You can do this:
./configure CC='ccache gcc'
for example and that will set the default value of CC
in your makefile to be ccache gcc
. I don't know what you mean by "it does not ask for CC".
If you would prefer, you can also override the setting of CC
on the make
command line, like this:
make CC='ccache gcc'
which also works fine.
As described by the fine manual: Create a symlink named "gcc" in a directory that is listed in your PATH before the one containing the real gcc. This will cause ccache to be used transparently, with no need for any change to the makefile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With