如何为目录树中某些类型的文件编写Make规则? [英] How to write a Make rule for files of certain type in a directory tree?

查看:68
本文介绍了如何为目录树中某些类型的文件编写Make规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下包含几个Markdown文件的目录树(深度可能超过一个级别).每个文件的PDF版本都存在于同一目录中,并且每次更新相应的Markdown文件时都必须更新.要实现此目的,必须在树的根目录中的单个Makefile中编写什么规则?

Imagine a directory tree (which might be more than one level deep) containing several Markdown files. A PDF version of each file exist in the same directory and must be updated each time the corresponding Markdown file is updated. What rule must be written in a single Makefile in the root directory of this tree to achieve this?

我正在寻找一种解决方案,可以在不更新Makefile的情况下从目录树中添加或删除文件.

I am looking a for a solution where files can be added or removed from the directory tree without a need for updating the Makefile.

假设:

  • 所有降价文件的名称均遵循特定模式;例如,它们以.md后缀结尾.
  • 正在使用GNU Make.

推荐答案

您可以使用$(shell find)递归查找文件.例如:

You can use $(shell find) to find files recursively. For example:

markdown := $(shell find . -name '*.md')

all: $(patsubst %.md, %.pdf, $(markdown))

%.pdf: %.md
    pandoc -o $@ $<

这篇关于如何为目录树中某些类型的文件编写Make规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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