我正在尝试在 Makefile 中生成文件的 MD5 校验和。在我的 Makefile 中,我有类似的东西;
CHECKSUM=md5sum $(我的文件)
但变量 CHECKSUM 始终为空
谁能告诉我这里出了什么问题?
最佳答案
这是一个略有不同的示例,我将预期的 md5 值设置为 make
变量,然后在我的配方中的 shell 命令中检查它。在这种情况下,我想下载特定版本的 Anaconda 并在安装之前检查其 md5sum。
生成文件:
SHELL:=/bin/bash
ANACONDA_MD5:=c989ecc8b648ab8a64731aaee9ed2e7e
none:
Anaconda3-5.0.1-Linux-x86_64.sh:
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
download: Anaconda3-5.0.1-Linux-x86_64.sh
verify: download
AnacondaMD5="$$(md5sum Anaconda3-5.0.1-Linux-x86_64.sh | cut -d ' ' -f1)" && \
if [ "$$AnacondaMD5" == '$(ANACONDA_MD5)' ]; then echo "md5sum matches"; fi
输出:
$ make verify
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
--2018-01-16 18:11:50-- https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
Resolving repo.continuum.io... 104.16.18.10, 104.16.19.10, 2400:cb00:2048:1::6810:130a, ...
Connecting to repo.continuum.io|104.16.18.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 550796553 (525M) [application/x-sh]
Saving to: `Anaconda3-5.0.1-Linux-x86_64.sh'
100%[====================================================================================================================>] 550,796,553 103M/s in 6.8s
2018-01-16 18:11:59 (77.0 MB/s) - `Anaconda3-5.0.1-Linux-x86_64.sh' saved [550796553/550796553]
AnacondaMD5="$(md5sum Anaconda3-5.0.1-Linux-x86_64.sh | cut -d ' ' -f1)" && \
if [ "$AnacondaMD5" == 'c989ecc8b648ab8a64731aaee9ed2e7e' ]; then echo "md5sum matches"; fi
md5sum matches
请注意使用 $$AnacondaMD5
填充内联 bash
变量与使用 $(ANACONDA_MD5)
填写make
变量
版本:
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
关于linux - Makefile 中的 MD5SUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5904910/