Hardwired
Hardwired

Reputation: 834

Makefile compile single file using Python

I'm migrating from Pythone 2.x to 3.x. And I'm trying to compile single file in Makefile using Python:

From the Makefile:

mySuperFile.c :  $(ROOT)/lib/mySuperFileGenerate $(FILES_DIR) $(REPO_STATE_FILE)
$(ROOT)/lib/mySuperFileGenerate --out-dir=$(OUT_DIR) --repo=$(ROOT) --output=mySuperFile.c

Where mySuperFileGenerate is the Python script, that says to use global python version, which is 2.x.x and does not satisfy me:

!/usr/bin/env python

That's why I want to call Python version explicitly, like this (added ${PYTHON373} variable before script):

mySuperFile.c : ${PYTHON373} $(ROOT)/lib/mySuperFileGenerate $(FILES_DIR) $(REPO_STATE_FILE)
     $(ROOT)/lib/mySuperFileGenerate --out-dir=$(OUT_DIR) --repo=$(ROOT) --output=mySuperFile.c

But it does not work at all. It still calls the version from environment - 2.x.

So my question is:

How to specify which Python to use exactly in Makefile? (Not changing environment). Is it possible?

Upvotes: 0

Views: 98

Answers (1)

MadScientist
MadScientist

Reputation: 100781

The first line in your rule describes the prerequisites of the target. It doesn't describe how to run the target. All adding ${PYTHON373} to that line does is say that if that file changes, the target should be rebuilt.

The second line (indented by a TAB) in your rule shows how to run the command. If you want to run the command using a different Python interpreter you have to add it to the command to be run:

mySuperFile.c : ${PYTHON373} $(ROOT)/lib/mySuperFileGenerate $(FILES_DIR) $(REPO_STATE_FILE)
         $(PYTHON373) $(ROOT)/lib/mySuperFileGenerate --out-dir=$(OUT_DIR) --repo=$(ROOT) --output=mySuperFile.c

Upvotes: 2

Related Questions