E.2 Macro Modifiers in OMAKE

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

Regular Expressions for the M Modifier

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

Regular Expressions for the S Modifier

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.

Table 30 Examples of Regular Expressions


Expression

Result

$(DIR,S/wild*_\(wild*\)/\1/)


L


$(DIR,S/wild*_\(wild*\)/&/)


NT_L


$(DIR,S/\(wild*\)_ /\1/)


NTL


$(DIR,S/_ //)


NTL


$(DIR,S/does not match/xyzzy/)


NT_L