Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionalize a makefile based upon grep results?

Tags:

grep

makefile

I'm looking for a way to bail out of a makefile if a certain string is not found when checking the version of a tool.

The grep expression I'm looking to match is:

dplus -VV | grep 'build date and time: Nov  1 2009 19:31:28'

which returns a matching line if the proper version of dplus is installed.

How do I work a conditional into my makefile based upon this expression?

like image 335
Mike Lewis Avatar asked Dec 09 '09 21:12

Mike Lewis


People also ask

What is* in grep?

* has a special meaning both as a shell globbing character ("wildcard") and as a regular expression metacharacter. You must take both into account, though if you quote your regular expression then you can prevent the shell from treating it specially and ensure that it passes it unchanged to grep .

What is $$ in Makefile?

$$ means be interpreted as a $ by the shell. the $(UNZIP_PATH) gets expanded by make before being interpreted by the shell.

How to search using grep command?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.

How do I display grep results?

To Display Line Numbers with grep MatchesAppend the -n operator to any grep command to show the line numbers. We will search for Phoenix in the current directory, show two lines before and after the matches along with their line numbers.


1 Answers

Here's another way that works in GNU Make:

DPLUSVERSION = $(shell dplus -VV | grep 'build date and time: Nov  1 2009 19:31:28')

target_of_interest: do_things do_things_that_uses_dplus

do_things:
    ...


do_things_that_uses_dplus:
ifeq ($(DPLUSVERSION),)
    $(error proper version of dplus not installed)
endif
    ...

This target can be something real, or just a PHONY target on which the real ones depend.

like image 170
Beta Avatar answered Oct 16 '22 14:10

Beta