I have a requirement where I have to run a python script through a makefile. Python script performs some calculations and return a value. I want to get that value in that makefile variable. How I can do that?
I want something like this:
mymakefile.mke
$output = python process.py
process.py
import os
def main():
value = "01.00.00"
return value
if __name__ == "__main__":
main()
If you want the value in a Make variable, you can do this:
output := $(shell python process.py)
(Note the use of :=
rather than =
, because if you use =
, Make will run the script every time it evaluates the variable.)
If you want the value in a shell variable within a recipe, look at the syntax you would use on the command line in your shell, which is probably something like:
output=$(python process.py); echo $output
but in a makefile rule you must escape the dollar signs with more dollar signs:
some_target:
output=$$(python process.py); echo $$output
Note that since each line of a recipe executes in its own sub-shell, the assignment and use of the variable must be on the same line; it won't survive to the next line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.