multiple stems in makefile rule

南笙酒味 提交于 2019-12-11 06:07:26

问题


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?


回答1:


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 > $@


来源:https://stackoverflow.com/questions/16777612/multiple-stems-in-makefile-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!