0
我有一台运行Linux的主机,GNU make使用日期偏移编译
我也有一个虚拟机运行Windows 7的时间不同; 偏移量是过去的,所以当我生成源代码时,这些文件的日期比真实日期早。
我在主机上使用GNU make构建源代码。
当我第一次构建时,它的构建没有任何问题; 当我修改虚拟机中的某些文件时,它们的日期比可执行文件更早,因此运行“make”不会将这些文件捕获为更改,也不会再次编译修改后的源文件。
有没有办法解决我的问题?
(在编译结束可能运行一个脚本来设置可执行相同的偏移或通知make保持来源的哈希?)
编辑: 由于我使用了一个临时解决方案由Makefile文件调用的外部bash脚本:
#!/bin/bash
# Makefile: @./Compile.sh "$(CC)" "$(SWITCHES)" "$(OBJECT)" "$(SOURCEFILE)"
# $1 $2 $3 $4
# TODO:
# P1 This approach does not consider .h files changing.
# "g++ -dD -fpreprocessed -E $SOURCEFILE" and whitespace/newline removal before comparison.
# diff -uwB $(g++ -dD -fpreprocessed -E $SOURCEFILE) $(g++ -dD -fpreprocessed -E $SOURCEFILE.previous)
# Checksum on all output object not to link again.
SOURCEFILE="$4"
CHECKSUM=$(cksum < "$SOURCEFILE")
CHECKSUMDIFFERENT=true
echo [email protected]
# If an hash is present already, we compare them.
if [ -f "${SOURCEFILE}.checksum" ]; then
OLDCHECKSUM=$(<"${SOURCEFILE}.checksum")
# If the old hash is the same as the new one, the output is up-to-date.
if [ "$OLDCHECKSUM" == "$CHECKSUM" ]; then
CHECKSUMDIFFERENT=false
fi
fi
if [ $CHECKSUMDIFFERENT == true ]; then
echo "Comparison for \"$SOURCEFILE\" failed, (re)compiling."
$1 $2 -o "$3" "$SOURCEFILE"
# Saving the new hash if the compilation has success.
if [ $? -eq 0 ]; then
echo -n "$CHECKSUM" > "$SOURCEFILE.checksum"
fi
fi
我还发现这http://blog.jgc.org/2006/04/rebuilding-when-hash-has-changed-not.html 但不知道如何将它应用到我的Makefile文件。
使用源代码管理来共享文件。 – nos 2014-10-26 18:22:23
修复虚拟机中的时间,使其与主机操作系统相同。 Make只通过比较修改时间戳进行操作,没有其他替代算法。 – MadScientist 2014-10-26 19:16:53
谢谢,我从未想过在机器上设置正确的日期...... – 2014-10-26 19:37:56