Karl
Karl

Reputation: 3113

How can default env variable in gnu makefile target

I want to do something like this

test.install:
        export BUILD_NUMBER=${BUILD_NUMBER:-$${ANOTHER_VAR}}

but its not working. it always come as blank

EDIT:

This works fine. provided i export BUILD_NUMBER in shell before invoking make command

test.install:
        export BUILD_NUMBER=${BUILD_NUMBER}

THese are not working . They both give blank BUILD_NUMBER

test.install:
        export BUILD_NUMBER=${BUILD_NUMBER:-$${ANOTHER_VAR}}

and

test.install:
        export BUILD_NUMBER=${BUILD_NUMBER:-55}}

Upvotes: 1

Views: 241

Answers (1)

user657267
user657267

Reputation: 21038

If you want to expand variables in bash rather than in the makefile, you'll need to escape the expansion otherwise make is going to look for a variable literally called BUILD_NUMBER:-${ANOTHER_VAR} or BUILD_NUMBER:-55

test.install:
        export BUILD_NUMBER=$${BUILD_NUMBER:-$${ANOTHER_VAR}}

test.install:
        export BUILD_NUMBER=$${BUILD_NUMBER:-55}}

Upvotes: 3

Related Questions