Make:如何生成除一个之外的所有 .c 文件的列表

fad*_*bee 3 c glob makefile

我有一个包含两个真实目标的 make 项目,一个测试套件和项目的可执行文件。

为了构建这些,我需要类似的规则:

testsuite: *.c (except executable.c) *.h
    clang ... *.c (except executable.c) -o testsuite

executable: *.c (except testsuite.c) *.h
    clang ... *.c (except testsuite.c) -o executable
Run Code Online (Sandbox Code Playgroud)

如果可能的话,正确的语法是什么?

Eta*_*ner 6

像这样的事情应该做你想做的事。

# Explicitly list the sources specific to each target.
EXECUTABLE_SOURCES := executable.c
TESTSUITE_SOURCES := testsuite.c

# Filter out all specific sources from the common wildcard-ed sources.
COMMON_SOURCES := $(filter-out $(TESTSUITE_SOURCES) $(EXECUTABLE_SOURCES),$(wildcard *.c))

testsuite: $(TESTSUITE_SOURCES) $(COMMON_SOURCES)
        clang ....

executable: $(EXECUTABLE_SOURCES) $(COMMON_SOURCES)
        clang ....
Run Code Online (Sandbox Code Playgroud)