关于Makefile的一些问题

Some questions on Makefile

本文关键字:问题 Makefile 关于      更新时间:2023-10-16

我正在尝试理解uboot的二级makefile(这个makefile在子目录中)

a) What is the difference between $(COBJS:.o=.c) and  COBJS   := test_main.o
b) What is the meaning of $(call cmd_link_o_target, $(OBJS)). What is the cmd_link_o_target and what is the call statement doing
c) Does this line creating 2 targets ?
ALL     :=       $(obj).depend $(LIB)

====

==========================================================
include $(TOPDIR)/config.mk
LIB     = $(obj)libtest.o
SOBJS   := test.o
COBJS   := test_main.o
COBJS   += diagnostic.o

SRCS    := $(SOBJS:.o=.S) $(COBJS:.o=.c)
OBJS    := $(addprefix $(obj),$(COBJS) $(SOBJS))
ALL     :=       $(obj).depend $(LIB)
all:    $(ALL)
$(LIB): $(OBJS)
        $(call cmd_link_o_target, $(OBJS))
#########################################################################
# defines $(obj).depend target
include $(SRCTREE)/rules.mk
sinclude $(obj).depend
#########################################################################

a) $(COBJS:.o=.c)COBJ的每个元素执行后缀替换,在这种情况下等效于使用SRCS := test.S test_main.c

b) $(call cmd_link_o_target, $(OBJS)) 是一种在 make 中创建参数函数的方法。它将采用表达式作为cmd_link_o_target(包含在包含的文件中),并将每次出现的$(1)替换为进一步扩展$(OBJS)

c) 是的,它确实如此(obj也包含在 Makefile 包含的文件中)。

如果您想知道,=赋值和:=赋值之间的区别在于=允许递归替换,而:=静态的,即只扩展一次,而不创建对其他变量的引用。