Unfortunately, in some old FreeBSD environments I can't use "gmake", so I need to write a Makefile which will work with FreeBSD make also. And the last problem I can't solve - use shell commands, for example, I need to get full path to Python executable:

PYTHON       := $(shell which python2.7 || which python)

But FreeBSD make simply ignores this.

     echo == $(PYTHON) ==

Then I run make test:

$ make test
echo ==  ==
== ==

Can anyone help, please?

Update #1: To those who can't read closely and accidentally downvotes the question:

Whole test script:

PYTHON       != which python2.7 || which python

        $(PYTHON) -c 'print "hello world"'

Run on FreeBSD:

/usr/bin/python -c 'print "hello world"'
hello world

Run on CentOS:

test_make:1: *** missing separator.  Stop.

And if I use command $(shell ...) it works on CentOS and doesn't work on FreeBSD. So, is there any solution without gmake?

Update #2: Eventually I found solution (put command in backticks):

PYTHON       ?= `which python2.7 || which python`

I don't know why it prints itself:

`which python2.7 || which python` -c 'print "hello world"'
hello world

But it works! You can use it, guys :)

  • Can't you just set PYTHON to the correct Python path outside of the Makefile? Also, the use of which is superfluous; if python can be found in the PATH, then just use python (or python2.7). Having the absolute path is usually not needed. – Kusalananda Sep 19 '18 at 7:32

You may be able to do:

PYTHON != which python2.7 || which python

This works in gnu make 4.1 and bmake 20160220-2+b1

But why bother? It's honestly probably less trouble to install gnu make and use it, or to write a configure script that generates the Makefile for you with PYTHON properly defined.

  • It work only on FreeBSD, on Centos it returns error: Makefile:15: *** missing separator. Stop 15 - number of that string – Sergius Sep 18 '18 at 16:07
  • @Sergius what is your complete Makefile? I can't see line 15. – uzsolt Sep 18 '18 at 18:26
  • I said that number 15 - string with line suggested in the answer. Also, I can't share whole Makefile, but I will share test file. – Sergius Sep 19 '18 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.