C GNU make,不需要隐式规则

C GNU make,不需要隐式规则,c,makefile,build,gnu-make,C,Makefile,Build,Gnu Make,我有以下目录: Makefile src/ main.c dummy.raw (main.o) (<- to be built) (dummy.txt) (<- to be built) build/ (main) (<- to be built) make仅当我自己使用make src/dummy.txt构建.txt文件时,才开始使用Makefile中的规则 为什么make会这样 如何更正Makefile以强制make生成中间

我有以下目录:

Makefile
src/
   main.c
   dummy.raw
   (main.o)    (<- to be built)
   (dummy.txt) (<- to be built)
build/
   (main)      (<- to be built)
make
仅当我自己使用
make src/dummy.txt构建.txt文件时,才开始使用Makefile中的规则

  • 为什么
    make
    会这样
  • 如何更正Makefile以强制
    make
    生成中间
    dummy.txt

谢谢

问题在于您的方法调用了一系列模式规则,一个用于构建
src/main.o
,另一个用于构建
src/dummy.txt
,以及

有几种方法可以解决这个问题。两个简单的问题:

您可以使用以下命令调用Make:

或者您可以为
src/dummy.txt
硬编码规则:

src/%.txt: src/%.raw
    touch $@
    @echo "Created dummy file"

src/dummy.txt: src/dummy.raw

或者,您可以通过添加内置规则来删除它,而不使用配方:
%.o:%.c
。或者,您可以通过添加
。后缀:
,删除几乎所有内置规则,包括这些规则,而不需要任何后缀先决条件来清除它。或者,如果您有GNU make 4.0或更高版本,您可以在makefile中添加
MAKEFLAGS+=-r
,它将具有与命令行相同的效果。。。还有几个选择:)
src/%.txt: src/%.raw
    touch $@
    @echo "Created dummy file"

src/dummy.txt: src/dummy.raw