Assign variable once when first used in Makefile [duplicate]

Multi tool use
Multi tool use












2
















This question already has an answer here:




  • How to get “at most once” semantics in variable assignments?

    2 answers




How do I only invoke a make shell function once in a variable expansion, and only when the variable is first used? I don't want to use := to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.



I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls twice:



.PHONY: test

FILES ?= $(warning Invoking the shell)$(shell ls)

test:
echo $(FILES) one
echo $(FILES) two









share|improve this question













marked as duplicate by Renaud Pacalet, Community Nov 21 '18 at 6:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

    – MadScientist
    Nov 18 '18 at 14:23
















2
















This question already has an answer here:




  • How to get “at most once” semantics in variable assignments?

    2 answers




How do I only invoke a make shell function once in a variable expansion, and only when the variable is first used? I don't want to use := to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.



I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls twice:



.PHONY: test

FILES ?= $(warning Invoking the shell)$(shell ls)

test:
echo $(FILES) one
echo $(FILES) two









share|improve this question













marked as duplicate by Renaud Pacalet, Community Nov 21 '18 at 6:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

    – MadScientist
    Nov 18 '18 at 14:23














2












2








2









This question already has an answer here:




  • How to get “at most once” semantics in variable assignments?

    2 answers




How do I only invoke a make shell function once in a variable expansion, and only when the variable is first used? I don't want to use := to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.



I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls twice:



.PHONY: test

FILES ?= $(warning Invoking the shell)$(shell ls)

test:
echo $(FILES) one
echo $(FILES) two









share|improve this question















This question already has an answer here:




  • How to get “at most once” semantics in variable assignments?

    2 answers




How do I only invoke a make shell function once in a variable expansion, and only when the variable is first used? I don't want to use := to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.



I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls twice:



.PHONY: test

FILES ?= $(warning Invoking the shell)$(shell ls)

test:
echo $(FILES) one
echo $(FILES) two




This question already has an answer here:




  • How to get “at most once” semantics in variable assignments?

    2 answers








makefile gnu-make






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 2:38









tekumaratekumara

5,14774058




5,14774058




marked as duplicate by Renaud Pacalet, Community Nov 21 '18 at 6:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Renaud Pacalet, Community Nov 21 '18 at 6:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

    – MadScientist
    Nov 18 '18 at 14:23














  • 1





    A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

    – MadScientist
    Nov 18 '18 at 14:23








1




1





A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

– MadScientist
Nov 18 '18 at 14:23





A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion

– MadScientist
Nov 18 '18 at 14:23












1 Answer
1






active

oldest

votes


















-1














Move the assignment inside the recipe



test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    Move the assignment inside the recipe



    test:
    FILES=$$(ls) ;
    echo $$FILES one ;
    echo $$FILES two





    share|improve this answer




























      -1














      Move the assignment inside the recipe



      test:
      FILES=$$(ls) ;
      echo $$FILES one ;
      echo $$FILES two





      share|improve this answer


























        -1












        -1








        -1







        Move the assignment inside the recipe



        test:
        FILES=$$(ls) ;
        echo $$FILES one ;
        echo $$FILES two





        share|improve this answer













        Move the assignment inside the recipe



        test:
        FILES=$$(ls) ;
        echo $$FILES one ;
        echo $$FILES two






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 7:21









        user657267user657267

        17.3k53160




        17.3k53160















            w,Q,7,q7wqGBVfluGhxZoPj4FzY xB0lDtH QV,iMUcDcCPmtfBDv8nwLO3ZMoV,rclMF6Iz06GvroZbGKM5
            1 cJv0I aN8qBdTb,axwI6YJQ1vgIpZq7GIdMvD4y8nJ3HUn3PnO,ft3HgDOUVjWUjii9G toT

            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            Guess what letter conforming each word

            Run scheduled task as local user group (not BUILTIN)