我使用Makefiles。我有一個run運行該構建目標的目標。簡化后,它看起來如下所示:prog: .... ...run: prog ./prog坐下來 我知道這很巧妙,但不需要站著鼓掌?,F在,我的問題是-有什么方法可以傳遞參數?以便make run asdf --> ./prog asdfmake run the dog kicked the cat --> ./prog the dog kicked the cat謝謝!
3 回答

嗶嗶one
TA貢獻1854條經驗 獲得超8個贊
我不知道完全按照自己的意愿做事的方法,但是一種解決方法可能是:
run: ./prog
./prog ${ARGS}
然后:
make ARGS="asdf" run

千巷貓影
TA貢獻1829條經驗 獲得超7個贊
您可以將變量傳遞給Makefile,如下所示:
run:
@echo ./prog $$FOO
用法:
$ make run FOO="the dog kicked the cat"
./prog the dog kicked the cat
要么:
$ FOO="the dog kicked the cat" make run
./prog the dog kicked the cat
或者使用Beta提供的解決方案:
run:
@echo ./prog $(filter-out $@,$(MAKECMDGOALS))
%:
@:
%:-與任何任務名稱匹配的規則; @:-空配方=不執行任何操作
用法:
$ make run the dog kicked the cat
./prog the dog kicked the cat
添加回答
舉報
0/150
提交
取消