How do I check if file exists in Makefile so I can delete it?

前端 未结 12 2160
心在旅途
心在旅途 2020-12-02 07:40

In the clean section of my Makefile I am trying to check if the file exists before deleting permanently. I use this code but I receive errors.

What\'s w

12条回答
  •  半阙折子戏
    2020-12-02 07:57

    The second top answer mentions ifeq, however, it fails to mention that these must be on the same level as the name of the target, e.g., to download a file only if it doesn't currently exist, the following code could be used:

    download:
    ifeq (,$(wildcard ./glob.c))
        curl … -o glob.c
    endif
    
    # THIS DOES NOT WORK!
    download:
        ifeq (,$(wildcard ./glob.c))
            curl … -o glob.c
        endif
    

提交回复
热议问题