Re: [問題] makefile語法疑問

看板Programming作者時間1年前 (2022/12/07 00:49), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串3/3 (看更多)
如果recipe的部分都是相同的,只是target有的有%有的沒有 那也可以考慮動態生成rule 概念就是從source變數把target一個一個抓出來,動態生出 target1: recipe target2: recipe ... 具體作法如下: ------------------------------------------------------------ define RULE $(1): @echo $$@ endef source := folder1_% \ folder2_% \ sim $(foreach target,$(source),$(eval $(call RULE,$(target)))) ------------------------------------------------------------ 執行結果: $ make folder1_01 folder1_01 $ make folder2__01 folder2__01 $ make sim sim 可以參考看看,比較需要注意的是define裡面要生成變數,要使用$$來跳脫$字元 不然的話就會在生成期間讀取變數,而不是生成包含變數的recipe ※ 引述《gecer (gecer)》之銘言: : 小弟試著更改makefile內容 : =============================================================================== : source:=folder1_%\ : folder2_%\ : $(source) : @echo $@ : =============================================================================== : 指令make folder1_01 : folder01_01 : 指令make folder2__01 : folder02_01 : 但是如果增加一個沒有%的target pattern : =============================================================================== : source:=sim\ : folder1_%\ : folder2_%\ : $(source) : @echo $@ : =============================================================================== : 指令make sim : mixed implicit and normal rules: deprecated syntax : sim : 指令make folder1_01 : mixed implicit and normal rules: deprecated syntax : No rule to make target 'folder1_01'. Stop. : 似乎增加一個normal target pattern會影響到含% target pattern的match -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.252.23.7 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1670345394.A.F55.html

12/08 19:26, 1年前 , 1F
感謝
12/08 19:26, 1F
文章代碼(AID): #1ZZtAozL (Programming)
文章代碼(AID): #1ZZtAozL (Programming)