找回密码
 注册
查看: 866|回复: 5

奇怪的表达式D_FILES := $(O_FILES:.o=

[复制链接]
发表于 2006-3-30 14:19:36 | 显示全部楼层 |阅读模式
今天看到了一个奇怪的表达式

D_FILES := $(O_FILES:.o=.d)
include $(D_FILES)

不知道这两行式什么意识??
发表于 2006-3-30 16:32:36 | 显示全部楼层
makefile里的?
回复

使用道具 举报

 楼主| 发表于 2006-3-30 17:43:13 | 显示全部楼层
是makefile里的


# Rule for compiling (always first)
%.o: %.c
        $(CC) $(CFLAGS) $< -c -o $@

%.o: %.cpp
        $(CC) $(CFLAGS) $< -c -o $@


# Rule for building dependencies from source (always second)
%.d: %.c
        $(CC) -M $(CFLAGS) $< > $@
%.d: %.cpp
        $(CC) -M $(CFLAGS) $< > $@

############################################################################
# Automatic source file dependencies
############################################################################

# include the dependencies (always third)
D_FILES := $(O_FILES:.o=.d)
include $(D_FILES)

all: $(EXEC)

# uses non LGPL librarys
$(EXEC): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBHTTPCLIENT) $(LDLIBS) -lpthread -dHTTP0
        -$(STRIP) $@
回复

使用道具 举报

发表于 2006-3-30 22:35:12 | 显示全部楼层
6.3.1 Substitution References

A substitution reference substitutes the value of a variable with alterations that you specify. It has the form `$(var:a=b)' (or `${var:a=b}') and its meaning is to take the value of the variable var, replace every a at the end of a word with b in that value, and substitute the resulting string.

When we say "at the end of a word", we mean that a must appear either followed by whitespace or at the end of the value in order to be replaced; other occurrences of a in the value are unaltered. For example:

       

foo := a.o b.o c.o
bar := $(foo:.o=.c)

sets `bar' to `a.c b.c c.c'. See section Setting Variables.

A substitution reference is actually an abbreviation for use of the patsubst expansion function (see section Functions for String Substitution and Analysis). We provide substitution references as well as patsubst for compatibility with other implementations of make.

Another type of substitution reference lets you use the full power of the patsubst function. It has the same form `$(var:a=b)' described above, except that now a must contain a single `%' character. This case is equivalent to `$(patsubst a,b,$(var))'. See section Functions for String Substitution and Analysis, for a description of the patsubst function.

       

For example:

foo := a.o b.o c.o
bar := $(foo:%.o=%.c)

sets `bar' to `a.c b.c c.c'.

------------------------------------------------
gmake的字符替换
回复

使用道具 举报

 楼主| 发表于 2006-4-3 16:58:47 | 显示全部楼层
谢谢斑竹
  请问这篇完整的文章什么地方可以得到
回复

使用道具 举报

发表于 2006-4-4 09:22:56 | 显示全部楼层
见置顶贴

http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=151237
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-7 02:42 , Processed in 0.039152 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表