0

In my makefile I implement a simple TODO counter like this

search-todo:
    @echo "${_RED}  --LOOKING FOR TODO ${_END}"
    @grep -I -ri 'todo' $(SRCDIR) | wc -l

It worked fine until I delete my last TODO. So my wc return 0 and make interpret 0 as an error. So I would improve my target "search-todo". My idea is just to return a string like TODO count is XXX

So last night I try a lot of things but none works :

NB_TODO:=$(grep -I -ri 'todo' $(SRCDIR) | wc -l)
search-todo:
    @echo "${_RED}  --LOOKING FOR TODO ${_END}"
    #echo interpret $v (and it's nothing) and display "TODO count is ar"
    var="$(grep -I -ri 'todo' $(SRCDIR) | wc -l)" ; echo "TODO count is $var"
    #echo interpret $(var) with nothing and display "TODO count is"
    var="$(grep -I -ri 'todo' $(SRCDIR) | wc -l)" ; echo "TODO count is $(var)"
    #info display nothing
    $(info grep -I -ri 'todo' $(SRCDIR) | wc -l)
    #echo display "toto  tata"
    echo "toto $(NB_TODO) tata"
    #echo display nothing
    echo $(grep -I -ri 'todo' $(SRCDIR) | wc -l)
    #info display nothing
    $(info $(NB_TODO))
    #return 0
    grep -I -ri 'todo' $(SRCDIR) | wc -l

With all this tests I understand that make can't store result of a command in a var. Or I don't know how to do it.

Any explanation of makefile mechanisms will be appreciated to understand how to store command result (and display it)

zzDiego
  • 37
  • 1
  • 8
  • You either store results into a file OR use .ONESHELL. – Andreas May 18 '22 at 11:05
  • You sure it's wc returning error and not grep? Think grep errors on zero unless passing some argument. – Andreas May 18 '22 at 11:08
  • @Andreas grep return nothing and wc return 0 (cause 0 line), so for me it's make that interpret the 0 (but perhaps I'm wrong – zzDiego May 18 '22 at 12:11
  • 1
    @Andreas my bad it's grep error, I will try a solution like this : https://stackoverflow.com/questions/6550484/prevent-grep-returning-an-error-when-input-doesnt-match/49627999#49627999 (possible duplicate) – zzDiego May 18 '22 at 12:25

0 Answers0