bugmake - Bugs: bug #63172, Using --just-print, -n on a target...

 
 

bug #63172: Using --just-print, -n on a target that uses a multiline macro function will print as a single line

Submitter:  None
Submitted:  Thu 06 Oct 2022 04:49:00 PM UTC
   
 
Severity:  3 - Normal Item Group:  None
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  None Operating System:  None
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 09 Oct 2022 06:06:29 PM UTC, comment #1: 

This behavior is expected, because make processes recipes like this: first the make variables and functions are expanded, then the results are printed to the screen, then the command is invoked.

In your example, the handling of the backslash/newlines is done during the expansion of the call function (just like any other expansion).  So by the time make gets around to the second step, printing the command, they have already been removed.

You can play a trick, if you know that this function will only be used inside a recipe, and "hide" the backslash so it's not considered a backslash-newline and removed during the first step:


x =
define test_function
        echo $(1) \$x
                $(2) \$x
                $(3)
endef


Now the first step will not consider that an escaped newline and won't remove the backslash, but the "$x" expands to the empty string so after expansion it IS a backslash-newline.  Now when make gets to the second step the backslash is still there, then it's removed by the shell:


$ make
echo 1 \
        2 \
        3
1 2 3


Paul D. Smith <psmith>
Group administrator
Thu 06 Oct 2022 04:49:00 PM UTC, original submission:  

Hi.

I noticed that if I have the following Makefile

```
define test_function
echo $(1) \
$(2) \
$(3)
endef

.PHONY: test_function
test_function:
$(call test_function,1,2,3)

.PHONY: test
test:
echo 1 \
2 \
3
```

If I run `make test -n`, I will get my expected multiline human readable output

```
✗ make test -n
echo 1 \
2 \
3
```

If I run `make test_function -n`, all of the commands will be

```
✗ make test_function -n
echo 1 2 3
```

People have found some odd workarounds

https://stackoverflow.com/questions/47228973/how-to-properly-escape-recipe-newlines-in-multi-line-variable


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-09 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code