[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: endif and line continue

From: Philip Guenther
Subject: Re: endif and line continue
Date: Mon, 29 May 2006 20:06:16 -0600

On 5/29/06, Tobias Contreras <address@hidden> wrote:
Code snippet:
    $(OBJ_DIR)/flash_info.o         \
    $(OBJ_DIR)/bootrom_persist.o    \
    $(OBJ_DIR)/rsa.o                \
    $(OBJ_DIR)/sha1.o               \
    $(OBJ_DIR)/crc32.o              \
$(OBJ_DIR)/crc32init.o          <- *
    $(OBJ_DIR)/osutil.o             \

First of all, that ifdef line probably doesn't do what you think.
ifdef expands variables on the rest of the line, verifies that the
result is a single word, and _then_ checks whether the variable with
that name is set.  So, the ifdef line you wrote will only 'match' if
the RUNTIME_CRC_TABLE variable contains the name of a variable.
Simply setting it to something like "yes" won't work unless you also
have a 'yes' variable.  So, when using ifdef, you generally want to
just write something like

*when I put a '\' on this line it thinks the endif is on the same line
and I get "missing `endif'.  Stop." And if I don't I get missing
separator.  Stop.

Right, because the variable assignment ended at the first line that
didn't end with a backslash.  That in turn implies that you can't put
a directive such as 'ifdef' into the middle of an assignment.

(I assume that's from a variable assignment and not from a rule or such...)

How do you get around that issue?

The are several ways.  If the order of the names in the variable isn't
important (it probably isn't) than you can conditionally append to the
variable, ala:

OBJS = $(OBJ_DIR)/flash_info.o    \
            $(OBJ_DIR)/rsa.o                \
           $(OBJ_DIR)/osutil.o             \

OBJS += $(OBJ_DIR)/crc32init.o

If the order is important, then you can use the $(if) function to do
the condition tesing inline:

OBJS = $(OBJ_DIR)/flash_info.o    \
            $(OBJ_DIR)/rsa.o                \
           $(OBJ_DIR)/crc32.o             \
           $(OBJ_DIR)/bsn.o                \
   $(if $(RUNTIME_CRC_TABLE),$(OBJ_DIR)/crc32init.o) \
           $(OBJ_DIR)/osutil.o             \

Note that you do use $(RUNTIME_CRC_TABLE) there because $(if) tests
whether its first argument is empty, so you do want variable expansion
to take place.

Personally, I find the version using ifdef and += to be easier to read
and clearer: you don't have to pick your way through the $(if) or
match parens to figure out what it's doing.  It's also more
efficiently because the test occurs when the makefile is read instead
of when the variable is expanded.

Philip Guenther

reply via email to

[Prev in Thread] Current Thread [Next in Thread]