Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use grep in a GNU make if-statement

First: I’m pretty new to linux and I’m already sorry for asking a probably dumb question.
I have a makefile that compiles a latex text into a pdf. That creates a logfile and I have to search for a string in that log file and compile again if the string is in the log-file.
So everything works fine until to the point of my if-statement.
I’m trying to check for the sub-string with the grep command but dont get it to work.
In my solution the if statement is executed even if the substring is not in my logfile.

GREP_FINDINGS := $(shell grep 'undefhrined' linux-20.log)

all: clean linux-20.pdf
ifeq ($(GREP_FINDINGS),)
    pdflatex linux-20
endif

linux-20.pdf:
    pdflatex linux-20
    bibtex linux-20
    pdflatex linux-20
    
.PHONY: clean
    
clean:
    echo Cleaning .aux .bbl .blg .log files
    -rm -f *.aux *.bbl *.blg *.log *.pdf
    echo Cleaning complete.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Some parts of this question make me uneasy (such as something being undefined after the first pass but all square after the second — or third?), but if what you’re asking for is actually what you want, then I’d put the conditional inside the rule:

linux-20.pdf:
    pdflatex linux-20
    bibtex linux-20
    pdflatex linux-20
    !(grep undefined linux-20.log) || pdflatex linux-20
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading