1

私がmakeルールを持っていると仮定します:

.PHONY:gen
gen: auto.template
        generate-sources auto.template

、などauto1.srcのファイルの束を作成します。auto2.srcauto3.src

*.srcファイルからターゲットを構築するルールがある場合は、次のようになります。

$(patsubst %.src,%.target,$(wildcard *.src)): %.target: %.src
        build $< > $@

gen最初にルールを実行してから、2番目のルールテンプレートの前提条件を展開するようにmakeに指示するにはどうすればよいですか?GNU拡張は大歓迎です。

注: 1回の make呼び出しで保持したいと思います。これに対する簡単な解決策は、2番目のルールをセカンダリに配置し、処理後にMakefile.secondrun呼び出すことです。しかし、私はもっと良い選択肢があるかどうか疑問に思いました。$(MAKE) -f Makefile.secondrungen

4

2 に答える 2

6

ベータ版の回答を踏まえて、GNU make でmakefileの再作成を使用してそれを行う方法を次に示します。これは、再帰的な make とは異なります。代わりに、メインのメイクファイルのルールを使用して含まれているメイクファイルを更新し、元のメイク インスタンスを再起動します。*.dこれは、依存ファイルが通常どのように生成され、使用されるかです。

# Get the list of auto-generated sources.  If this file doesn't exist, or if it is older 
# than auto.template, it will get built using the rule defined below, according to the 
# standard behavior of GNU make.  If autosrcs.mk is rebuilt, GNU make will automatically 
# restart itself after autosrcs.mk is updated.

include autosrcs.mk

# Once we have the list of auto-generated sources, getting the list of targets to build 
# from them is a simple pattern substitution.

TARGETS=$(patsubst %.src,%.target,$(AUTO_SRCS))

all: $(TARGETS)

# Rule describing how to build autosrcs.mk.  This generates the sources, then computes 
# the list of autogenerated sources and writes that to autosrcs.mk in the form of a 
# make variable.  Note that we use *shell* constructs to get the list of sources, not
# make constructs like $(wildcard), which could be expanded at the wrong time relative
# to when the source files are actually created.

autosrcs.mk: auto.template
        ./generate-sources auto.template
        echo "AUTO_SRCS=`echo *.src`" > autosrcs.mk

# How to build *.target files from *.src files.

%.target: %.src
        @echo 'build $< > $@'
于 2012-04-15T20:41:33.153 に答える
1

簡単な答え: できません。Make は、ルールを実行する前に実行する必要があるすべてのルールを決定します。

より長い答え: できるかもしれません。あなたが言うように、再帰的な Make を明示的に、または秘密裏に、たとえば、makefile が実行するファイルを作成することで使用できますinclude(私はあなたのことを見ています、Jack Kelly)。または、ビルドするファイルのリストを何らかの方法で取得できる場合は、それgenに関するルールを作成できます。または、次のように大胆に判断することもできます。

%.target: %.src
        build $< > $@

%.src: gen;
于 2012-04-15T19:23:13.720 に答える