0

At a BASH prompt, I can do the following:

~/repo$ HISTORY_LOG=$(git log $(get_old_version)..$(get_new_version)); [[ ! -z ${HISTOR_LOG} ]] && ( echo "Some header"; echo "${HISTORY_LOG}" )

Where git log is demonstrably simplified version of what I actually have.

In a make file I have the following command as part of a target:

$(OUTPUT): $(INPUT)
        ...
        echo "Some header" > $(LOG_FILE)
        git log $(shell get_old_version)..$(shell get_new_version) >> $(LOG_FILE)

How can I rewrite the make target to behave like the bash command?

If I do the following line-feeds are being stripped:

$(OUTPUT): $(INPUT)
        ...
        HISTORY_LOG="$(shell git log $(shell get_old_version)..$(shell get_new_version))" ; \
           [ -z "$${HISTORY_LOG}" ] && \
             true || \ 
             (echo "Some header" ; echo "$${HISTORY_LOG}" )

when run looks like:

~/repo $ make
commit 2b4d87b0e64d129028c1a7a0b46ccde2f42c5e93     Author: Jamie   <[email protected]>   Date:   Mon Jun 25 18:46:27 2012 -0400              Issue #468: This sucker's been sped up.

and what I prefer would be:

~/repo $ make
commit 2b4d87b0e64d129028c1a7a0b46ccde2f42c5e93     
Author: Jamie   <[email protected]>
Date:   Mon Jun 25 18:46:27 2012 -0400 

    Issue #468: This sucker's been sped up.

I think the issue is the that make executes commands in /bin/sh and not /bin/bash. Regardless I'm looking for a portable solution if there is one.

3
  • Is there some reason you want to assign the output to a variable? Note that the variable passes out of scope at the end of the command. Commented Jul 3, 2012 at 17:41
  • Because I want to add a preamble only if the output is non-empty. The command generating the output is a bit unwieldy, I don't want to put it in the make file twice. And the fact the variable passes out of scope at the end of the command is desirable. An edit shows the a header is also printed if the output is non-empty. Commented Jul 3, 2012 at 17:47
  • GNUMake allows you to choose the shell, but not being a shell expert I'd probably just store the output in a temporary file. Commented Jul 3, 2012 at 17:55

1 Answer 1

5

Make's shell is eating your newlines. Just stop using it. Instead of $( shell get_old_version ), escape the $:

$$( get_old_version )
Sign up to request clarification or add additional context in comments.

1 Comment

The escaping idea worked; but the spot you picked wasn't the culprit it was the $(shell git log ...) that needed the $$(git log ...) treatment. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.