2022-12-19

Tools: redo (part 3) CFLAGS and friends, config.sh, compile.do

#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 3: How about CFLAGS and friends? config.sh and compile.do

Of course I was wondering, how to deal with our old friends like CFLAGS and their kin. Looking into the documentation and projects using redo, I came up with two possible solutions --- there are more, of course.

config.sh

Our friends the make variables convert to shell variables and are living in a shell script named config.sh

This file is being sourced (evaluated) in order to make their values known before calling gcc. So we change default.o.do accordingly:

Calling redo in verbose mode will show, that config.sh is indeed sourced.

config.sh and compile.do

While this works, it is fairly obvious that "source config.sh" is being run every single time, the commands in default.o.do are executed. And it might not work with every shell or environment, even if source is replaced by a dot '.'.

In order to avoid, that CFLAGS and friends are evaluated more often than absolutely needed, one can produce a compile script from a template. There are variables in the template, and they are expanded to create the script only once per build. The script itself does not have variables any more. So this is the plan:

This is a short, but not a particularly nice script. You must watch the quoting at all times. The output of this script is captured as compile.

So one more change is needed, call the freshly generated script in default.o.do:

Calling redo to build everything from scratch works as expected:

Home

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

Gemini request details:

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

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