help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assign the result of my python script to a variable of my makefile


From: Paul Smith
Subject: Re: assign the result of my python script to a variable of my makefile
Date: Wed, 25 Mar 2015 07:55:34 -0400

On Wed, 2015-03-25 at 02:54 -0700, guylobster wrote:
> this is the first time I do a makefile.
> But I block to assign the result of my python script to a variable of my
> makefile.
> The function works. Here the function and the result.
> 
> *My makefile*
> G_SIZE=10
> Quake:
>         python estimationkmer.py $(G_SIZE)
>         ESTK=$(python estimationkmer.py $(G_SIZE))
>         echo $(ESTK)

You have three problems here:

First you have to escape dollar signs which you want to be passed to the
shell:

   ESTK=$$(python estimationkmer.py $(G_SIZE))

(note the double "$$" here) to escape the "$" so make passes it to your
shell.

The second problem is that make invokes every line of a recipe as a
separate shell script, so variables assigned in one line are lost before
the next line.  If you want to set a shell variable and use it again you
have to put both commands in the same shell:

   ESTK=$$(python estimationkmer.py $(G_SIZE)) ; \
   echo $$ESTK

Finally, note this is setting a SHELL variable.

You can't set a MAKE variable from within a recipe, because recipes are
passed to the shell and run there.  If you want to set a make variable
you have to do it outside of a recipe, using make's shell function:

  ESTK := $(shell python estimationkmer.py $(G_SIZE))

  Quake:
          echo $(ESTK)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]