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

前端 未结 12 2138
心在旅途
心在旅途 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:54

    ifneq ("$(wildcard $(PATH_TO_FILE))","")
        FILE_EXISTS = 1
    else
        FILE_EXISTS = 0
    endif
    

    This solution posted above works best. But make sure that you do not stringify the PATH_TO_FILE assignment E.g.,

    PATH_TO_FILE = "/usr/local/lib/libhl++.a" # WILL NOT WORK
    

    It must be

    PATH_TO_FILE = /usr/local/lib/libhl++.a
    

提交回复
热议问题