Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makefile - check variable is one of them

Tags:

makefile

In the makefile of my project, there's code which is similiar 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

It's too tired.. Is there any way to make it more simple?

like image 747
ikh Avatar asked Dec 20 '22 13:12

ikh


1 Answers

@keltar's answer works but findstring is not really the best choice since it succeeds even for substrings. Better is to use filter which is exact word matches:

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

ifeq (,$(filter $(GOALS),$(MAKECMDGOALS)))
  include $(DEPENDENCIES)
endif
like image 50
MadScientist Avatar answered Jan 06 '23 05:01

MadScientist