GNU Make 忽略除第一个之外的所有规则
GNU Make ignore all rules except first
我有一个包含一堆源文件的项目,其中一些(但不是全部)必须在更改一个特定的 *.h 文件后重建 (currtype.h)。我的 makefile 中对此有明确的规定:
%.obj: %.c
$(COMPILE)
main.obj: main.c currtype.h
$(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
$(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
$(COMPILE)
COMPILE = -"$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)
但是当我更改我的 currtype.h 时,我只看到 main.c 被重新编译了。如果我将 CustomHTTPApp 放在第一行,将 main.c 放在第二行,那么只会重新编译 CustomHTTPApp 等等。如何解决这个问题?
如果您只是 运行 "make",则会执行第一个非隐式规则,它只会构建 main.obj。您需要添加另一个构建所有输出文件的目标,例如称为 "all":
all: main.obj CustomHTTPApp.obj CustomSNMPApp.obj
%.obj: %.c
$(COMPILE)
main.obj: main.c currtype.h
$(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
$(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
$(COMPILE)
COMPILE = "$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)
我有一个包含一堆源文件的项目,其中一些(但不是全部)必须在更改一个特定的 *.h 文件后重建 (currtype.h)。我的 makefile 中对此有明确的规定:
%.obj: %.c
$(COMPILE)
main.obj: main.c currtype.h
$(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
$(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
$(COMPILE)
COMPILE = -"$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)
但是当我更改我的 currtype.h 时,我只看到 main.c 被重新编译了。如果我将 CustomHTTPApp 放在第一行,将 main.c 放在第二行,那么只会重新编译 CustomHTTPApp 等等。如何解决这个问题?
如果您只是 运行 "make",则会执行第一个非隐式规则,它只会构建 main.obj。您需要添加另一个构建所有输出文件的目标,例如称为 "all":
all: main.obj CustomHTTPApp.obj CustomSNMPApp.obj
%.obj: %.c
$(COMPILE)
main.obj: main.c currtype.h
$(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
$(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
$(COMPILE)
COMPILE = "$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)