0

I have this code inside Makefile

SHELL=/bin/bash

define PYTHON_VERSION
3.7.4
endef

define DEFAULT
echo BUILD_ENV:

  if [ -z "$(PYTHON_VERSION)" ]
  then
    printf '$(PYTHON_VERSION) is empty.\n'
    exit 1
  fi
endef

default:
    $(DEFAULT)

build:
    $(DEFAULT)

It gives me (running make build):

echo BUILD_ENV: BUILD_ENV: if [ -z "3.7.4" ] then printf '3.7.4 is empty.\n' exit 1 /bin/bash: -c: line 1: syntax error: unexpected end of file

How to fix this error? (it happens on macOs BigSur)

techkuz
  • 3,608
  • 5
  • 34
  • 62
  • Is your code supposed to be a bash script, or a Makefile? – Shane Bishop Jan 26 '21 at 17:14
  • @ShaneBishop this code is inside Makefile and I run it with `make build` – techkuz Jan 26 '21 at 17:14
  • Why do you have a colon at the end of `echo BUILD_ENV:`? – Shane Bishop Jan 26 '21 at 17:16
  • @ShaneBishop I am trying to use legacy code, but deleting the : doesn't help anyway – techkuz Jan 26 '21 at 17:16
  • Same problem as the issue marked as dup – MadScientist Jan 26 '21 at 18:15
  • (note, just sticking something inside a variable doesn't free you from the responsibility of making it into one logical line) – MadScientist Jan 26 '21 at 18:15
  • @MadScientist I checked and code works on my ubuntu but not on macos – techkuz Jan 27 '21 at 01:29
  • @MadScientist I resolved the issue. It was because my gnu version was outdated. Could you vote to reopen? I want to add answer and resolve the question. It is not duplicate as here the issue is in the GNU make version – techkuz Jan 27 '21 at 06:07
  • 1
    There is no version of GNU make where your makefile shown above will work. You _must_ modify your `define`d value to contain appropriate semicolons and backslashes so that they become a single logical line, as described in the duplicate. That's true for all versions of GNU make. – MadScientist Jan 27 '21 at 13:54

0 Answers0