make:规则调用规则

时间:2011-12-27 16:09:17

标签: makefile

在makefile中,我可以从其他规则调用规则吗?

类似于:

rule1:
        echo "bye"
rule2:
        date
rule3:
        @echo "hello"
        rule1

5 个答案:

答案 0 :(得分:90)

使用依赖关系或递归制作从一个规则连接到另一个规则。

依赖关系会像这样完成(虽然顺序不同):

rule1:
        echo "bye"
rule2:
        date
rule3: rule1
        @echo "hello"

递归make会像这样完成(尽管它涉及一个子进程):

rule1:
        echo "bye"
rule2:
        date
rule3:
        @echo "hello"
        $(MAKE) rule1

两者都不完美;事实上,如果你构建一个循环,你可以通过递归使你遇到重大问题。您还可能应该添加.PHONY规则,以便将上述规则标记为合成规则,以便目录中的迷路rule1(等)不会引起混淆。

答案 1 :(得分:21)

只需添加您想要的新规则..

create table [table] 
(
    Name varchar(50),
    ID int,
    [Date] date,
    [Time] time
);

insert into [table] values('Williams', 55555, '13-feb-2016', '11:39:00');
insert into [table] values('Williams', 55555, '23-mar-2016', '09:20:00');
insert into [table] values('Johnson', 55555, '13-feb-2016', '11:39:00');
insert into [table] values('Williams', 55555, '13-feb-2016', '11:39:00');
insert into [table] values('Jackson', 99999, '01-sep-2016', '11:39:00');
insert into [table] values('Smith', 77777, '10-oct-2016', '11:39:00');

with cte as (
    select id, name
    from [table]
    group by id, name 
    having count(*) > 1
)
select *
from [table]
inner join cte on [table].id = cte.id 
and [table].name != cte.name

答案 2 :(得分:19)

Makefile不是程序性的; “规则”与功能不同。也就是说,您可以指定一个规则是另一个规则的先决条件:

rule1:
    @echo "Rule 1"

rule2: rule1
    @echo "Rule 2"

如果你make rule2,你应该看到:

Rule 1
Rule 2

答案 3 :(得分:3)

There are two advanced functions in GNU Make which can do this, although it should only be used in extenuating circumstances. This SO is top rated in google.

Rule prerequisites are more recommended, but sometimes you need a post-requisite.

GNU Make Call function

GNU Make Eval function

Essentially, Eval lets you build targets on the fly, and Call allows function like "defines" to be created.

答案 4 :(得分:0)

一个简单的方法是:

ifeq (a, b)
    build_target:=one
else
    build_target:=two
endif

mytarget: $(build_target)