bug-make
[Top][All Lists]
Advanced

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

[bug #47913] newlines lost with $(foreach)


From: Paul D. Smith
Subject: [bug #47913] newlines lost with $(foreach)
Date: Sun, 15 May 2016 15:45:30 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0

Update of bug #47913 (project make):

                  Status:                    None => Not A Bug              
             Open/Closed:                    Open => Closed                 

    _______________________________________________________

Follow-up Comment #2:

I'm having a hard time understanding what you're doing, not least because
there are apparently arbitrary newlines added to your examples :).  Also, I
assume the output you expect to get from the operation below would be:


File.cpp: /my/dir/here/File.h
Other.cpp: /my/dir/here/Other.h


However, that's not what you actually get.  What you get (with prior versions
of GNU make) is:


/my/dir/here/File.cpp: /my/dir/here/File.h
Other.cpp: /my/dir/here/Other.h


If you change the makefile to show the deps in the loop you'll see what's
happening:


$ cat Makefile
define FILEDEPS
File.cpp: File.h
Other.cpp: Other.h
endef

here = here

ifdef FILEDEPS
$(foreach dep,$(FILEDEPS),$(info dep = '$(dep)'))
endif

all:;@:

$ make
dep = 'File.cpp:'
dep = 'File.h
Other.cpp:'
dep = 'Other.h'


So you can see why you get the output you do: there are actually only three
"words" in the FILEDEPS variable, not four, because the newline is not
considered to be a word-separating character in this context.  Which is sort
of bogus (IMO).  Your setup is somewhat rickety anyway: if you have any
whitespace at the end of a line, for example, it will break (even in the old
version of GNU make).

The change you're running into isn't directly related to bug #46995.  As
above, previously make had a kind of schizophrenic attitude towards newlines:
sometimes they were treated as word-separating and sometimes they were not
treated as word-separating.  I made a change to sanitize this, so that make
treats newlines as word-separating whitespace in virtually all situations,
which is why you're seeing this; if you run the above makefile using make
4.1.90 you get:


dep = 'File.cpp:'
dep = 'File.h'
dep = 'Other.cpp:'
dep = 'Other.h'


This is much more clean, and IMO correct, but it does break your usage.  To
work around it, you can use subst to replace newlines with some other
character that you're sure will never appear in your FILEDEPS, then convert it
back again, like this:


$ cat Makefile
# create a variable containing exactly one newline
# (requires 2 newlines since make strips the last one)
define N


endef

define FILEDEPS
File.cpp: File.h
Other.cpp: Other.h
endef

here = here

ifdef FILEDEPS
$(foreach dep,$(subst $N,!,$(FILEDEPS)),$(info dep = '$(subst !,$N,$(dep))'))
endif

all:;@:

$ make
dep = 'File.cpp:'
dep = 'File.h
Other.cpp:'
dep = 'Other.h'


which should work equivalently in both old and new versions of GNU make.  If
for some reason this isn't going to work please provide updated details for
why.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?47913>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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