我有一个make项目,有两个真正的目标,一个testsuite和项目的可执行文件。
要建立这些规则,我需要如下规则:

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

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

最佳答案

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

# 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 ....

10-07 19:42