[prev in list] [next in list] [prev in thread] [next in thread] 

List:       dropbear
Subject:    Re: [RFC 00] Makefile dependencies and `#if' conversion
From:       Michael Witten <mfwitten () gmail ! com>
Date:       2017-08-02 20:38:23
Message-ID: 3a9e751a9b3740fe8e37023ec0de3352-mfwitten () gmail ! com
[Download RAW message or body]

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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic