Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile 'if' condition with regexp

Tags:

regex

makefile

I need to do something like this:

case `uname -m` in
i?86) echo "CFLAGS += -march=i486 -mtune=native" > configparms ;;
esac

But I need to do this in makefile for a particular target. I have not found a method to make an if condition with a regular expression.

I tried this:

ifeq ($(shell uname -m), i*86)

But it does not work. Even

ifeq ($(shell uname -m), i686)

does not work.

like image 255
Kron Avatar asked Jul 04 '12 11:07

Kron


1 Answers

Using Makefile built-in conditionals (as opposite of Ωmega's Bash solution)

ifeq ($(shell uname -m | egrep "i.86"),) # empty result from egrep
    @echo "No match"
else
    @echo "Match"
endif

See here using this approach to validate a Git tag https://gist.github.com/jesugmz/a155b4a6686c4172048fabc6836c59e1.

like image 141
jesugmz Avatar answered Sep 19 '22 20:09

jesugmz