macrosrpmrpmbuildrpm-spec

Give RPM macro an argument with spaces


Example RPM macro:

%define hello() \
    printf 'hello, %{1}.\\n';

I would like to be able to give it macros with spaces in it, as in:

%{hello "Dak Tyson"}

->

printf 'hello, Dak Tyson.\n'

However, it keeps doing this:

%{hello "Dak Tyson"}

->

printf 'hello, "Dak.\n'

In other words, it doesn't interpret the double quotes, but uses them as-is.

Single quotes don't work either:

%{hello 'Dak Tyson'}

->

printf 'hello, 'Dak\.\n'

Nor backslashes:

%{hello Dak\ Tyson}

->

printf 'hello, Dak\.\n'

Nor braces:

%{hello {Dak Tyson}}

->

printf 'hello, {Dak.\n'

Is there any way to give an RPM macro arguments with spaces?


Solution

  • I trawled through the RPM API C code having to do with macro expansion. I found a loop in there which uses spaces to parse out the arguments and (I think) there is no way around this loop. I don't think you can give arguments with spaces.

    I did find that macro arguments are safe, though.

    My .rpmmacros file:

    %hello() '%{1}'
    %name Dak Tyson
    

    With the above macros defined, This command:

    rpm --eval '%{hello %{name}}'
    

    yields:

    'Dak Tyson'
    

    So that if I really needed spaces in my macros definitions, I can define them as macros first.

    I also found, incidentally, that nested parameterized macros don't work.

    This command:

    rpm --eval '%{hello %{hello name}}'
    

    yields:

    error: Unterminated {: {hello
      2<     (empty)
      1<   (empty)
      0< '
    '