Makefile - the control variable is one of them

There is code in the makefile of my project that is similar to this:

ifneq ($(MAKECMDGOALS), rebuild)
ifneq ($(MAKECMDGOALS), rerun)
ifneq ($(MAKECMDGOALS), distclean)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), mostlyclean)
ifneq ($(MAKECMDGOALS), dep-clean)
ifneq ($(MAKECMDGOALS), tools)
ifneq ($(MAKECMDGOALS), tools-clean)
include $(DEPENDENCIES)
endif
endif
endif
endif
endif
endif
endif
endif

He's too tired .. Is there a way to make it simpler?

+4
source share
2 answers

@keltar answers, but findstringis actually not the best choice, as it is suitable even for substrings. Better to use filter, which is an exact match of words:

GOALS := rebuild rerun distclean clean mostlyclean dep-clean tools tools-clean

ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
  include $(DEPENDENCIES)
endif
+8
source

You can use something like this

GOALS:=rebuild rerun distclean clean mostlyclean dep-clean tools tools-clean
ifneq ($(findstring $(MAKECMDGOALS), $(GOALS)),)
include $(DEPENDENCIES)
endif

But this will be a problem if you specify several goals at once (for example, make clean distclean).

? -include , , , ?

+1

All Articles