The build counter system presented in this article can be used to keep
track of how many times your linker is invoked when you build your
executables. The system is comprised of two pieces of code, one m4
source file and some code that goes into your Makefile after the
linker is invoked. Suppose your executable is called
2010/tests/hello.exe. Then the name of the file that keeps track
of how many times the linker is invoked is called
2010/tests/hello.num where the .num file extension stands for
number. The system is robust enough to handle cases where the
file 2010/tests/hello.num does not exist as will be the case when
the linker is run for the first time with the extra linker code. The
reason that the number of linker invocations is counted is that
linking is always done once at the end of a series of compilations.
2. How to install the system
The following m4 code can be used to keep track to the build counts of
your linker:
m4_define(COUNTER,m4_eval(m4_sinclude(FILE) + 1))m4_dnlm4_esyscmd(echo >FILE COUNTER)m4_dnl
*** Updated build count to new value: COUNTER
Place the above code into a file called build-counter.txt and add
the following code to your Makefile's linker call:
m4 -P -DFILE=$*.num build-counter.txt
so that the command to invoke the linker looks something like what
follows:
If /path/to/X.num is the name of your *.num file, then you can
use m4 to include it in other documents using the command
m4_include(/path/to/X.num), or you can issue the command cat
/path/to/X.num to print out the value of the number stored in the file
like so in your Makefile:
@echo "The current value for build count is: " $$(cat /path/to/X.num)
4. How to customise GNU Emacs to hide *.num files
By altering the variable dired-omit-extensions and
completion-ignored-extensions you can hide the *.num files
from being visible in Emacs' directory editor, dired and from
showing up using TAB file completion. Here are the values for
dired-omit-extensions and completion-ignored-extensions that
work for my version of Emacs: