Search code examples
preprocessorm4

m4 does not obey expansion?


I use m4 for a little text preprocessing here, and it behaves in a way I don't understand.

This is the portion in question:

ifdef(`TEST',
    define(`O_EXT', `.obj'),
    define(`O_EXT', `.o'))

This macro will always be expanded to .o, regardless whether TEST is defined (m4 -DTEST) or not.

What am I doing wrong?


Solution

  • You're not quoting the other arguments to ifdef. Try this:

    ifdef(`TEST', `define(`O_EXT', `.obj')', `define(`O_EXT', `.o')')