什么是$<和$ @在makefile文件中意味着什么? [英] What do $< and $@ mean in makefiles?

查看:67
本文介绍了什么是$<和$ @在makefile文件中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的docs/csv目录中有a.csvb.csv,...,我需要将每个文件转换为json文件.

I have a.csv,b.csv, ... in a my docs/csv directory, I need convert each of this file to a json file.

我遵循问题编写这样的Makefile.

I follow this question to write a Makefile like this.

SRCS = $(wildcard docs/csv/*.csv)
DESTS = $(patsubst docs/csv/%.csv, scripts/data/%.lua, $(SRCS))

all: $(DESTS)

$(DESTS): $(SRCS)
    echo $@
    echo $<

但是每次我运行make all时,echo $@都会按预期显示每个文件,但是echo $<总是显示单个文件,在我的csv文件夹中称为items.csv.

but every time I ran make all, the echo $@ show every file as expected, but echo $< always show the single file, called items.csv in my csv folder.

推荐答案

问题在于此规则:

$(DESTS): $(SRCS)
    ...

每个 lua文件取决于所有 csv文件,这不是我想的.而且由于$<扩展到 first 先决条件,所以每个目标都得到相同的一个(items.csv).

every lua file depends on all csv files, which is not what I think you intend. And since $< expands to the first prerequisite, you get the same one (items.csv) for every target.

尝试一下:

all: $(DESTS)

scripts/data/%.lua: docs/csv/%.csv 
    echo $@
    echo $<

这篇关于什么是$&lt;和$ @在makefile文件中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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