Test whether a directory exists inside a makefile

前端 未结 7 1443
-上瘾入骨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 had a case where I wanted to define a variable based on the test whether a directory exists or not at the top-most level of the Makefile where the approaches described above don't work. I found here a nice solution which can be used like this:

    MY_DIRNAME=../External
    ifneq "$(wildcard $(MY_DIRNAME) )" ""
      # if directory MY_DIRNAME exists:
      INCLUDES += -I../External
    else
      # if it doesn't:
      INCLUDES += -I$(HOME)/Code/External
    endif
    

    This will modify the variable INCLUDES based on whether the directory stored in MY_DIRNAME exists or not.

    (Motivation: In my case this variable would be used in another Makefile included later by the first:

    include $(SFRAME_DIR)/Makefile.common
    

    I wanted to have the same Makefile work in two different environments in a simple way.)

提交回复
热议问题