make m4 see macro when macro ends with same character as string following macro

StackOverflow https://stackoverflow.com/questions/6814117

  •  25-10-2019
  •  | 
  •  

Question

I'm working on a system that uses M4 to expand some files out, but I'm getting a problem with the expansion in certain cases. The convention for definition / macro naming (which I'd rather not change if possible) is __<name>__ (i.e. double leading and trailing underscores.) So this expands correctly:

define(`__ROOT__', `/home/mydir')
...
__ROOT__/bin

gives

/home/mydir/bin

but,

define(`__PREFIX__', `App_Mnemonic')
...
__PREFIX___some_service

should give:

App_Mnemonic_some_service

but gives

__PREFIX___some_service

(i.e. it missed the expansion)

I presume the lack of space between the trailing underscore of the macro and the valid underscore of the underlying text is confusing m4. Is there anything I can do about this? Can I delimit the macro with silent braces, for example, like enviromnment variables?

Was it helpful?

Solution

Deceptively simple really, all I had to do in the underlying text was change this:

__PREFIX___some_service

for this:

__PREFIX__()_some_service

It looks a bit clunky perhaps, but it is a macro after all and there's no need to change the macro definition. So this can stay as it is:

define(`__PREFIX__', `App_Mnemonic')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top