[makefile] # 5. Conditional part of Makefiles

문연수·2022년 9월 16일
0

Makefile

목록 보기
6/8

1. Conditional if/else

foo = ok

all:
ifeq ($(foo), ok)
    @echo "foo equals ok"
else
    @echo "nope"
endif

2. Check if a variable is empty

nullstring = 
foo = $(nullstring) # end of line; there is a space here

all:
ifeq ($(strip $(foo)),)
	@echo "foo is empty after being stripped"
endif
ifeq ($(nullstring),)
	@echo "nullstring doesn't even have spaces"
endif

3. Check if a variable is defined

bar = 
foo = $(bar)

all:
ifdef foo
    @echo "foo is defined"
endif
ifndef bar
	@echo "but bar is not"
endif

4. $(makeflags)

 이하의 예제는 MAKEFLAGSfindstring 를 통해 어떻게 make 의 플래그를 검사하는지를 보여준다. 이하의 예제를 make -i 와 함께 실행하고 echo 구문의 출력 결과를 보라:

bar = 
foo = $(bar)

all:
# Search for the "-i" flag. MAKEFLGS is just a list of single characters, one per flag. So look for "i" in this case.
ifneq (,$(findstring i, $(MAKEFLAGS)))
	echo "i was passed to MAKEFLAGS"
endif

출처

[사이트] https://makefiletutorial.com/

profile
2000.11.30

0개의 댓글