Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex in makefile

Tags:

regex

makefile

I am trying to find how to use regular expressions in a makefile, for example:

foo:
ifeq ($(bar),^ver[0-9]+)
     do something
else ($(baz),word)
     do something else
endif

When i type,

foo bar = ver1.1.0 - must do "do something",

foo baz = word - must do "do something else".

This doesn't work. Can someone help me to understand how to resolve my issue?

like image 317
Alexey Nikulin Avatar asked Nov 15 '25 23:11

Alexey Nikulin


1 Answers

Make can't handle regular expressions, so it must delegate that work to the shell:

ZAP := $(shell [[ $(bar) =~ ver[0-9.]+$$ ]] && echo matched)

foo:
ifdef ZAP
    @echo BLUE
else
    @echo GREEN
endif
like image 161
Beta Avatar answered Nov 17 '25 22:11

Beta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!