Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile : contains string

A variable returns MINGW32_NT-5.1 or CYGWIN_NT-5.1. (yea, dot at the end)

Need to compare that given var contains NT-5.1 positioned anywhere.

Using cygwin and would like to be compatible with pretty much any *nix.

like image 600
Pablo Avatar asked Apr 30 '10 00:04

Pablo


People also ask

How do I use Ifdef in Makefile?

The ifdef directive begins the conditional, and specifies the condition. It contains single argument. If the given argument is true then condition becomes true. The ifndef directive begins the conditional, and specifies the condition.

What is IFEQ in Makefile?

The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.

What is strip in Makefile?

$(strip string ) Removes leading and trailing whitespace from string and replaces each internal sequence of one or more whitespace characters with a single space. Thus, ' $(strip a b c ) ' results in ' a b c '. The function strip can be very useful when used in conjunction with conditionals.


2 Answers

The findstring function is what your heart desires:

$(findstring find,in) 

Searches in for an occurrence of find. If it occurs, the value is find; otherwise, the value is empty. You can use this function in a conditional to test for the presence of a specific substring in a given string. Thus, the two examples,

$(findstring a,a b c) $(findstring a,b c) 

produce the values "a" and "" (the empty string), respectively. See Testing Flags, for a practical application of findstring.

Something like:

ifneq (,$(findstring NT-5.1,$(VARIABLE)))     # Found else     # Not found endif 

What is the comma here for ifneq (,$(...?

Parse it as ifneq(A,B) where A is the empty string and B is $(findstring...). It looks odd because you don't quote strings in Makefiles.

like image 103
John Kugelman Avatar answered Sep 30 '22 04:09

John Kugelman


VARIABLE=NT-5.1_Can_be_any_string ifeq ($(findstring NT-5.1,$(VARIABLE)),NT-5.1)     # Found     RESULT=found else     # Not found     RESULT=notfound endif  all:     @echo "RESULT=${RESULT} , output=$(findstring NT-5.1,$(VARIABLE))" 

It matches the given string and returns

like image 30
vimjet Avatar answered Sep 30 '22 04:09

vimjet