0

我正在尝试编写一个生成文件以在执行时执行以下操作:

CMVC_VIEW = ../../.. 
TB_DIR = $(CMVC_VIEW)/tarball_images 
SMAC_TOOLS = $(TB_DIR)/smac_tools 
SMAC_BIN = $(SMAC_TOOLS)/bin 
DIR_LIST = $(TB_DIR) \
    $(SMAC_TOOLS) \
    $(SMAC_BIN)

install:
    rm -f *.o
    for DIR in $(DIR_LIST); do \
      echo $${DIR}; \
      chmod 2775 $${DIR}; \
    done

但是,当 makefile 运行时,我收到一条错误消息,提示 chmod: missing operand after 2775。我不明白为什么会发生这种情况,因为它$${DIR}应该包含与需要更改其访问权限的目录相对应的路径。

$${DIR}当我用静态目录路径替换时,这似乎有效。

出于此 makefile 的目的,假设该DIR_LIST宏被分配给由空格分隔的目录列表。

4

1 回答 1

0

You're getting confused by make variable references and shell variable references. Remember, make will interpret any string like $(FOO) as a reference to a make variable, lookup the variable with that name, and replace the reference with the value. Your shell-based for loop creates a shell variable called DIR, but since you have (had) just $(DIR), make was trying (and failing) to find a make variable called DIR.

Your solution works because the double $ prevents make from doing its own variable reference resolution, so the literal $(DIR) gets passed to the shell, which then does its own variable resolution! That works, of course, because the for loop created the DIR variable.

于 2012-06-08T17:03:26.763 回答