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

前端 未结 12 2179
心在旅途
心在旅途 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 08:10

    It's strange to see so many people using shell scripting for this. I was looking for a way to use native makefile syntax, because I'm writing this outside of any target. You can use the wildcard function to check if file exists:

     ifeq ($(UNAME),Darwin)
         SHELL := /opt/local/bin/bash
         OS_X  := true
     else ifneq (,$(wildcard /etc/redhat-release))
         OS_RHEL := true
     else
         OS_DEB  := true
         SHELL := /bin/bash
     endif 
    

    Update:

    I found a way which is really working for me:

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

提交回复
热议问题