makefile规则中有多个主干 [英] multiple stems in makefile rule

查看:221
本文介绍了makefile规则中有多个主干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 % -  foo-(k).out :%-foo-(k-1).out 
#做某事,例如
cat $< $ @

有文件有任意的句柄,然后是 -foo - ,然后是一个整数,后跟 .out 。每个文件取决于具有相同名称的文件,整数一个更小。



例如,如果文件 blah / bleh-foo-1存在,然后

  make blah / bleh-foo-2.out 

将工作。



我可以用多个词干如果有这样的事情...在(gnu)make中做什么另外一种方法?

解决方案

不是很容易做这样的事情。您基本上有两个选项:您可以使用自动生成的makefile,或者您可以使用 $(eval ...)。对我来说,自动生成的makefile更容易,所以这里有一个解决方案:

  SOURCELIST = blah / bleh-foo-1.out 

全部:

-include generated.mk

generated.mk:$ $ $ $ $ $ $ $ $ $ $ $ do \
n =`echo$$ f| sed -n的/.*- \([0-9] * \)\.out $ / \1 / p'`; \
echo$$ {f%-foo- [0-9] *。out} -foo-`expr $$ n + 1`.out:$$ f; cat $$& $$ @; \
done> $ @


I am trying to write a makefile that does something like the following:

%-foo-(k).out : %-foo-(k-1).out
    # do something, e.g.
    cat $< $@

i.e. there are files with arbitrary stems, then -foo-, then an integer, followed by .out. Each file depends on the one with the same name, with integer one smaller.

For instance, if the file blah/bleh-foo-1.out exists, then

make blah/bleh-foo-2.out

would work.

I could do this with multiple stems if there were such a thing... what's another way to do this sort of thing in (gnu) make?

解决方案

There is no easy way to do something like this. You basically have two options: you can use auto-generated makefiles, or you can use $(eval ...). To me auto-generated makefiles are easier, so here's a solution:

SOURCELIST = blah/bleh-foo-1.out

all:

-include generated.mk

generated.mk: Makefile
        for f in $(SOURCELIST); do \
            n=`echo "$$f" | sed -n 's/.*-\([0-9]*\)\.out$/\1/p'`; \
            echo "$${f%-foo-[0-9]*.out}-foo-`expr $$n + 1`.out: $$f ; cat $$< > $$@"; \
        done > $@

这篇关于makefile规则中有多个主干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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