Makefile Puzzle:多种编程语言

bob*_*nto 5 c makefile fortran90

我有一个简单的测试Makefile:

hello: hello.o
.SUFFIXES: .c .f90 .o
.f90.o:
    pgf90 -c -o $@ $<
.c.o:
    cc -c -o $@ $<
Run Code Online (Sandbox Code Playgroud)

您不必告诉我它在同一目录中有foo.c和foo.f90会造成混淆.我永远不会真的这样做.我只是想知道Make如何处理一些先例.所以,当我只发出make命令时,make运行:

pgf90 -c -o hello.o hello.f90
cc hello.o -o hello
Run Code Online (Sandbox Code Playgroud)

当然,"cc"链接失败,因为"cc"无法链接FORTRAN对象以生成可执行文件.精细.但我的问题是:我已经尝试了一些我能想到的阻止make使用pgf90命令作为其第一个编译命令,并选择cc命令.我已经改变了后缀规则的顺序.我在.SUFFIXES语句中更改了后缀的顺序.唯一可行的方法是完全不使用.f90后缀规则.为什么会这样,可以改变吗?谢谢.(如果不言而喻,我的目录中确实有简单的hello.f90和hello.c源文件,并且编译和执行都很好.)

更新:使用-d进行运行.相关输出(AFAICT)如下所示:

Considering target file 'hello.o'.
 File 'hello.o' does not exist.
 Looking for an implicit rule for 'hello.o'.
 Trying pattern rule with stem 'hello'.
 Trying implicit prerequisite 'hello.c'.
Run Code Online (Sandbox Code Playgroud)

没有给"隐含的先决条件'hello.c'留下深刻的印象",make会在它之前尝试一大堆其他的东西

 Found an implicit rule for 'hello.o'.
  Considering target file 'hello.f90'.
   Looking for an implicit rule with stem 'hello.f90'
    .
    .
    .
   No implicit rule found for 'hello.f90'.    #???????
    .
    .
 Must remake target 'hello.o'
pgf90 -c -o hello.o hello.f90
Run Code Online (Sandbox Code Playgroud)

Curiouser和curiouser

Bet*_*eta 1

由于对我来说是个谜(但可能是晦涩且历史悠久)的原因,您可以通过更改后缀规则来更改此行为

.f90.o:
    pgf90 -c -o $@ $<
.c.o:
    cc -c -o $@ $<
Run Code Online (Sandbox Code Playgroud)

进入模式规则(并颠倒顺序):

%.o : %.c
    cc -c -o $@ $<
%.o : %.f90
    pgf90 -c -o $@ $<
Run Code Online (Sandbox Code Playgroud)