GNU make似乎忽略了中间文件的非终端匹配规则 [英] GNU make seems to ignore non-terminal match-anything rules for intermediate files

查看:92
本文介绍了GNU make似乎忽略了中间文件的非终端匹配规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录中有以下文件:

I have the following files in a directory:

FP01.c:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    long double ld = 0.1L; // long double constant (L or l suffix)
    scanf("%Lf", &ld);
    return 0;
}

makefile:

MAKEFLAGS += -rR

# the default target
.PHONY: all
all: FP01.elf

%.elf: %
    cp $< $@

# prevents non-terminal match-anything rules from matching target '%.c'
# see section 10.5.5 of GNU make manual
%.c:

# a non-terminal match-anything rule
%: %.c
    gcc -Wall -g $< -o $@

如果FP01不存在,则运行make会给出以下输出:

If FP01 does not exist, running make gives the following output:

make: *** No rule to make target 'FP01.elf', needed by 'all'. Stop.

但是,如果我在make之前运行以下命令,那么一切都会按预期进行:

However, if I run the following commands before make, then everything works as expected:

$ touch FP01
$ touch FP01.c
$ make
gcc -Wall -g FP01.c -o FP01
cp FP01 FP01.elf

我丢失了某些东西还是GNU make中存在错误?

Am I missing something or there is a bug in GNU make?

make --version给出以下输出:

GNU make 4.1
Built for i686-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Fundation, Inc.
License GPLv3+: ...
...



似乎使任何内容匹配的规则终端都可以解决该问题,但是我想尽可能使用内置规则来生成FP01,不幸的是它不是终端终端.

It seems that making match-anything rule terminal somehow fixes the problem, but I want to use built-in rule to generate FP01 if possible and unfortunately it is non-terminal.

另一件事是,我认为非终止规则应该起作用,因此使用终止规则并不能真正解决问题,因为我仍然不知道该错误是在make还是在我的心理makefile解析器"中. /p>

Another thing is that I believe that non-terminal rule should work so using terminal rule doesn't actually solve the problem as I still don't know whether the bug is in make or in my "mental makefile parser".

推荐答案

我认为您应该在% : %.c规则上使用::,因为您实际上希望将其作为任何内容的最终匹配规则(因为您不希望这样做)需要构建.c文件):

I think you should use :: on the % : %.c rule because you actually want that to be a terminal match-anything rule (since you don't need the .c file to be built):

MAKEFLAGS += -rR

.PHONY: all
all: FP01.elf

%.elf: % ; cp $< $@
% :: %.c ; gcc -Wall -g $< -o $@

请注意,这里我将;表单用于配方,因为它更容易复制和粘贴,因为无需担心制表符.

Note that I used the ; form for the recipes here because it's easier to copy and paste because no need to worry about tabs.

这篇关于GNU make似乎忽略了中间文件的非终端匹配规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆