开发者

Makefile and regex match in shell

My makefile is failing to determine the make and version of ld.

A typical version string (I expect) is as follows. I'm looking for (1) GNU ld anchored on the left, (2) a version somewhere in the middle:

$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.20.1-system.20100303

It does not match开发者_如何学C when using an asterisk. Below, the count (from -c) is always 0.

EGREP = egrep
GNU_LD210_OR_LATER = $(shell $(LD) -v 2>&1 | $(EGREP) -i -c "^gnu ld * (2.1[0-9]|2.[2-9])")

If I remove the asterisk and version, I can catch part of what I am looking for:

GNU_LD = $(shell $(LD) -v 2>&1 | $(EGREP) -i -c "^gnu ld")

Later, I go on to use the flags similar to:

ifeq ($(GNU_LD210_OR_LATER),1)
  LDFLAGS +=    -Wl,-z,nodlopen
endif

ifneq ($(GNU_LD212_OR_LATER),0)
  LDFLAGS +=    -Wl,--exclude-libs,ALL
endif

ifneq ($(GNU_LD215_OR_LATER),0)
  LDFLAGS +=    -Wl,-z,relro -Wl,-z,now
endif

Are there any problems with the regex I want to use? Or are there problems with the shell's regex interpreter? (I also realize I should be using \. - omitted for clarity).


Perhaps the regexp is incomplete

Try:

EGREP = egrep
GNU_LD210_OR_LATER = $(shell $(LD) -v 2>&1 | $(EGREP) -i -c '^gnu ld \(.*\) (2.1[0-9]|2.[2-9])')

Note the \(.*\) to match for the brackets.


Found it.... I needed an extra period before the asterisk:

# For -nodlopen, which appeared around 2000 (Binutils 2.10).
# http://sourceware.org/ml/binutils/2011-09/msg00049.html
GNU_LD210_OR_LATER = $(shell $(LD) -v 2>&1 | $(EGREP) -i -c '^gnu ld .* (2\.1[0-9]|2\.[2-9])')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜