Reputation: 51
It is very well possible to run a python script from rule embedded inside a target in makefile (in order to do post processing on output of mkaefile components). But is it possible to return some vales from python script back to makefile and assign it to some varibale inside the makefile.
So i thought it can be done by two ways: Process 1: 1. Call the python script from makefile 2. Allow python script to store the output in some known file 3. Read the value from makefile and assign it to variable inside it
I have tried this approach and have been able to do Step1 and Step2 but unable to do step 3.
Process 2: 1. Call the python script from makefile 2. Let the python script return some value which gets assigned to a variable inside makefile
I couldn't try it because i couldn't find any examples to do it
----------------- makefile----------------
help: detect_term_type
file := term_type
TERM_TYPE := $(cat ${file})
detect_term_type:
python configure_things.py
-------configure_things.py-----
import platform
class TerminalType:
def __init__(self):
self.find_terminal_name()
def find_terminal_name(self):
f= open("term_type","w+")
f.write(platform.system())
f.write('\n')
f.close()
I wish to assign the output of python script which may be 'Linux' or 'Cygwin' to the makefile variable TERM_TYPE.
Upvotes: 3
Views: 5511
Reputation: 109
Use the following in a rule of makefile to re assign the value to variables. In this case TERM_TYPE is reassigned with the value stored in file 'term_type'(file name where python stores the output).
run_python:
@python configure_things.py
detect_term_type:run_python
$(info xyz)
$(eval TERM_TYPE=$(shell cat term_type|head -1))
$(info $(TERM_TYPE))
Upvotes: -1
Reputation: 180113
It is very well possible to run a python script from rule embedded inside a target in makefile (in order to do post processing on output of mkaefile components). But is it possible to return some vales from python script back to makefile and assign it to some varibale inside the makefile.
The POSIX specifications for make
do not define any capability that would serve this purpose. If you happen to be relying specifically on GNU make
, however, it has a $(shell)
function that serves the purpose:
TERM_TYPE := $(shell python figure_it_out.py)
You cannot in any case do this by building a file and then reading it back, because variables get their values before anything is built.
Upvotes: 2