Reputation: 2957
I am learning some basics of Makefile, and write simple example as below:
urname=Chang
givenname=SJ
fullname=$(givenname) $(surname)
hello:
@echo $(fullname)
surname=Lin
ALL_PACKAGES=
hello1:
ifeq (,$(ALL_PACKAGES))
@echo There is no package
$(error $(ALL_PACKAGES) is empty)
else
@echo there are some packages
endif
@echo $(ALL_PACKAGES)
ALL_PACKAGES += package1
I can understand make hello
result will be "SJ Lin", cause $(surname) is "Lin" finally.
However, in result of make hello1
,why $(ALL_PACKAGES) is empty in the if condition(I guess if will be "package1" in the same way on make hello
)?
Moreover, why the first echo message("There is no package") will not be printed but only error message do?
Thanks teachers.
Upvotes: 0
Views: 43
Reputation: 224944
make hello
will yield "Jay Lin", not "SJ Lin". I don't know where you got "SJ" from.
ALL_PACKAGES
is empty at that point in the parsing, so that's why you get that result. The ifeq
is handled at the time of parsing the makefile, before it actually starts to run and build targets.
The error message prints out (and causes make
to exit) while it is parsing the makefile, before it starts to run and build targets.
If you were to comment out the $(error
line, you'll get two printouts from make hello1
- both the There is no package
message (included because of the state of ALL_PACKAGES
at that point in the parsing), and then also package1
, from $(ALL_PACKAGES)
being expanded later, during the actual make
processing.
Upvotes: 1