当在 echo 内部使用字符串时 Makefile 覆盖配方错误

Makefile overriding recipe error when string is used inside of echo

我有以下 Makefile,当我使用 all 目标时出现错误。我不确定问题的根本原因是什么。

APSTOP= ../..
VERSION=2.12.8
SVERSION=2.12
SCALAC= /afs/package/scala/scala-${VERSION}/common/bin/scalac
APSLIB = ${APSTOP}/lib/aps-library-${SVERSION}.jar
COOLCOMPILERDIR= /afs/project/cool/scala
SCALAFLAGS= -cp .:${APSLIB}
SCALACFLAGS= ${SCALAFLAGS}
APS2SCALA = ${APSTOP}/bin/aps2scala
APS2SCALAFLAGS = -p ..:${APSTOP}/base -G
SCALASRC = cool-symbol.handcode.scala cool-semant-driver.scala cool-handcode.scala cool-noinherit-semant-driver.scala
SCALAGEN = cool-symbol.scala cool-tree.scala \
    cool-noinherit-semant.scala  cool-dynamic-semant.scala
SCALACOPY= basic.scala A2I.scala \
       CoolTokens.scala CoolScanner.scala CoolOptions.scala \
    CoolParser.scala 
SCALAHAND = CoolCompiler.scala
EXAMPLEDIR = ../examples

.PHONY: all clean src

src : ${SCALASRC}

all : ${SCALAGEN}
all : cool_symbol_implicit.class \
    cool_tree_implicit.class \
    cool_noinherit_semant_implicit.class \
    cool_dynamic_semant_implicit.class

%.scala : ../%.aps 
    ${APS2SCALA} ${APS2SCALAFLAGS} $*

cool-symbol.scala : ../cool-symbol.aps
    ${APS2SCALA} ${APS2SCALAFLAGS} --omit SYMBOL --omit gensym cool-symbol

%_implicit.class : %.scala
    ${SCALAC} ${SCALACFLAGS} $*.scala

cool_symbol_implicit.class : cool-symbol.scala cool-symbol.handcode.scala
    ${SCALAC} ${SCALACFLAGS} cool-symbol.scala cool-symbol.handcode.scala

cool_tree_implicit.class : cool-tree.scala cool_symbol_implicit.class
    ${SCALAC} ${SCALACFLAGS} cool-tree.scala

cool_noinherit_semant_implicit.class : cool-noinherit-semant.scala
    ${SCALAC} ${SCALACFLAGS} $<

cool_dynamic_semant_implicit.class : cool-dynamic-semant.scala
    ${SCALAC} ${SCALACFLAGS} $<

%.scala : RCS/%.scala,v
    co $<

.PHONY: %.run
%.run : %.class
    scala ${SCALAFLAGS} $*

.PHONY: %.compile
%.compile : %.scala
    scalac ${SCALACFLAGS} $*.scala

.PHONY: %.semant
%.semant : ${EXAMPLEDIR}/%.cool Semant.class
    scala ${SCALAFLAGS} CoolCompiler $<

.PHONY: %.debug
%.debug : ${EXAMPLEDIR}/%.cool Semant.class
    scala ${SCALAFLAGS} CoolCompiler -s $<

COOLCOMPILERSCALA = \
        cool-symbol.scala cool-symbol.handcode.scala cool-tree.scala \
        cool-handcode.scala ${SCALACOPY} \
        cool-dummy-semant-driver.scala ${SCALAHAND}

${SCALACOPY} :
    echo "import cool_implicit._" | cat - ${COOLCOMPILERDIR}/$@ > $@

CoolParser.scala :
    echo "import cool_implicit._" | cat - ${COOLCOMPILERDIR}/$@ > $@.tmp
    sed 's/result.set_inheritablep(/t_Tree.s_inheritablep(result,/' \
        < $@.tmp > $@

cool-parser-${SVERSION}.jar : ${COOLCOMPILERSCALA}
    @rm -f *.class
    ${SCALAC} -deprecation ${SCALACFLAGS} ${COOLCOMPILERSCALA}
    jar cvf $@ *.class

install: cool-parser-${SVERSION}.jar
    cp cool-parser-${SVERSION}.jar ../../lib/.

clean:
    rm -f *.class ${SCALAGEN} ${SCALACOPY} *.jar

错误:

Makefile:79: warning: overriding recipe for target 'CoolParser.scala'
Makefile:76: warning: ignoring old recipe for target 'CoolParser.scala'
make: Nothing to be done for 'src'.

这不是错误:如果是错误,构建就会失败。这个构建成功了。在 make 错误消息中包含 ***。这只是关于您的 makefile 中的奇怪内容的警告。

要理解它,您只需查看 make 抱怨的 makefile 中的行,并阅读它打印的消息。

您设置了这个变量:

SCALACOPY= basic.scala A2I.scala \
   CoolTokens.scala CoolScanner.scala CoolOptions.scala \
   CoolParser.scala

所以这个变量包含CoolParser.scala.

接下来在 Makefile 第 76 行,你有这个:

${SCALACOPY} :
        echo "import cool_implicit._" | cat - ${COOLCOMPILERDIR}/$@ > $@

这定义了告诉 make 如何构建变量 SCALACOPY 中所有目标的规则,包括 CoolParser.scala.

然后在 Makefile 第 79 行,你有这个:

CoolParser.scala :
        echo "import cool_implicit._" | cat - ${COOLCOMPILERDIR}/$@ > $@.tmp
        sed 's/result.set_inheritablep(/t_Tree.s_inheritablep(result,/' \
            < $@.tmp > $@

这告诉 make ANOTHER 规则也可以构建 CoolParser.scala,您已经为其提供了规则; make 将放弃第一条规则并使用第二条规则,但它也会给你一条警告消息告诉你它,因为这是非常不寻常的,通常不是你想要做的:

Makefile:79: warning: overriding recipe for target 'CoolParser.scala'
Makefile:76: warning: ignoring old recipe for target 'CoolParser.scala'