2017-07-17 91 views
0

我已經修改了這個片段將它升級到SHA-256:Makefile - 將命令輸出保存到變量中? (SHA-256和計算)

https://unix.stackexchange.com/questions/28994/how-can-a-makefile-detect-whether-a-command-is-available-in-the-local-machine

determine_sum = \ 
    sum=; \ 
    for x in sha256sum sha256 'shasum -a 256' 'openssl dgst -sha256'; do \ 
     if type "$${x%% *}" >/dev/null 2>/dev/null; then sum=$$x; break; fi; \ 
    done; \ 
    if [ -z "$$sum" ]; then echo 1>&2 "Unable to find a SHA-256 utility"; exit 2; fi 

check: 
    $(determine_sum); \ 
    $$sum $(archive_name); \ 
    #Save ^^^ to a variable - fails 
    #archive_sha256=`$$sum $(archive_name)`; \ 

它正確地計算SHA-256校驗 - 但我堅持在努力將我在執行$$sum $(archive_name); \期間看到的輸出保存到一個變量中。請你幫忙嗎?

+1

是否CMake的涉及到這個問題?如果不是,刪除「cmake」標籤。 – Tsyvarev

回答

0

你嘗試:

check: 
    $(determine_sum); \ 
    archive_sha256=$$($$sum $(archive_name)); \ 
    ... 
+0

非常感謝,你的例子真的有用!祝你的項目好運;-) –