Check if a makefile exists before including it

You could do it like that (no if or else)

-include Tool/Rules.mak
include common/Rules-Tool

like this you won't get an error if Tool/Rules.mak does not exists. (The '-' does the trick)

In common/Rules-Tool you then use the ?= operator ("conditional variable assignment operator") to assign values to the variable. This operator will assign the value only if the variable does not exists yet. IOW, it will not overwrite a pre-existing value. If Tool/Rules.mak does not exist or only partially fills in variable common/Rules-Tool will complete them.


If for some reason you don't want to use the ?= operator, (perhaps you have more action than just setting the variable) then you can do the if..then..else..fi this way:

ifneq ("$(wildcard Tool/Rules.mak)","")
  $(info using Tools/Rules.mak)
  include Tool/Rules.mak
else
  $(info using common/Rules-Tool.mak)
  include common/Rules-Tool.mak
endif