代码之家  ›  专栏  ›  技术社区  ›  MarkWeston

模式规则起作用,但后缀规则不起作用

  •  1
  • MarkWeston  · 技术社区  · 8 年前

    模式规则工作:

    $ ls
    Makefile   hello.txt  world.txt
    $ cat Makefile
    all: hello.out world.out
    
    %.out: %.txt
            cp $< $@
    
    $ make
    cp hello.txt hello.out
    cp world.txt world.out
    

    但是,当我试图用我认为完全等价的后缀规则替换它们时,它们不起作用:

    $ ls
    Makefile   hello.txt  world.txt
    $ cat Makefile
    .POSIX:
    .SUFFIXES:
    .SUFFIXES:.txt.out
    
    all: hello.out world.out
    
    .txt.out:
            cp $< $@
    
    $ make
    make: *** No rule to make target 'hello.out', needed by 'all'.  Stop.
    

    我不明白为什么。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Florian Weimer    8 年前

    问题出在这一行:

    .SUFFIXES: .txt.out
    

    它声明一个后缀, .txt.out 不是两个。您可以将其更改为:

    .SUFFIXES: .txt .out