2022-12-18

Tools: redo (part 2) Automatic Recording of Dependencies on Header Files

#software

Content

Part 0: Intro

Part 1: Hello, world!

Part 2: Automatic Recording of Dependencies on Header Files

Part 3: CFLAGS and friends, config.sh, compile.do

Part 4: CFLAGS and friends, env/VAR, default.run.do

Part 5: Auto-update BUILDDATE in version.h

Part 6: The yacc/bison problem: one call produces two artifacts

Part 7: Test: Generator for N source files

My code featured in this series can be found at

https://git.sr.ht/~ew/ew.redo/

Part 2: Automatic Recording of Dependencies on Header Files

The dependency tree produced in Part 1 does not record the fact, that hello.o must be rebuild if resources.h has changed. Of course we could add such a dependency in hello.do, however, we are lazy and we want the computer to take care of this. One way of doing this, is to nicely ask the compiler to produce this information. The compiler, or more precicely the preprocessor needs to evaluate all '#include' pragmas anyway, it is in the position to record, what it encountered along its course. Fortunately there are flags to instruct gcc to list the include dependencies:

The output rightfully states, that hello.o needs to be rebuild, if either hello.c or resources.h have changed. The output is formatted in makefile syntax, it can be included as is into a Makefile. In order to make this information known to redo, we are reading the content of the file back into our .do file and call "redo-ifchange" on the part after the colon ':'. The change occurs in "default.o.do" only, and I use shell variable editing to remove the part up to and including the colon.

With this change in place, the build proceeds including the new commands. The explicit dependency is also visible in the output of redo-dot.

In order to explicitly record the dependency to system include files like /usr/include/stdio.h, the flag "-MMD" can be changed to "-MD", if so desired.

Do not forget, to add '*.d' in .gitignore and clean.do.

Home

Proxied content from gemini://ew.srht.site/en/2022/20221218-redo-2.gmi (external content)

Gemini request details:

Original URL
gemini://ew.srht.site/en/2022/20221218-redo-2.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.