0

I have a shell script with some variables w/ variable expansions:

$ cat version
#!/bin/bash
export GIT_TAG=`git describe --tags --always --dirty`
export BUILD_NUM=${TRAVIS_BUILD_NUMBER:-${GIT_TAG}}
export VERSION="0.1.${BUILD_NUM}"

Then I'm trying to import the variables into a Makefile:

$ cat Makefile
MAKEFLAGS += --warn-undefined-variables
include version
all:
    @echo $(VERSION)

However it seems variable expansion isn't working:

$ make
Makefile:5: warning: undefined variable `TRAVIS_BUILD_NUMBER:-`git describe --tags --always --dirty`'
version:16: warning: undefined variable `TRAVIS_BUILD_NUMBER:-`git describe --tags --always --dirty`'
version:13: warning: undefined variable `TRAVIS_BUILD_NUMBER:-`git describe --tags --always --dirty`'
0.1.

Any suggestions?

jersey bean
  • 3,321
  • 4
  • 28
  • 43
  • 1
    The `include` file should be a makefile, not a shell script. – Barmar Jun 10 '22 at 22:11
  • There's a lot written about importing .env files, shell scripts, etc..., in addition to other Makefiles. And it does work if I don't use variable expansion. Its only when I start using variable expansion that I'm hitting issues like this. – jersey bean Jun 10 '22 at 22:14
  • 2
    The [documentation](https://www.gnu.org/software/make/manual/html_node/Include.html) says **The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing.** It's only able to read the file because `export` is also a `make` command. But make doesn't understand `${TRAVIS_BUILD_NUMBER:-${GIT_TAG}}` as a parameter expansion operation, that's a bash feature. – Barmar Jun 10 '22 at 22:18
  • @jerseybean try adding other bash commands (i.e. `echo $VERSION`) to the bash script and you will see how it doesn't work – Diego Torres Milano Jun 10 '22 at 22:22
  • @DiegoTorresMilano oic.. thx for pointing out – jersey bean Jun 10 '22 at 22:23
  • @Barmar so I guess your right. thx for the response. – jersey bean Jun 10 '22 at 22:24

0 Answers0