簡體   English   中英

如何在makefile中創建目標來調用makefile中的另一個目標

[英]How do I make a target in a makefile invoke another target in the makefile

所以我有這個makefile,我希望目標只是調用目標expertest,但顯然我正在做的方式是錯誤的,因為我收到錯誤“make:exprtest:Command not found make: * [all]錯誤127“這是makefile:

all:
    exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
    g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o
driver.o: driver.cpp scanner.hpp driver.hpp
    g++ -Wall -g -c driver.cpp
parser.tab.o: parser.tab.hpp parser.tab.cpp
    bison parser.ypp
    g++ -Wall -g -c parser.tab.cpp
scanner.o: scanner.cpp scanner.hpp
    flex -t scanner.ll > scanner.cpp
    g++ -Wall -g -c scanner.cpp
clean:
    rm parser.tab.hpp parser.tab.cpp scanner.cpp

exprtest放在與all相同的行上。 冒號后面的依賴關系,命令來自以下行,縮進。

target: dependencies
[tab] system command

所以在你的情況下,這一切都變為:

all: exprtest
exprtest: exptrtest.o driver.o parser.tab.o scanner.o
    g++ -Wall -g -o exprtest exptrtest.o driver.o parser.tab.o scanner.o

你可以總是有make調用一個新的實例make
例如:

all:
    $(MAKE) exprtest

exprtest:  
    do exprtest stuff

鍵入make all將間接做make exprtest

你想做點什么

all: exprtest

什么,說是“ all取決於exprtest是成功的”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM