Remove whitespace from the output of foreach

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove whitespace from the output of foreach

Rakesh Sharma-6

Hello Makers,

I have a niggling query regarding how to remove the spaces from the output of a foreach command in GNU Make.

I have this code:

###### begin make file ###
SHELL := /bin/sh
empty :=
sp ;= $(empty) $(empty)
k0 := $(empty)
k1 := x
k2 := $(k1) x
k3 := $(k2) x
k4 := $(k3) x
k5 := $(k4) x
k6 := $(k5) x
k7 := $(k6) x
k8 := $(k7) x
k9 := $(k8) x

# $(call replicate,char,kount)
replicate = $(subst $(sp),$(empty),$(foreach i,$(k$(2)),$1))

nop:
    @echo "[$(call replicate,*,4)]";
############################## end of make file

Output is:
[* * * *]


As we can see the spaces are intact & should have been deleted by the subst function but for some reason weren't.

How can I fix this anomaly?

I am using GNU Make 3.81.
Cygwin Platform


Thanks in advance,
Rakesh

     
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Remove whitespace from the output of foreach

Paul Smith-20
On Thu, 2012-10-18 at 21:32 -0700, Rakesh Sharma wrote:
> sp ;= $(empty) $(empty)

Change this to ":=" instead of ";=" and it will work.



_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Remove whitespace from the output of foreach

Reinier Post
On Fri Oct 19 01:33:13 2012, [hidden email] (Paul Smith) wrote:
> On Thu, 2012-10-18 at 21:32 -0700, Rakesh Sharma wrote:
> > sp ;= $(empty) $(empty)
>
> Change this to ":=" instead of ";=" and it will work.

A lint for make would be nice ...

--
Reinier Post

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Remove whitespace from the output of foreach

Paul Smith-20
On Fri, 2012-10-19 at 09:49 +0200, Reinier Post wrote:
> On Fri Oct 19 01:33:13 2012, [hidden email] (Paul Smith) wrote:
> > On Thu, 2012-10-18 at 21:32 -0700, Rakesh Sharma wrote:
> > > sp ;= $(empty) $(empty)
> >
> > Change this to ":=" instead of ";=" and it will work.
>
> A lint for make would be nice ...

Yes, it would.

However in this particular case all it would have taken is using a newer
version of make than 3.81.  make 3.82 was released 2 years ago, and it
doesn't allow whitespace in variable names.  So the mistake above would
have been flagged as a syntax error:

        Makefile:3: *** missing separator.  Stop.




_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Remove whitespace from the output of foreach

Martin d'Anjou-5
In reply to this post by Reinier Post
Syntax highlighting helps too in this case. I use vim.

Martin

On 2012-10-19, at 08:50, Reinier Post <[hidden email]> wrote:

> On Fri Oct 19 01:33:13 2012, [hidden email] (Paul Smith) wrote:
>> On Thu, 2012-10-18 at 21:32 -0700, Rakesh Sharma wrote:
>>> sp ;= $(empty) $(empty)
>>
>> Change this to ":=" instead of ";=" and it will work.
>
> A lint for make would be nice ...
>
> --
> Reinier Post
>
> _______________________________________________
> Help-make mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-make

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make