1

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.

test:
     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

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

Run on FreeBSD:

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

Run on CentOS:

make                                 
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:

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

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

1
  • 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
    Commented Sep 19, 2018 at 7:32

1 Answer 1

1

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.

3
  • It work only on FreeBSD, on Centos it returns error: Makefile:15: *** missing separator. Stop 15 - number of that string
    – Sergius
    Commented Sep 18, 2018 at 16:07
  • @Sergius what is your complete Makefile? I can't see line 15.
    – uzsolt
    Commented Sep 18, 2018 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
    Commented Sep 19, 2018 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .