Test whether a directory exists inside a makefile

前端 未结 7 1431
-上瘾入骨i
-上瘾入骨i 2020-12-23 09:11

In his answer @Grundlefleck explains how to check whether a directory exists or not. I tried some to use this inside a makefile as follow:

foo.b         


        
7条回答
  •  庸人自扰
    2020-12-23 09:41

    I use the following to detect if a file or a directory exists and act upon it :

    $(if $(filter expected,$(wildcard *)), the expected file exists)
    

    With your request :

    .PHONY: ~/Dropbox
    
    ~/Dropbox:
        echo "Dir exists"
    
    foo.bak: foo.bar | $(if $(filter ~/Dropbox,$(wildcard ~/*)), the expected file exists)
    

    Which can further be simplify :

    foo.bak: foo.bar | $(wildcard ~/Dropbox)
    

提交回复
热议问题