The M, N, and S modifiers use regular expressions to match macro elements. The regular expression is matched against each macro element individually. For the following examples, assume the following macro definitions:
SRCS |
= main.c sub.cpp io.cpp |
CFLAGS |
= -AX -Ifoo -Ibar /Ibaz -DX=-IT xI.c yi.c |
To select files whose names include .c:
$(SRCS,M.c) is main.c sub.cpp
To select files that end in .c, anchor the search to the end with the regular expression character $. To get $ to the regular expression, use $$ in the makefile:
$(SRCS,M.c$$) is main.c
The ^ regular expression character anchors the search to the front of the macro element:
$(CFLAGS,M-I) is -Ifoo -Ibar -DX=-IT
$(CFLAGS,M^-I) is -Ifoo -Ibar
The [set] regular expression characters indicate a set of characters, where set can be single characters ([aA@] matches a, A, or @), a range of characters ([a-z] matches a through z), or a mixture. For example:
$(CFLAGS,M^[-/]I) is -Ifoo -Ibar /Ibaz
One powerful feature of regular expressions is that when they are used in substitutions, they can access the matched parts of the string. The S/rfrom/rto/ (substitution) modifier uses regular expression rfrom to substitute the matched part of an element with the rto regular expression. For example, when DIR = NT_L
, the expression $(DIR,S/\(wild*\)_wild*/\1/)
is NT
The \( \) pair surround part of the regular expression that can be referenced later. Inside the pair is wild*, which matches any character repeated zero or more times. Taken together, they mean instruct omake to match any character, zero or more times, and tag it. The rest of the regular expression is _, which matches _ and wild*, which matches any character repeated zero or more times.
The substitution replaces the matched part of the element with the expression \1, which is the stuff matched in the first pair of \( \). The entire element was matched, so the substitution produces NT
. Table 30 shows other expressions.
Expression | Result |
---|---|
$(DIR,S/wild*_\(wild*\)/\1/) |
|
$(DIR,S/wild*_\(wild*\)/&/) |
|
$(DIR,S/\(wild*\)_ /\1/) |
|
$(DIR,S/_ //) |
|
$(DIR,S/does not match/xyzzy/) |
|
Feedback on the documentation in this site? We welcome any comments!
Copyright © 2001 by Rational Software Corporation. All rights reserved. |