[RFC 00] Makefile dependencies and `#if' conversion
Michael Witten
mfwitten at gmail.com
Thu Aug 3 04:38:23 AWST 2017
On Wed, 02 Aug 2017 00:25:21 -0000, Michael Witten wrote:
> While you're at it, you can ensure that there really is no more usage
> of `#ifdef/#ifndef' when handling an option; this is a nifty little
> exercise that employs the new `make show-options' capability:
>
> $ export GIT_WORK_TREE="$srcdir" # So we can use `git grep' out-of-tree
> $ o=/tmp/options.$$.txt; make PAGER="cat >$o" show-options && cat "$o" |
> {
> ((i=0))
> while read option _; do
> printf .; ((++i == 54)) && { ((i=0)); echo; }
> git grep -l -P "#if[n]def\\s+\\b$option\\b" |
> grep -q -v sysoptions &&
> printf '\n%s\n' Failure: "$option"
> done || printf '\n%s\n' Success\!
> }; rm -f "$o"
> ......................................................
> ......................................................
> .....................................................
> Success!
Woops! There always seems to be something that I need to revise.
* The regular expression for finding `#if[n]def' conditionals is wrong;
I suspect you can see what I was thinking when I wrote that...
* The handling of the Failure/Success messages is broken.
Here is a version that not only works correctly (I think...), but also
ensures that every relevant option has a non-empty value:
print_dot() { printf .; ((++i == 54)) && { ((i=0)); echo; }; }
failure() { printf '\n%s: %s\n' "$1" "$option"; ((found=1)); }
neither_ifdef_nor_ifndef_is_used()
{
! git grep -l -P "#ifn?def\\s+\\b$option\\b" |
grep -q -v sysoptions
}
o=/tmp/options.$$.txt; make PAGER="cat >$o" show-options && cat "$o" |
{
((i=0))
((found=0))
while read option value; do
print_dot
[ "$option" != LTM_DESC ] || continue
[ -n "$value" ] || failure 'Empty value'
neither_ifdef_nor_ifndef_is_used || failure 'if[n]def'
done; echo
((found)) || echo Success\!
}; rm -f "$o"
Of course, you'll note that `LTM_DESC' must be ignored; that suggests
it should be defined elswhere. (Remove that test to see what happens
when the script fails. Go on! Try it!)
Sincerely,
Michael Witten
More information about the Dropbear
mailing list