1

I have the following line in the Makefile of a software I'm working with:

VERSION = $(subst $(space),.,$(wordlist 1,2,$(subst ., ,$(patsubst v%,%,$(shell cat VERSION)))))

Where VERSION is a file containing the exact version of the software (f.e 3.12.3)

I'm not such an expert in Makefiles but this line should return the major version (without the v indicating TAG), in this case, 3.12. And it does, or, at least, it does it when you run it with GNU make <= 4.2

I've recently updated to make 4.3 (because I use a rolling release, Arch Linux) and then executing the same line in my makefile, I got 3 12. instead of 3.12

I've been reading Make changelog in order to check if there is any change in something related to the line in charge of retrieving the major version but I can't find where the problem is.

I've confirmed that the problem appears only with GNU make 4.3 (it works with make 4.2) and I'm wondering if there is a bug or I am missing something.

Maybe someone could help me.

Best regards

spotHound
  • 320
  • 2
  • 15
  • 1
    Can you provide a complete makefile? How is `space` defined? – G.M. May 10 '20 at 18:43
  • Oh. You're absolutely right, I didn't notice that I've defined space as: ``` space = space += ``` And the behaviour of `+=` on empty variables changed! – spotHound May 10 '20 at 19:18

2 Answers2

1

As G.M. mentioned, it all depends on how you've defined space, which you haven't shown us.

It worked for me using the "normal" way of defining space, with GNU make 4.3:

E =
space = $E $E
VERSION = $(subst $(space),.,$(wordlist 1,2,$(subst ., ,$(patsubst v%,%,$(shell cat VERSION)))))

$(info VERSION='$(VERSION)')

Then:

$ cat VERSION
v3.12.3

$ make --version
GNU Make 4.3
 ...

$ make
VERSION='3.12'
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Hello! You're right, I didn't noticed I had defined space using a `+=` into an empty var... and this have changed in this new version! – spotHound May 10 '20 at 19:19
1

As MadScientist and G.M mentioned, the problem was in the definition of space. I dind't noticed it was defined as

space =
space +=

and, according to Makefile 4.3 change log:

* WARNING: Backward-incompatibility!
  Previously appending using '+=' to an empty variable would result in a value
  starting with a space.  Now the initial space is only added if the variable
  already contains some value.  Similarly, appending an empty string does not
  add a trailing space.

The expected behavior for += to an empty variable has changed... so here is the problem!

Thank you very much!

spotHound
  • 320
  • 2
  • 15