制作干净后给出错误

时间:2013-01-23 16:04:13

标签: gcc makefile dependencies gnu-make

虽然Make工作正常,但默认情况下它只编译那些已更改的文件,即使我运行make all。它说像Nothing to Do

我需要编译所有文件的一个场景是当我在多个.c文件中访问的头文件中更改某些内容时。但是,在我再次打开.csave & quit文件之前,make无法识别它。

Makefile内容可以在这篇文章中看到:

Questions about Makefile - what is "$+" & where are .c files/dependencies called here ?

虽然这也是一个问题,但我想在这里讨论的实际问题是不同的。

为了编译所有文件,我所做的是我运行了make clean,它确实删除了所有目标文件,然后我再次运行make,但这次它给出了一个错误: -

 ....
 mec/gen_crc32table > mec/crc32table.h
 mec/gen_crc32table: 1: mec/gen_crc32table: Syntax error: end of file unexpected    
 (expecting ")")
 make: *** [mec/crc32table.h] Error 2

我检查了crc32table.h的内容,但文件为空。因此,我从以前代码的备份中复制crc32table.h,现在它已成功运行。现在我再次运行make clean和'make'来检查它,但这次它运行正常。

我不知道这里有什么神秘之处?

我猜这些线路正在做一些我无法理解的事情?请帮帮我。

crc32.o: mec/crc32table.h mec/crc32.c
$(CC) -o $@ -c -I. $(CFLAGS) mec/crc32.c

mec/crc32table.h: mec/gen_crc32table
mec/gen_crc32table > mec/crc32table.h 

1 个答案:

答案 0 :(得分:1)

问题是这个片段:

mec/crc32table.h: mec/gen_crc32table
    mec/gen_crc32table > mec/crc32table.h 

问问自己“如果gen_crc32table命令退出并出错,会发生什么?”停止(好)但留下腐败的crc32table.h(坏)。两种选择:(i)重写gen_crc32table,使其接受-o参数; (ii)shell tr​​ickery。

(ⅰ)

mec/crc32table.h: mec/gen_crc32table
    mec/gen_crc32table -o mec/crc32table.h 

(ⅱ)

mec/crc32table.h: mec/gen_crc32table
    mec/gen_crc32table >temp-file-with-an-obscure-name
    mv temp-file-with-an-obscure-name $@

如果mv错误,则gen_crc32table不会发生。