作者Windycelesti (雲の狐)
看板C_and_CPP
標題[問題] Makefile賦值問題
時間Thu Oct 21 17:50:13 2021
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Makefile
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
Nope
問題(Question):
根目錄底下剛開始有的檔案
Makefile
Neko.bin
FUNCTION_0.txt
FUNCTION_1.txt
FUNCTION_2.txt
FUNCTION_3.txt
依照生出來的Cat.bin去決定我要把哪個FUNCTION給送出去
餵入的資料(Input):
直接執行make Makefile all
預期的正確結果(Expected Output):
原本的流程, Cat.bin是在這個Makefile才生出來的玩意兒
這裡為了模擬, 所以多做了cp ./Neko.bin ./Cat.bin的動作, 然後拿Cat.bin做計算
TT的值預期會生出0~3隨機數字(因為每次執行, Neko.bin的size都會改變)
預期在每次計算完Cat.bin的size後
選擇對應的FUNCTION_$(1).txt送到其他資料夾去.(在此單純用cp而已)
錯誤結果(Wrong Output):
all 的第四行目前沒辦法正常取出TT的值帶入PATH的$(1)
曾經用過define去定義expr `du -b ./Cat.bin|cut -f1` % 4
想當然而程式看不懂
cp ./FUNCTIONexpr `du -b ./Neko_tmp.bin|cut -f1` % 4.txt ./YAAAAA.GG
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
#define TestDef
#expr `du -b ./Cat.bin|cut -f1` % 4
#endef
PATH=./FUNCTION_$(1).txt
all:
cp ./Neko.bin ./Cat.bin
expr `du -b ./Cat.bin|cut -f1` % 4 > TT
cat TT
# cp $(call PATH, $(call TestDef)) ./ YAAAAAA.GG
cp $(call PATH, echo`cat TT`) ./YAAAAA.GG
rm Cat.bin TT
echo "TEST END....."
如果有其他問題麻煩告知, 感謝.
另外想問問, 有沒有可以模擬Makefile的模擬網頁...(囧
感謝C_and_CPP版
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.51.192 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1634809815.A.7FA.html
推 closer76: 總覺得你這些事情不需要用make來做...寫 shell script 10/21 19:39
→ closer76: 會不會比較快? 10/21 19:39
推 closer76: 如果你真的需要makefile幫你產生cat.bin,也可以剩下的 10/21 19:47
→ closer76: 動作寫在shell script裡,然後makefile就單純call那個 10/21 19:47
→ closer76: script 就好。不需要所有的事都用makefile完成。 10/21 19:48
推 Schottky: 同意一樓,你要做的事完全沒有使用到 Makefile 的機能 10/21 20:25
→ Schottky: 把 all: 裡面的指令全部放進 shell script 不就解決了? 10/21 20:26
→ Schottky: Makefile 不是不能做到,但很容易讓你的腦筋打結 10/21 20:27
先感謝各位給的建議, 也感謝下一篇的回文. (抱歉回晚了.)
我先前確實有考慮過用shell的方式
但是會碰上shell的內容會在all執行前先做..
以下是Makefile主程式碼
PTTNum = $(shell expr `du -b ./Cat.bin|cut -f1` % 4)
PATH=./FUNCTION_$(1).txt
all:
cp ./Neko.bin ./Cat.bin
cp $(call PATH,$(PTTNum)) ./YAAAAA.GG
rm Cat.bin TT
echo "TEST END....."
以下是執行錯誤紀錄
xxxx@TWPC:~$ make Makefile all
make: Nothing to be done for `Makefile'.
du: cannot access `./Cat.bin': No such file or directory
expr: syntax error
cp ./Neko.bin ./Cat.bin
cp ./FUNCTION_.txt ./YAAAAA.GG
cp: cannot stat `./FUNCTION_.txt': No such file or directory
make: *** [all] Error 1
不過我目前的認知, 所謂的"寫動作在 shell script裡"
應該是類似 peterbrucele 提供的例子
把 function = $(shell ~~~)寫在同一個makefile內, 要用時再去call就好.
如果不是的話, 可能需要請教一下了.
感謝C_and_CPP版
※ 編輯: Windycelesti (118.163.51.192 臺灣), 10/26/2021 14:56:37