Makefile目标上的多个词干 [英] Multiple stems on makefile target

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

问题描述

假设 ls 产生 abcd ,我想创建文件 ab bd cb 等,以使 ab ,我会使用 cat ab>a-b ,其他类似.我想使用 makefile ,但不知道如何使用.我需要一些东西,例如:

Assume ls produces a b c d and I want to create files a-b b-d c-b, etc. To make a-b, I'd use a command such as cat a b > a-b, and similarly for the other ones. I wanted to use a makefile, but couldn't figure out how. I needed something such as:

FILES := a-b b-d c-b

$(FILES): %1-%2: %1 %2
     cat $^ > $@

在某些正则表达式中,%1 %2 类似于 \ 1 \ 2 .有没有简单的方法可以做到这一点?我找到了这个答案,但是对我来说,对于这样一个简单的例子来说,它似乎太复杂又难看任务.也许我问得太多了.

Here %1 and %2 would be something like \1 and \2 in some regex notations. Is there any simple way to do this? I found this answer, but it seemed to me too complicated and ugly for such a simple task. Maybe I'm asking too much, though.

推荐答案

类似于此问题,您基本上有两种选择:可以使用自动生成的makefile,也可以使用$(eval ...).",这是使用自动生成的方法的解决方案,

It's similar to this question, "You basically have two options: you can use auto-generated makefiles,or you can use $(eval ...).", here is the solution using auto-generated method,

FILE =a-b b-c c-d

all: $(FILE)

-include generated.mk

generated.mk: Makefile
        @for f in $(FILE); do \
                echo $$f: `echo $$f | sed 's/-/ /'`; \
                echo '\t'"@cat $$^ > $$"@; \
                echo ;\
        done > $@

这篇关于Makefile目标上的多个词干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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