Assign a makefile variable value to a bash command result?

前端 未结 3 1607
长发绾君心
长发绾君心 2020-12-02 15:32

I\'m trying to assign the output of this command ( that is in my makefile ) to the makefile HEADER var like in this following line of code:

HEADER = $(shell          


        
相关标签:
3条回答
  • 2020-12-02 15:58

    You will need to double-escape the $ character within the shell command:

    HEADER = $(shell for file in `find . -name *.h`;do echo $$file; done)
    

    The problem here is that make will try to expand $f as a variable, and since it doesn't find anything, it simply replaces it with "". That leaves your shell command with nothing but echo ile, which it faithfully does.

    Adding $$ tells make to place a single $ at that position, which results in the shell command looking exactly the way you want it to.

    0 讨论(0)
  • 2020-12-02 16:08

    Why not simply do

    HEADER = $(shell find . -name '*.h')
    
    0 讨论(0)
  • 2020-12-02 16:19

    The makefile tutorial suggested to use wildcard to get list of files in a directory. In your case, it means this :

    HEADERS=$(wildcard *.h)
    
    0 讨论(0)
提交回复
热议问题