make giving error after make clean
Although Make is working fine but by default it only compiling those files that have been changed, even when I run make all. It say like Nothing to Do.
One scenario where I neeed to compile all the files is when I change something in a header file which is being accessed in multiple .c files. But make does not recognize it until I open any .c file any save & quit again.
Makefile contents can be seen in this post :
Although this is also a problem but actual problem I want to discuss here is something different.
In order to compile all files what I did was that I ran make clean which indeed removed all object files and then I ran make again but this time it gives an error :-
.... 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
I checked contents of crc32table.h but file is empty. So, I copy crc32table.h from my backup of previous code and now its running successfully. Now I run make clean and 'make' again to check it but this time it is working fine.
I do not know what the mystery here ?
I guess these lines are doing something which I am not able to understand ? Please help me on this.
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
The issue is this snippet:
mec/crc32table.h: mec/gen_crc32table mec/gen_crc32table > mec/crc32table.h
Ask yourself "What happens if the gen_crc32table command exits with an error?" Make stops (good) but leaves behind a corrupt crc32table.h (bad). Two choices: (i) re-write gen_crc32table so that it accepts a -o parameter; (ii) shell trickery.
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 $@
The mv will not happen if gen_crc32table errors.