help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MAKECMDGOALS and spaces


From: Kaz Kylheku (gmake)
Subject: Re: MAKECMDGOALS and spaces
Date: Sat, 13 Feb 2021 15:37:29 -0800
User-agent: Roundcube Webmail/0.9.2

On 2021-02-13 13:13, Christof Warlich wrote:
Kaz Kylheku wrote:

I think to make use of this, you need to define a target that has
a space. It seems this is possible as follows


  hi\ ho:
  [tab]echo yes

Then make "hi ho" runs the recipe and "yes" is echoed.

In order to do this with a generated rule from $(MAKECMDGOALS),
you would need some way to do the expansion such that the
spaces are similarly escaped.

The problem is that replacing every space with an escaped space only
works as long as MAKECMDGOALS consists of one goal only: If more goals
are given on the command line, their separating space would be replaced
as well, as the distinction between target separating spaces and
in-target spaces obviously get lost in MAKECMDGOALS.

Thus, I'm pretty sure that there is no generic way to do what I was
asking for, but I just want to double-check in case I'm missing something.

The problem is that the value of a GNU Make variable is just a "char *" string.

When main.c adds targets to the MAKECMDGOALS variable, it's just this:

      {
        /* Add this target name to the MAKECMDGOALS variable. */
        struct variable *gv;
        const char *value;

        gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
        if (gv == 0)
          value = f->name;
        else
          {
            /* Paste the old and new values together */
            size_t oldlen, newlen;
            char *vp;

            oldlen = strlen (gv->value);
            newlen = strlen (f->name);
            vp = alloca (oldlen + 1 + newlen + 1);
            memcpy (vp, gv->value, oldlen);
            vp[oldlen] = ' ';
            memcpy (&vp[oldlen + 1], f->name, newlen + 1);
            value = vp;
          }
        define_variable_cname ("MAKECMDGOALS", value, o_default, 0);
      }
    }


"Add a space followed by the datum to a stack-allocated copy of the variable,
then install the result as a replacement of the variable."

MAKECMDGOALS does not have the information required to recover targets
with spaces.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]