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

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

    FILE1 = /usr/bin/perl
    FILE2 = /nofile
    
    ifeq ($(shell test -e $(FILE1) && echo -n yes),yes)
        RESULT1=$(FILE1) exists.
    else
        RESULT1=$(FILE1) does not exist.
    endif
    
    ifeq ($(shell test -e $(FILE2) && echo -n yes),yes)
        RESULT2=$(FILE2) exists.
    else
        RESULT2=$(FILE2) does not exist.
    endif
    
    all:
        @echo $(RESULT1)
        @echo $(RESULT2)
    

    execution results:

    bash> make
    /usr/bin/perl exists.
    /nofile does not exist.
    

提交回复
热议问题