多个目标的构建后步骤 [英] Post-build step for multiple targets
问题描述
我有一个makefile,它有多个目标,可以输出不同格式的数据,例如制作html
,制作pdf
,制作txt
等.这些选项被使用.我已经对构建前步骤进行了排序,但是不确定如何使构建后步骤正常运行.
I have a makefile that has multiple targets for outputting data in different formats, e.g. make html
, make pdf
, make txt
etc. and I would like to have pre-build and post-build steps that run when any of these options are used. I have the pre-build step sorted, but not sure how I can get the post-build step working properly.
.PHONY: html pdf txt pre-build post-build
pre-build:
do-pre-build-stuff
post-build:
do-post-build-stuff
html: data.dat
generate-html data.dat
pdf: data.dat
generate-pdf data.dat
txt: data.dat
generate-txt data.dat
data.dat: pre-build
generate-some-data > data.dat
如何使 post-build
步骤在每个目标之后运行?
How can I get the post-build
step to run after every target?
推荐答案
不幸的是,您必须为每个规则编写不同的规则.但是您可以使用静态模式规则使其更简单:
You have to write a different rule for each one, unfortunately. But you can make it simpler with a static pattern rule:
html pdf txt: %: real-%
do-post-build-stuff
real-html: data.dat
generate-html data.dat
real-pdf: data.dat
generate-pdf data.dat
real-txt: data.dat
generate-txt data.dat
这将根据 real-
版本创建目标 html
, pdf
和 txt
. real-
版本完成实际工作,然后在完成后,将后构建内容作为基本目标中的配方完成( html
, pdf
和 txt
).
This creates targets html
, pdf
, and txt
which depend on the real-
versions. The real-
versions do the actual work, then after they're done the post-build stuff is done as a recipe in the base target (html
, pdf
, and txt
).
这条规则只是一个速记,因此您不必全部写下来;结果是相同的:
That rule is just a shorthand so you don't have to write it all out; the result is identical:
html: real-html
do-post-build-stuff
pdf: real-pdf
do-post-build-stuff
txt: real-txt
do-post-build-stuff
这篇关于多个目标的构建后步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!